leadlight 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/Gemfile.lock +20 -18
  2. data/default.gems +1 -1
  3. data/leadlight.gemspec +24 -4
  4. data/lib/leadlight.rb +4 -5
  5. data/lib/leadlight/connection_builder.rb +29 -0
  6. data/lib/leadlight/errors.rb +11 -5
  7. data/lib/leadlight/hyperlinkable.rb +31 -10
  8. data/lib/leadlight/lib_ext.rb +3 -0
  9. data/lib/leadlight/lib_ext/faraday/README +6 -0
  10. data/lib/leadlight/lib_ext/faraday/adapter.rb +7 -0
  11. data/lib/leadlight/lib_ext/faraday/builder.rb +47 -0
  12. data/lib/leadlight/lib_ext/faraday/connection.rb +40 -0
  13. data/lib/leadlight/lib_ext/faraday/middleware.rb +7 -0
  14. data/lib/leadlight/link.rb +91 -4
  15. data/lib/leadlight/link_template.rb +13 -5
  16. data/lib/leadlight/null_link.rb +21 -0
  17. data/lib/leadlight/param_hash.rb +42 -0
  18. data/lib/leadlight/representation.rb +23 -3
  19. data/lib/leadlight/request.rb +42 -10
  20. data/lib/leadlight/service.rb +11 -9
  21. data/lib/leadlight/service_class_methods.rb +11 -3
  22. data/lib/leadlight/tint_helper.rb +32 -2
  23. data/spec/cassettes/Leadlight/authorized_GitHub_example/_user/has_the_expected_content.yml +72 -54
  24. data/spec/cassettes/Leadlight/authorized_GitHub_example/_user/indicates_the_expected_oath_scopes.yml +73 -55
  25. data/spec/cassettes/Leadlight/authorized_GitHub_example/adding_and_removing_team_members.yml +353 -265
  26. data/spec/cassettes/Leadlight/authorized_GitHub_example/adding_and_removing_teams.yml +75 -175
  27. data/spec/cassettes/Leadlight/authorized_GitHub_example/team_list/should_have_a_link_back_to_the_org.yml +196 -0
  28. data/spec/cassettes/Leadlight/authorized_GitHub_example/test_team/.yml +152 -108
  29. data/spec/cassettes/Leadlight/authorized_GitHub_example/test_team/has_a_root_link.yml +197 -0
  30. data/spec/cassettes/Leadlight/basic_GitHub_example/_root/.yml +15 -43
  31. data/spec/cassettes/Leadlight/basic_GitHub_example/_root/__location__/.yml +15 -43
  32. data/spec/cassettes/Leadlight/basic_GitHub_example/_root/should_be_a_204_no_content.yml +15 -43
  33. data/spec/cassettes/Leadlight/tinted_GitHub_example/_root/.yml +15 -43
  34. data/spec/cassettes/Leadlight/tinted_GitHub_example/_root/__location__/.yml +15 -43
  35. data/spec/cassettes/Leadlight/tinted_GitHub_example/_root/should_be_a_204_no_content.yml +15 -43
  36. data/spec/cassettes/Leadlight/tinted_GitHub_example/_user/has_the_expected_content.yml +35 -90
  37. data/spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/enables_custom_error_matching.yml +25 -17
  38. data/spec/cassettes/Leadlight/tinted_GitHub_example/bad_links/should_raise_ResourceNotFound.yml +26 -90
  39. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/.yml +57 -140
  40. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_able_to_follow_next_link.yml +79 -192
  41. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable.yml +279 -350
  42. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable_over_page_boundaries.yml +98 -243
  43. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_have_next_and_last_links.yml +59 -142
  44. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_link/exists.yml +15 -43
  45. data/spec/cassettes/Leadlight/tinted_GitHub_example/user_link/links_to_the_expected_URL.yml +15 -43
  46. data/spec/leadlight/hyperlinkable_spec.rb +50 -4
  47. data/spec/leadlight/link_spec.rb +70 -10
  48. data/spec/leadlight/link_template_spec.rb +20 -4
  49. data/spec/leadlight/null_link_spec.rb +14 -0
  50. data/spec/leadlight/param_hash_spec.rb +26 -0
  51. data/spec/leadlight/representation_spec.rb +36 -4
  52. data/spec/leadlight/request_spec.rb +39 -22
  53. data/spec/leadlight/service_spec.rb +14 -13
  54. data/spec/leadlight/tint_helper_spec.rb +36 -2
  55. data/spec/leadlight_spec.rb +31 -17
  56. data/spec/support/link_matchers.rb +59 -0
  57. data/spec/support/misc.rb +9 -0
  58. metadata +49 -34
@@ -10,10 +10,10 @@ describe Leadlight, vcr: true do
10
10
  Addressable::Template.new(pattern)
11
11
  end
12
12
 
13
- let(:logger) {
13
+ let(:logger) {
14
14
  logfile = Pathname('../../log/test.log').expand_path(__FILE__)
15
15
  logfile.dirname.mkpath
16
- Logger.new(logfile)
16
+ Logger.new(logfile)
17
17
  }
18
18
 
19
19
  describe 'basic GitHub example' do
@@ -56,7 +56,7 @@ describe Leadlight, vcr: true do
56
56
  match_content_type('application/json')
57
57
  match_class(Hash)
58
58
  match{self['type'] == 'User'}
59
- add_link "#{__location__}/followers", 'followers', 'List followers'
59
+ add_link "./followers", 'followers', 'List followers'
60
60
  end
61
61
  end
62
62
  end
@@ -83,7 +83,7 @@ describe Leadlight, vcr: true do
83
83
  end
84
84
 
85
85
  it 'links to the expected URL' do
86
- subject.root.link('user').href.should eq(uri('/users/{login}'))
86
+ subject.root.link('user').href.path.should eq('/users/{login}')
87
87
  end
88
88
  end
89
89
 
@@ -129,7 +129,7 @@ describe Leadlight, vcr: true do
129
129
  describe 'bad links' do
130
130
  class MyAwesomeError < StandardError
131
131
  end
132
-
132
+
133
133
  it 'should raise ResourceNotFound' do
134
134
  expect{
135
135
  session.root.bad_link
@@ -174,7 +174,7 @@ describe Leadlight, vcr: true do
174
174
 
175
175
  tint 'organization' do
176
176
  match_path(%r{^/orgs/\w+$})
177
- add_link "#{__location__}/teams", 'teams'
177
+ add_link "./teams", 'teams'
178
178
 
179
179
  extend do
180
180
  def team_for_name(name)
@@ -182,9 +182,8 @@ describe Leadlight, vcr: true do
182
182
  end
183
183
 
184
184
  def add_team(name, permission)
185
- link('teams').post({},
186
- { 'name' => name,
187
- 'permission' => permission}).
185
+ link('teams').post('name' => name,
186
+ 'permission' => permission).
188
187
  raise_on_error.
189
188
  submit_and_wait do |new_team|
190
189
  return new_team
@@ -195,7 +194,9 @@ describe Leadlight, vcr: true do
195
194
  end
196
195
 
197
196
  tint 'teamlist' do
198
- match_path(%r{^/orgs/\w+/teams$})
197
+ match_template('/orgs/{org_id}/teams')
198
+
199
+ add_link '/orgs/{org_id}', 'organization'
199
200
 
200
201
  add_link_set('child', :get) do
201
202
  map{|team|
@@ -206,17 +207,18 @@ describe Leadlight, vcr: true do
206
207
 
207
208
  tint 'team' do
208
209
  match_template('/teams/{id}')
209
-
210
- add_link "#{__location__}/members", 'members'
211
- add_link_template "#{__location__}/members/{id}", 'member'
210
+
211
+ add_link "./members", 'members'
212
+ add_link_template "./members/{id}", 'member'
213
+ add_link "../..", "root"
212
214
 
213
215
  extend do
214
216
  def add_member(member_name)
215
- link('member').put(member_name).submit_and_wait.raise_on_error
217
+ link('member', member_name).put.submit_and_wait.raise_on_error
216
218
  end
217
219
 
218
220
  def remove_member(member_name)
219
- link('member').delete(member_name).submit_and_wait.raise_on_error
221
+ link('member', member_name).delete.submit_and_wait.raise_on_error
220
222
  end
221
223
 
222
224
  def destroy
@@ -250,7 +252,7 @@ describe Leadlight, vcr: true do
250
252
  #
251
253
  # 'event.source' is the Leadlight request, which delegates
252
254
  # #service_options to the service
253
- request.headers['Authorization'] =
255
+ request.headers['Authorization'] =
254
256
  "Bearer #{event.source.service_options[:oauth2_token]}"
255
257
  end
256
258
 
@@ -275,10 +277,22 @@ describe Leadlight, vcr: true do
275
277
  end
276
278
  end
277
279
 
280
+ describe 'team list' do
281
+ subject { session.root.organization('shiprise').teams }
282
+
283
+ it 'should have a link back to the org' do
284
+ subject.organization['name'].should eq('ShipRise')
285
+ end
286
+ end
287
+
278
288
  describe 'test team' do
279
289
  subject { session.root.organization('shiprise').team_for_name('Leadlight Test Team') }
280
-
290
+
281
291
  it { should be }
292
+
293
+ it 'has a root link' do
294
+ subject.link('root').href.path.should eq('/')
295
+ end
282
296
  end
283
297
 
284
298
  specify "adding and removing teams" do
@@ -0,0 +1,59 @@
1
+ module Leadlight
2
+ module LinkMatchers
3
+ extend RSpec::Matchers::DSL
4
+
5
+ matcher :expand_to do |expected|
6
+ match{|actual|
7
+ @failures = []
8
+ href_matches?(actual, expected) && params_match?(actual, expected)
9
+ }
10
+
11
+ chain(:given) do |params|
12
+ @params = params
13
+ end
14
+
15
+ chain(:with_params) do |expected_params|
16
+ @expected_params = expected_params
17
+ end
18
+
19
+ failure_message_for_should do |actual|
20
+ @failures.join("\n")
21
+ end
22
+
23
+ def expanded
24
+ CGI.unescape(expanded_link.href.to_s)
25
+ end
26
+
27
+ def expanded_link
28
+ actual.expand(@params)
29
+ end
30
+
31
+ def subscript_expanded
32
+ CGI.unescape(actual[@params].href.to_s)
33
+ end
34
+
35
+ def params_match?(actual, expected)
36
+ if @expected_params
37
+ @expected_params.each do |key, value|
38
+ unless expanded_link.params[key] == value
39
+ @failures << "Expected #{expanded_link.params.inspect} to include "\
40
+ "#{key.inspect} => #{value.inspect}"
41
+ return false
42
+ end
43
+ end
44
+ end
45
+ return true
46
+ end
47
+
48
+ def href_matches?(actual, expected)
49
+ if expanded == expected && subscript_expanded == expected
50
+ true
51
+ else
52
+ @failures << "expected #{actual} to expand to #{expected.inspect} given " \
53
+ "params #{@params.inspect}, but got #{expanded.inspect}"
54
+ false
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ module MiscSpecHelpers
2
+ def u(*args)
3
+ Addressable::URI.parse(*args)
4
+ end
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.include(MiscSpecHelpers)
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leadlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-15 00:00:00.000000000 Z
12
+ date: 2012-08-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
16
- requirement: &70328504344440 !ruby/object:Gem::Requirement
16
+ requirement: &15429720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70328504344440
24
+ version_requirements: *15429720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: faraday
27
- requirement: &70328504343560 !ruby/object:Gem::Requirement
27
+ requirement: &15428900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - =
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.8.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70328504343560
35
+ version_requirements: *15428900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fattr
38
- requirement: &70328504343140 !ruby/object:Gem::Requirement
38
+ requirement: &15427780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70328504343140
46
+ version_requirements: *15427780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: link_header
49
- requirement: &70328504342460 !ruby/object:Gem::Requirement
49
+ requirement: &15427080 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70328504342460
57
+ version_requirements: *15427080
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70328504341640 !ruby/object:Gem::Requirement
60
+ requirement: &15426060 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.4
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70328504341640
68
+ version_requirements: *15426060
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mime-types
71
- requirement: &70328504341000 !ruby/object:Gem::Requirement
71
+ requirement: &15424700 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70328504341000
79
+ version_requirements: *15424700
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: hookr
82
- requirement: &70328504340400 !ruby/object:Gem::Requirement
82
+ requirement: &15415060 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70328504340400
90
+ version_requirements: *15415060
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &70328504339740 !ruby/object:Gem::Requirement
93
+ requirement: &15413840 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70328504339740
101
+ version_requirements: *15413840
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec
104
- requirement: &70328504339060 !ruby/object:Gem::Requirement
104
+ requirement: &15411580 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,21 +109,21 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70328504339060
112
+ version_requirements: *15411580
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: vcr
115
- requirement: &70328504338520 !ruby/object:Gem::Requirement
115
+ requirement: &15410480 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
119
119
  - !ruby/object:Gem::Version
120
- version: 2.0.0.rc1
120
+ version: '2.0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70328504338520
123
+ version_requirements: *15410480
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: guard
126
- requirement: &70328504338020 !ruby/object:Gem::Requirement
126
+ requirement: &15409340 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70328504338020
134
+ version_requirements: *15409340
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: guard-rspec
137
- requirement: &70328504337420 !ruby/object:Gem::Requirement
137
+ requirement: &15408220 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70328504337420
145
+ version_requirements: *15408220
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: guard-bundler
148
- requirement: &70328504336840 !ruby/object:Gem::Requirement
148
+ requirement: &15407180 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70328504336840
156
+ version_requirements: *15407180
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: ruby-debug19
159
- requirement: &70328504336180 !ruby/object:Gem::Requirement
159
+ requirement: &15406620 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *70328504336180
167
+ version_requirements: *15406620
168
168
  description: Rose colored stained glass windows for HTTP.
169
169
  email: avdi@avdi.org
170
170
  executables: []
@@ -182,13 +182,22 @@ files:
182
182
  - lib/leadlight/basic_converter.rb
183
183
  - lib/leadlight/blank.rb
184
184
  - lib/leadlight/codec.rb
185
+ - lib/leadlight/connection_builder.rb
185
186
  - lib/leadlight/entity.rb
186
187
  - lib/leadlight/enumerable_representation.rb
187
188
  - lib/leadlight/errors.rb
188
189
  - lib/leadlight/header_helpers.rb
189
190
  - lib/leadlight/hyperlinkable.rb
191
+ - lib/leadlight/lib_ext.rb
192
+ - lib/leadlight/lib_ext/faraday/README
193
+ - lib/leadlight/lib_ext/faraday/adapter.rb
194
+ - lib/leadlight/lib_ext/faraday/builder.rb
195
+ - lib/leadlight/lib_ext/faraday/connection.rb
196
+ - lib/leadlight/lib_ext/faraday/middleware.rb
190
197
  - lib/leadlight/link.rb
191
198
  - lib/leadlight/link_template.rb
199
+ - lib/leadlight/null_link.rb
200
+ - lib/leadlight/param_hash.rb
192
201
  - lib/leadlight/representation.rb
193
202
  - lib/leadlight/request.rb
194
203
  - lib/leadlight/service.rb
@@ -201,7 +210,9 @@ files:
201
210
  - spec/cassettes/Leadlight/authorized_GitHub_example/_user/indicates_the_expected_oath_scopes.yml
202
211
  - spec/cassettes/Leadlight/authorized_GitHub_example/adding_and_removing_team_members.yml
203
212
  - spec/cassettes/Leadlight/authorized_GitHub_example/adding_and_removing_teams.yml
213
+ - spec/cassettes/Leadlight/authorized_GitHub_example/team_list/should_have_a_link_back_to_the_org.yml
204
214
  - spec/cassettes/Leadlight/authorized_GitHub_example/test_team/.yml
215
+ - spec/cassettes/Leadlight/authorized_GitHub_example/test_team/has_a_root_link.yml
205
216
  - spec/cassettes/Leadlight/basic_GitHub_example/_root/.yml
206
217
  - spec/cassettes/Leadlight/basic_GitHub_example/_root/__location__/.yml
207
218
  - spec/cassettes/Leadlight/basic_GitHub_example/_root/should_be_a_204_no_content.yml
@@ -222,6 +233,8 @@ files:
222
233
  - spec/leadlight/hyperlinkable_spec.rb
223
234
  - spec/leadlight/link_spec.rb
224
235
  - spec/leadlight/link_template_spec.rb
236
+ - spec/leadlight/null_link_spec.rb
237
+ - spec/leadlight/param_hash_spec.rb
225
238
  - spec/leadlight/representation_spec.rb
226
239
  - spec/leadlight/request_spec.rb
227
240
  - spec/leadlight/service_middleware_spec.rb
@@ -232,6 +245,8 @@ files:
232
245
  - spec/leadlight_spec.rb
233
246
  - spec/spec_helper_lite.rb
234
247
  - spec/support/credentials.rb
248
+ - spec/support/link_matchers.rb
249
+ - spec/support/misc.rb
235
250
  - spec/support/vcr.rb
236
251
  homepage: https://github.com/avdi/leadlight
237
252
  licenses: []
@@ -253,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
268
  version: '0'
254
269
  requirements: []
255
270
  rubyforge_project: leadlight
256
- rubygems_version: 1.8.15
271
+ rubygems_version: 1.8.10
257
272
  signing_key:
258
273
  specification_version: 2
259
274
  summary: Rose colored stained glass windows for HTTP.