demo_api 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/demo_api.rb +54 -0
- data/lib/demo_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ff7afc984faedc8ced81df1d759a9a774dbe8f654407be48b2ed925f8da7574
|
4
|
+
data.tar.gz: 7146b056ac497a20c0c01c221bb3dca4b6eaa5756f503bd0dc696aa07a8620ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e7e8f53bfac1ed5b31d21ba67051ea599727dffd0bb9c14f0fb4d3b3eba2b01de233871ca3b595e1fc1f34da497904466ea26881105a18a03459e0d5ea5c9c5
|
7
|
+
data.tar.gz: a98d96610b47f82e34f5b6c53a129702124301cc4c601799ca5cced62615f1f1a5d4e3dcd76f0aef8b76168ec110ed598053299a83dc16cd532b0e341a130b8f
|
data/lib/demo_api.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require_relative "demo_api/version"
|
2
|
+
require "net/http"
|
3
|
+
require "net/https"
|
2
4
|
|
3
5
|
module DemoApi
|
4
6
|
REQUEST_HEADER = {'Content-Type' => 'application/json'}
|
@@ -27,6 +29,47 @@ module DemoApi
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
32
|
+
# Verify the business profile
|
33
|
+
def verify_profile(auth_token, profile_id, api_key)
|
34
|
+
auth_link = SABEQ_URL + "/api/v1/verify_business"
|
35
|
+
auth_json = { auth_token: auth_token, profile_id: profile_id, api_key: api_key }
|
36
|
+
json_response = make_post_request(auth_link, auth_json)
|
37
|
+
|
38
|
+
result, the_response = get_error_or_returned_value(json_response)
|
39
|
+
if result
|
40
|
+
return true, the_response["verification_token"]
|
41
|
+
else
|
42
|
+
return false, the_response
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def query_parcel(verification_token, parcel_number)
|
47
|
+
auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}"
|
48
|
+
auth_json = { verification_token: verification_token }
|
49
|
+
json_response = make_get_request(auth_link, auth_json)
|
50
|
+
return json_response
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_areas(verification_token)
|
54
|
+
auth_link = SABEQ_URL + "/api/v1/parcels/get_areas"
|
55
|
+
auth_json = { verification_token: verification_token }
|
56
|
+
json_response = make_get_request(auth_link, auth_json)
|
57
|
+
return json_response
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_parcel(verification_token, name, phone1, phone2, content,
|
61
|
+
payment_amount, area_id, address, delivery_notes)
|
62
|
+
auth_link = SABEQ_URL + "/api/v1/parcels"
|
63
|
+
auth_json = { verification_token: verification_token,
|
64
|
+
name: name, phone1: phone1, phone2: phone2,
|
65
|
+
content: content, payment_amount: payment_amount,
|
66
|
+
area_id: area_id, address: address,
|
67
|
+
delivery_notes: delivery_notes }
|
68
|
+
json_response = make_post_request(auth_link, auth_json)
|
69
|
+
|
70
|
+
return json_response
|
71
|
+
end
|
72
|
+
|
30
73
|
private
|
31
74
|
def make_post_request(url_link, json_content)
|
32
75
|
uri = URI.parse(url_link)
|
@@ -38,6 +81,17 @@ module DemoApi
|
|
38
81
|
return a_response.body
|
39
82
|
end
|
40
83
|
|
84
|
+
def make_get_request(url_link, json_content)
|
85
|
+
uri = URI.parse(url_link)
|
86
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
87
|
+
http.use_ssl = false
|
88
|
+
the_params = json_content
|
89
|
+
uri.query = URI.encode_www_form(the_params)
|
90
|
+
a_request = Net::HTTP::Get.new(uri.request_uri)
|
91
|
+
a_response = http.request(a_request)
|
92
|
+
return a_response.body
|
93
|
+
end
|
94
|
+
|
41
95
|
def get_error_or_returned_value(json_response)
|
42
96
|
# check if the response has errors
|
43
97
|
hashed_response = JSON.parse(json_response)
|
data/lib/demo_api/version.rb
CHANGED