demo_api 0.1.8 → 0.1.9
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 +1 -116
- data/lib/demo_api/railtie.rb +2 -2
- data/lib/demo_api/{view_helpers.rb → sabeq_helpers.rb} +1 -5
- data/lib/demo_api/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 571b05602fca5a59dbe5e06bcc843e1c31b9255d8cdd273637ffd4e8f7fcff43
|
4
|
+
data.tar.gz: 2d26b8a8427838f3fef1d143a178da507154747e66e62a95fb97c4f8b8472a3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 559c919dd1bf6deb76f67120c87d1719fb60e1fe26f1a0f80334be03e385fef636c60c903f03d733251f54daed9ff0db0940e043a43e7ae4f4552b906300d84d
|
7
|
+
data.tar.gz: deeb5f5fedadf16d67fe2eefc988d61368007991cd860ba23e217489e0c0b5946894a0175de8f135f3e4bc787306ba236506a5dc8fbb39f67f3d7c61afadcfe2
|
data/lib/demo_api.rb
CHANGED
@@ -1,118 +1,3 @@
|
|
1
1
|
require "demo_api/version"
|
2
|
-
require 'demo_api/
|
2
|
+
require 'demo_api/sabeq_helpers'
|
3
3
|
require "demo_api/railtie" if defined? Rails
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
=begin
|
9
|
-
require_relative "demo_api/version"
|
10
|
-
require "net/http"
|
11
|
-
require "net/https"
|
12
|
-
|
13
|
-
module DemoApi
|
14
|
-
REQUEST_HEADER = {'Content-Type' => 'application/json'}
|
15
|
-
#SABEQ_URL = "https://sabeq.ps"
|
16
|
-
SABEQ_URL = "https://localhost:3001/"
|
17
|
-
|
18
|
-
class << self
|
19
|
-
def print_hello
|
20
|
-
SABEQ_URL
|
21
|
-
end
|
22
|
-
|
23
|
-
# Authorize the request
|
24
|
-
# parameters: login_token
|
25
|
-
# return: true, auth_token in case of success
|
26
|
-
# false, errors in case of failure, errors contain code and message
|
27
|
-
def authorize(login_token)
|
28
|
-
auth_link = SABEQ_URL + "/api/v1/auth"
|
29
|
-
auth_json = { login_token: login_token }
|
30
|
-
json_response = make_post_request(auth_link, auth_json)
|
31
|
-
|
32
|
-
result, the_response = get_error_or_returned_value(json_response)
|
33
|
-
if result
|
34
|
-
return true, the_response["auth_token"]
|
35
|
-
else
|
36
|
-
return false, the_response
|
37
|
-
end
|
38
|
-
end
|
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
|
-
|
81
|
-
private
|
82
|
-
def make_post_request(url_link, json_content)
|
83
|
-
uri = URI.parse(url_link)
|
84
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
-
#http.use_ssl = true
|
86
|
-
http.use_ssl = false
|
87
|
-
a_request = Net::HTTP::Post.new(uri.request_uri, REQUEST_HEADER)
|
88
|
-
a_request.body = json_content.to_json
|
89
|
-
a_response = http.request(a_request)
|
90
|
-
return a_response.body
|
91
|
-
end
|
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
|
-
|
105
|
-
def get_error_or_returned_value(json_response)
|
106
|
-
# check if the response has errors
|
107
|
-
hashed_response = JSON.parse(json_response)
|
108
|
-
errors = hashed_response["errors"]
|
109
|
-
|
110
|
-
if errors.present?
|
111
|
-
return false, errors
|
112
|
-
else
|
113
|
-
return true, hashed_response
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
=end
|
data/lib/demo_api/railtie.rb
CHANGED
@@ -2,15 +2,11 @@ require "net/http"
|
|
2
2
|
require "net/https"
|
3
3
|
|
4
4
|
module DemoApi
|
5
|
-
module
|
5
|
+
module SabeqHelpers
|
6
6
|
REQUEST_HEADER = {'Content-Type' => 'application/json'}
|
7
7
|
#SABEQ_URL = "https://sabeq.ps"
|
8
8
|
SABEQ_URL = "https://localhost:3001/"
|
9
9
|
|
10
|
-
def print_hello
|
11
|
-
SABEQ_URL
|
12
|
-
end
|
13
|
-
|
14
10
|
# Authorize the request
|
15
11
|
# parameters: login_token
|
16
12
|
# return: true, auth_token in case of success
|
data/lib/demo_api/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ShaimaKaraki
|
@@ -10,7 +10,7 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: a
|
13
|
+
description: Its a gem for sabeq.ps API helper functionalities
|
14
14
|
email:
|
15
15
|
- shaimakaraki@gmail.com
|
16
16
|
executables: []
|
@@ -19,8 +19,8 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/demo_api.rb
|
21
21
|
- lib/demo_api/railtie.rb
|
22
|
+
- lib/demo_api/sabeq_helpers.rb
|
22
23
|
- lib/demo_api/version.rb
|
23
|
-
- lib/demo_api/view_helpers.rb
|
24
24
|
homepage: https://github.com/ShaimaKaraki/s_api.git
|
25
25
|
licenses:
|
26
26
|
- MIT
|
@@ -43,5 +43,5 @@ requirements: []
|
|
43
43
|
rubygems_version: 3.0.8
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
|
-
summary:
|
46
|
+
summary: gem for sabeq.ps API helper functionalities
|
47
47
|
test_files: []
|