arkaan 1.2.3 → 1.2.4

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
  SHA1:
3
- metadata.gz: 7e637cb5e1fa056c3f4f089a1401b042739c67cd
4
- data.tar.gz: 6500cf515bebc7ebc61a96efa85e32a3c245e694
3
+ metadata.gz: c150ea52265ab4b70de42580ce3ed8697b945ae5
4
+ data.tar.gz: be079d94632022d6d9aafec43a6b74661a6d786c
5
5
  SHA512:
6
- metadata.gz: e56ea3ee40a4fe14a0ae85c61f504b6814558358200ad0eab1bf13e5dc618f53483e0b7e2c3046f22d8cb62f0ef5daa3120ed65ddac4a43ae3d5e2d798d8a4c5
7
- data.tar.gz: 30850da655321af49f4cc6390b15b1d033972514d065fec69d7cf9412f2caeed2a81a95ce20dfaf0f4f4ba1ed32ed151ee7d8b61afc894b9a5d550d3668a1436
6
+ metadata.gz: 20920dafe21f8e8f0cce76e0b2f0a1dc7c0671a8296bbbde3bd026adfa0b77c40004e3804076c9d2e3b05b3a47f1df6a96fbb3fb6a7a99a70626e8b65b7c7209
7
+ data.tar.gz: 9f3874ce2d0b9f932449efbfb2c8b3c7ba8ff655d4a1b6877720174d26f1fd1c5ff9656cf16dac805624cf85d59acf051ccc447558ccfb5b36dfb6cf2d57e8ae
@@ -19,7 +19,7 @@ module Arkaan
19
19
  # @param url [String] the URL you want to reach on the service.
20
20
  # @param params [Hash] the additional parameters to pass in the JSON body.
21
21
  def delete(session:, url:, params:)
22
- return make_request(verb: 'delete', session: session, url: url, params: params)
22
+ return make_request_without_body(verb: 'delete', session: session, url: url, params: params)
23
23
  end
24
24
 
25
25
  # Shortcut to make a GET request on the API.
@@ -27,7 +27,7 @@ module Arkaan
27
27
  # @param url [String] the URL you want to reach on the service.
28
28
  # @param params [Hash] the additional parameters to pass in the JSON body.
29
29
  def get(session:, url:, params:)
30
- return make_request(verb: 'get', session: session, url: url, params: params)
30
+ return make_request_without_body(verb: 'get', session: session, url: url, params: params)
31
31
  end
32
32
 
33
33
  # Shortcut to make a POST request on the API.
@@ -61,16 +61,8 @@ module Arkaan
61
61
  # @return [Hash, Boolean] FALSE if no instance are found, or an object with :status and :body keys correspding
62
62
  # to the status and body of the response to the request
63
63
  def make_request(verb:, session:, url:, params:)
64
- if ENV['APP_KEY'].nil?
65
- raise Arkaan::Decorators::Errors::EnvVariableMissing.new(action: action)
66
- end
67
- params[:app_key] = ENV['APP_KEY']
68
- params[:session_id] = session.token
69
- connection = Faraday.new(object.url) do |faraday|
70
- faraday.request :url_encoded
71
- faraday.response :logger
72
- faraday.adapter Faraday.default_adapter
73
- end
64
+ params = before_requests(params)
65
+ connection = get_connection
74
66
  response = connection.send(verb) do |req|
75
67
  req.url url
76
68
  req.headers['Content-Type'] = 'application/json'
@@ -82,6 +74,32 @@ module Arkaan
82
74
  body: JSON.parse(response.body)
83
75
  }
84
76
  end
77
+
78
+ def make_request_without_body(verb:, session:, url:, params:)
79
+ params = before_requests(params)
80
+ connection = get_connection
81
+ response = connection.send(verb) do |req|
82
+ req.url url, params
83
+ req.headers['Content-Type'] = 'application/json'
84
+ end
85
+ end
86
+
87
+ def before_requests(params)
88
+ if ENV['APP_KEY'].nil?
89
+ raise Arkaan::Decorators::Errors::EnvVariableMissing.new(action: action)
90
+ end
91
+ params[:app_key] = ENV['APP_KEY']
92
+ params[:session_id] = session.token
93
+ return params
94
+ end
95
+
96
+ def get_connection
97
+ Faraday.new(object.url) do |faraday|
98
+ faraday.request :url_encoded
99
+ faraday.response :logger
100
+ faraday.adapter Faraday.default_adapter
101
+ end
102
+ end
85
103
  end
86
104
  end
87
105
  end
@@ -8,6 +8,7 @@ module Arkaan
8
8
 
9
9
  configure do
10
10
  set :logger, Logger.new(STDOUT)
11
+ logger.level = Logger::ERROR if ENV['RACK_ENV'] == 'test'
11
12
  end
12
13
 
13
14
  # Creates a premium route whithin the Sinatra application, and registers it in the database if it does not already exists.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arkaan
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois