demo_api 0.1.1 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2795aef5413bd122105e08229d2cd67656627ca981b5cea22f909c71c7957f4b
4
- data.tar.gz: 588d0c6be6e901d39cf2d2030040fd21d8c544a383ee2f7d90a9703e099439b8
3
+ metadata.gz: 5ff7afc984faedc8ced81df1d759a9a774dbe8f654407be48b2ed925f8da7574
4
+ data.tar.gz: 7146b056ac497a20c0c01c221bb3dca4b6eaa5756f503bd0dc696aa07a8620ac
5
5
  SHA512:
6
- metadata.gz: 365099f1e8e8cdbf53008f836aa265e75cd7075160202646658f1614a9df7e1e2777239506344f69b54208931787090d4ac3eef3ba7034e32217dd5b22397aa6
7
- data.tar.gz: 7acb10692d0456ba7d6e70ce2323b5ada47f0e058adfbc4ae0888041b94bcff969314189e4a4abe2c9b773ce79f9caaa1a457b4350576900c6c2ea806f4960d6
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)
@@ -1,3 +1,3 @@
1
1
  module DemoApi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShaimaKaraki