arkaan 0.10.21 → 0.10.22

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: d9e5590c7b5776567dfca8179a55c9ea24ddd76c
4
- data.tar.gz: 359cd55594d85a2146c2b3bcbbea688b8a83f503
3
+ metadata.gz: 9558fd9ac23d57362899823ae089ac10ff78e1e0
4
+ data.tar.gz: 27f9532aeedb7b456676b74ebc4c57b95ec45a0a
5
5
  SHA512:
6
- metadata.gz: 7d9d612b8ae8dabb4ed92c673daa203dae96984cb7758b4c69641ebac359589787bf22c4874923d4d717c2a12690b82e945e570874cc8f99e1edaadd73856734
7
- data.tar.gz: c969f7ebef770b1ddf1f3820a3f8f36916e27b5f6b48be70e003b2204b36b4af540ff45bcb9859f54d08556972d2dc8ed7edaa81dcf2ff59d419c94cae40f6f4
6
+ metadata.gz: 593bfc4c2d2db36b11f64cf7feb5dcd0bb861563fc67616f872ba48c500a85ac1b952f7de2461fab3c5799ad41b970511479f253eebb9eb360112e95efe24b0d
7
+ data.tar.gz: 894e993156092a369acb3a0de1ceedcab5f16d4f0f2f34bc1287216f43b4e02eb8c6a7644113efcb92413183ac0775ab85d132cea3891e002036b74498dc1c31
@@ -14,7 +14,7 @@ module Arkaan
14
14
  autoload :Campaigns , 'arkaan/campaigns'
15
15
  autoload :Concerns , 'arkaan/concerns'
16
16
  autoload :Dacorators , 'arkaan/decorators'
17
- autoload :Phone , 'arkaan/factories'
17
+ autoload :Factories , 'arkaan/factories'
18
18
  autoload :Monitoring , 'arkaan/monitoring'
19
19
  autoload :OAuth , 'arkaan/oauth'
20
20
  autoload :Permissions , 'arkaan/permissions'
@@ -2,6 +2,7 @@ module Arkaan
2
2
  # Decorators are used to enrich the features of the model classes without making it too big.
3
3
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
4
  module Decorators
5
- autoload :Service, 'arkaan/decorators/service'
5
+ autoload :Gateway, 'arkaan/decorators/gateway'
6
+ autoload :Errors , 'arkaan/decorators/errors'
6
7
  end
7
8
  end
@@ -0,0 +1,9 @@
1
+ module Arkaan
2
+ module Decorators
3
+ # Module holding all the errors concerning the code of the decorators.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ module Errors
6
+ autoload :EnvVariableMissing, 'arkaan/decorators/errors/env_variable_missing'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Arkaan
2
+ module Decorators
3
+ module Errors
4
+ # Error raised if the application key variable is missing.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
6
+ class EnvVariableMissing < Arkaan::Utils::Errors::HTTPError
7
+
8
+ def initialize(action:)
9
+ super(action, 'app_key', 'not_found', 404)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,9 +2,18 @@ module Arkaan
2
2
  module Decorators
3
3
  # Decorator for a service, providing methods to make requests on it.
4
4
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class Service < Draper::Decorator
5
+ class Gateway < Draper::Decorator
6
6
  delegate_all
7
7
 
8
+ # @!attribute [rw] action
9
+ # @return [String] the action of the route using this API.
10
+ attr_accessor :action
11
+
12
+ def initialize(action, _object)
13
+ super(_object)
14
+ @action = action
15
+ end
16
+
8
17
  # Makes a POST request to the given service with the following steps :
9
18
  # 1. Gets an active and running instance of the service to make the request.
10
19
  # 2. Creates a Faraday connection to use it as a pipeline for the request.
@@ -15,9 +24,11 @@ module Arkaan
15
24
  # @return [Hash, Boolean] FALSE if no instance are found, or an object with :status and :body keys correspding
16
25
  # to the status and body of the response to the request
17
26
  def post(route, parameters)
18
- instance = object.instances.where(active: true, running: true).first
19
- return false if instance.nil?
20
- connection = Faraday.new(instance.url) do
27
+ if ENV['APP_KEY'].nil?
28
+ raise Arkaan::Decorators::Errors::EnvVariableMissing.new(action)
29
+ end
30
+ parameters[:app_key] = ENV['APP_KEY']
31
+ connection = Faraday.new(object.url) do
21
32
  faraday.request :url_encoded
22
33
  faraday.response :logger
23
34
  faraday.adapter Faraday.default_adapter
@@ -2,6 +2,7 @@ module Arkaan
2
2
  # Static factories are used to create decorated objects easily.
3
3
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
4
  module Factories
5
- autoload :Services, 'arkaan/factories/services'
5
+ autoload :Gateways, 'arkaan/factories/gateways'
6
+ autoload :Errors , 'arkaan/factories/errors'
6
7
  end
7
8
  end
@@ -0,0 +1,9 @@
1
+ module Arkaan
2
+ module Factories
3
+ # Module holding all the errors concerning the code of the factories.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ module Errors
6
+ autoload :GatewayNotFound, 'arkaan/factories/errors/gateway_not_found'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Arkaan
2
+ module Factories
3
+ module Errors
4
+ # Error raised when not gateway active and running is found in the factory.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
6
+ class GatewayNotFound < Arkaan::Utils::Errors::HTTPError
7
+
8
+ def initialize(action:)
9
+ super(action, 'gateway_id', 'not_found', 404)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Arkaan
2
+ module Factories
3
+ # This class provides methods to create decorated services.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Gateways
6
+
7
+ # Searches for a gateway via its key and returns it decorated.
8
+ # @param key [String] the key of the server you want to find.
9
+ # @return [Arkaan::Decorators::Gateway, NilClass] nil if the gateway is not found, or the decorated gateway.
10
+ def self.random(action)
11
+ gateway = Arkaan::Monitoring::Gateway.where(active: true, running: true).first
12
+ if gateway.nil?
13
+ raise Arkaan::Factories::Errors::GatewayNotFound.new(action)
14
+ end
15
+ return Arkaan::Decorators::Gateway.new(action, gateway)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -138,6 +138,14 @@ module Arkaan
138
138
  error Arkaan::Utils::Errors::NotFound do |exception|
139
139
  handle_arkaan_exception(exception)
140
140
  end
141
+
142
+ error Arkaan::Factories::Errors::GatewayNotFound do |exception|
143
+ handle_arkaan_exception(exception)
144
+ end
145
+
146
+ error StandardError do
147
+ custom_error(500, 'system_error.unknown_field.unknown_error')
148
+ end
141
149
  end
142
150
  end
143
151
  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.21
4
+ version: 0.10.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
@@ -241,9 +241,13 @@ files:
241
241
  - lib/arkaan/concerns/premiumable.rb
242
242
  - lib/arkaan/concerns/sluggable.rb
243
243
  - lib/arkaan/decorators.rb
244
- - lib/arkaan/decorators/service.rb
244
+ - lib/arkaan/decorators/errors.rb
245
+ - lib/arkaan/decorators/errors/env_variable_missing.rb
246
+ - lib/arkaan/decorators/gateway.rb
245
247
  - lib/arkaan/factories.rb
246
- - lib/arkaan/factories/services.rb
248
+ - lib/arkaan/factories/errors.rb
249
+ - lib/arkaan/factories/errors/gateway_not_found.rb
250
+ - lib/arkaan/factories/gateways.rb
247
251
  - lib/arkaan/monitoring.rb
248
252
  - lib/arkaan/monitoring/action.rb
249
253
  - lib/arkaan/monitoring/gateway.rb
@@ -1,17 +0,0 @@
1
- module Arkaan
2
- module Factories
3
- # This class provides methods to create decorated services.
4
- # @author Vincent Courtois <courtois.vincent@outlook.com>
5
- class Services
6
-
7
- # Searches for a service via its key and returns it decorated.
8
- # @param key [String] the key of the server you want to find.
9
- # @return [Arkaan::Decorators::Service, NilClass] nil if the service is not found, or the decorated service.
10
- def self.search(key)
11
- service = Arkaan::Monitoring::Service.where(key: key).first
12
- return nil if service.nil?
13
- return Arkaan::Decorators::Service.new(service)
14
- end
15
- end
16
- end
17
- end