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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09534a5c496c3cea048ad49e2e1c66ba0b589c59e64f0461604d711eab6dd197'
4
- data.tar.gz: b78f7e5babfaaed340c96c162a7320dd78013cb9f0c91a474086cbad1b7bd572
3
+ metadata.gz: 571b05602fca5a59dbe5e06bcc843e1c31b9255d8cdd273637ffd4e8f7fcff43
4
+ data.tar.gz: 2d26b8a8427838f3fef1d143a178da507154747e66e62a95fb97c4f8b8472a3e
5
5
  SHA512:
6
- metadata.gz: ab2d12f827e3c012b3aa357c421a5460f2f6b4f6b16028470cf239c01bd209c4e0eae61a879459ab927579f45bdcffd73291609ace0217927f4b6921af568d9f
7
- data.tar.gz: 15f0740853a401d15fc018355295cf95191e6d98c58ca21ecea8ff4d903a2675b4c544cfff7c49917bf5c50b3487cf9bfeb2329b3318a2a81be9f4c371104b26
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/view_helpers'
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
@@ -1,8 +1,8 @@
1
1
  module DemoApi
2
2
  class Railtie < Rails::Railtie
3
- initializer "sabeq_include" do
3
+ initializer "controllers_include" do
4
4
  ActiveSupport.on_load(:action_controller) do
5
- include DemoApi::ViewHelpers
5
+ include DemoApi::SabeqHelpers
6
6
  end
7
7
  end
8
8
  end
@@ -2,15 +2,11 @@ require "net/http"
2
2
  require "net/https"
3
3
 
4
4
  module DemoApi
5
- module ViewHelpers
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
@@ -1,3 +1,3 @@
1
1
  module DemoApi
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
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.8
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 longer description.
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: short summary.
46
+ summary: gem for sabeq.ps API helper functionalities
47
47
  test_files: []