fixer_client 0.1.0 → 0.1.1

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: 6b2804caf3476551d2e77e70a3f4522faec86a2d
4
- data.tar.gz: 2dbed2d9c37d72811806071fe515de5689576641
3
+ metadata.gz: 3ba7944c758bde84335f90488ce2df501f68296d
4
+ data.tar.gz: 03a2fe995c0bc5dee65da83d3851e1dbdad80fe2
5
5
  SHA512:
6
- metadata.gz: b6ef6ef9c05f6613645a5ed1151f8c04bec81c71db0a4995ac95c3e691dfb6325a450c2138bfb5ae4b5bfebfd45c59b8d772d8303ecca03da79e029273afb011
7
- data.tar.gz: 8033f880b90362bee739fe5e3f4cf27c948d919a6c360f1eddcc2757706d24e21bd674fdd451e0f950757f9f95537025e595085cd15d4d39196cd4cfc8de782a
6
+ metadata.gz: 9400fd06d80dead91c5ca9ee03ab9c539db5f86728d8ba6f060a58f39bd06dee5c1a7471d651ea9e67edc9d74d64aa77810d2543553e1691b34bbb4a56f36c7a
7
+ data.tar.gz: cd5f5440e97e5f7525fefa905daedbb9df3cdd44c19dd8814c2a9c4823acad88d622ac3750eeb52e97472e5785c48b642174952e347970ad3650c49871887588
data/.hound.yml ADDED
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ enabled: true
3
+ config_file: .rubocop.yml
data/.rubocop.yml ADDED
@@ -0,0 +1,261 @@
1
+ # from https://github.com/thoughtbot/hound/blob/114d4dfff8365e906d8b389f82d3ff9e0a47f747/config/style_guides/ruby.yml
2
+
3
+ AllCops:
4
+ Exclude:
5
+ - db/schema.rb
6
+
7
+ AccessorMethodName:
8
+ Enabled: false
9
+
10
+ ActionFilter:
11
+ Enabled: false
12
+
13
+ Alias:
14
+ Enabled: false
15
+
16
+ ArrayJoin:
17
+ Enabled: false
18
+
19
+ AsciiComments:
20
+ Enabled: false
21
+
22
+ AsciiIdentifiers:
23
+ Enabled: false
24
+
25
+ Attr:
26
+ Enabled: false
27
+
28
+ BlockNesting:
29
+ Enabled: false
30
+
31
+ CaseEquality:
32
+ Enabled: false
33
+
34
+ CharacterLiteral:
35
+ Enabled: false
36
+
37
+ ClassAndModuleChildren:
38
+ Enabled: false
39
+
40
+ ClassLength:
41
+ Enabled: false
42
+
43
+ ClassVars:
44
+ Enabled: false
45
+
46
+ CollectionMethods:
47
+ PreferredMethods:
48
+ find: detect
49
+ reduce: inject
50
+ collect: map
51
+ find_all: select
52
+
53
+ ColonMethodCall:
54
+ Enabled: false
55
+
56
+ CommentAnnotation:
57
+ Enabled: false
58
+
59
+ CyclomaticComplexity:
60
+ Enabled: false
61
+
62
+ Delegate:
63
+ Enabled: false
64
+
65
+ DeprecatedHashMethods:
66
+ Enabled: false
67
+
68
+ Documentation:
69
+ Enabled: false
70
+
71
+ DotPosition:
72
+ EnforcedStyle: trailing
73
+
74
+ DoubleNegation:
75
+ Enabled: false
76
+
77
+ EachWithObject:
78
+ Enabled: false
79
+
80
+ EmptyLiteral:
81
+ Enabled: false
82
+
83
+ Encoding:
84
+ Enabled: false
85
+
86
+ EvenOdd:
87
+ Enabled: false
88
+
89
+ FileName:
90
+ Enabled: false
91
+
92
+ FlipFlop:
93
+ Enabled: false
94
+
95
+ FormatString:
96
+ Enabled: false
97
+
98
+ GlobalVars:
99
+ Enabled: false
100
+
101
+ GuardClause:
102
+ Enabled: false
103
+
104
+ IfUnlessModifier:
105
+ Enabled: false
106
+
107
+ IfWithSemicolon:
108
+ Enabled: false
109
+
110
+ InlineComment:
111
+ Enabled: false
112
+
113
+ Lambda:
114
+ Enabled: false
115
+
116
+ LambdaCall:
117
+ Enabled: false
118
+
119
+ LineEndConcatenation:
120
+ Enabled: false
121
+
122
+ LineLength:
123
+ Max: 80
124
+
125
+ MethodLength:
126
+ Enabled: false
127
+
128
+ ModuleFunction:
129
+ Enabled: false
130
+
131
+ NegatedIf:
132
+ Enabled: false
133
+
134
+ NegatedWhile:
135
+ Enabled: false
136
+
137
+ Next:
138
+ Enabled: false
139
+
140
+ NilComparison:
141
+ Enabled: false
142
+
143
+ Not:
144
+ Enabled: false
145
+
146
+ NumericLiterals:
147
+ Enabled: false
148
+
149
+ OneLineConditional:
150
+ Enabled: false
151
+
152
+ OpMethod:
153
+ Enabled: false
154
+
155
+ ParameterLists:
156
+ Enabled: false
157
+
158
+ PercentLiteralDelimiters:
159
+ Enabled: false
160
+
161
+ PerlBackrefs:
162
+ Enabled: false
163
+
164
+ PredicateName:
165
+ NamePrefixBlacklist:
166
+ - is_
167
+
168
+ Proc:
169
+ Enabled: false
170
+
171
+ RaiseArgs:
172
+ Enabled: false
173
+
174
+ RegexpLiteral:
175
+ Enabled: false
176
+
177
+ SelfAssignment:
178
+ Enabled: false
179
+
180
+ SingleLineBlockParams:
181
+ Enabled: false
182
+
183
+ SingleLineMethods:
184
+ Enabled: false
185
+
186
+ SignalException:
187
+ Enabled: false
188
+
189
+ SpecialGlobalVars:
190
+ Enabled: false
191
+
192
+ StringLiterals:
193
+ EnforcedStyle: single_quotes
194
+
195
+ VariableInterpolation:
196
+ Enabled: false
197
+
198
+ TrailingComma:
199
+ Enabled: false
200
+
201
+ TrivialAccessors:
202
+ Enabled: false
203
+
204
+ VariableInterpolation:
205
+ Enabled: false
206
+
207
+ WhenThen:
208
+ Enabled: false
209
+
210
+ WhileUntilModifier:
211
+ Enabled: false
212
+
213
+ WordArray:
214
+ Enabled: false
215
+
216
+ # Lint
217
+
218
+ AmbiguousOperator:
219
+ Enabled: false
220
+
221
+ AmbiguousRegexpLiteral:
222
+ Enabled: false
223
+
224
+ AssignmentInCondition:
225
+ Enabled: false
226
+
227
+ ConditionPosition:
228
+ Enabled: false
229
+
230
+ DeprecatedClassMethods:
231
+ Enabled: false
232
+
233
+ ElseLayout:
234
+ Enabled: false
235
+
236
+ HandleExceptions:
237
+ Enabled: false
238
+
239
+ InvalidCharacterLiteral:
240
+ Enabled: false
241
+
242
+ LiteralInCondition:
243
+ Enabled: false
244
+
245
+ LiteralInInterpolation:
246
+ Enabled: false
247
+
248
+ Loop:
249
+ Enabled: false
250
+
251
+ ParenthesesAsGroupedExpression:
252
+ Enabled: false
253
+
254
+ RequireParentheses:
255
+ Enabled: false
256
+
257
+ UnderscorePrefixedVariableName:
258
+ Enabled: false
259
+
260
+ Void:
261
+ Enabled: false
data/README.md CHANGED
@@ -51,7 +51,6 @@ require 'fixer_client'
51
51
 
52
52
  client = Fixer::Client.new
53
53
 
54
-
55
54
  # list jobs
56
55
  js = client.jobs.list
57
56
 
@@ -82,6 +81,47 @@ j = client.jobs.create(job)
82
81
 
83
82
  ```
84
83
 
84
+ You can also create jobs by dropping them on an SQS queue (assuming your fixer server is so configured):
85
+ See the `examples/sqs_client.rb`:
86
+ ```
87
+ Fixer.configure do |c|
88
+
89
+ # required: client_id identifies the application for this job
90
+ c.client_id = ''
91
+ c.client_secret = ''
92
+
93
+ # this is the default value
94
+ c.queue = 'production_fixer_job_create'
95
+
96
+ # optional: aws-sdk-core gem's config can be ENV vars, or in Fixer
97
+ c.aws = {
98
+ access_key_id: '',
99
+ secret_access_key: '',
100
+ region: 'us-east-1'
101
+ }
102
+ end
103
+
104
+ client = Fixer::SqsClient.new
105
+
106
+ job = {
107
+ job: {
108
+ original: 's3://test-fixer/audio.wav',
109
+ job_type: 'audio',
110
+ tasks: [
111
+ {
112
+ task_type: 'transcode',
113
+ options: { format: 'mp3', bit_rate: 64, sample_rate: 44100 },
114
+ result: 's3://test-fixer/audio.mp3'
115
+ }
116
+ ]
117
+ }
118
+ }
119
+
120
+ # if not present, id is assigned to a GUID before sending to SQS
121
+ new_job = client.create_job(job)
122
+ puts "new job created with id: #{new_job.id}"
123
+ ```
124
+
85
125
  ## License
86
126
  [The MIT License](http://opensource.org/licenses/MIT)
87
127
 
data/examples/basic.rb CHANGED
@@ -29,4 +29,5 @@ job = {
29
29
  }
30
30
  }
31
31
 
32
- j = client.jobs.create(job)
32
+ new_job = client.jobs.create(job)
33
+ puts "new job created: #{new_job.inspect}"
data/examples/sequence.rb CHANGED
@@ -34,4 +34,5 @@ job = {
34
34
  }
35
35
  }
36
36
 
37
- j = client.jobs.create(job)
37
+ new_job = client.jobs.create(job)
38
+ puts "new job created: #{new_job.inspect}"
@@ -0,0 +1,42 @@
1
+ require 'dotenv'
2
+ Dotenv.load '.env-fixer_client'
3
+
4
+ require 'fixer_client'
5
+ Fixer.reset!
6
+
7
+ # you also need AWS configured via ENV vars
8
+ # id, secret, and region for aws-adk-core to work
9
+ # AWS_ACCESS_KEY_ID
10
+ # AWS_SECRET_ACCESS_KEY
11
+ # AWS_REGION
12
+ # or they can be config options under the :aws config
13
+ # :access_key_id, :secret_access_key, and :region
14
+ Fixer.configure do |c|
15
+ c.client_id = ENV['FIXER_CLIENT_ID']
16
+ c.client_secret = ENV['FIXER_CLIENT_SECRET']
17
+ c.queue = 'development_fixer_job_create'
18
+ # c.aws = {
19
+ # access_key_id: 'AMADEUPKEYNOTREAL',
20
+ # secret_access_key: '11111111111111111111111',
21
+ # region: 'us-east-1'
22
+ # }
23
+ end
24
+
25
+ client = Fixer::SqsClient.new
26
+
27
+ job = {
28
+ job: {
29
+ original: 's3://test-fixer/audio.wav',
30
+ job_type: 'audio',
31
+ tasks: [
32
+ {
33
+ task_type: 'transcode',
34
+ options: { format: 'mp3', bit_rate: 64, sample_rate: 44100 },
35
+ result: 's3://test-fixer/audio.mp3'
36
+ }
37
+ ]
38
+ }
39
+ }
40
+
41
+ new_job = client.create_job(job)
42
+ puts "new job created with id: #{new_job.id}"
@@ -26,4 +26,5 @@ job = {
26
26
  }
27
27
  }
28
28
 
29
- j = client.jobs.create(job)
29
+ new_job = client.jobs.create(job)
30
+ puts "new job created: #{new_job.inspect}"
data/fixer_client.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency('excon')
26
26
  spec.add_runtime_dependency('hashie')
27
27
  spec.add_runtime_dependency('activesupport')
28
+ spec.add_runtime_dependency('aws-sdk-core')
28
29
 
29
30
  spec.add_development_dependency('bundler', '~> 1.3')
30
31
  spec.add_development_dependency('rake')
data/lib/fixer/api.rb CHANGED
@@ -19,13 +19,13 @@ module Fixer
19
19
  end
20
20
  end
21
21
 
22
- def initialize(options={}, &block)
22
+ def initialize(options = {})
23
23
  apply_options(options)
24
24
  yield(self) if block_given?
25
25
  end
26
26
 
27
- def apply_options(options={})
28
- self.current_options ||= ActiveSupport::HashWithIndifferentAccess.new(Fixer.options)
27
+ def apply_options(options = {})
28
+ self.current_options ||= Fixer.options.with_indifferent_access
29
29
  self.current_options = current_options.merge(args_to_options(options))
30
30
  Configuration.keys.each do |key|
31
31
  send("#{key}=", current_options[key])
@@ -97,4 +97,4 @@ module Fixer
97
97
  end
98
98
  end
99
99
  end
100
- end
100
+ end
data/lib/fixer/client.rb CHANGED
@@ -2,10 +2,8 @@
2
2
 
3
3
  module Fixer
4
4
  class Client < API
5
-
6
5
  def jobs(params={}, &block)
7
6
  @jobs ||= ApiFactory.api('Fixer::Jobs', self, params, &block)
8
7
  end
9
-
10
8
  end
11
9
  end
@@ -8,7 +8,9 @@ module Fixer
8
8
  :client_secret,
9
9
  :adapter,
10
10
  :endpoint,
11
- :user_agent
11
+ :user_agent,
12
+ :aws,
13
+ :queue
12
14
  ].freeze
13
15
 
14
16
  # Adapters are whatever Faraday supports - I like excon alot, so I'm defaulting it
@@ -20,6 +22,9 @@ module Fixer
20
22
  # The value sent in the http header for 'User-Agent' if none is set
21
23
  DEFAULT_USER_AGENT = "Fixer Ruby Gem #{Fixer::VERSION}".freeze
22
24
 
25
+ # sqs queue to write messages
26
+ DEFAULT_QUEUE = 'production_fixer_job_create'.freeze
27
+
23
28
  attr_accessor *VALID_OPTIONS_KEYS
24
29
 
25
30
  # Convenience method to allow for global setting of configuration options
@@ -50,6 +55,8 @@ module Fixer
50
55
  self.adapter = DEFAULT_ADAPTER
51
56
  self.endpoint = ENV['FIXER_ENDPOINT'] || DEFAULT_ENDPOINT
52
57
  self.user_agent = DEFAULT_USER_AGENT
58
+ self.aws = nil
59
+ self.queue = ENV['FIXER_QUEUE'] || DEFAULT_QUEUE
53
60
  self
54
61
  end
55
62
  end
data/lib/fixer/jobs.rb CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Fixer
4
4
  class Jobs < API
5
- include Configuration
6
-
7
5
  def tasks(params={}, &block)
8
6
  @jobs ||= ApiFactory.api('Fixer::Tasks', self, params, &block)
9
7
  end
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'aws-sdk-core'
4
+
5
+ module Fixer
6
+ class SqsClient
7
+ include Configuration
8
+
9
+ attr_accessor *Fixer::Configuration.keys
10
+
11
+ def create_job(job, opts = {})
12
+ job[:job][:id] ||= SecureRandom.uuid
13
+ job[:job][:client_id] ||= client_id
14
+
15
+ sqs_options = options.merge(opts)
16
+ sqs_queue = sqs_options[:queue]
17
+ conn = sqs(sqs_options[:aws])
18
+ queue_url = conn.get_queue_url(queue_name: sqs_queue).queue_url
19
+ conn.send_message(queue_url: queue_url, message_body: job.to_json)
20
+ job
21
+ end
22
+
23
+ def sqs(options = nil)
24
+ @sqs ||= Aws::SQS::Client.new(options)
25
+ end
26
+
27
+ def sqs=(sqs)
28
+ @sqs = sqs
29
+ end
30
+
31
+ def initialize(options = {})
32
+ apply_options(options)
33
+ yield(self) if block_given?
34
+ end
35
+
36
+ def apply_options(options = {})
37
+ current_options = Fixer.options.merge(options).with_indifferent_access
38
+ Fixer::Configuration.keys.each do |key|
39
+ send("#{key}=", current_options[key])
40
+ end
41
+ end
42
+ end
43
+ end
data/lib/fixer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fixer
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/fixer.rb CHANGED
@@ -7,6 +7,7 @@ require 'fixer/response'
7
7
  require 'fixer/api'
8
8
  require 'fixer/api_factory'
9
9
  require 'fixer/client'
10
+ require 'fixer/sqs_client'
10
11
  require 'fixer/jobs'
11
12
  require 'dotenv'
12
13
 
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest_helper'
4
+
5
+ describe Fixer::SqsClient do
6
+ let(:client) { Fixer::SqsClient.new }
7
+
8
+ let(:job_params) do
9
+ {
10
+ job: {
11
+ job_type: 'test',
12
+ priority: 1,
13
+ retry_max: 10,
14
+ retry_delay: 300,
15
+ tasks: [
16
+ sequence: {
17
+ tasks: [
18
+ {
19
+ task_type: 'echo',
20
+ label: 'test1',
21
+ options: { foo: 'bar' },
22
+ call_back: 'http://cms.prx.dev/call_back'
23
+ },
24
+ {
25
+ task_type: 'echo',
26
+ label: 'test2',
27
+ options: { bar: 'foo' },
28
+ call_back: 'http://cms.prx.dev/call_back',
29
+ result: 'http://cms.prx.dev/echo.txt'
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ end
37
+
38
+ let(:sqs) do
39
+ queue = Minitest::Mock.new
40
+ queue.expect(:queue_url, 'http://sqs.us-east-1.aws.amazon.com/test_fixer_callback')
41
+
42
+ sqs = Minitest::Mock.new
43
+ sqs.expect(:get_queue_url, queue, [Hash])
44
+ sqs.expect(:send_message, true, [Hash])
45
+ sqs
46
+ end
47
+
48
+ it 'makes a new client' do
49
+ client.must_be_instance_of Fixer::SqsClient
50
+ end
51
+
52
+ it 'sets config' do
53
+ client.client_id.must_equal '1111111111111111111111111111111111111111111111111111111111111111'
54
+ end
55
+
56
+ it 'creates a complex job, sets id and client id' do
57
+ client.sqs = sqs
58
+ j = client.create_job(job_params)
59
+ j[:job][:id].wont_be_nil
60
+ j[:job][:client_id].wont_be_nil
61
+ end
62
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixer_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kuklewicz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aws-sdk-core
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -214,6 +228,8 @@ extensions: []
214
228
  extra_rdoc_files: []
215
229
  files:
216
230
  - ".gitignore"
231
+ - ".hound.yml"
232
+ - ".rubocop.yml"
217
233
  - ".travis.yml"
218
234
  - Gemfile
219
235
  - LICENSE.txt
@@ -221,6 +237,7 @@ files:
221
237
  - Rakefile
222
238
  - examples/basic.rb
223
239
  - examples/sequence.rb
240
+ - examples/sqs_client.rb
224
241
  - examples/transcode.rb
225
242
  - fixer_client.gemspec
226
243
  - lib/fixer.rb
@@ -231,11 +248,13 @@ files:
231
248
  - lib/fixer/connection.rb
232
249
  - lib/fixer/jobs.rb
233
250
  - lib/fixer/response.rb
251
+ - lib/fixer/sqs_client.rb
234
252
  - lib/fixer/tasks.rb
235
253
  - lib/fixer/version.rb
236
254
  - lib/fixer_client.rb
237
255
  - test/files/audio.wav
238
256
  - test/fixer/client_test.rb
257
+ - test/fixer/sqs_client_test.rb
239
258
  - test/minitest_helper.rb
240
259
  homepage: https://github.org/PRX/fixer_client
241
260
  licenses:
@@ -264,4 +283,5 @@ summary: Client for the fixer application.
264
283
  test_files:
265
284
  - test/files/audio.wav
266
285
  - test/fixer/client_test.rb
286
+ - test/fixer/sqs_client_test.rb
267
287
  - test/minitest_helper.rb