evostream-event 0.2.3 → 0.2.4.pre.31

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: 9aef4188d5a8087438593f34d1aa78d94a5c91c3
4
- data.tar.gz: 1d2a5800a2245f9feaf55a53e3e1a6350bc1db31
3
+ metadata.gz: 5f81886b80f646e5667351832115afeddf3d166e
4
+ data.tar.gz: 9de2250347b899d3f30cd8d9224d22e7e85ee2b6
5
5
  SHA512:
6
- metadata.gz: 1464f4208173fc09369d40af29471c8cc44bbd2d9f67ac35fe5d1c1cdba492e56bb7b99f847ce7c8bac650c804353505b6023da33ed685171f01de7aa2f015b8
7
- data.tar.gz: 5d9ca90975ba4c1ea7a8dba5abe9d52186e07998e7185c316406b81699785cb79343fc380da1971397eecbc72e68d5ebe3ef835a653e0e146c92c7d1300b84ee
6
+ metadata.gz: 3da7f11d9882c0b823d0ae04447ddf383d655318e4b8e4eb262ba43a02c0eead56ae084b81222e510c09d6872f79d8190abc2920baba78d3486d8b501ad04bef
7
+ data.tar.gz: e14106b57b10fe1e99adf4d2b95746f1a86bd0384ee48bb5f6234e8aa2f767daa1816d52913a877582fe765601585e649baf4e278fcf419cfb9fb4a2bee9ee45
@@ -10,15 +10,38 @@ require 'net/http'
10
10
  # Primary command to gem
11
11
  module Evostream
12
12
  def self.send_command(cmd)
13
- uri = URI.parse("#{Evostream::Service.uri_in}/#{cmd}")
14
- http = Net::HTTP.new(uri.host, uri.port)
15
- http.request(Net::HTTP::Get.new(uri.request_uri))
13
+ response = prepare_request(cmd)
14
+ body = JSON.parse(response.body).to_hash
15
+ { status: Evostream.status(body), message: body['description'] }
16
+ end
17
+
18
+ def self.send_command_action(cmd)
19
+ response = prepare_request(cmd)
20
+ body = response.body
21
+ if body.blank?
22
+ { status: 403, message: 'Error with evostream !' }
23
+ else
24
+ body = JSON.parse(body).to_hash
25
+ { status: 200, message: body['description'] }
26
+ end
16
27
  end
17
28
 
18
29
  def self.logger(message)
19
30
  Rails.logger.debug "[#{Evostream::GEM_NAME}] #{message}" if defined?(Rails)
20
31
  end
21
32
 
33
+ def self.status(body)
34
+ body['status'].eql?('FAIL') ? 403 : 200
35
+ end
36
+
37
+ def self.prepare_request(cmd)
38
+ uri = URI.parse("#{Evostream::Service.uri_in}/#{cmd}")
39
+ http = Net::HTTP.new(uri.host, uri.port)
40
+ http.request(Net::HTTP::Get.new(uri.request_uri))
41
+ end
42
+ end
43
+
44
+ module Evostream
22
45
  # Send an action to evostream server
23
46
  class Action
24
47
  def initialize(payload)
@@ -28,7 +51,7 @@ module Evostream
28
51
  def execute_action(command_name)
29
52
  cmd = command_name.sub(/^(\w)/, &:capitalize)
30
53
  klass = "Evostream::Commands::#{cmd}".constantize
31
- Evostream.send_command(klass.new(@payload).cmd)
54
+ Evostream.send_command_action(klass.new(@payload).cmd)
32
55
  end
33
56
  end
34
57
 
@@ -9,11 +9,13 @@ module Evostream
9
9
  Evostream.logger "Initialize event #{class_name}"
10
10
  @id_flux = id_flux
11
11
  @model = Service.model.find_by(Service.model_id => id_flux)
12
+ @result = nil
12
13
  end
13
14
 
14
- def execute(type_flux = %w(hls dash))
15
+ def execute(type_flux = %w[hls dash])
15
16
  Evostream.logger "Execute action for event #{class_name}"
16
17
  type_flux.each { |flux| yield(flux) } if block_given?
18
+ @result
17
19
  end
18
20
 
19
21
  def class_name
@@ -27,6 +29,7 @@ module Evostream
27
29
  private
28
30
 
29
31
  attr_reader :id_flux, :model
32
+ attr_accessor :result
30
33
  end
31
34
  end
32
35
  end
@@ -12,8 +12,8 @@ module Evostream
12
12
  def execute
13
13
  super do |type_flux|
14
14
  klass = Evostream::Commands::Destroy.new(remove_config(type_flux))
15
- Evostream.send_command(klass.cmd)
16
- yield if block_given?
15
+ @result = Evostream.send_command(klass.cmd)
16
+ # yield if block_given?
17
17
  end
18
18
  end
19
19
 
@@ -8,7 +8,7 @@ module Evostream
8
8
  super do |type_flux|
9
9
  klass = "Evostream::Commands::Create#{type_flux.upcase}".constantize
10
10
  command = send(type_flux, type_flux)
11
- Evostream.send_command(klass.new(command).cmd)
11
+ @result = Evostream.send_command(klass.new(command).cmd)
12
12
  end
13
13
  end
14
14
 
@@ -13,6 +13,7 @@ module Evostream
13
13
  stream_flux = what_flux.upcase.constantize
14
14
  model.streams.push(stream_flux.new(config_id: ex_config, flux: ex_flux))
15
15
  model.save
16
+ @result = { status: 201, message: 'Action successfully executed.' }
16
17
  end
17
18
 
18
19
  private
@@ -6,7 +6,7 @@
6
6
  # Define constant to gem.
7
7
  module Evostream
8
8
  # Define version to gem
9
- VERSION = '0.2.3'
9
+ VERSION = '0.2.4'
10
10
 
11
11
  # Name to gem
12
12
  GEM_NAME = 'evostream-event'
@@ -3,5 +3,5 @@
3
3
  RSpec.shared_examples 'test request action' do
4
4
  let(:request) { action.execute_action(action_name) }
5
5
 
6
- it { expect(request).to be_an_instance_of(Net::HTTPOK) }
6
+ it { expect(request).to be_kind_of(Hash) }
7
7
  end
@@ -4,11 +4,7 @@ RSpec.shared_examples 'payload is correct' do |request = true|
4
4
  include_examples 'body type'
5
5
  include_examples 'evostream::event new'
6
6
  include_examples 'instance variable model'
7
- if request
8
- include_examples 'request test'
9
- else
10
- include_examples 'type stream'
11
- end
7
+ include_examples 'type stream' unless request
12
8
  it { expect(type).to eql(type_default) }
13
9
  end
14
10
 
@@ -34,11 +30,6 @@ RSpec.shared_examples 'instance variable model' do
34
30
  it { expect(evo.instance_variable_get(:@model)).to eql(model) }
35
31
  end
36
32
 
37
- RSpec.shared_examples 'request test' do
38
- let(:response) { Evostream::Event.new(type, payload).execute_action }
39
- it { expect(response).to be_an_instance_of(Array) }
40
- end
41
-
42
33
  RSpec.shared_examples 'type stream' do
43
34
  let(:stream) do
44
35
  Evostream::Events::OutStreamCreated.new(1234, payload).send(:what_flux)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evostream-event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4.pre.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - VAILLANT Jeremy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -303,9 +303,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
303
303
  version: '0'
304
304
  required_rubygems_version: !ruby/object:Gem::Requirement
305
305
  requirements:
306
- - - ">="
306
+ - - ">"
307
307
  - !ruby/object:Gem::Version
308
- version: '0'
308
+ version: 1.3.1
309
309
  requirements: []
310
310
  rubyforge_project:
311
311
  rubygems_version: 2.4.5