api_sabeq_ps_v1 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/api_sabeq_ps_v1.rb +3 -0
- data/lib/api_sabeq_ps_v1/railtie.rb +9 -0
- data/lib/api_sabeq_ps_v1/sabeq_helpers.rb +104 -0
- data/lib/api_sabeq_ps_v1/version.rb +3 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c7191f152ec344c33f442a89fc983153421c00b18612e9419db467e9bf63f6d6
|
4
|
+
data.tar.gz: 2bdd22fc843e4c188741ac59cbc6ac93e200462c4d73f02d86cbee4811c70301
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3644688a82814c90f678de2e3e99bdbff697b7e358fd54d7cc406a207f04293e569a0bd611a3d946386eff6d661477f0ef1dcd10d7a1f90a6d48c75f5d4c028d
|
7
|
+
data.tar.gz: 7b2a41e48a29583f4c1f28912a2c07ca55a8a5eb08b06d74e2788cb4301d5b6657ee40ed17847373316bb88bfb0d38a3736151e67fe9ef05c0516e1fe6cd7f48
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
|
4
|
+
module ApiSabeqPsV1
|
5
|
+
module SabeqHelpers
|
6
|
+
REQUEST_HEADER = {'Content-Type' => 'application/json'}
|
7
|
+
#SABEQ_URL = "https://sabeq.ps"
|
8
|
+
SABEQ_URL = "https://localhost:3001/"
|
9
|
+
|
10
|
+
# Authorize the request
|
11
|
+
# parameters: login_token
|
12
|
+
# return: true, auth_token in case of success
|
13
|
+
# false, errors in case of failure, errors contain code and message
|
14
|
+
def authorize(login_token)
|
15
|
+
auth_link = SABEQ_URL + "/api/v1/auth"
|
16
|
+
auth_json = { login_token: login_token }
|
17
|
+
json_response = make_post_request(auth_link, auth_json)
|
18
|
+
|
19
|
+
result, the_response = get_error_or_returned_value(json_response)
|
20
|
+
if result
|
21
|
+
return true, the_response["auth_token"]
|
22
|
+
else
|
23
|
+
return false, the_response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Verify the business profile
|
28
|
+
def verify_profile(auth_token, profile_id, api_key)
|
29
|
+
auth_link = SABEQ_URL + "/api/v1/verify_business"
|
30
|
+
auth_json = { auth_token: auth_token, profile_id: profile_id, api_key: api_key }
|
31
|
+
json_response = make_post_request(auth_link, auth_json)
|
32
|
+
|
33
|
+
result, the_response = get_error_or_returned_value(json_response)
|
34
|
+
if result
|
35
|
+
return true, the_response["verification_token"]
|
36
|
+
else
|
37
|
+
return false, the_response
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def query_parcel(verification_token, parcel_number)
|
42
|
+
auth_link = SABEQ_URL + "/api/v1/parcels/#{parcel_number}"
|
43
|
+
auth_json = { verification_token: verification_token }
|
44
|
+
json_response = make_get_request(auth_link, auth_json)
|
45
|
+
return json_response
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_areas(verification_token)
|
49
|
+
auth_link = SABEQ_URL + "/api/v1/parcels/get_areas"
|
50
|
+
auth_json = { verification_token: verification_token }
|
51
|
+
json_response = make_get_request(auth_link, auth_json)
|
52
|
+
return json_response
|
53
|
+
end
|
54
|
+
|
55
|
+
def create_parcel(verification_token, name, phone1, phone2, content,
|
56
|
+
payment_amount, area_id, address, delivery_notes)
|
57
|
+
auth_link = SABEQ_URL + "/api/v1/parcels"
|
58
|
+
auth_json = { verification_token: verification_token,
|
59
|
+
name: name, phone1: phone1, phone2: phone2,
|
60
|
+
content: content, payment_amount: payment_amount,
|
61
|
+
area_id: area_id, address: address,
|
62
|
+
delivery_notes: delivery_notes }
|
63
|
+
json_response = make_post_request(auth_link, auth_json)
|
64
|
+
|
65
|
+
return json_response
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def make_post_request(url_link, json_content)
|
70
|
+
uri = URI.parse(url_link)
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
72
|
+
#http.use_ssl = true
|
73
|
+
http.use_ssl = false
|
74
|
+
a_request = Net::HTTP::Post.new(uri.request_uri, REQUEST_HEADER)
|
75
|
+
a_request.body = json_content.to_json
|
76
|
+
a_response = http.request(a_request)
|
77
|
+
return a_response.body
|
78
|
+
end
|
79
|
+
|
80
|
+
def make_get_request(url_link, json_content)
|
81
|
+
uri = URI.parse(url_link)
|
82
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
83
|
+
#http.use_ssl = true
|
84
|
+
http.use_ssl = false
|
85
|
+
the_params = json_content
|
86
|
+
uri.query = URI.encode_www_form(the_params)
|
87
|
+
a_request = Net::HTTP::Get.new(uri.request_uri)
|
88
|
+
a_response = http.request(a_request)
|
89
|
+
return a_response.body
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_error_or_returned_value(json_response)
|
93
|
+
# check if the response has errors
|
94
|
+
hashed_response = JSON.parse(json_response)
|
95
|
+
errors = hashed_response["errors"]
|
96
|
+
|
97
|
+
if errors.present?
|
98
|
+
return false, errors
|
99
|
+
else
|
100
|
+
return true, hashed_response
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: api_sabeq_ps_v1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ShaimaKaraki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Its a gem for sabeq.ps API helper functionalities
|
14
|
+
email:
|
15
|
+
- shaimakaraki@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/api_sabeq_ps_v1.rb
|
21
|
+
- lib/api_sabeq_ps_v1/railtie.rb
|
22
|
+
- lib/api_sabeq_ps_v1/sabeq_helpers.rb
|
23
|
+
- lib/api_sabeq_ps_v1/version.rb
|
24
|
+
homepage: https://github.com/ShaimaKaraki/s_api.git
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.4.0
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.0.8
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: gem for sabeq.ps API helper functionalities
|
47
|
+
test_files: []
|