relax 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +63 -0
- data/Gemfile +3 -0
- data/LICENSE +3 -1
- data/README.md +80 -0
- data/Rakefile +2 -52
- data/examples/delicious.rb +61 -0
- data/examples/flickr.rb +66 -0
- data/examples/vimeo.rb +65 -0
- data/lib/relax.rb +6 -16
- data/lib/relax/client.rb +18 -0
- data/lib/relax/config.rb +12 -0
- data/lib/relax/delegator.rb +25 -0
- data/lib/relax/resource.rb +32 -0
- data/lib/relax/version.rb +3 -0
- data/relax.gemspec +17 -0
- data/spec/relax/client_spec.rb +39 -0
- data/spec/relax/config_spec.rb +17 -0
- data/spec/relax/delegator_spec.rb +32 -0
- data/spec/relax/resource_spec.rb +60 -0
- data/spec/spec_helper.rb +9 -13
- metadata +75 -96
- data/README.rdoc +0 -194
- data/VERSION.yml +0 -4
- data/lib/relax/action.rb +0 -49
- data/lib/relax/context.rb +0 -46
- data/lib/relax/contextable.rb +0 -15
- data/lib/relax/endpoint.rb +0 -21
- data/lib/relax/instance.rb +0 -25
- data/lib/relax/parameter.rb +0 -23
- data/lib/relax/performer.rb +0 -58
- data/lib/relax/service.rb +0 -45
- data/spec/relax/context_spec.rb +0 -18
- data/spec/relax/endpoint_spec.rb +0 -99
- data/spec/relax/integration_spec.rb +0 -63
- data/spec/relax/service_spec.rb +0 -32
- data/spec/services/blank_values_service.rb +0 -19
- data/spec/services/custom_parser_service.rb +0 -24
- data/spec/services/flickr.rb +0 -78
- data/spec/services/parameter_alias_service.rb +0 -17
data/lib/relax/client.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Relax
|
4
|
+
module Client
|
5
|
+
USER_AGENT = "Relax Ruby Gem Client #{Relax::VERSION}"
|
6
|
+
|
7
|
+
def config
|
8
|
+
@config ||= Config.new.configure do |config|
|
9
|
+
config.adapter = Faraday.default_adapter
|
10
|
+
config.user_agent = USER_AGENT
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(&block)
|
15
|
+
config.configure(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/relax/config.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Relax
|
2
|
+
module Delegator
|
3
|
+
def self.[](client_method)
|
4
|
+
Module.new do
|
5
|
+
include ClassMethods
|
6
|
+
|
7
|
+
define_method(:client_instance) { send(client_method) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def respond_to?(method, include_private=false)
|
13
|
+
super || client_instance.respond_to?(method, include_private)
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(method, *args, &block)
|
17
|
+
if client_instance.respond_to?(method)
|
18
|
+
client_instance.send(method, *args, &block)
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Relax
|
4
|
+
module Resource
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
delegate Faraday::Connection::METHODS => :connection
|
8
|
+
private *Faraday::Connection::METHODS
|
9
|
+
|
10
|
+
def initialize(client, options={})
|
11
|
+
@client = client
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def connection(options={})
|
16
|
+
options[:url] ||= config.base_uri
|
17
|
+
options[:headers] ||= {}
|
18
|
+
options[:headers][:user_agent] ||= config.user_agent
|
19
|
+
|
20
|
+
Faraday.new(options) do |builder|
|
21
|
+
yield(builder) if block_given?
|
22
|
+
builder.adapter(config.adapter)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
private :connection
|
26
|
+
|
27
|
+
def config
|
28
|
+
@client.config
|
29
|
+
end
|
30
|
+
private :config
|
31
|
+
end
|
32
|
+
end
|
data/relax.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require './lib/relax/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'relax'
|
5
|
+
gem.version = Relax::VERSION
|
6
|
+
gem.summary = 'A flexible library for creating web service consumers.'
|
7
|
+
gem.homepage = 'http://github.com/tylerhunt/relax'
|
8
|
+
gem.author = 'Tyler Hunt'
|
9
|
+
|
10
|
+
gem.add_dependency 'faraday', '~> 0.8.0'
|
11
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relax::Client do
|
4
|
+
let(:client) { Class.new { include Relax::Client }.new }
|
5
|
+
|
6
|
+
subject { client }
|
7
|
+
|
8
|
+
context '#config' do
|
9
|
+
it 'returns an instance of Relax::Config' do
|
10
|
+
subject.config.should be_a(Relax::Config)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'memoizes the configuration' do
|
14
|
+
subject.config.should == subject.config
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'defaults' do
|
18
|
+
subject { client.config }
|
19
|
+
|
20
|
+
its(:adapter) { should == Faraday.default_adapter }
|
21
|
+
its(:base_uri) { should be_nil }
|
22
|
+
its(:user_agent) { should == "Relax Ruby Gem Client #{Relax::VERSION}" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '#configure' do
|
27
|
+
it 'yields an instance of the configuration' do
|
28
|
+
expect {
|
29
|
+
subject.configure do |config|
|
30
|
+
config.base_uri = 'http://api.example.com/v2'
|
31
|
+
end
|
32
|
+
}.to change(subject.config, :base_uri).to('http://api.example.com/v2')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the configuration' do
|
36
|
+
subject.configure { }.should == subject.config
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relax::Config do
|
4
|
+
context '#configure' do
|
5
|
+
it 'yields an instance of the configuration' do
|
6
|
+
expect {
|
7
|
+
subject.configure do |config|
|
8
|
+
config.base_uri = 'http://api.example.com/v2'
|
9
|
+
end
|
10
|
+
}.to change(subject, :base_uri).to('http://api.example.com/v2')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns the configuration' do
|
14
|
+
subject.configure { }.should == subject
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relax::Delegator do
|
4
|
+
let(:client) { Class.new { include Relax::Client } }
|
5
|
+
|
6
|
+
subject do
|
7
|
+
Class.new do
|
8
|
+
extend Relax::Delegator[:client]
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr :client, true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
before { subject.client = client.new }
|
17
|
+
|
18
|
+
context '.[]' do
|
19
|
+
it 'accepts a client method name and returns a module' do
|
20
|
+
described_class[:client].should be_a(Module)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'delegation' do
|
25
|
+
Relax::Client.instance_methods.each do |method|
|
26
|
+
it "delegates .#{method} to the client" do
|
27
|
+
subject.client.should_receive(method)
|
28
|
+
subject.send(method)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relax::Resource do
|
4
|
+
let(:client) do
|
5
|
+
Class.new do
|
6
|
+
include Relax::Client
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
config.base_uri = 'http://api.example.com/v2'
|
10
|
+
end
|
11
|
+
end.new
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:resource_class) { Class.new { include Relax::Resource } }
|
15
|
+
|
16
|
+
subject { resource_class.new(client) }
|
17
|
+
|
18
|
+
context '.new' do
|
19
|
+
it 'accepts an options hash' do
|
20
|
+
resource_class.new(client, key: :value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context '#connection' do
|
25
|
+
let(:connection) { subject.send(:connection) }
|
26
|
+
|
27
|
+
it 'returns an instance of Faraday::Connection' do
|
28
|
+
connection.should be_a(Faraday::Connection)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'uses the configured base URI as the URL' do
|
32
|
+
connection.url_prefix.should == URI.parse(client.config.base_uri)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'accepts an options hash to be passed to Faraday::Connection' do
|
36
|
+
headers = { user_agent: "#{described_class} Test" }
|
37
|
+
connection = subject.send(:connection, headers: headers)
|
38
|
+
connection.headers['User-Agent'].should == headers[:user_agent]
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'yields a builder to allow the middleware to be customized' do
|
42
|
+
subject.send(:connection) do |builder|
|
43
|
+
builder.use(Faraday::Response::Logger)
|
44
|
+
end.builder.handlers.should include(Faraday::Response::Logger)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'connection delegation' do
|
49
|
+
let(:connection) { stub(:connection) }
|
50
|
+
|
51
|
+
before { subject.stub(:connection).and_return(connection) }
|
52
|
+
|
53
|
+
Faraday::Connection::METHODS.each do |method|
|
54
|
+
it "delegates ##{method} to #connection" do
|
55
|
+
connection.should_receive(method)
|
56
|
+
subject.send(method)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
|
1
|
+
require 'relax'
|
2
2
|
|
3
|
-
|
3
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |file|
|
4
|
+
require(file)
|
5
|
+
end
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require File.join(File.dirname(__FILE__), '..', 'lib', 'relax')
|
12
|
-
require File.join(File.dirname(__FILE__), 'services', 'flickr')
|
13
|
-
require File.join(File.dirname(__FILE__), 'services', 'custom_parser_service')
|
14
|
-
require File.join(File.dirname(__FILE__), 'services', 'parameter_alias_service')
|
15
|
-
require File.join(File.dirname(__FILE__), 'services', 'blank_values_service')
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
metadata
CHANGED
@@ -1,124 +1,103 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: relax
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Tyler Hunt
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: relief
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.0
|
27
22
|
type: :runtime
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
|
31
|
-
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.4
|
34
|
-
version:
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: jeweler
|
37
|
-
type: :development
|
38
|
-
version_requirement:
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
41
27
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.
|
44
|
-
|
45
|
-
- !ruby/object:Gem::Dependency
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
46
31
|
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.6'
|
47
38
|
type: :development
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
51
43
|
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
version:
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.6'
|
55
46
|
description:
|
56
|
-
email:
|
47
|
+
email:
|
57
48
|
executables: []
|
58
|
-
|
59
49
|
extensions: []
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
-
|
64
|
-
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- .rspec
|
54
|
+
- CHANGELOG.md
|
55
|
+
- Gemfile
|
65
56
|
- LICENSE
|
66
|
-
- README.
|
57
|
+
- README.md
|
67
58
|
- Rakefile
|
68
|
-
-
|
59
|
+
- examples/delicious.rb
|
60
|
+
- examples/flickr.rb
|
61
|
+
- examples/vimeo.rb
|
69
62
|
- lib/relax.rb
|
70
|
-
- lib/relax/
|
71
|
-
- lib/relax/
|
72
|
-
- lib/relax/
|
73
|
-
- lib/relax/
|
74
|
-
- lib/relax/
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
- spec/relax/
|
79
|
-
- spec/relax/
|
80
|
-
- spec/relax/integration_spec.rb
|
81
|
-
- spec/relax/service_spec.rb
|
82
|
-
- spec/services/blank_values_service.rb
|
83
|
-
- spec/services/custom_parser_service.rb
|
84
|
-
- spec/services/flickr.rb
|
85
|
-
- spec/services/parameter_alias_service.rb
|
63
|
+
- lib/relax/client.rb
|
64
|
+
- lib/relax/config.rb
|
65
|
+
- lib/relax/delegator.rb
|
66
|
+
- lib/relax/resource.rb
|
67
|
+
- lib/relax/version.rb
|
68
|
+
- relax.gemspec
|
69
|
+
- spec/relax/client_spec.rb
|
70
|
+
- spec/relax/config_spec.rb
|
71
|
+
- spec/relax/delegator_spec.rb
|
72
|
+
- spec/relax/resource_spec.rb
|
86
73
|
- spec/spec_helper.rb
|
87
|
-
has_rdoc: true
|
88
74
|
homepage: http://github.com/tylerhunt/relax
|
89
75
|
licenses: []
|
90
|
-
|
91
76
|
post_install_message:
|
92
|
-
rdoc_options:
|
93
|
-
|
94
|
-
require_paths:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
95
79
|
- lib
|
96
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
108
92
|
requirements: []
|
109
|
-
|
110
|
-
|
111
|
-
rubygems_version: 1.3.5
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.24
|
112
95
|
signing_key:
|
113
96
|
specification_version: 3
|
114
97
|
summary: A flexible library for creating web service consumers.
|
115
|
-
test_files:
|
116
|
-
- spec/relax/
|
117
|
-
- spec/relax/
|
118
|
-
- spec/relax/
|
119
|
-
- spec/relax/
|
120
|
-
- spec/services/blank_values_service.rb
|
121
|
-
- spec/services/custom_parser_service.rb
|
122
|
-
- spec/services/flickr.rb
|
123
|
-
- spec/services/parameter_alias_service.rb
|
98
|
+
test_files:
|
99
|
+
- spec/relax/client_spec.rb
|
100
|
+
- spec/relax/config_spec.rb
|
101
|
+
- spec/relax/delegator_spec.rb
|
102
|
+
- spec/relax/resource_spec.rb
|
124
103
|
- spec/spec_helper.rb
|