demo_api 0.1.2 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d88d783ccd8c51948adf55892d52e026281bc6a16b677a2a749b8afd927a264b
4
- data.tar.gz: 9dbe1a5439657eacb0ad5afdb6d157408106f37dfe0f8f14160dc67f026c4c3f
3
+ metadata.gz: 6441cfa615687b7cb1a9318fc3de7130464c51db2b2b0119867905475e17bd0a
4
+ data.tar.gz: d6d30d04d1369b5b35cf46c98f31b1ab629f20677a1af6acfccfdfecbac05342
5
5
  SHA512:
6
- metadata.gz: 43b8fafe865d97ed8c2f6bb2fb4db9ba6a555a6dcb2b1d6b51b46f9fd70aec81995a81ea00a93c5e4ef95d2b93dfffdecc6a150cb0645efdf00200700a24d48b
7
- data.tar.gz: f39441a550263c5dee072230c4ea36554dafbf56e3b19eec02adf4f5ab7f11cc13b705e3d88bbb8f8e37a5cf3f5712ccada221d2c9df9aa60f75e260499f0656
6
+ metadata.gz: 99d96f6a94bad6b2f16ae2a089a353b4d7aeb2f1ca28c6beb31ae5c1bb98fa4e67aa1e4e0f3ea268e663df742ec16535778a659ff5256a9435eab7f735a8cba9
7
+ data.tar.gz: cccbbd1ca0e5e91e001579f21b7b3a83a929f749db2d06d9969e6c21e19cdb0b6182693a976f1f4dfef6f846e2253e82f7bb49a081a7b2cbfbc7821897063553
data/lib/demo_api.rb CHANGED
@@ -1,3 +1,11 @@
1
+ require "demo_api/version"
2
+ require 'demo_api/view_helpers'
3
+ require "demo_api/railtie" if defined? Rails
4
+
5
+
6
+
7
+
8
+ =begin
1
9
  require_relative "demo_api/version"
2
10
  require "net/http"
3
11
  require "net/https"
@@ -29,10 +37,52 @@ module DemoApi
29
37
  end
30
38
  end
31
39
 
40
+ # Verify the business profile
41
+ def verify_profile(auth_token, profile_id, api_key)
42
+ auth_link = SABEQ_URL + "/api/v1/verify_business"
43
+ auth_json = { auth_token: auth_token, profile_id: profile_id, api_key: api_key }
44
+ json_response = make_post_request(auth_link, auth_json)
45
+
46
+ result, the_response = get_error_or_returned_value(json_response)
47
+ if result
48
+ return true, the_response["verification_token"]
49
+ else
50
+ return false, the_response
51
+ end
52
+ end
53
+
54
+ def query_parcel(verification_token, parcel_number)
55
+ auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}"
56
+ auth_json = { verification_token: verification_token }
57
+ json_response = make_get_request(auth_link, auth_json)
58
+ return json_response
59
+ end
60
+
61
+ def get_areas(verification_token)
62
+ auth_link = SABEQ_URL + "/api/v1/parcels/get_areas"
63
+ auth_json = { verification_token: verification_token }
64
+ json_response = make_get_request(auth_link, auth_json)
65
+ return json_response
66
+ end
67
+
68
+ def create_parcel(verification_token, name, phone1, phone2, content,
69
+ payment_amount, area_id, address, delivery_notes)
70
+ auth_link = SABEQ_URL + "/api/v1/parcels"
71
+ auth_json = { verification_token: verification_token,
72
+ name: name, phone1: phone1, phone2: phone2,
73
+ content: content, payment_amount: payment_amount,
74
+ area_id: area_id, address: address,
75
+ delivery_notes: delivery_notes }
76
+ json_response = make_post_request(auth_link, auth_json)
77
+
78
+ return json_response
79
+ end
80
+
32
81
  private
33
82
  def make_post_request(url_link, json_content)
34
83
  uri = URI.parse(url_link)
35
84
  http = Net::HTTP.new(uri.host, uri.port)
85
+ #http.use_ssl = true
36
86
  http.use_ssl = false
37
87
  a_request = Net::HTTP::Post.new(uri.request_uri, REQUEST_HEADER)
38
88
  a_request.body = json_content.to_json
@@ -40,6 +90,18 @@ module DemoApi
40
90
  return a_response.body
41
91
  end
42
92
 
93
+ def make_get_request(url_link, json_content)
94
+ uri = URI.parse(url_link)
95
+ http = Net::HTTP.new(uri.host, uri.port)
96
+ #http.use_ssl = true
97
+ http.use_ssl = false
98
+ the_params = json_content
99
+ uri.query = URI.encode_www_form(the_params)
100
+ a_request = Net::HTTP::Get.new(uri.request_uri)
101
+ a_response = http.request(a_request)
102
+ return a_response.body
103
+ end
104
+
43
105
  def get_error_or_returned_value(json_response)
44
106
  # check if the response has errors
45
107
  hashed_response = JSON.parse(json_response)
@@ -53,3 +115,4 @@ module DemoApi
53
115
  end
54
116
  end
55
117
  end
118
+ =end
@@ -1,3 +1,3 @@
1
1
  module DemoApi
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShaimaKaraki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-29 00:00:00.000000000 Z
11
+ date: 2021-07-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a longer description.
14
14
  email: