rest-more 2.0.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -6
- data/.gitignore +1 -2
- data/.gitmodules +1 -1
- data/.travis.yml +5 -4
- data/CHANGES.md +1 -1
- data/Gemfile +16 -10
- data/README.md +209 -44
- data/Rakefile +11 -22
- data/doc/{tutorial/facebook.md → facebook.md} +1 -1
- data/example/multi.rb +3 -3
- data/example/rails3/Gemfile +18 -8
- data/example/rails3/app/controllers/application_controller.rb +2 -5
- data/example/rails3/config/application.rb +1 -1
- data/example/rails3/test/functional/application_controller_test.rb +0 -12
- data/example/rails3/test/test_helper.rb +12 -5
- data/example/rails3/test/unit/rails_util_test.rb +1 -6
- data/example/simple.rb +2 -2
- data/lib/rest-core/client/firebase.rb +50 -0
- data/lib/rest-core/client/instagram.rb +59 -0
- data/lib/rest-core/client/linkedin.rb +0 -4
- data/lib/rest-more.rb +8 -6
- data/lib/rest-more/test.rb +0 -11
- data/lib/rest-more/version.rb +1 -1
- data/rest-more.gemspec +20 -17
- data/task/README.md +54 -0
- data/task/gemgem.rb +151 -156
- data/test/dropbox/test_api.rb +1 -1
- data/test/facebook/test_api.rb +6 -7
- data/test/facebook/test_error.rb +1 -1
- data/test/facebook/test_handler.rb +2 -2
- data/test/facebook/test_load_config.rb +1 -1
- data/test/facebook/test_misc.rb +4 -14
- data/test/facebook/test_oauth.rb +1 -1
- data/test/facebook/test_old.rb +1 -1
- data/test/facebook/test_page.rb +4 -5
- data/test/facebook/test_parse.rb +0 -7
- data/test/facebook/test_serialize.rb +1 -1
- data/test/facebook/test_timeout.rb +4 -4
- data/test/instagram/test_api.rb +54 -0
- data/test/twitter/test_api.rb +1 -1
- metadata +26 -23
- data/example/rainbows.rb +0 -67
- data/task/.gitignore +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 114edfb70e3422213e0ce427a3485d50286fc3ef
|
4
|
+
data.tar.gz: 696bac783f1f2d55260ace0410bd1df717ca5ea5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5209ab15d420ef791699570c7c27ddb156ce6f989d81d523f52ce452e40f4c1abadfff844ef5e35eef91e48a68aeb869a23f2bcc52323bb5fe8f53c6869fecc
|
7
|
+
data.tar.gz: 319216fafc3c9fc4205d9edcc70a4a31f0f6776b6a67cfdd79d9b845a3953eedc13f1657d9853e60d498027ee8d3caf6b9670571f30314e310828451e1cd7a58
|
data/.gitignore
CHANGED
data/.gitmodules
CHANGED
data/.travis.yml
CHANGED
@@ -2,11 +2,12 @@ before_install: 'git submodule update --init'
|
|
2
2
|
script: 'ruby -r bundler/setup -S rake test:travis'
|
3
3
|
|
4
4
|
env:
|
5
|
-
- 'RESTMORE=rest-more
|
6
|
-
- 'RESTMORE=rails3
|
5
|
+
- 'RESTMORE=rest-more'
|
6
|
+
- 'RESTMORE=rails3'
|
7
7
|
|
8
8
|
rvm:
|
9
9
|
- 1.9.3
|
10
10
|
- 2.0.0
|
11
|
-
-
|
12
|
-
-
|
11
|
+
- ruby
|
12
|
+
- rbx
|
13
|
+
- jruby
|
data/CHANGES.md
CHANGED
data/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
source '
|
2
|
+
source 'https://rubygems.org/'
|
3
3
|
|
4
4
|
gemspec
|
5
5
|
|
@@ -7,12 +7,9 @@ gemspec
|
|
7
7
|
gem 'rest-core', :path => 'rest-core' if
|
8
8
|
File.exist?("#{File.dirname(File.expand_path(__FILE__))}/rest-core/Gemfile")
|
9
9
|
|
10
|
-
gem 'rest-client'
|
11
|
-
gem 'em-http-request'
|
12
|
-
|
13
10
|
gem 'rake'
|
14
11
|
gem 'bacon'
|
15
|
-
gem '
|
12
|
+
gem 'muack'
|
16
13
|
gem 'webmock'
|
17
14
|
|
18
15
|
gem 'json'
|
@@ -20,15 +17,24 @@ gem 'json_pure'
|
|
20
17
|
gem 'multi_json'
|
21
18
|
|
22
19
|
gem 'rack'
|
23
|
-
gem 'ruby-hmac'
|
24
20
|
|
25
|
-
platforms
|
21
|
+
platforms :ruby do
|
26
22
|
gem 'yajl-ruby'
|
27
|
-
gem 'psych' if ENV['RESTMORE'] == 'rails3' # why?
|
28
23
|
end
|
29
24
|
|
30
|
-
platforms
|
25
|
+
platforms :rbx do
|
26
|
+
gem 'rubysl-weakref' # used in rest-core
|
27
|
+
gem 'rubysl-singleton' # used in rake
|
28
|
+
gem 'rubysl-rexml' # used in crack used in webmock
|
29
|
+
gem 'rubysl-bigdecimal' # used in crack used in webmock
|
30
|
+
gem 'rubysl-test-unit' # used in activesupport
|
31
|
+
gem 'rubysl-enumerator' # used in activesupport
|
32
|
+
gem 'rubysl-benchmark' # used in activesupport
|
33
|
+
gem 'racc' # used in journey used in actionpack
|
34
|
+
end
|
35
|
+
|
36
|
+
platforms :jruby do
|
31
37
|
gem 'jruby-openssl'
|
32
38
|
end
|
33
39
|
|
34
|
-
gem 'rails', '3.2.
|
40
|
+
gem 'rails', '3.2.16' if ENV['RESTMORE'] == 'rails3'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# rest-more [![Build Status](https://secure.travis-ci.org/godfat/rest-more.png?branch=master)](http://travis-ci.org/godfat/rest-more)
|
2
2
|
|
3
|
-
by
|
3
|
+
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
4
|
|
5
5
|
Lin Jen-Shin ([godfat][]) had given a talk about rest-core on
|
6
6
|
[RubyConf Taiwan 2011][talk]. The slide is in English, but the
|
@@ -11,45 +11,58 @@ talk is in Mandarin.
|
|
11
11
|
|
12
12
|
## LINKS:
|
13
13
|
|
14
|
-
* [github](https://github.com/
|
14
|
+
* [github](https://github.com/godfat/rest-more)
|
15
15
|
* [rubygems](https://rubygems.org/gems/rest-more)
|
16
|
-
* [rdoc](http://rdoc.info/projects/
|
16
|
+
* [rdoc](http://rdoc.info/projects/godfat/rest-more)
|
17
17
|
* [mailing list](http://groups.google.com/group/rest-core/topics)
|
18
18
|
|
19
19
|
## DESCRIPTION:
|
20
20
|
|
21
|
-
Various REST clients such as Facebook and Twitter built with [rest-core][]
|
21
|
+
Various REST clients such as Facebook and Twitter built with [rest-core][].
|
22
22
|
|
23
|
-
[rest-core]: https://github.com/
|
23
|
+
[rest-core]: https://github.com/godfat/rest-core
|
24
24
|
|
25
25
|
## FEATURES:
|
26
26
|
|
27
27
|
Out-of-box REST clients built with rest-core for:
|
28
28
|
|
29
|
-
* Dropbox
|
30
|
-
* Facebook
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
29
|
+
* [RC::Dropbox][]
|
30
|
+
* [RC::Facebook][] (most completed)
|
31
|
+
* [RC::Firebase][]
|
32
|
+
* [RC::Github][]
|
33
|
+
* [RC::Instagram][]
|
34
|
+
* [RC::Linkedin][]
|
35
|
+
* [RC::Twitter][]
|
34
36
|
|
35
|
-
|
37
|
+
[RC::Dropbox]: lib/rest-core/client/dropbox.rb
|
38
|
+
[RC::Facebook]: lib/rest-core/client/facebook.rb
|
39
|
+
[RC::Firebase]: lib/rest-core/client/firebase.rb
|
40
|
+
[RC::Github]: lib/rest-core/client/github.rb
|
41
|
+
[RC::Instagram]: lib/rest-core/client/instagram.rb
|
42
|
+
[RC::Linkedin]: lib/rest-core/client/linkedin.rb
|
43
|
+
[RC::Twitter]: lib/rest-core/client/twitter.rb
|
44
|
+
|
45
|
+
Rails utilities are also included for some clients.
|
36
46
|
|
37
47
|
## REQUIREMENTS:
|
38
48
|
|
39
49
|
### Mandatory:
|
40
50
|
|
41
|
-
* MRI (official CRuby)
|
42
|
-
* gem rest-core
|
43
|
-
* gem
|
51
|
+
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
52
|
+
* gem [rest-core][]
|
53
|
+
* gem [httpclient][]
|
54
|
+
* gem [mime-types][]
|
55
|
+
* gem [timers][]
|
56
|
+
|
57
|
+
[httpclient]: https://github.com/nahi/httpclient
|
58
|
+
[mime-types]: https://github.com/halostatue/mime-types
|
59
|
+
[timers]: https://github.com/celluloid/timers
|
44
60
|
|
45
61
|
### Optional:
|
46
62
|
|
47
|
-
* gem [em-http-request][] (if using eventmachine)
|
48
63
|
* gem json or yajl-ruby, or multi_json (if `JsonResponse` or
|
49
64
|
`JsonRequest` middlewares are used)
|
50
65
|
|
51
|
-
[em-http-request]: https://github.com/igrigorik/em-http-request
|
52
|
-
|
53
66
|
## INSTALLATION:
|
54
67
|
|
55
68
|
``` shell
|
@@ -59,45 +72,203 @@ gem install rest-more
|
|
59
72
|
Or if you want development version, put this in Gemfile:
|
60
73
|
|
61
74
|
``` ruby
|
62
|
-
gem 'rest-more', :git => 'git://github.com/
|
75
|
+
gem 'rest-more', :git => 'git://github.com/godfat/rest-more.git',
|
63
76
|
:submodules => true
|
64
77
|
```
|
65
78
|
|
66
79
|
## SYNOPSIS:
|
67
80
|
|
68
|
-
|
81
|
+
### Dropbox example:
|
82
|
+
|
83
|
+
Check out their
|
84
|
+
[API documentation](https://www.dropbox.com/developers/reference/api)
|
85
|
+
for a complete reference, and [RC::Dropbox][] for built-in APIs.
|
86
|
+
|
87
|
+
``` ruby
|
88
|
+
require 'rest-more'
|
89
|
+
|
90
|
+
d = RC::Dropbox.new :root => 'sandbox',
|
91
|
+
:consumer_key => 'key',
|
92
|
+
:consumer_secret => 'secret',
|
93
|
+
:log_method => method(:puts)
|
94
|
+
|
95
|
+
# Redirect the user to:
|
96
|
+
d.authorize_url!
|
97
|
+
|
98
|
+
# After the user authorized, then we can do this to obtain the access token:
|
99
|
+
d.authorize!
|
100
|
+
|
101
|
+
# Then we could call the API:
|
102
|
+
p [d.me, d.ls]
|
103
|
+
```
|
104
|
+
|
105
|
+
### Facebook example:
|
106
|
+
|
107
|
+
Check out their
|
108
|
+
[Graph API documentation](https://developers.facebook.com/docs/graph-api/reference/v2.0/)
|
109
|
+
for a complete reference, and [RC::Facebook][] for built-in APIs.
|
110
|
+
[RC::Facebook::RailsUtil][] for Facebook is also available.
|
111
|
+
|
112
|
+
[RC::Facebook::RailsUtil]: lib/rest-core/client/facebook/rails_util.rb
|
113
|
+
|
114
|
+
``` ruby
|
115
|
+
require 'rest-more'
|
116
|
+
|
117
|
+
f = RC::Facebook.new :app_id => '123',
|
118
|
+
:secret => 'secret',
|
119
|
+
:access_token => 'if you have the token',
|
120
|
+
:log_method => method(:puts)
|
121
|
+
|
122
|
+
redirect_uri = 'http://example.com'
|
123
|
+
scope = 'public_profile,email'
|
124
|
+
|
125
|
+
# Redirect the user to:
|
126
|
+
f.authorize_url(:redirect_uri => redirect_uri, :scope => scope)
|
127
|
+
|
128
|
+
# After the user authorized, then we can do this to obtain the access token:
|
129
|
+
f.authorize!(:redirect_uri => redirect_uri, :code => 'code')
|
130
|
+
|
131
|
+
# Then we could call the API:
|
132
|
+
p [f.me, f.get('me/posts')]
|
133
|
+
```
|
134
|
+
|
135
|
+
### Firebase example:
|
136
|
+
|
137
|
+
Check out their
|
138
|
+
[REST API documentation](https://www.firebase.com/docs/rest-api.html)
|
139
|
+
for a complete reference, and [RC::Firebase][] for built-in APIs.
|
69
140
|
|
70
141
|
``` ruby
|
71
142
|
require 'rest-more'
|
72
143
|
|
73
|
-
RC::
|
74
|
-
|
144
|
+
f = RC::Firebase.new :site => 'https://example.firebaseio.com/',
|
145
|
+
:secret => 'secret',
|
146
|
+
:d => {:auth_data => 'something'},
|
147
|
+
:log_method => method(:puts)
|
148
|
+
|
149
|
+
# Listen on test.json
|
150
|
+
es = f.event_source('test')
|
151
|
+
es.onopen{ |sock| p sock }
|
152
|
+
es.onmessage{ |event| p event }
|
153
|
+
es.onerror{ |error| p error }
|
154
|
+
es.start
|
155
|
+
|
156
|
+
# Update test.json
|
157
|
+
p f.put('test', :some => 'data')
|
158
|
+
p f.post('test', :some => 'other')
|
159
|
+
p f.get('test')
|
160
|
+
p f.delete('test')
|
161
|
+
|
162
|
+
# Stop listening on test.json
|
163
|
+
es.close
|
164
|
+
```
|
165
|
+
|
166
|
+
### Github example:
|
167
|
+
|
168
|
+
Check out their
|
169
|
+
[API documentation](https://developer.github.com/v3/)
|
170
|
+
for a complete reference, and [RC::Github][] for built-in APIs.
|
171
|
+
|
172
|
+
``` ruby
|
173
|
+
require 'rest-more'
|
75
174
|
|
76
|
-
|
77
|
-
|
78
|
-
linkedin.authorize_url! # copy and paste the URL in browser to authorize
|
79
|
-
linkedin.authorize!('..') # paste your code from browser
|
80
|
-
linkedin.me # get current user info
|
175
|
+
g = RC::Github.new :access_token => 'if you have the token',
|
176
|
+
:log_method => method(:puts)
|
81
177
|
|
82
|
-
|
178
|
+
p [g.me, g.get('users/godfat')]
|
83
179
|
```
|
84
180
|
|
181
|
+
### Instagram example:
|
182
|
+
|
183
|
+
Check out their
|
184
|
+
[Developer documentation](http://instagram.com/developer/)
|
185
|
+
for a complete reference, and [RC::Instagram][] for built-in APIs.
|
186
|
+
|
187
|
+
``` ruby
|
188
|
+
require 'rest-more'
|
189
|
+
|
190
|
+
i = RC::Instagram.new :client_id => 'id',
|
191
|
+
:client_secret => 'secret',
|
192
|
+
:log_method => method(:puts)
|
193
|
+
|
194
|
+
redirect_uri = 'http://example.com'
|
195
|
+
|
196
|
+
# Redirect the user to:
|
197
|
+
i.authorize_url(:redirect_uri => redirect_uri)
|
198
|
+
|
199
|
+
# After the user authorized, then we can do this to obtain the access token:
|
200
|
+
i.authorize!(:redirect_uri => redirect_uri, :code => 'code')
|
201
|
+
|
202
|
+
# Then we could call the API:
|
203
|
+
p i.me
|
204
|
+
```
|
205
|
+
|
206
|
+
### Linkedin example:
|
207
|
+
|
208
|
+
Check out their
|
209
|
+
[API documentation](http://developer.linkedin.com/documents/linkedin-api-resource-map)
|
210
|
+
for a complete reference, and [RC::Linkedin][] for built-in APIs.
|
211
|
+
|
212
|
+
``` ruby
|
213
|
+
require 'rest-more'
|
214
|
+
|
215
|
+
l = RC::Linkedin.new :consumer_key => 'key',
|
216
|
+
:consumer_secret => 'secret',
|
217
|
+
:log_method => method(:puts)
|
218
|
+
|
219
|
+
# Redirect the user to:
|
220
|
+
l.authorize_url!
|
221
|
+
|
222
|
+
# After the user authorized, then we can do this to obtain the access token:
|
223
|
+
l.authorize!(:oauth_verifier => 'oauth_verifier')
|
224
|
+
|
225
|
+
# Then we could call the API:
|
226
|
+
p l.me
|
227
|
+
```
|
228
|
+
|
229
|
+
### Twitter example:
|
230
|
+
|
231
|
+
Check out their
|
232
|
+
[REST API documentation](https://dev.twitter.com/docs/api/1.1)
|
233
|
+
for a complete reference, and [RC::Twitter][] for built-in APIs.
|
234
|
+
|
235
|
+
``` ruby
|
236
|
+
require 'rest-more'
|
237
|
+
|
238
|
+
t = RC::Twitter.new :consumer_key => 'key',
|
239
|
+
:consumer_secret => 'secret',
|
240
|
+
:log_method => method(:puts)
|
241
|
+
|
242
|
+
# Redirect the user to:
|
243
|
+
t.authorize_url!
|
244
|
+
|
245
|
+
# After the user authorized, then we can do this to obtain the access token:
|
246
|
+
t.authorize!(:oauth_token => 'oauth_token',
|
247
|
+
:oauth_verifier => 'oauth_verifier')
|
248
|
+
|
249
|
+
# Then we could call the API:
|
250
|
+
p [t.me, t.statuses('godfat')]
|
251
|
+
p t.tweet('Aloha!', File.open('screen.png')) # Image is optional
|
252
|
+
```
|
253
|
+
|
254
|
+
### Example codes:
|
255
|
+
|
85
256
|
Runnable example is at: [example/simple.rb][]. Please see [slides][] from
|
86
257
|
[rubyconf.tw/2011][rubyconf.tw] for concepts.
|
87
258
|
|
88
|
-
[example/simple.rb]: https://github.com/
|
259
|
+
[example/simple.rb]: https://github.com/godfat/rest-more/blob/master/example/simple.rb
|
89
260
|
[slides]: http://www.godfat.org/slide/2011-08-27-rest-core.html
|
90
261
|
[rubyconf.tw]: http://rubyconf.tw/2011/#6
|
91
262
|
|
92
263
|
## Concurrent HTTP Requests:
|
93
264
|
|
94
|
-
Inherited from rest-core, you can do concurrent requests quite easily.
|
265
|
+
Inherited from [rest-core][], you can do concurrent requests quite easily.
|
95
266
|
Here's a very quick example of getting Facebook users' names for UID 4 and 5:
|
96
267
|
|
97
268
|
``` ruby
|
98
269
|
require 'rest-more'
|
99
270
|
facebook = RC::Facebook.new(:log_method => method(:puts))
|
100
|
-
puts "
|
271
|
+
puts "httpclient with threads doing concurrent requests"
|
101
272
|
a = [facebook.get('4'), facebook.get('5')]
|
102
273
|
puts "It's not blocking... but doing concurrent requests underneath"
|
103
274
|
p a.map{ |r| r['name'] } # here we want the values, so it blocks here
|
@@ -110,9 +281,9 @@ If you prefer callback based solution, this would also work:
|
|
110
281
|
require 'rest-more'
|
111
282
|
facebook = RC::Facebook.new(:log_method => method(:puts))
|
112
283
|
puts "callback also works"
|
113
|
-
facebook.get('6')
|
284
|
+
facebook.get('6') do |r|
|
114
285
|
p r['name']
|
115
|
-
|
286
|
+
end
|
116
287
|
puts "It's not blocking... but doing concurrent requests underneath"
|
117
288
|
facebook.wait # we block here to wait for the request done
|
118
289
|
puts "DONE"
|
@@ -121,20 +292,14 @@ puts "DONE"
|
|
121
292
|
Runnable example is at: [example/multi.rb][]. For a detailed demonstration,
|
122
293
|
see: [Advanced Concurrent HTTP Requests -- Embrace the Future][future]
|
123
294
|
|
124
|
-
[example/multi.rb]: https://github.com/
|
125
|
-
[future]: https://github.com/
|
295
|
+
[example/multi.rb]: https://github.com/godfat/rest-more/blob/master/example/multi.rb
|
296
|
+
[future]: https://github.com/godfat/rest-core#advanced-concurrent-http-requests----embrace-the-future
|
126
297
|
|
127
298
|
## Rails Utilities
|
128
299
|
|
129
300
|
To be added. But you can take a look at [Facebook tutorial][] first.
|
130
301
|
|
131
|
-
[Facebook tutorial]:
|
132
|
-
|
133
|
-
## EventMachine inside Rainbows!
|
134
|
-
|
135
|
-
To be added. But you can take a look at [Rainbows configuration][] first.
|
136
|
-
|
137
|
-
[Rainbows configuration]: https://github.com/cardinalblue/rest-more/blob/master/example/rainbows.rb
|
302
|
+
[Facebook tutorial]: doc/facebook.md
|
138
303
|
|
139
304
|
## A simple interactive shell with [rib][]:
|
140
305
|
|
@@ -146,7 +311,7 @@ Then you can try this by running `rib rest-core`:
|
|
146
311
|
|
147
312
|
rest-core>> self.site = 'https://api.github.com/users/'
|
148
313
|
rest-core>> self.json_response = true
|
149
|
-
rest-core>> get '
|
314
|
+
rest-core>> get 'godfat'
|
150
315
|
|
151
316
|
Which is using `RestCore::Universal` for accessing arbitrary websites.
|
152
317
|
|
@@ -163,7 +328,7 @@ Which is using `RestCore::Universal` for accessing arbitrary websites.
|
|
163
328
|
|
164
329
|
## CHANGES:
|
165
330
|
|
166
|
-
* [CHANGES](
|
331
|
+
* [CHANGES](CHANGES.md)
|
167
332
|
|
168
333
|
## CONTRIBUTORS:
|
169
334
|
|
@@ -177,7 +342,7 @@ Which is using `RestCore::Universal` for accessing arbitrary websites.
|
|
177
342
|
|
178
343
|
Apache License 2.0
|
179
344
|
|
180
|
-
Copyright (c) 2011-
|
345
|
+
Copyright (c) 2011-2014, Lin Jen-Shin (godfat)
|
181
346
|
|
182
347
|
Licensed under the Apache License, Version 2.0 (the "License");
|
183
348
|
you may not use this file except in compliance with the License.
|