remotely 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/README.md +53 -0
- data/lib/remotely/application.rb +26 -2
- data/lib/remotely/http_methods.rb +1 -1
- data/lib/remotely/version.rb +1 -1
- data/spec/remotely/application_spec.rb +31 -0
- data/spec/remotely/http_methods_spec.rb +2 -2
- data/spec/remotely/model_spec.rb +75 -0
- data/spec/remotely_spec.rb +15 -0
- metadata +20 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ba680c908518656cda92b0f0b38f2eb73db06ce
|
4
|
+
data.tar.gz: b2fc47594894157857682de954a0679b3755561d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15de8ebc5f4f41ddca9bf7004f09d3e2a595f8b0a632c1aa4bba432e38faac6e0775cbcc05e350ee2fb97e279dec93a0cfd7007fe8ad13a5f91012a4bbc2cb75
|
7
|
+
data.tar.gz: f6c015352eebebf77eeff181238de6590e264a286ffe9355c6e2de12a6bb65a1d04d0fd629f769f42d95cc981ddbc47e649b7970f77cb79d24281abe48844808
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -73,6 +73,59 @@ A path can include "`:id`" anywhere in it, which is replaced by the instance's `
|
|
73
73
|
m.id # => 1
|
74
74
|
m.legs # => Requests "/millepieds/1/legs"
|
75
75
|
|
76
|
+
## Authorization
|
77
|
+
|
78
|
+
Remotely is setup to allow basic auth, token auth, or custom authentication schemes.
|
79
|
+
|
80
|
+
**Basic Auth**
|
81
|
+
|
82
|
+
`basic_auth` accepts 2 String params: `username` and `password`
|
83
|
+
|
84
|
+
# 'Authorization' header => "Basic dXNlcjpwYXNzd29yZA=="
|
85
|
+
|
86
|
+
Remotely.configure do
|
87
|
+
app :legsapp do
|
88
|
+
url "http://somanylegs.com/api/v1"
|
89
|
+
basic_auth "username", "password"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
**Token Auth**
|
94
|
+
|
95
|
+
`token_auth` accepts a String param for the `token`, and an optional Hash of token options
|
96
|
+
|
97
|
+
# 'Authorization' header => "Token token=\"abcdef\", foo=\"bar\""
|
98
|
+
|
99
|
+
Remotely.configure do
|
100
|
+
app :legsapp do
|
101
|
+
url "http://somanylegs.com/api/v1"
|
102
|
+
token_auth "abcdef", {:foo => 'bar'}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
**Custom Authorization**
|
107
|
+
|
108
|
+
`authorization` accepts a String param for the `type`, and either a String or Hash `token`. A String value is taken literally, and a Hash is encoded into comma separated key/value pairs.
|
109
|
+
|
110
|
+
# 'Authorization' header => "Bearer mF_9.B5f-4.1JqM"
|
111
|
+
|
112
|
+
Remotely.configure do
|
113
|
+
app :legsapp do
|
114
|
+
url "http://somanylegs.com/api/v1"
|
115
|
+
authorization 'Bearer', 'mF_9.B5f-4.1JqM'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# 'Authorization' header => "OAuth token=\"abcdef\", foo=\"bar\""
|
121
|
+
|
122
|
+
Remotely.configure do
|
123
|
+
app :legsapp do
|
124
|
+
url "http://somanylegs.com/api/v1"
|
125
|
+
authorization 'OAuth', {:token => 'abcdef', :foo => 'bar'}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
76
129
|
## Fetched Objects
|
77
130
|
|
78
131
|
Remote associations are Remotely::Model objects. Whatever data the API returns, becomes the attributes of the Model.
|
data/lib/remotely/application.rb
CHANGED
@@ -25,6 +25,28 @@ module Remotely
|
|
25
25
|
return @basic_auth unless user && password
|
26
26
|
@basic_auth = [user, password]
|
27
27
|
end
|
28
|
+
|
29
|
+
# Set or get the Authorization header.
|
30
|
+
# - As seen here: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L204
|
31
|
+
#
|
32
|
+
# @param [String] token - The String token.
|
33
|
+
# @param [Hash] options - Optional Hash of extra token options.
|
34
|
+
#
|
35
|
+
def token_auth(token=nil, options={})
|
36
|
+
return @token_auth unless token
|
37
|
+
@token_auth = [token, options]
|
38
|
+
end
|
39
|
+
|
40
|
+
# Set or get a custom Authorization header.
|
41
|
+
# - As seen here: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L227
|
42
|
+
#
|
43
|
+
# @param [String] type - The String authorization type.
|
44
|
+
# @param [String|Hash] token - The String or Hash token. A String value is taken literally, and a Hash is encoded into comma separated key/value pairs.
|
45
|
+
#
|
46
|
+
def authorization(type=nil, token=nil)
|
47
|
+
return @authorization unless type && token
|
48
|
+
@authorization = [type, token]
|
49
|
+
end
|
28
50
|
|
29
51
|
# Connection to the application (with BasicAuth if it was set).
|
30
52
|
#
|
@@ -35,8 +57,10 @@ module Remotely
|
|
35
57
|
b.request :url_encoded
|
36
58
|
b.adapter :net_http
|
37
59
|
end
|
38
|
-
|
39
|
-
@connection.basic_auth(*@basic_auth)
|
60
|
+
|
61
|
+
@connection.basic_auth(*@basic_auth) if @basic_auth
|
62
|
+
@connection.token_auth(*@token_auth) if @token_auth
|
63
|
+
@connection.authorization(*@authorization) if @authorization
|
40
64
|
@connection
|
41
65
|
end
|
42
66
|
|
data/lib/remotely/version.rb
CHANGED
@@ -15,6 +15,21 @@ describe Remotely::Application do
|
|
15
15
|
app = Remotely::Application.new(:name) { basic_auth "user", "pass" }
|
16
16
|
app.basic_auth.should == ["user", "pass"]
|
17
17
|
end
|
18
|
+
|
19
|
+
it "sets token auth credentials" do
|
20
|
+
app = Remotely::Application.new(:name) { token_auth "token", {:foo => :bar} }
|
21
|
+
app.token_auth.should == ["token", {:foo => :bar}]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "sets custom authorization credentials as a string" do
|
25
|
+
app = Remotely::Application.new(:name) { authorization "OAuth", "token=foo" }
|
26
|
+
app.authorization.should == ["OAuth", "token=foo"]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets custom authorization credentials as a hash" do
|
30
|
+
app = Remotely::Application.new(:name) { authorization "OAuth", {:token => :foo} }
|
31
|
+
app.authorization.should == ["OAuth", {:token => :foo}]
|
32
|
+
end
|
18
33
|
|
19
34
|
it "has a connection to the app" do
|
20
35
|
app = Remotely::Application.new(:name) { url "http://example.com" }
|
@@ -28,4 +43,20 @@ describe Remotely::Application do
|
|
28
43
|
end
|
29
44
|
app.connection.headers["authorization"].should_not be_nil
|
30
45
|
end
|
46
|
+
|
47
|
+
it "has a connection with token auth to the app" do
|
48
|
+
app = Remotely::Application.new(:name) do
|
49
|
+
url "http://example.com"
|
50
|
+
token_auth "token", {:foo => :bar}
|
51
|
+
end
|
52
|
+
app.connection.headers["authorization"].should_not be_nil
|
53
|
+
end
|
54
|
+
|
55
|
+
it "has a connection with custom authorization to the app" do
|
56
|
+
app = Remotely::Application.new(:name) do
|
57
|
+
url "http://example.com"
|
58
|
+
authorization "OAuth", {:token => :foo}
|
59
|
+
end
|
60
|
+
app.connection.headers["authorization"].should_not be_nil
|
61
|
+
end
|
31
62
|
end
|
@@ -4,12 +4,12 @@ describe Remotely::HTTPMethods do
|
|
4
4
|
include Remotely::HTTPMethods
|
5
5
|
|
6
6
|
it "raises NonJsonResponseError when HTML is returned on GET" do
|
7
|
-
stub_request(:get, %r(/things)).to_return(body: "<html><head><title></title></head></html>")
|
7
|
+
stub_request(:get, %r(/things)).to_return(body: "<html lang='en'><head><title></title></head></html>")
|
8
8
|
expect { get("/things") }.to raise_error(Remotely::NonJsonResponseError)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "raises NonJsonResponseError when HTML is returned on POST" do
|
12
|
-
stub_request(:post, %r(/things)).to_return(body: "<
|
12
|
+
stub_request(:post, %r(/things)).to_return(body: "<HTML><HEAD><TITLE></TITLE></HEAD></HTML>")
|
13
13
|
expect { post("/things") }.to raise_error(Remotely::NonJsonResponseError)
|
14
14
|
end
|
15
15
|
|
data/spec/remotely/model_spec.rb
CHANGED
@@ -279,6 +279,81 @@ describe Remotely::Model do
|
|
279
279
|
a_request(:get, "#{app}/adventures/1").with(headers: {})
|
280
280
|
end
|
281
281
|
end
|
282
|
+
|
283
|
+
context "token auth" do
|
284
|
+
before do
|
285
|
+
Remotely.configure do
|
286
|
+
app :adventure_app do
|
287
|
+
url "http://localhost:3000"
|
288
|
+
token_auth "token", {:foo => :bar}
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
after do
|
294
|
+
Remotely.reset!
|
295
|
+
end
|
296
|
+
|
297
|
+
it "sends Authorization headers when token auth is configured" do
|
298
|
+
Adventure.find(1)
|
299
|
+
a_request(:get, "#{app}/adventures/1").with(headers: {'Authorization' => "Token token=token foo=bar"})
|
300
|
+
end
|
301
|
+
|
302
|
+
it "doesn't send Authorization headers when token auth is not configured" do
|
303
|
+
Adventure.find(1)
|
304
|
+
a_request(:get, "#{app}/adventures/1").with(headers: {})
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context "custom authorization as a string" do
|
309
|
+
before do
|
310
|
+
Remotely.configure do
|
311
|
+
app :adventure_app do
|
312
|
+
url "http://localhost:3000"
|
313
|
+
authorization "OAuth", "token=foo"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
after do
|
319
|
+
Remotely.reset!
|
320
|
+
end
|
321
|
+
|
322
|
+
it "sends Authorization headers when custom authorization is configured" do
|
323
|
+
Adventure.find(1)
|
324
|
+
a_request(:get, "#{app}/adventures/1").with(headers: {'Authorization' => "OAuth token=foo"})
|
325
|
+
end
|
326
|
+
|
327
|
+
it "doesn't send Authorization headers when custom authorization is not configured" do
|
328
|
+
Adventure.find(1)
|
329
|
+
a_request(:get, "#{app}/adventures/1").with(headers: {})
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "custom authorization as a hash" do
|
334
|
+
before do
|
335
|
+
Remotely.configure do
|
336
|
+
app :adventure_app do
|
337
|
+
url "http://localhost:3000"
|
338
|
+
authorization "OAuth", {:token => :foo}
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
after do
|
344
|
+
Remotely.reset!
|
345
|
+
end
|
346
|
+
|
347
|
+
it "sends Authorization headers when custom authorization is configured" do
|
348
|
+
Adventure.find(1)
|
349
|
+
a_request(:get, "#{app}/adventures/1").with(headers: {'Authorization' => "OAuth token=foo"})
|
350
|
+
end
|
351
|
+
|
352
|
+
it "doesn't send Authorization headers when custom authorization is not configured" do
|
353
|
+
Adventure.find(1)
|
354
|
+
a_request(:get, "#{app}/adventures/1").with(headers: {})
|
355
|
+
end
|
356
|
+
end
|
282
357
|
|
283
358
|
it "sets the app it belongs to" do
|
284
359
|
Adventure.app.name.should == :adventure_app
|
data/spec/remotely_spec.rb
CHANGED
@@ -25,4 +25,19 @@ describe Remotely do
|
|
25
25
|
Remotely.configure { app(:appname) { basic_auth "user", "pass" }}
|
26
26
|
Remotely.apps[:appname].basic_auth.should == ["user", "pass"]
|
27
27
|
end
|
28
|
+
|
29
|
+
it "saves the token auth credentials" do
|
30
|
+
Remotely.configure { app(:appname) { token_auth "token", {:foo => :bar} }}
|
31
|
+
Remotely.apps[:appname].token_auth.should == ["token", {:foo => :bar}]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "saves the authorization credentials as a string" do
|
35
|
+
Remotely.configure { app(:appname) { authorization "OAuth", "token=foo" }}
|
36
|
+
Remotely.apps[:appname].authorization.should == [ "OAuth", "token=foo" ]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "saves the authorization credentials as a hash" do
|
40
|
+
Remotely.configure { app(:appname) { authorization "OAuth", {:token => :foo} }}
|
41
|
+
Remotely.apps[:appname].authorization.should == [ "OAuth", {:token => :foo}]
|
42
|
+
end
|
28
43
|
end
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matte Noble
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,81 +41,71 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: webmock
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: activesupport
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: activemodel
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: faraday
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :runtime
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: multi_json
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - '>='
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
description: Remote API based model associations.
|
@@ -158,27 +143,26 @@ files:
|
|
158
143
|
- spec/support/webmock.rb
|
159
144
|
homepage: ''
|
160
145
|
licenses: []
|
146
|
+
metadata: {}
|
161
147
|
post_install_message:
|
162
148
|
rdoc_options: []
|
163
149
|
require_paths:
|
164
150
|
- lib
|
165
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
-
none: false
|
167
152
|
requirements:
|
168
|
-
- -
|
153
|
+
- - '>='
|
169
154
|
- !ruby/object:Gem::Version
|
170
155
|
version: '0'
|
171
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
|
-
none: false
|
173
157
|
requirements:
|
174
|
-
- -
|
158
|
+
- - '>='
|
175
159
|
- !ruby/object:Gem::Version
|
176
160
|
version: '0'
|
177
161
|
requirements: []
|
178
162
|
rubyforge_project:
|
179
|
-
rubygems_version:
|
163
|
+
rubygems_version: 2.0.0
|
180
164
|
signing_key:
|
181
|
-
specification_version:
|
165
|
+
specification_version: 4
|
182
166
|
summary: Remote API based model associations.
|
183
167
|
test_files:
|
184
168
|
- spec/remotely/application_spec.rb
|
@@ -191,3 +175,4 @@ test_files:
|
|
191
175
|
- spec/spec_helper.rb
|
192
176
|
- spec/support/test_classes.rb
|
193
177
|
- spec/support/webmock.rb
|
178
|
+
has_rdoc:
|