arkaan 0.10.20 → 0.10.21

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: 802dde822c6a67b3cc42513f6842d738fe927b4f
4
- data.tar.gz: bcf79de27b982ecd9d3efd2a0930fa26ed3d637a
3
+ metadata.gz: d9e5590c7b5776567dfca8179a55c9ea24ddd76c
4
+ data.tar.gz: 359cd55594d85a2146c2b3bcbbea688b8a83f503
5
5
  SHA512:
6
- metadata.gz: d7898d11625e1e4e87ddbbb63e7f0ef47a0355709966550bf7803eb91c7131d064ec234b1ae8e9e79d41838e7f09ea38827bab1f98c67ed73ea0c014677d8932
7
- data.tar.gz: c256372eb33847cc2d7ea3aee83e0e43556617d6016db7bb6a91b36e054cd84e296bdb362b47f2100524c9967474b45d521e3402d93921c930cf8684a257056e
6
+ metadata.gz: 7d9d612b8ae8dabb4ed92c673daa203dae96984cb7758b4c69641ebac359589787bf22c4874923d4d717c2a12690b82e945e570874cc8f99e1edaadd73856734
7
+ data.tar.gz: c969f7ebef770b1ddf1f3820a3f8f36916e27b5f6b48be70e003b2204b36b4af540ff45bcb9859f54d08556972d2dc8ed7edaa81dcf2ff59d419c94cae40f6f4
@@ -13,6 +13,8 @@ module Arkaan
13
13
  autoload :Campaign , 'arkaan/campaign'
14
14
  autoload :Campaigns , 'arkaan/campaigns'
15
15
  autoload :Concerns , 'arkaan/concerns'
16
+ autoload :Dacorators , 'arkaan/decorators'
17
+ autoload :Phone , 'arkaan/factories'
16
18
  autoload :Monitoring , 'arkaan/monitoring'
17
19
  autoload :OAuth , 'arkaan/oauth'
18
20
  autoload :Permissions , 'arkaan/permissions'
@@ -0,0 +1,7 @@
1
+ module Arkaan
2
+ # Decorators are used to enrich the features of the model classes without making it too big.
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ module Decorators
5
+ autoload :Service, 'arkaan/decorators/service'
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ module Arkaan
2
+ module Decorators
3
+ # Decorator for a service, providing methods to make requests on it.
4
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
5
+ class Service < Draper::Decorator
6
+ delegate_all
7
+
8
+ # Makes a POST request to the given service with the following steps :
9
+ # 1. Gets an active and running instance of the service to make the request.
10
+ # 2. Creates a Faraday connection to use it as a pipeline for the request.
11
+ # 3. Makes the actual request and returns an object with the status and body of the response.
12
+ #
13
+ # @param route [String] the URL you want to reach on the service.
14
+ # @param parameters [Hash] the additional parameters to pass in the JSON body.
15
+ # @return [Hash, Boolean] FALSE if no instance are found, or an object with :status and :body keys correspding
16
+ # to the status and body of the response to the request
17
+ 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
21
+ faraday.request :url_encoded
22
+ faraday.response :logger
23
+ faraday.adapter Faraday.default_adapter
24
+ end
25
+ responde = connection.post do |req|
26
+ req.url route
27
+ req.headers['Content-Type'] = 'application/json'
28
+ req.body = parameters.to_json
29
+ end
30
+ return {
31
+ status: response.status,
32
+ body: JSON.parse(response.body)
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Arkaan
2
+ # Static factories are used to create decorated objects easily.
3
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
4
+ module Factories
5
+ autoload :Services, 'arkaan/factories/services'
6
+ end
7
+ end
@@ -0,0 +1,17 @@
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
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.20
4
+ version: 0.10.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
@@ -240,6 +240,10 @@ files:
240
240
  - lib/arkaan/concerns/enumerable.rb
241
241
  - lib/arkaan/concerns/premiumable.rb
242
242
  - lib/arkaan/concerns/sluggable.rb
243
+ - lib/arkaan/decorators.rb
244
+ - lib/arkaan/decorators/service.rb
245
+ - lib/arkaan/factories.rb
246
+ - lib/arkaan/factories/services.rb
243
247
  - lib/arkaan/monitoring.rb
244
248
  - lib/arkaan/monitoring/action.rb
245
249
  - lib/arkaan/monitoring/gateway.rb