frenetic 0.0.12 → 0.0.20.alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.irbrc +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +0 -1
- data/Gemfile +1 -3
- data/README.md +138 -125
- data/frenetic.gemspec +5 -6
- data/lib/frenetic.rb +31 -43
- data/lib/frenetic/concerns/collection_rest_methods.rb +13 -0
- data/lib/frenetic/concerns/configurable.rb +59 -0
- data/lib/frenetic/concerns/hal_linked.rb +59 -0
- data/lib/frenetic/concerns/member_rest_methods.rb +15 -0
- data/lib/frenetic/concerns/structured.rb +53 -0
- data/lib/frenetic/configuration.rb +40 -76
- data/lib/frenetic/middleware/hal_json.rb +23 -0
- data/lib/frenetic/resource.rb +77 -62
- data/lib/frenetic/resource_collection.rb +46 -0
- data/lib/frenetic/version.rb +2 -2
- data/spec/concerns/configurable_spec.rb +50 -0
- data/spec/concerns/hal_linked_spec.rb +116 -0
- data/spec/concerns/member_rest_methods_spec.rb +41 -0
- data/spec/concerns/structured_spec.rb +214 -0
- data/spec/configuration_spec.rb +99 -0
- data/spec/fixtures/test_api_requests.rb +88 -0
- data/spec/frenetic_spec.rb +137 -0
- data/spec/middleware/hal_json_spec.rb +83 -0
- data/spec/resource_collection_spec.rb +80 -0
- data/spec/resource_spec.rb +211 -0
- data/spec/spec_helper.rb +4 -13
- data/spec/support/rspec.rb +5 -0
- data/spec/support/webmock.rb +3 -0
- metadata +59 -57
- data/.rvmrc +0 -1
- data/lib/frenetic/hal_json.rb +0 -23
- data/lib/frenetic/hal_json/response_wrapper.rb +0 -43
- data/lib/recursive_open_struct.rb +0 -79
- data/spec/fixtures/vcr_cassettes/description_error_unauthorized.yml +0 -36
- data/spec/fixtures/vcr_cassettes/description_success.yml +0 -38
- data/spec/lib/frenetic/configuration_spec.rb +0 -189
- data/spec/lib/frenetic/hal_json/response_wrapper_spec.rb +0 -70
- data/spec/lib/frenetic/hal_json_spec.rb +0 -68
- data/spec/lib/frenetic/resource_spec.rb +0 -182
- data/spec/lib/frenetic_spec.rb +0 -129
@@ -0,0 +1,211 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Frenetic::Resource do
|
4
|
+
let(:test_cfg) { { url:'http://example.com/api' } }
|
5
|
+
|
6
|
+
let(:my_temp_resource) do
|
7
|
+
cfg = test_cfg
|
8
|
+
|
9
|
+
Class.new(described_class) do
|
10
|
+
api_client { Frenetic.new(cfg) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
stub_const 'MyNamespace::MyTempResource', my_temp_resource
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.api_client' do
|
19
|
+
context 'calling with' do
|
20
|
+
def configure_with_block!
|
21
|
+
cfg_copy = test_cfg
|
22
|
+
|
23
|
+
MyNamespace::MyTempResource.class_eval do
|
24
|
+
api_client { Frenetic.new(cfg_copy) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure_with_instance!
|
29
|
+
cfg_copy = test_cfg
|
30
|
+
|
31
|
+
MyNamespace::MyTempResource.class_eval do
|
32
|
+
api_client Frenetic.new(cfg_copy)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'a block argument' do
|
37
|
+
before do
|
38
|
+
configure_with_block!
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { MyNamespace::MyTempResource.instance_variable_get '@api_client' }
|
42
|
+
|
43
|
+
it 'should save a reference to the argument' do
|
44
|
+
subject.should be_a Proc
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'a Frenetic instance' do
|
49
|
+
before do
|
50
|
+
configure_with_instance!
|
51
|
+
end
|
52
|
+
|
53
|
+
subject { MyNamespace::MyTempResource.instance_variable_get '@api_client' }
|
54
|
+
|
55
|
+
it 'should save a reference to the argument' do
|
56
|
+
subject.should be_an_instance_of Frenetic
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'no argument' do
|
61
|
+
subject { MyNamespace::MyTempResource.api_client }
|
62
|
+
|
63
|
+
context 'and a previously stored @api_client' do
|
64
|
+
context 'Proc' do
|
65
|
+
before do
|
66
|
+
configure_with_block!
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should call the Proc' do
|
70
|
+
MyNamespace::MyTempResource.instance_variable_get('@api_client')
|
71
|
+
.should_receive 'call'
|
72
|
+
|
73
|
+
subject
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'Frenetic instance' do
|
78
|
+
before do
|
79
|
+
configure_with_instance!
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should return the instance' do
|
83
|
+
subject.should be_an_instance_of Frenetic
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '.namespace' do
|
92
|
+
before do
|
93
|
+
stub_const 'MyNamespace::MyTempResource', my_temp_resource
|
94
|
+
end
|
95
|
+
|
96
|
+
subject { MyNamespace::MyTempResource.namespace }
|
97
|
+
|
98
|
+
context 'with an argument' do
|
99
|
+
before do
|
100
|
+
MyNamespace::MyTempResource.class_eval do
|
101
|
+
namespace :test_spec
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should return that value' do
|
106
|
+
subject.should == 'test_spec'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should internally save the value' do
|
110
|
+
subject
|
111
|
+
|
112
|
+
ns = MyNamespace::MyTempResource.instance_variable_get '@namespace'
|
113
|
+
|
114
|
+
ns.should == 'test_spec'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'with no argument' do
|
119
|
+
it 'should infer the value' do
|
120
|
+
subject.should == 'my_temp_resource'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should cache the inferrence' do
|
124
|
+
subject
|
125
|
+
|
126
|
+
ns = MyNamespace::MyTempResource.instance_variable_get '@namespace'
|
127
|
+
|
128
|
+
ns.should == 'my_temp_resource'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '.properties' do
|
134
|
+
before { @stubs.api_description }
|
135
|
+
|
136
|
+
subject { MyNamespace::MyTempResource.properties }
|
137
|
+
|
138
|
+
context 'for a known resource' do
|
139
|
+
it 'should return a list of properties defined by the API' do
|
140
|
+
subject.should_not be_empty
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'for an unknown resource' do
|
145
|
+
before do
|
146
|
+
MyNamespace::MyTempResource.stub(:namespace).and_return Time.now.to_i.to_s
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should raise an error' do
|
150
|
+
expect{ subject }.to raise_error Frenetic::HypermediaError
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#initialize' do
|
156
|
+
before { @stubs.api_description }
|
157
|
+
|
158
|
+
subject { MyNamespace::MyTempResource.new args }
|
159
|
+
|
160
|
+
context 'with no arguments' do
|
161
|
+
let(:args) {}
|
162
|
+
|
163
|
+
it 'should have default attributes' do
|
164
|
+
subject.name.should be_nil
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'with known attributes' do
|
169
|
+
let(:args) { { name:'foo' } }
|
170
|
+
|
171
|
+
it 'should set the appropriate values' do
|
172
|
+
subject.name.should == 'foo'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'with unknown attributes' do
|
177
|
+
let(:args) { { gender:'male' } }
|
178
|
+
|
179
|
+
it 'should not create accessors' do
|
180
|
+
expect{ subject.gender }.to raise_error NoMethodError
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should be accessible in @params' do
|
184
|
+
params = subject.instance_variable_get( '@params' )
|
185
|
+
|
186
|
+
params.should include 'gender' => 'male'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'for a schemaless resource' do
|
191
|
+
let(:args) {}
|
192
|
+
|
193
|
+
before do
|
194
|
+
MyNamespace::MyTempResource.stub(:namespace).and_return Time.now.to_i.to_s
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should raise an error' do
|
198
|
+
expect{ subject }.to raise_error Frenetic::HypermediaError
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe '#attributes' do
|
204
|
+
before { @stubs.api_description }
|
205
|
+
|
206
|
+
subject { MyNamespace::MyTempResource.new(name:'me').attributes }
|
207
|
+
|
208
|
+
it { should == { 'name' => 'me' } }
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
|
3
|
-
require 'rspec'
|
4
3
|
require 'awesome_print'
|
5
|
-
require '
|
6
|
-
require 'patron'
|
4
|
+
require 'rspec'
|
7
5
|
require 'frenetic'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
-
end
|
14
|
-
|
15
|
-
VCR.configure do |c|
|
16
|
-
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
17
|
-
c.hook_into :webmock
|
18
|
-
end
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
Dir['./spec/support/**/*.rb'].each {|f| require f}
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frenetic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.20.alpha.0
|
5
|
+
prerelease: 7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Derek Lindahl
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.8.
|
21
|
+
version: 0.8.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.8.
|
29
|
+
version: 0.8.7
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: faraday_middleware
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '3'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,23 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rack-cache
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '1.1'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '1.1'
|
61
|
+
version: '3'
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: addressable
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +66,7 @@ dependencies:
|
|
82
66
|
requirements:
|
83
67
|
- - ~>
|
84
68
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
69
|
+
version: 2.3.4
|
86
70
|
type: :runtime
|
87
71
|
prerelease: false
|
88
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,23 +74,23 @@ dependencies:
|
|
90
74
|
requirements:
|
91
75
|
- - ~>
|
92
76
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
77
|
+
version: 2.3.4
|
94
78
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
79
|
+
name: awesome_print
|
96
80
|
requirement: !ruby/object:Gem::Requirement
|
97
81
|
none: false
|
98
82
|
requirements:
|
99
|
-
- -
|
83
|
+
- - ! '>='
|
100
84
|
- !ruby/object:Gem::Version
|
101
|
-
version: 0
|
85
|
+
version: '0'
|
102
86
|
type: :development
|
103
87
|
prerelease: false
|
104
88
|
version_requirements: !ruby/object:Gem::Requirement
|
105
89
|
none: false
|
106
90
|
requirements:
|
107
|
-
- -
|
91
|
+
- - ! '>='
|
108
92
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0
|
93
|
+
version: '0'
|
110
94
|
- !ruby/object:Gem::Dependency
|
111
95
|
name: rspec
|
112
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,13 +108,13 @@ dependencies:
|
|
124
108
|
- !ruby/object:Gem::Version
|
125
109
|
version: 2.13.0
|
126
110
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
111
|
+
name: rack-cache
|
128
112
|
requirement: !ruby/object:Gem::Requirement
|
129
113
|
none: false
|
130
114
|
requirements:
|
131
115
|
- - ~>
|
132
116
|
- !ruby/object:Gem::Version
|
133
|
-
version: 1.
|
117
|
+
version: '1.2'
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -138,15 +122,15 @@ dependencies:
|
|
138
122
|
requirements:
|
139
123
|
- - ~>
|
140
124
|
- !ruby/object:Gem::Version
|
141
|
-
version: 1.
|
125
|
+
version: '1.2'
|
142
126
|
- !ruby/object:Gem::Dependency
|
143
|
-
name:
|
127
|
+
name: webmock
|
144
128
|
requirement: !ruby/object:Gem::Requirement
|
145
129
|
none: false
|
146
130
|
requirements:
|
147
131
|
- - ~>
|
148
132
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
133
|
+
version: 1.11.0
|
150
134
|
type: :development
|
151
135
|
prerelease: false
|
152
136
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -154,7 +138,7 @@ dependencies:
|
|
154
138
|
requirements:
|
155
139
|
- - ~>
|
156
140
|
- !ruby/object:Gem::Version
|
157
|
-
version:
|
141
|
+
version: 1.11.0
|
158
142
|
description: An opinionated Ruby-based Hypermedia API client.
|
159
143
|
email:
|
160
144
|
- dlindahl@customink.com
|
@@ -163,7 +147,8 @@ extensions: []
|
|
163
147
|
extra_rdoc_files: []
|
164
148
|
files:
|
165
149
|
- .gitignore
|
166
|
-
- .
|
150
|
+
- .irbrc
|
151
|
+
- .ruby-version
|
167
152
|
- .travis.yml
|
168
153
|
- Gemfile
|
169
154
|
- LICENSE
|
@@ -171,20 +156,29 @@ files:
|
|
171
156
|
- Rakefile
|
172
157
|
- frenetic.gemspec
|
173
158
|
- lib/frenetic.rb
|
159
|
+
- lib/frenetic/concerns/collection_rest_methods.rb
|
160
|
+
- lib/frenetic/concerns/configurable.rb
|
161
|
+
- lib/frenetic/concerns/hal_linked.rb
|
162
|
+
- lib/frenetic/concerns/member_rest_methods.rb
|
163
|
+
- lib/frenetic/concerns/structured.rb
|
174
164
|
- lib/frenetic/configuration.rb
|
175
|
-
- lib/frenetic/hal_json.rb
|
176
|
-
- lib/frenetic/hal_json/response_wrapper.rb
|
165
|
+
- lib/frenetic/middleware/hal_json.rb
|
177
166
|
- lib/frenetic/resource.rb
|
167
|
+
- lib/frenetic/resource_collection.rb
|
178
168
|
- lib/frenetic/version.rb
|
179
|
-
-
|
180
|
-
- spec/
|
181
|
-
- spec/
|
182
|
-
- spec/
|
183
|
-
- spec/
|
184
|
-
- spec/
|
185
|
-
- spec/
|
186
|
-
- spec/
|
169
|
+
- spec/concerns/configurable_spec.rb
|
170
|
+
- spec/concerns/hal_linked_spec.rb
|
171
|
+
- spec/concerns/member_rest_methods_spec.rb
|
172
|
+
- spec/concerns/structured_spec.rb
|
173
|
+
- spec/configuration_spec.rb
|
174
|
+
- spec/fixtures/test_api_requests.rb
|
175
|
+
- spec/frenetic_spec.rb
|
176
|
+
- spec/middleware/hal_json_spec.rb
|
177
|
+
- spec/resource_collection_spec.rb
|
178
|
+
- spec/resource_spec.rb
|
187
179
|
- spec/spec_helper.rb
|
180
|
+
- spec/support/rspec.rb
|
181
|
+
- spec/support/webmock.rb
|
188
182
|
homepage: http://dlindahl.github.com/frenetic/
|
189
183
|
licenses: []
|
190
184
|
post_install_message:
|
@@ -197,25 +191,33 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
191
|
- - ! '>='
|
198
192
|
- !ruby/object:Gem::Version
|
199
193
|
version: '0'
|
194
|
+
segments:
|
195
|
+
- 0
|
196
|
+
hash: 1697722815283438357
|
200
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
198
|
none: false
|
202
199
|
requirements:
|
203
|
-
- - ! '
|
200
|
+
- - ! '>'
|
204
201
|
- !ruby/object:Gem::Version
|
205
|
-
version:
|
202
|
+
version: 1.3.1
|
206
203
|
requirements: []
|
207
204
|
rubyforge_project:
|
208
|
-
rubygems_version: 1.8.
|
205
|
+
rubygems_version: 1.8.23
|
209
206
|
signing_key:
|
210
207
|
specification_version: 3
|
211
208
|
summary: Here lies a Ruby-based Hypermedia API client that expects HAL+JSON and makes
|
212
209
|
a lot of assumptions about your API.
|
213
210
|
test_files:
|
214
|
-
- spec/
|
215
|
-
- spec/
|
216
|
-
- spec/
|
217
|
-
- spec/
|
218
|
-
- spec/
|
219
|
-
- spec/
|
220
|
-
- spec/
|
211
|
+
- spec/concerns/configurable_spec.rb
|
212
|
+
- spec/concerns/hal_linked_spec.rb
|
213
|
+
- spec/concerns/member_rest_methods_spec.rb
|
214
|
+
- spec/concerns/structured_spec.rb
|
215
|
+
- spec/configuration_spec.rb
|
216
|
+
- spec/fixtures/test_api_requests.rb
|
217
|
+
- spec/frenetic_spec.rb
|
218
|
+
- spec/middleware/hal_json_spec.rb
|
219
|
+
- spec/resource_collection_spec.rb
|
220
|
+
- spec/resource_spec.rb
|
221
221
|
- spec/spec_helper.rb
|
222
|
+
- spec/support/rspec.rb
|
223
|
+
- spec/support/webmock.rb
|