demo_api 0.1.0 → 0.1.1

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: 2eaf0961d88c28b984171f293da80f479171bdcb0e8c14f7e56047d7a273893e
4
- data.tar.gz: 6de767222e975bee1da83983e7b5422386c808015d1966ea7bfe219665545713
3
+ metadata.gz: 2795aef5413bd122105e08229d2cd67656627ca981b5cea22f909c71c7957f4b
4
+ data.tar.gz: 588d0c6be6e901d39cf2d2030040fd21d8c544a383ee2f7d90a9703e099439b8
5
5
  SHA512:
6
- metadata.gz: 545c8b7ced3f5e8a31b5614f0078dc2c00491015250a5783ae79efdd814f81ec17abfd000ffdf89199f16942b37203b2e5257a88c00b2864a8a2e9c795678623
7
- data.tar.gz: 2f6976d158ee7431e3d3ad793e43c91d7dce2aa1011eb0468efbefe5360d4193140141ce132ce2aaf79f326f9491bd1babdf7dd9d8edf4ff2a5771fa4e0d5621
6
+ metadata.gz: 365099f1e8e8cdbf53008f836aa265e75cd7075160202646658f1614a9df7e1e2777239506344f69b54208931787090d4ac3eef3ba7034e32217dd5b22397aa6
7
+ data.tar.gz: 7acb10692d0456ba7d6e70ce2323b5ada47f0e058adfbc4ae0888041b94bcff969314189e4a4abe2c9b773ce79f9caaa1a457b4350576900c6c2ea806f4960d6
data/lib/demo_api.rb CHANGED
@@ -1,9 +1,53 @@
1
1
  require_relative "demo_api/version"
2
2
 
3
3
  module DemoApi
4
+ REQUEST_HEADER = {'Content-Type' => 'application/json'}
5
+ #SABEQ_URL = "https://sabeq.ps"
6
+ SABEQ_URL = "https://localhost:3001/"
7
+
4
8
  class << self
5
9
  def print_hello
6
- "Hello world!!!!!!!!!!!!!!!!"
10
+ SABEQ_URL
11
+ end
12
+
13
+ # Authorize the request
14
+ # parameters: login_token
15
+ # return: true, auth_token in case of success
16
+ # false, errors in case of failure, errors contain code and message
17
+ def authorize(login_token)
18
+ auth_link = SABEQ_URL + "/api/v1/auth"
19
+ auth_json = { login_token: login_token }
20
+ json_response = make_post_request(auth_link, auth_json)
21
+
22
+ result, the_response = get_error_or_returned_value(json_response)
23
+ if result
24
+ return true, the_response["auth_token"]
25
+ else
26
+ return false, the_response
27
+ end
7
28
  end
29
+
30
+ private
31
+ def make_post_request(url_link, json_content)
32
+ uri = URI.parse(url_link)
33
+ http = Net::HTTP.new(uri.host, uri.port)
34
+ http.use_ssl = false
35
+ a_request = Net::HTTP::Post.new(uri.request_uri, REQUEST_HEADER)
36
+ a_request.body = json_content.to_json
37
+ a_response = http.request(a_request)
38
+ return a_response.body
39
+ end
40
+
41
+ def get_error_or_returned_value(json_response)
42
+ # check if the response has errors
43
+ hashed_response = JSON.parse(json_response)
44
+ errors = hashed_response["errors"]
45
+
46
+ if errors.present?
47
+ return false, errors
48
+ else
49
+ return true, hashed_response
50
+ end
51
+ end
8
52
  end
9
53
  end
@@ -1,3 +1,3 @@
1
1
  module DemoApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShaimaKaraki