fixer_client 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +11 -0
- data/examples/basic.rb +31 -0
- data/examples/transcode.rb +28 -0
- data/fixer_client.gemspec +35 -0
- data/lib/fixer/api.rb +100 -0
- data/lib/fixer/api_factory.rb +13 -0
- data/lib/fixer/client.rb +11 -0
- data/lib/fixer/configuration.rb +56 -0
- data/lib/fixer/connection.rb +59 -0
- data/lib/fixer/jobs.rb +11 -0
- data/lib/fixer/response.rb +61 -0
- data/lib/fixer/tasks.rb +3 -0
- data/lib/fixer/version.rb +3 -0
- data/lib/fixer.rb +15 -0
- data/lib/fixer_client.rb +8 -0
- data/test/files/audio.wav +0 -0
- data/test/fixer/client_test.rb +39 -0
- data/test/minitest_helper.rb +42 -0
- metadata +251 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f377f792a0d1175f3fa975ffdf31d2321664b79f
|
4
|
+
data.tar.gz: 4d551f74892ed7baa5e81c53a7594425def70b74
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c797e2e7d191b70e6399a0eea79e500a4364a7fa9e8193c24da7267273d6da2441088d461fc7ee6c8813d5ac8cf3c70e1aa60544bc142dfa273a59a460c5640
|
7
|
+
data.tar.gz: eaede9a0e2bc6d0b70435afb19851250c6baad1d27b976264c8b3988f0a135822ab8b97bb7117d231b0fae9354f9a2ecb6eacb9c13143340f50184c5b31d335d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Public Radio Exchange
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# FixerClient
|
2
|
+
|
3
|
+
Client lib for the fixer application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fixer_client'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fixer_client
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You need to configure the client credentials:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'fixer_client'
|
27
|
+
|
28
|
+
# by default it will get credentials from ENV
|
29
|
+
puts ENV['FIXER_CLIENT_ID'] + " is the id"
|
30
|
+
puts ENV['FIXER_CLIENT_SECRET'] + " is the secret"
|
31
|
+
|
32
|
+
# or set them explicitly
|
33
|
+
|
34
|
+
Fixer.configure do |c|
|
35
|
+
c.client_id = ''
|
36
|
+
c.client_secret = ''
|
37
|
+
c.endpoint = 'http://fixer.prx.dev/api/' # default
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Once configured, you can use the client to access jobs and tasks:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'fixer_client'
|
45
|
+
|
46
|
+
client = Fixer::Client.new
|
47
|
+
|
48
|
+
|
49
|
+
# list jobs
|
50
|
+
js = client.jobs.list
|
51
|
+
|
52
|
+
# get a particular job by id
|
53
|
+
j = client.jobs.get('some-job-id')
|
54
|
+
|
55
|
+
# update a job
|
56
|
+
j = client.jobs.update(j)
|
57
|
+
|
58
|
+
# create a job
|
59
|
+
job = {
|
60
|
+
job: {
|
61
|
+
job_type: 'test',
|
62
|
+
priority: 1,
|
63
|
+
retry_max: 10,
|
64
|
+
retry_delay: 300,
|
65
|
+
tasks: [
|
66
|
+
{
|
67
|
+
task_type: 'echo',
|
68
|
+
label: 'test1',
|
69
|
+
options: { foo: 'bar' },
|
70
|
+
call_back: 'http://cms.prx.dev/call_back'
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
}
|
75
|
+
j = client.jobs.create(job)
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. Fork it ( https://github.com/[my-github-username]/fixer_client/fork )
|
82
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
84
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
85
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/examples/basic.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
Dotenv.load '.env-fixer_client'
|
3
|
+
|
4
|
+
require 'fixer_client'
|
5
|
+
|
6
|
+
Fixer.configure do |c|
|
7
|
+
c.client_id = 'yourclientid'
|
8
|
+
c.client_secret = 'yoursecret'
|
9
|
+
c.endpoint = 'http://fixer.prx.dev/api/' # default
|
10
|
+
end
|
11
|
+
|
12
|
+
client = Fixer::Client.new
|
13
|
+
|
14
|
+
job = {
|
15
|
+
job: {
|
16
|
+
job_type: 'test',
|
17
|
+
priority: 1,
|
18
|
+
retry_max: 10,
|
19
|
+
retry_delay: 300,
|
20
|
+
tasks: [
|
21
|
+
{
|
22
|
+
task_type: 'echo',
|
23
|
+
label: 'test1',
|
24
|
+
options: { foo: 'bar' },
|
25
|
+
call_back: 'http://cms.prx.dev/call_back'
|
26
|
+
}
|
27
|
+
]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
j = client.jobs.create(job)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
Dotenv.load '.env-fixer_client'
|
3
|
+
|
4
|
+
require 'fixer_client'
|
5
|
+
|
6
|
+
Fixer.configure do |c|
|
7
|
+
c.client_id = ENV['FIXER_CLIENT_ID']
|
8
|
+
c.client_secret = ENV['FIXER_CLIENT_SECRET']
|
9
|
+
c.endpoint = 'http://fixer-dev.prx.dev/api/'
|
10
|
+
end
|
11
|
+
|
12
|
+
client = Fixer::Client.new
|
13
|
+
|
14
|
+
job = {
|
15
|
+
job: {
|
16
|
+
original: 's3://test-fixer/audio.wav',
|
17
|
+
job_type: 'audio',
|
18
|
+
tasks: [
|
19
|
+
{
|
20
|
+
task_type: 'transcode',
|
21
|
+
options: { format: 'mp3', bit_rate: 64, sample_rate: 44100 },
|
22
|
+
result: 's3://test-fixer/audio.mp3'
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
j = client.jobs.create(job)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fixer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'fixer_client'
|
8
|
+
spec.version = Fixer::VERSION
|
9
|
+
spec.authors = ['Andrew Kuklewicz']
|
10
|
+
spec.email = ['andrew@prx.org']
|
11
|
+
spec.summary = %q{Client for the fixer application.}
|
12
|
+
spec.description = %q{Client for the fixer application.}
|
13
|
+
spec.homepage = 'https://github.org/PRX/fixer_client'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency('faraday')
|
22
|
+
spec.add_runtime_dependency('faraday_middleware')
|
23
|
+
spec.add_runtime_dependency('oauth2')
|
24
|
+
spec.add_runtime_dependency('multi_json')
|
25
|
+
spec.add_runtime_dependency('excon')
|
26
|
+
spec.add_runtime_dependency('hashie')
|
27
|
+
spec.add_runtime_dependency('activesupport')
|
28
|
+
|
29
|
+
spec.add_development_dependency('bundler', '~> 1.3')
|
30
|
+
spec.add_development_dependency('rake')
|
31
|
+
spec.add_development_dependency('minitest')
|
32
|
+
spec.add_development_dependency('simplecov')
|
33
|
+
spec.add_development_dependency('webmock')
|
34
|
+
spec.add_development_dependency('dotenv')
|
35
|
+
end
|
data/lib/fixer/api.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Fixer
|
4
|
+
class API
|
5
|
+
|
6
|
+
include Configuration
|
7
|
+
include Connection
|
8
|
+
|
9
|
+
attr_reader *Fixer::Configuration.keys
|
10
|
+
|
11
|
+
attr_accessor :current_options
|
12
|
+
|
13
|
+
class_eval do
|
14
|
+
Fixer::Configuration.keys.each do |key|
|
15
|
+
define_method "#{key}=" do |arg|
|
16
|
+
self.instance_variable_set("@#{key}", arg)
|
17
|
+
self.current_options.merge!({:"#{key}" => arg})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(options={}, &block)
|
23
|
+
apply_options(options)
|
24
|
+
yield(self) if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def apply_options(options={})
|
28
|
+
self.current_options ||= ActiveSupport::HashWithIndifferentAccess.new(Fixer.options)
|
29
|
+
self.current_options = current_options.merge(args_to_options(options))
|
30
|
+
Configuration.keys.each do |key|
|
31
|
+
send("#{key}=", current_options[key])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(method, path, params={}) # :nodoc:
|
36
|
+
unless (method && [:get, :post, :put, :patch, :delete].include?(method))
|
37
|
+
raise ArgumentError, "whoops, that isn't a valid http method: #{method}"
|
38
|
+
end
|
39
|
+
|
40
|
+
conn = connection((params[:options] || {}).merge(current_options))
|
41
|
+
request_path = ('/' + conn.path_prefix + '/' + path).gsub(/\/+/, '/')
|
42
|
+
|
43
|
+
response = conn.send(method) do |request|
|
44
|
+
case method.to_sym
|
45
|
+
when :get, :delete
|
46
|
+
request.url(request_path, params)
|
47
|
+
when :post, :put
|
48
|
+
request.path = request_path
|
49
|
+
request.body = params[:data]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
Fixer::Response.new(response, {api: self, method: method, path: path, params: params})
|
53
|
+
end
|
54
|
+
|
55
|
+
def base_path
|
56
|
+
parts = self.class.name.split("::").inject([]){|a, c|
|
57
|
+
if c != 'Fixer'
|
58
|
+
base = c.underscore
|
59
|
+
a << base.tr('_','-')
|
60
|
+
a << current_options["#{base.singularize}_id"] if current_options["#{base.singularize}_id"]
|
61
|
+
end
|
62
|
+
a
|
63
|
+
}
|
64
|
+
parts.join('/') + '/'
|
65
|
+
end
|
66
|
+
|
67
|
+
def list(params={})
|
68
|
+
self.current_options = current_options.merge(args_to_options(params))
|
69
|
+
request(:get, base_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
def get(params={})
|
73
|
+
self.current_options = current_options.merge(args_to_options(params))
|
74
|
+
request(:get, base_path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def create(params={})
|
78
|
+
self.current_options = current_options.merge(args_to_options(params))
|
79
|
+
request(:post, base_path, {data: params})
|
80
|
+
end
|
81
|
+
|
82
|
+
def update(params={})
|
83
|
+
self.current_options = current_options.merge(args_to_options(params))
|
84
|
+
request(:put, base_path, {data: params})
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete(params={})
|
88
|
+
self.current_options = current_options.merge(args_to_options(params))
|
89
|
+
request(:delete, base_path)
|
90
|
+
end
|
91
|
+
|
92
|
+
def args_to_options(args)
|
93
|
+
params = if args.is_a?(String) || args.is_a?(Symbol) || args.is_a?(Numeric)
|
94
|
+
{"#{self.class.name.demodulize.downcase.singularize}_id" => args.to_s}
|
95
|
+
elsif args.is_a?(Hash)
|
96
|
+
args
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/fixer/client.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Fixer
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:client_id,
|
8
|
+
:client_secret,
|
9
|
+
:adapter,
|
10
|
+
:endpoint,
|
11
|
+
:user_agent,
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
# Adapters are whatever Faraday supports - I like excon alot, so I'm defaulting it
|
15
|
+
DEFAULT_ADAPTER = :excon
|
16
|
+
|
17
|
+
# The api endpoint to get REST
|
18
|
+
DEFAULT_ENDPOINT = 'http://fixer.prx.dev/api/'.freeze
|
19
|
+
|
20
|
+
# The value sent in the http header for 'User-Agent' if none is set
|
21
|
+
DEFAULT_USER_AGENT = "Fixer Ruby Gem #{Fixer::VERSION}".freeze
|
22
|
+
|
23
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
24
|
+
|
25
|
+
# Convenience method to allow for global setting of configuration options
|
26
|
+
def configure
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.extended(base)
|
31
|
+
base.reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def keys
|
36
|
+
VALID_OPTIONS_KEYS
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def options
|
41
|
+
options = {}
|
42
|
+
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
43
|
+
options
|
44
|
+
end
|
45
|
+
|
46
|
+
# Reset configuration options to their defaults
|
47
|
+
def reset!
|
48
|
+
self.client_id = ENV['FIXER_CLIENT_ID']
|
49
|
+
self.client_secret = ENV['FIXER_CLIENT_SECRET']
|
50
|
+
self.adapter = DEFAULT_ADAPTER
|
51
|
+
self.endpoint = ENV['FIXER_ENDPOINT'] || DEFAULT_ENDPOINT
|
52
|
+
self.user_agent = DEFAULT_USER_AGENT
|
53
|
+
self
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require 'oauth2'
|
5
|
+
|
6
|
+
module Fixer
|
7
|
+
module Connection
|
8
|
+
|
9
|
+
ALLOWED_OPTIONS = [
|
10
|
+
:headers,
|
11
|
+
:url,
|
12
|
+
:params,
|
13
|
+
:request,
|
14
|
+
:ssl,
|
15
|
+
:proxy
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
def process_options(opts={})
|
19
|
+
headers = opts.delete(:headers) || {}
|
20
|
+
options = {
|
21
|
+
headers: {
|
22
|
+
# generic http headers
|
23
|
+
'User-Agent' => user_agent,
|
24
|
+
'Accept' => "application/json;charset=utf-8"
|
25
|
+
},
|
26
|
+
ssl: { verify: false },
|
27
|
+
url: endpoint
|
28
|
+
}.merge(opts)
|
29
|
+
options[:headers] = options[:headers].merge(headers)
|
30
|
+
|
31
|
+
options.select{|k,v| ALLOWED_OPTIONS.include?(k.to_sym)}
|
32
|
+
end
|
33
|
+
|
34
|
+
def connection(opts={})
|
35
|
+
@token ||= get_token(opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
def connection(options={})
|
39
|
+
Faraday::Connection.new(process_options(options)) do |connection|
|
40
|
+
connection.request :authorization, 'Bearer', get_token(options).token
|
41
|
+
connection.request :url_encoded
|
42
|
+
connection.response :mashify
|
43
|
+
connection.response :logger if options[:debug]
|
44
|
+
connection.response :json
|
45
|
+
connection.adapter adapter
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_token(opts)
|
50
|
+
opts = process_options(options)
|
51
|
+
opts[:site] = opts.delete(:url)
|
52
|
+
@token ||= OAuth2::Client.new(client_id, client_secret, opts) do |connection|
|
53
|
+
connection.request :url_encoded
|
54
|
+
connection.response :logger if options[:debug]
|
55
|
+
connection.adapter adapter
|
56
|
+
end.client_credentials.get_token
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/fixer/jobs.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Fixer
|
4
|
+
class Response
|
5
|
+
attr_accessor :raw, :request
|
6
|
+
|
7
|
+
def initialize(response, request={})
|
8
|
+
@raw = response
|
9
|
+
@request = request
|
10
|
+
|
11
|
+
check_for_error(response)
|
12
|
+
end
|
13
|
+
|
14
|
+
def check_for_error(response)
|
15
|
+
status_code_type = response.status.to_s[0]
|
16
|
+
case status_code_type
|
17
|
+
when "2"
|
18
|
+
# puts "all is well, status: #{response.status}"
|
19
|
+
when "4", "5"
|
20
|
+
raise "Whoops, error back from Fixer: #{response.status}"
|
21
|
+
else
|
22
|
+
raise "Unrecognized status code: #{response.status}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def body
|
27
|
+
self.raw.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def object
|
31
|
+
body
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](key)
|
35
|
+
if self.object.is_a?(Array) || self.object.is_a?(Hash)
|
36
|
+
self.object[key]
|
37
|
+
else
|
38
|
+
self.object.send(:"#{key}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_key?(key)
|
43
|
+
self.object.is_a?(Hash) && self.object.has_key?(key)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Coerce any method calls for body attributes
|
47
|
+
#
|
48
|
+
def method_missing(method_name, *args, &block)
|
49
|
+
if self.has_key?(method_name.to_s)
|
50
|
+
self.[](method_name, &block)
|
51
|
+
elsif self.body.respond_to?(method_name)
|
52
|
+
self.body.send(method_name, *args, &block)
|
53
|
+
elsif self.request[:api].respond_to?(method_name)
|
54
|
+
self.request[:api].send(method_name, *args, &block)
|
55
|
+
else
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/fixer/tasks.rb
ADDED
data/lib/fixer.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require "fixer/version"
|
4
|
+
require 'fixer/configuration'
|
5
|
+
require 'fixer/connection'
|
6
|
+
require 'fixer/response'
|
7
|
+
require 'fixer/api'
|
8
|
+
require 'fixer/api_factory'
|
9
|
+
require 'fixer/client'
|
10
|
+
require 'fixer/jobs'
|
11
|
+
require 'dotenv'
|
12
|
+
|
13
|
+
module Fixer
|
14
|
+
extend Configuration
|
15
|
+
end
|
data/lib/fixer_client.rb
ADDED
Binary file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'minitest_helper'
|
4
|
+
|
5
|
+
describe Fixer::Client do
|
6
|
+
|
7
|
+
let(:client) { Fixer::Client.new }
|
8
|
+
|
9
|
+
let(:job) do
|
10
|
+
{
|
11
|
+
job: {
|
12
|
+
job_type: 'test',
|
13
|
+
priority: 1,
|
14
|
+
retry_max: 10,
|
15
|
+
retry_delay: 300,
|
16
|
+
tasks: [
|
17
|
+
{
|
18
|
+
task_type: 'echo',
|
19
|
+
label: 'test1',
|
20
|
+
options: { foo: 'bar' },
|
21
|
+
call_back: 'http://cms.prx.dev/call_back'
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'makes a new client' do
|
29
|
+
client.must_be_instance_of Fixer::Client
|
30
|
+
end
|
31
|
+
|
32
|
+
# it 'gets a list of jobs' do
|
33
|
+
# stub_request(:post, "http://fixer.prx.dev/oauth/token").
|
34
|
+
# with(:body => {"grant_type"=>"client_credentials"}).
|
35
|
+
# to_return(:status => 200, :body => "", :headers => {})
|
36
|
+
|
37
|
+
# jobs = client.jobs.list
|
38
|
+
# end
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'dotenv'
|
7
|
+
Dotenv.load '.env-fixer_client'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
10
|
+
|
11
|
+
require 'minitest'
|
12
|
+
require 'minitest/autorun'
|
13
|
+
require 'minitest/spec'
|
14
|
+
require 'minitest/mock'
|
15
|
+
require 'fileutils'
|
16
|
+
require 'active_support'
|
17
|
+
require 'webmock/minitest'
|
18
|
+
require 'hashie/mash'
|
19
|
+
|
20
|
+
require 'fixer_client'
|
21
|
+
|
22
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
23
|
+
|
24
|
+
# helper method to create mashified test docs, that look like what comes out of the faraday middleware
|
25
|
+
def mashify(body)
|
26
|
+
case body
|
27
|
+
when Hash
|
28
|
+
::Hashie::Mash.new(body)
|
29
|
+
when Array
|
30
|
+
body.map { |item| parse(item) }
|
31
|
+
else
|
32
|
+
body
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def json_fixture(name)
|
37
|
+
mashify(JSON.parse(json_file(name)))
|
38
|
+
end
|
39
|
+
|
40
|
+
def json_file(name)
|
41
|
+
File.read( File.dirname(__FILE__) + "/fixtures/#{name}.json")
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fixer_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Kuklewicz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oauth2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: excon
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hashie
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: minitest
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: dotenv
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: Client for the fixer application.
|
196
|
+
email:
|
197
|
+
- andrew@prx.org
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- ".gitignore"
|
203
|
+
- Gemfile
|
204
|
+
- LICENSE.txt
|
205
|
+
- README.md
|
206
|
+
- Rakefile
|
207
|
+
- examples/basic.rb
|
208
|
+
- examples/transcode.rb
|
209
|
+
- fixer_client.gemspec
|
210
|
+
- lib/fixer.rb
|
211
|
+
- lib/fixer/api.rb
|
212
|
+
- lib/fixer/api_factory.rb
|
213
|
+
- lib/fixer/client.rb
|
214
|
+
- lib/fixer/configuration.rb
|
215
|
+
- lib/fixer/connection.rb
|
216
|
+
- lib/fixer/jobs.rb
|
217
|
+
- lib/fixer/response.rb
|
218
|
+
- lib/fixer/tasks.rb
|
219
|
+
- lib/fixer/version.rb
|
220
|
+
- lib/fixer_client.rb
|
221
|
+
- test/files/audio.wav
|
222
|
+
- test/fixer/client_test.rb
|
223
|
+
- test/minitest_helper.rb
|
224
|
+
homepage: https://github.org/PRX/fixer_client
|
225
|
+
licenses:
|
226
|
+
- MIT
|
227
|
+
metadata: {}
|
228
|
+
post_install_message:
|
229
|
+
rdoc_options: []
|
230
|
+
require_paths:
|
231
|
+
- lib
|
232
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
version: '0'
|
242
|
+
requirements: []
|
243
|
+
rubyforge_project:
|
244
|
+
rubygems_version: 2.2.3
|
245
|
+
signing_key:
|
246
|
+
specification_version: 4
|
247
|
+
summary: Client for the fixer application.
|
248
|
+
test_files:
|
249
|
+
- test/files/audio.wav
|
250
|
+
- test/fixer/client_test.rb
|
251
|
+
- test/minitest_helper.rb
|