omnikiq 0.1.1 → 0.1.2

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: b1a85bac23ae74c3e63e7d5b86a115c47c6eec20
4
- data.tar.gz: e17f6a9d4ef7182de40dd5da2d85a51e14819664
3
+ metadata.gz: 9969a72a008ee28248a92ded037fe2b845c8caf8
4
+ data.tar.gz: 724a33407e94857b493741921b6d37794f8a5c43
5
5
  SHA512:
6
- metadata.gz: 9ba97055b7db8168b16b3ffbd66a7a457ff16704f34541a0bb4cd856393666c07ee5fd53da25291651f896ac29c5eb57597f1a2535d29458da00488c74cb375f
7
- data.tar.gz: cbe0a0fd8190a7020c5d3c2e7b08b019d9fd75e8f0d4e042c62eb29d7286783d20aa17740c92338a5231119eda98e81e2ab46b3bb6b0ec098dbb4c8f3c7fa7ee
6
+ metadata.gz: 99fb60d680bb25b5b4db4857491d347236a02cfea2852bed548c424696aecf88abf50af5bcc792c625f0ffc3ac1fafc58b6fc85fb069b3215635cdae846b0af6
7
+ data.tar.gz: c5acf3f92c7ad57f9ddbf793311657f9514133307a3259f7c519b56f4844c362863f032a44f8bd9f1cc2221783da73b364abdf85e62741cccc035f057023b8c8
@@ -0,0 +1,27 @@
1
+ require 'singleton'
2
+ require 'active_support/core_ext/module/attribute_accessors'
3
+
4
+ module OmniApi
5
+ mattr_accessor :test_mode
6
+ self.test_mode = false
7
+
8
+ mattr_accessor :base_url
9
+ self.base_url = ''
10
+
11
+ mattr_accessor :client_access_token
12
+ def self.client_access_token=(token)
13
+ @client_access_token = "bearer #{token}"
14
+ end
15
+
16
+ def self.client_access_token
17
+ @client_access_token || 'bearer empty'
18
+ end
19
+
20
+ def self.config
21
+ self
22
+ end
23
+
24
+ def self.setup
25
+ yield self
26
+ end
27
+ end
@@ -1,5 +1,6 @@
1
1
  require 'sidekiq'
2
2
  require 'mixpanel-ruby'
3
+ require 'omni_api'
3
4
 
4
5
  require 'omnikiq/configuration'
5
6
  require 'omnikiq/trackers/base'
@@ -15,6 +16,10 @@ module OmniKiq
15
16
  autoload :MixpanelPeople, 'omnikiq/trackers/mixpanel_people'
16
17
  end
17
18
 
19
+ module Workers
20
+ autoload :SendScheduledSmsWorker, 'omnikiq/workers/send_scheduled_sms_worker'
21
+ end
22
+
18
23
  def self.configuration
19
24
  @configuration ||= begin
20
25
  config = OmniKiq::Configuration.new
@@ -36,12 +41,16 @@ module OmniKiq
36
41
  }
37
42
  end
38
43
 
39
- if OmniKiq.configuration.test_mode
40
- require 'sidekiq/testing'
41
- Sidekiq::Testing.fake!
42
- end
44
+ enable_testing if OmniKiq.configuration.test_mode
43
45
  end
44
46
 
45
47
  # default config for the client
46
48
  configure_client
49
+
50
+ private
51
+
52
+ def self.enable_testing
53
+ require 'sidekiq/testing'
54
+ Sidekiq::Testing.fake!
55
+ end
47
56
  end
@@ -0,0 +1,18 @@
1
+ require 'net/http'
2
+
3
+ module OmniKiq
4
+ module Workers
5
+ class SendScheduledSmsWorker
6
+ include Sidekiq::Worker
7
+
8
+ def perform(sms_message_id, device_id)
9
+ http = Net::HTTP.new(::OmniApi.config.base_url)
10
+ path = "/api/v1/sms_messages/#{sms_message_id}"
11
+
12
+ data = { state: 'sending', device_id: device_id }.to_json
13
+ header = { 'Authorization' => OmniApi.config.client_access_token }
14
+ http.send_request('PATCH', path, data, header)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,6 +5,12 @@ ENV['RACK_ENV'] ||= 'test'
5
5
  require 'omnikiq'
6
6
  require 'rspec/its'
7
7
 
8
+ OmniApi.config.base_url = 'localhost:9292'
9
+ OmniApi.config.client_access_token = 'random'
10
+
11
+ require 'webmock/rspec'
12
+ WebMock.disable_net_connect!(allow_localhost: false)
13
+
8
14
  # Require all of the RSpec Support libraries
9
15
  Dir[File.expand_path(File.join('../support/**/*.rb'), __FILE__)].each { |f| require f }
10
16
 
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniKiq::Workers::SendScheduledSmsWorker do
4
+ describe :perform do
5
+ subject { OmniKiq::Workers::SendScheduledSmsWorker.new }
6
+
7
+ before do
8
+ headers = {
9
+ 'Accept' => '*/*',
10
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
11
+ 'Authorization' => 'bearer random',
12
+ 'User-Agent' => 'Ruby'
13
+ }
14
+ stub_request(:patch, 'http://localhost:9292/api/v1/sms_messages/1234')
15
+ .with(body: "{\"state\":\"sending\",\"device_id\":\"4321\"}", headers: headers)
16
+ .to_return(status: 200, body: '{\"status\":\"200\"}', headers: {})
17
+ end
18
+
19
+ it 'makes a put request to the OmniApi with correct parameters' do
20
+ expect(subject.perform('1234', '4321')).to be_a Net::HTTPOK
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnikiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Nistor
@@ -88,12 +88,14 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - lib/capistrano/templates/puma.rb
91
+ - lib/omni_api.rb
91
92
  - lib/omnikiq.rb
92
93
  - lib/omnikiq/configuration.rb
93
94
  - lib/omnikiq/trackers/base.rb
94
95
  - lib/omnikiq/trackers/mixpanel_alias.rb
95
96
  - lib/omnikiq/trackers/mixpanel_events.rb
96
97
  - lib/omnikiq/trackers/mixpanel_people.rb
98
+ - lib/omnikiq/workers/send_scheduled_sms_worker.rb
97
99
  - spec/configuration_spec.rb
98
100
  - spec/omnikiq_spec.rb
99
101
  - spec/spec_helper.rb
@@ -101,6 +103,7 @@ files:
101
103
  - spec/trackers/mixpanel_alias_spec.rb
102
104
  - spec/trackers/mixpanel_events_spec.rb
103
105
  - spec/trackers/mixpanel_people_spec.rb
106
+ - spec/workers/send_scheduled_sms_worker_spec.rb
104
107
  homepage: https://github.com/Agilefreaks/OmniKiq
105
108
  licenses:
106
109
  - "© 2015 Omnipaste"
@@ -121,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
124
  version: '0'
122
125
  requirements: []
123
126
  rubyforge_project:
124
- rubygems_version: 2.4.5
127
+ rubygems_version: 2.4.7
125
128
  signing_key:
126
129
  specification_version: 4
127
130
  summary: Integrate mixpanel and sidekiq in your ruby app
@@ -133,3 +136,4 @@ test_files:
133
136
  - spec/trackers/mixpanel_alias_spec.rb
134
137
  - spec/trackers/mixpanel_events_spec.rb
135
138
  - spec/trackers/mixpanel_people_spec.rb
139
+ - spec/workers/send_scheduled_sms_worker_spec.rb