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.
Files changed (43) hide show
  1. checksums.yaml +6 -6
  2. data/.gitignore +1 -2
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +5 -4
  5. data/CHANGES.md +1 -1
  6. data/Gemfile +16 -10
  7. data/README.md +209 -44
  8. data/Rakefile +11 -22
  9. data/doc/{tutorial/facebook.md → facebook.md} +1 -1
  10. data/example/multi.rb +3 -3
  11. data/example/rails3/Gemfile +18 -8
  12. data/example/rails3/app/controllers/application_controller.rb +2 -5
  13. data/example/rails3/config/application.rb +1 -1
  14. data/example/rails3/test/functional/application_controller_test.rb +0 -12
  15. data/example/rails3/test/test_helper.rb +12 -5
  16. data/example/rails3/test/unit/rails_util_test.rb +1 -6
  17. data/example/simple.rb +2 -2
  18. data/lib/rest-core/client/firebase.rb +50 -0
  19. data/lib/rest-core/client/instagram.rb +59 -0
  20. data/lib/rest-core/client/linkedin.rb +0 -4
  21. data/lib/rest-more.rb +8 -6
  22. data/lib/rest-more/test.rb +0 -11
  23. data/lib/rest-more/version.rb +1 -1
  24. data/rest-more.gemspec +20 -17
  25. data/task/README.md +54 -0
  26. data/task/gemgem.rb +151 -156
  27. data/test/dropbox/test_api.rb +1 -1
  28. data/test/facebook/test_api.rb +6 -7
  29. data/test/facebook/test_error.rb +1 -1
  30. data/test/facebook/test_handler.rb +2 -2
  31. data/test/facebook/test_load_config.rb +1 -1
  32. data/test/facebook/test_misc.rb +4 -14
  33. data/test/facebook/test_oauth.rb +1 -1
  34. data/test/facebook/test_old.rb +1 -1
  35. data/test/facebook/test_page.rb +4 -5
  36. data/test/facebook/test_parse.rb +0 -7
  37. data/test/facebook/test_serialize.rb +1 -1
  38. data/test/facebook/test_timeout.rb +4 -4
  39. data/test/instagram/test_api.rb +54 -0
  40. data/test/twitter/test_api.rb +1 -1
  41. metadata +26 -23
  42. data/example/rainbows.rb +0 -67
  43. data/task/.gitignore +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: f6c1734aa90af4216bde1eb8b94091ccdc5fae97
4
- data.tar.gz: 40483e18c8ae3c9c638335732066b5f4318836a7
5
- !binary "U0hBNTEy":
6
- metadata.gz: bb36d1c9cc01564aa5225f81593ef18395689b72de1aec9c95f797c5df77cf1bade26e4455cfb0d232efedc90c8238b6df96c330c28107bcef22f5805660aeb3
7
- data.tar.gz: e96d8a2ec4501e0d56b3a6f9bd125a7c46ae5bd6aa40e7cb5c894b7b5b363d2c454d2214666b84f2b86fd0a00d193c77da1f886f31c8fa4ba77c732ae3d4e488
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
@@ -1,3 +1,2 @@
1
- pkg
2
- *.rbc
1
+ /pkg/
3
2
  Gemfile.lock
data/.gitmodules CHANGED
@@ -3,4 +3,4 @@
3
3
  url = git://github.com/godfat/gemgem.git
4
4
  [submodule "rest-core"]
5
5
  path = rest-core
6
- url = git://github.com/cardinalblue/rest-core.git
6
+ url = git://github.com/godfat/rest-core.git
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 RBXOPT=-X19'
6
- - 'RESTMORE=rails3 RBXOPT=-X19'
5
+ - 'RESTMORE=rest-more'
6
+ - 'RESTMORE=rails3'
7
7
 
8
8
  rvm:
9
9
  - 1.9.3
10
10
  - 2.0.0
11
- - rbx-head
12
- - jruby-head
11
+ - ruby
12
+ - rbx
13
+ - jruby
data/CHANGES.md CHANGED
@@ -188,4 +188,4 @@ of being raised.
188
188
  error. From now on it would simply ignore it and wipe out the data.
189
189
  * [`Flurry`] Some minor updates.
190
190
 
191
- [rest-core]: https://github.com/cardinalblue/rest-core
191
+ [rest-core]: https://github.com/godfat/rest-core
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- source 'http://rubygems.org'
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 'rr'
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(:ruby) do
21
+ platforms :ruby do
26
22
  gem 'yajl-ruby'
27
- gem 'psych' if ENV['RESTMORE'] == 'rails3' # why?
28
23
  end
29
24
 
30
- platforms(:jruby) do
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.11' if ENV['RESTMORE'] == 'rails3'
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 Cardinal Blue <http://cardinalblue.com>
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/cardinalblue/rest-more)
14
+ * [github](https://github.com/godfat/rest-more)
15
15
  * [rubygems](https://rubygems.org/gems/rest-more)
16
- * [rdoc](http://rdoc.info/projects/cardinalblue/rest-more)
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/cardinalblue/rest-core
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
- * Github
32
- * Linkedin
33
- * Twitter
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
- Rails utilities are also included.
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) 1.9.3, Rubinius 1.9 and JRuby 1.9
42
- * gem rest-core
43
- * gem rest-client
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/cardinalblue/rest-more.git',
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
- The simplest usage:
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::Twitter.new.statuses('_cardinalblue') # get user tweets
74
- RC::Github.new.get('users/cardinalblue') # get user info
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
- linkedin = RC::Linkedin.new(:consumer_key => '...',
77
- :consumer_secret => '...')
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
- RC::Facebook.new.get('4') # get user info
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/cardinalblue/rest-more/blob/master/example/simple.rb
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 "rest-client with threads doing concurrent requests"
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'){ |r|
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/cardinalblue/rest-more/blob/master/example/multi.rb
125
- [future]: https://github.com/cardinalblue/rest-core#advanced-concurrent-http-requests----embrace-the-future
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]: https://github.com/cardinalblue/rest-more/blob/master/doc/tutorial/facebook.md
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 'cardinalblue'
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](https://github.com/cardinalblue/rest-more/blob/master/CHANGES.md)
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-2012, Cardinal Blue
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.