Module: ApiSabeqPsV1::SabeqHelpers

Defined in:
lib/api_sabeq_ps_v1/sabeq_helpers.rb

Constant Summary collapse

REQUEST_HEADER =
{'Content-Type' => 'application/json'}
SABEQ_URL =
"https://sabeq.ps"

Instance Method Summary collapse

Instance Method Details

#sabeq_api_v1_1_create_parcel(verification_token, name, phone1, phone2, content, payment_amount, area_id, street_id, address, service_type, delivery_notes, special_notes) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 90

def sabeq_api_v1_1_create_parcel(verification_token, name, phone1, phone2, content,
                 payment_amount, area_id, street_id, address, service_type,
                 delivery_notes, special_notes)
  auth_link = SABEQ_URL + "/api/v1/parcels"
  auth_json = { verification_token: verification_token,
                name: name, phone1: phone1, phone2: phone2,
                content: content, payment_amount: payment_amount,
                area_id: area_id, street_id: street_id, address: address,
                service_type: service_type,
                delivery_notes: delivery_notes,
                special_notes: special_notes }
  json_response = make_post_request(auth_link, auth_json)

  return json_response
end

#sabeq_api_v1_2_create_parcel(verification_token, name, phone1, phone2, content, payment_amount, area_id, street_id, address, location_url, service_type, delivery_notes, special_notes) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 106

def sabeq_api_v1_2_create_parcel(verification_token, name, phone1, phone2, content,
                 payment_amount, area_id, street_id, address, location_url,
                 service_type, delivery_notes, special_notes)
  auth_link = SABEQ_URL + "/api/v1/parcels"
  auth_json = { verification_token: verification_token,
                name: name, phone1: phone1, phone2: phone2,
                content: content, payment_amount: payment_amount,
                area_id: area_id, street_id: street_id,
                address: address, location_url: location_url,
                service_type: service_type,
                delivery_notes: delivery_notes,
                special_notes: special_notes }
  json_response = make_post_request(auth_link, auth_json)

  return json_response
end

#sabeq_api_v1_authorize(login_token) ⇒ Object

Authorize the request parameters: login_token return: true, auth_token in case of success

false, errors in case of failure, errors contain code and message


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 13

def sabeq_api_v1_authorize()
  auth_link = SABEQ_URL + "/api/v1/auth"
  auth_json = { login_token:  }
  json_response = make_post_request(auth_link, auth_json)

  result, the_response = get_error_or_returned_value(json_response)
  if result
    return true, the_response["auth_token"]
  else
    return false, the_response
  end
end

#sabeq_api_v1_cancel_parcel(verification_token, parcel_number) ⇒ Object



139
140
141
142
143
144
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 139

def sabeq_api_v1_cancel_parcel(verification_token, parcel_number)
  auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}/cancel_parcel"
  auth_json = { verification_token: verification_token }
  json_response = make_get_request(auth_link, auth_json)
  return json_response
end

#sabeq_api_v1_create_parcel(verification_token, name, phone1, phone2, content, payment_amount, area_id, address, delivery_notes, special_notes) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 76

def sabeq_api_v1_create_parcel(verification_token, name, phone1, phone2, content,
                 payment_amount, area_id, address, delivery_notes, special_notes)
  auth_link = SABEQ_URL + "/api/v1/parcels"
  auth_json = { verification_token: verification_token,
                name: name, phone1: phone1, phone2: phone2,
                content: content, payment_amount: payment_amount,
                area_id: area_id, address: address,
                delivery_notes: delivery_notes,
                special_notes: special_notes }
  json_response = make_post_request(auth_link, auth_json)

  return json_response
end

#sabeq_api_v1_get_areas(verification_token) ⇒ Object



69
70
71
72
73
74
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 69

def sabeq_api_v1_get_areas(verification_token)
  auth_link = SABEQ_URL + "/api/v1/parcels/get_areas"
  auth_json = { verification_token: verification_token }
  json_response = make_get_request(auth_link, auth_json)
  return json_response
end

#sabeq_api_v1_print_parcel(verification_token, parcel_number, the_size) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 61

def sabeq_api_v1_print_parcel(verification_token, parcel_number, the_size)
  auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}/print"
  auth_json = { verification_token: verification_token,
                size: the_size }
  json_response = make_get_request(auth_link, auth_json)
  return json_response
end

#sabeq_api_v1_update_parcel(verification_token, parcel_number, collect_money, name, phone1, phone2, content, address, area_id, street_id) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 123

def sabeq_api_v1_update_parcel(verification_token, parcel_number, collect_money, name, phone1, phone2, content, address, area_id, street_id)
  auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}"
  auth_json = { verification_token: verification_token,
                payment_amount: collect_money,
                customer_name: name,
                phone1: phone1,
                phone2: phone2,
                content: content,
                address: address,
                area_id: area_id,
                street_id:  street_id}
  json_response = make_patch_request(auth_link, auth_json)

  return json_response
end

#sabeq_api_v1_verify_profile(auth_token, profile_id, api_key) ⇒ Object

Verify the business profile



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 27

def sabeq_api_v1_verify_profile(auth_token, profile_id, api_key)
  auth_link = SABEQ_URL + "/api/v1/verify_business"
  auth_json = { auth_token: auth_token, profile_id: profile_id, api_key: api_key }
  json_response = make_post_request(auth_link, auth_json)

  result, the_response = get_error_or_returned_value(json_response)
  if result
    return true, the_response["verification_token"]
  else
    return false, the_response
  end
end

#sabeq_api_v2_print_parcel(verification_token, parcel_number, the_size = "default") ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/api_sabeq_ps_v1/sabeq_helpers.rb', line 40

def sabeq_api_v2_print_parcel(verification_token, parcel_number, the_size = "default")
  url = SABEQ_URL + "/api/v1/parcels/#{parcel_number}/print"

  params = {
    verification_token: verification_token,
    size: the_size
  }

  uri = URI.parse(url)
  uri.query = URI.encode_www_form(params)

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)

  # IMPORTANT: return raw HTML, not JSON parsing
  response.body
end