arkaan 0.10.23 → 0.10.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 572e451be0e72248cf6c0ed386d2a8da6755cf4a
4
- data.tar.gz: 8392d4f80339b7fd7b20d3006eed6a19f6e5cffa
3
+ metadata.gz: 10054ec59c36dfb69ce43553469e07bb156c83f0
4
+ data.tar.gz: 21822cb99ab1c672e796096cda30ec9ccef4fb01
5
5
  SHA512:
6
- metadata.gz: 7c5c1b394e0ec3c58b708c80c7cca2f4c87afb124b7cc912a065cbf0d0042af607fabb039e7b01344d26d05d522f6f5b0088c54da53cb80b367d41b249fefd1e
7
- data.tar.gz: 689b8668b590b407006dea0af733fb270299d9736086f40d1d321b01da1e984740d97e729b06bcc47b721057c7d446526eb4af477b11fed8ff4452fe4b06d665
6
+ metadata.gz: 9077ac7f917c9a13257dff98cf3528a84e3bde30ea5af7ed045f434cb98eea760e9ace89a5ca226443d1b63b230aaba71403ad326cc876839693387d81e60747
7
+ data.tar.gz: fdc7509b41a13c14d279b7ff05ad76d19437b7ef69607b224e097a9dd5710553dadc478d33391ca975b26076b642e8936e77218f98216173eed6f786e1f7323e
@@ -5,6 +5,7 @@ require 'sinatra/base'
5
5
  require 'sinatra/config_file'
6
6
  require 'platform-api'
7
7
  require 'draper'
8
+ require 'faraday'
8
9
 
9
10
  # Main module of the application, holding all the subsequent classes.
10
11
  # @author Vincent Courtois <courtois.vincent@outlook.com>
@@ -14,29 +14,67 @@ module Arkaan
14
14
  @action = action
15
15
  end
16
16
 
17
+ # Shortcut to make a DELETE request on the API.
18
+ # @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
19
+ # @param url [String] the URL you want to reach on the service.
20
+ # @param params [Hash] the additional parameters to pass in the JSON body.
21
+ def delete(session:, url:, params:)
22
+ return make_request(verb: 'delete', session: session, url: url, params: params)
23
+ end
24
+
25
+ # Shortcut to make a GET request on the API.
26
+ # @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
27
+ # @param url [String] the URL you want to reach on the service.
28
+ # @param params [Hash] the additional parameters to pass in the JSON body.
29
+ def get(session:, url:, params:)
30
+ return make_request(verb: 'get', session: session, url: url, params: params)
31
+ end
32
+
33
+ # Shortcut to make a POST request on the API.
34
+ # @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
35
+ # @param url [String] the URL you want to reach on the service.
36
+ # @param params [Hash] the additional parameters to pass in the JSON body.
37
+ def post(session:, url:, params:)
38
+ return make_request(verb: 'post', session: session, url: url, params: params)
39
+ end
40
+
41
+ # Shortcut to make a PUT request on the API.
42
+ # @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
43
+ # @param url [String] the URL you want to reach on the service.
44
+ # @param params [Hash] the additional parameters to pass in the JSON body.
45
+ def put(session:, url:, params:)
46
+ return make_request(verb: 'put', session: session, url: url, params: params)
47
+ end
48
+
49
+ private
50
+
17
51
  # Makes a POST request to the given service with the following steps :
18
52
  # 1. Gets an active and running instance of the service to make the request.
19
53
  # 2. Creates a Faraday connection to use it as a pipeline for the request.
20
54
  # 3. Makes the actual request and returns an object with the status and body of the response.
21
55
  #
22
- # @param route [String] the URL you want to reach on the service.
23
- # @param parameters [Hash] the additional parameters to pass in the JSON body.
56
+ # @param verb [String] the HTTP verb to use for this request.
57
+ # @param session [Arkaan::Authentication::Session] the session of the user requesting the API.
58
+ # @param url [String] the URL you want to reach on the service.
59
+ # @param params [Hash] the additional parameters to pass in the JSON body.
60
+ #
24
61
  # @return [Hash, Boolean] FALSE if no instance are found, or an object with :status and :body keys correspding
25
62
  # to the status and body of the response to the request
26
- def post(route, parameters)
63
+ def make_request(verb:, session:, url:, params:)
27
64
  if ENV['APP_KEY'].nil?
28
- raise Arkaan::Decorators::Errors::EnvVariableMissing.new(action)
65
+ raise Arkaan::Decorators::Errors::EnvVariableMissing.new(action: action)
29
66
  end
30
- parameters[:app_key] = ENV['APP_KEY']
31
- connection = Faraday.new(object.url) do
67
+ params[:app_key] = ENV['APP_KEY']
68
+ params[:session_d] = session.token
69
+ connection = Faraday.new(object.url) do |faraday|
32
70
  faraday.request :url_encoded
33
71
  faraday.response :logger
34
72
  faraday.adapter Faraday.default_adapter
35
73
  end
36
- responde = connection.post do |req|
37
- req.url route
74
+ responde = connection.send(verb) do |req|
75
+ req.url url
38
76
  req.headers['Content-Type'] = 'application/json'
39
- req.body = parameters.to_json
77
+ req.body = params.to_json
40
78
  end
41
79
  return {
42
80
  status: response.status,
@@ -10,7 +10,7 @@ module Arkaan
10
10
  def self.random(action)
11
11
  gateway = Arkaan::Monitoring::Gateway.where(active: true, running: true).first
12
12
  if gateway.nil?
13
- raise Arkaan::Factories::Errors::GatewayNotFound.new(action)
13
+ raise Arkaan::Factories::Errors::GatewayNotFound.new(action: action)
14
14
  end
15
15
  return Arkaan::Decorators::Gateway.new(action, gateway)
16
16
  end
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: 0.10.23
4
+ version: 0.10.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
@@ -234,6 +234,20 @@ dependencies:
234
234
  - - '='
235
235
  - !ruby/object:Gem::Version
236
236
  version: 2.1.0
237
+ - !ruby/object:Gem::Dependency
238
+ name: faraday
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
237
251
  description: This gem holds the model layer for my table-top RPG games application.
238
252
  email: courtois.vincent@outlook.com
239
253
  executables: []