rest-core 0.3.0 → 0.4.0.pre.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +55 -0
- data/README.md +101 -4
- data/bin/rib-rest-core +22 -0
- data/example/rails2/app/controllers/application_controller.rb +1 -0
- data/example/rails2/app/views/application/helper.html.erb +2 -1
- data/example/rails2/config/rest-core.yaml +4 -0
- data/example/rails2/test/functional/application_controller_test.rb +3 -1
- data/example/rails3/app/controllers/application_controller.rb +1 -0
- data/example/rails3/app/views/application/helper.html.erb +2 -1
- data/example/rails3/config/rest-core.yaml +4 -0
- data/example/rails3/test/functional/application_controller_test.rb +3 -1
- data/lib/rest-core/app/{ask.rb → dry.rb} +1 -1
- data/lib/rest-core/builder.rb +19 -3
- data/lib/rest-core/client/facebook/rails_util.rb +26 -37
- data/lib/rest-core/client/facebook.rb +19 -23
- data/lib/rest-core/client/flurry/rails_util.rb +72 -0
- data/lib/rest-core/client/flurry.rb +89 -0
- data/lib/rest-core/client/github.rb +3 -6
- data/lib/rest-core/client/linkedin.rb +3 -7
- data/lib/rest-core/client/mixi.rb +51 -0
- data/lib/rest-core/client/simple.rb +2 -0
- data/lib/rest-core/client/twitter.rb +5 -9
- data/lib/rest-core/client/universal.rb +18 -0
- data/lib/rest-core/client.rb +40 -82
- data/lib/rest-core/error.rb +5 -0
- data/lib/rest-core/middleware/bypass.rb +13 -0
- data/lib/rest-core/middleware/common_logger.rb +3 -2
- data/lib/rest-core/middleware/json_decode.rb +1 -0
- data/lib/rest-core/middleware/oauth2_header.rb +23 -0
- data/lib/rest-core/middleware.rb +2 -1
- data/lib/rest-core/test.rb +1 -3
- data/lib/rest-core/util/rails_util_util.rb +19 -0
- data/lib/rest-core/version.rb +1 -1
- data/lib/rest-core/wrapper.rb +10 -4
- data/lib/rest-core.rb +9 -2
- data/lib/rib/app/rest-core.rb +15 -0
- data/rest-core.gemspec +26 -8
- data/task/gemgem.rb +75 -9
- data/test/client/facebook/test_api.rb +3 -3
- data/test/client/facebook/test_misc.rb +3 -3
- data/test/test_builder.rb +14 -0
- data/test/test_client.rb +14 -0
- data/test/test_oauth1_header.rb +1 -1
- data/test/test_wrapper.rb +30 -0
- metadata +29 -11
data/CHANGES.md
CHANGED
@@ -1,5 +1,59 @@
|
|
1
1
|
# rest-core CHANGES
|
2
2
|
|
3
|
+
## rest-core 0.4.0 -- ?
|
4
|
+
|
5
|
+
### Incompatible changes:
|
6
|
+
|
7
|
+
* [dry] Now `RestCore::Ask` is renamed to `RestCore::Dry` for better
|
8
|
+
understanding. Thanks miaout17
|
9
|
+
|
10
|
+
* [client] Now `request` method takes an env and an app to make requests,
|
11
|
+
instead of a weird requests array.
|
12
|
+
|
13
|
+
### Compatible changes:
|
14
|
+
|
15
|
+
* [client] Introduced a new method `request_full` which is exactly the same
|
16
|
+
as `request` but also returns various information from the app, including
|
17
|
+
`RESPONSE_STATUS` and `RESPONSE_HEADERS`
|
18
|
+
|
19
|
+
* [client] Removed various unused, untested, undocumented legacy from
|
20
|
+
rest-graph.
|
21
|
+
|
22
|
+
* [error] Introduced `RestCore::Error` which is the base class for all
|
23
|
+
exceptions raised by rest-core
|
24
|
+
|
25
|
+
* [builder] Now `RestCore::Builder.default_app` is the default app which
|
26
|
+
would be used for building clients without setting an app. By default,
|
27
|
+
it's `RestClient`, but you can change it if you like.
|
28
|
+
|
29
|
+
* [builder] It no longer builds a @wrapped app. If you don't understand this,
|
30
|
+
then this does nothing for you. It's an internal change. (or bug fix)
|
31
|
+
|
32
|
+
* [wrapper] Now `RestCore::Wrapper.default_app` is the default app which
|
33
|
+
would be used for wrapping middlewares without setting an app. By default,
|
34
|
+
it's `Dry`, but you can change it if you like.
|
35
|
+
|
36
|
+
* [wrapped] Fixed a bug that force middlewares to implement `members` method,
|
37
|
+
which should be optional. Thanks miaout17
|
38
|
+
|
39
|
+
* [simple] Added a Simple client, which only wraps RestClient
|
40
|
+
* [univeral] Added an Universal client, which could be used for anything
|
41
|
+
* [flurry] Added a Flurry client, along with its `Flurry::RailsUtil`
|
42
|
+
* [mixi] Added a Mixi client
|
43
|
+
|
44
|
+
* [bypass] Added a Bypass middleware which does nothing but passing env
|
45
|
+
* [oauth2_header] OAuth2Header is a middleware which would pass access_token
|
46
|
+
in header instead of in query string.
|
47
|
+
* [common_logger] nil object would no longer be logged
|
48
|
+
* [json_decode] Do nothing if we are being asked for env (dry mode)
|
49
|
+
* [middleware] Now not only query values would be escaped, but also keys.
|
50
|
+
|
51
|
+
* [rib-rest-core] Introduced an interactive shell. You'll need [rib][] to
|
52
|
+
run this: `rib rest-core`. It is using an universal client to access
|
53
|
+
arbitrary websites.
|
54
|
+
|
55
|
+
[rib]: https://github.com/godfat/rib
|
56
|
+
|
3
57
|
## rest-core 0.3.0 -- 2011-09-03
|
4
58
|
|
5
59
|
* [facebook] RestGraph is Facebook now.
|
@@ -16,6 +70,7 @@
|
|
16
70
|
* [oauth2_query] Now we always use the term "access_token"
|
17
71
|
* [config] Now Config#load and Config#load_for_rails take namespace
|
18
72
|
e.g. rest-core.yaml:
|
73
|
+
|
19
74
|
development:
|
20
75
|
facebook:
|
21
76
|
app_id: 123
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# rest-core [![Build Status](http://travis-ci.org/godfat/rest-core.png)](http://travis-ci.org/godfat/rest-core)
|
2
|
+
|
2
3
|
by Cardinal Blue <http://cardinalblue.com>
|
3
4
|
|
4
5
|
## LINKS:
|
@@ -10,7 +11,7 @@ by Cardinal Blue <http://cardinalblue.com>
|
|
10
11
|
|
11
12
|
## DESCRIPTION:
|
12
13
|
|
13
|
-
A modular Ruby REST client collection/infrastructure
|
14
|
+
A modular Ruby REST client collection/infrastructure
|
14
15
|
|
15
16
|
In this era of web services and mashups, we have seen a blooming of REST
|
16
17
|
APIs. One might wonder, how do we use these APIs easily and elegantly?
|
@@ -53,9 +54,7 @@ Or if you want development version, put this in Gemfile:
|
|
53
54
|
linkedin.authorize!('..') # paste your code from browser
|
54
55
|
linkedin.me # get current user info
|
55
56
|
|
56
|
-
#
|
57
|
-
require 'rest-core/client/rest-graph'
|
58
|
-
RestGraph.new.get('4') # get user info
|
57
|
+
RestCore::Facebook.new.get('4') # get user info
|
59
58
|
|
60
59
|
See [example][] for more complex examples.
|
61
60
|
|
@@ -86,6 +85,104 @@ See [built-in clients][] for more complex examples.
|
|
86
85
|
|
87
86
|
[built-in clients]: https://github.com/cardinalblue/rest-core/tree/master/lib/rest-core/client
|
88
87
|
|
88
|
+
## A simple interactive shell with [rib][]
|
89
|
+
|
90
|
+
You need to install [rib][] in order to try this interactive shell:
|
91
|
+
|
92
|
+
gem install rib
|
93
|
+
|
94
|
+
Then you can try this by running `rib rest-core`:
|
95
|
+
|
96
|
+
rest-core>> self.site = 'https://api.github.com/users/'
|
97
|
+
rest-core>> get 'cardinalblue', {}, :json_decode => true
|
98
|
+
|
99
|
+
Which is using `RestCore::Universal` for accessing arbitrary websites.
|
100
|
+
|
101
|
+
[rib]: https://github.com/godfat/rib
|
102
|
+
|
103
|
+
## GLOSSARY:
|
104
|
+
|
105
|
+
* A _client_ is a class which can new connections to make requests.
|
106
|
+
For instance, `RestCore::Facebook.new.get('4')`
|
107
|
+
|
108
|
+
* An _app_ is an HTTP client which would do the underneath HTTP requests.
|
109
|
+
For instance, `RestCore::RestClient` is an HTTP client which uses
|
110
|
+
rest-client gem (`::RestClient`) to make HTTP requests.
|
111
|
+
|
112
|
+
* A _middleware_ is a component for a rest-core stack.
|
113
|
+
For instance, `RestCore::DefaultSite` is a middleware which would add
|
114
|
+
default site URL in front of the request URI if it is not started with
|
115
|
+
http://, thus you can do this: `RestCore::Facebook.get('4')` without
|
116
|
+
specifying where the site (Facebook) it is.
|
117
|
+
|
118
|
+
* `RestCore::Wrapper` is a utility which could help you wrap a number of
|
119
|
+
middlewares into another middleware. Currently, it's used in
|
120
|
+
`RestCore::Buidler` and `RestCore::Cache`.
|
121
|
+
|
122
|
+
* `RestCore::Builder` is a utility which could help you build a _client_
|
123
|
+
with a collection of _middlewares_ and an _app_. i.e. a rest-core stack.
|
124
|
+
|
125
|
+
* `RestCore::Middleware` is a utility which could help you build a non-trivial
|
126
|
+
middleware. More explanation to come...
|
127
|
+
|
128
|
+
* `RestCore::Client` is a module which would be included in a generated
|
129
|
+
_client_ by `RestCore::Builder`. It contains a number of convenient
|
130
|
+
functions which is generally useful.
|
131
|
+
|
132
|
+
* `RestCore::ClientOAuth1` is a module which should be included in a OAuth1.0
|
133
|
+
client. It contains a number of convenient functions which is useful for an
|
134
|
+
OAuth 1.0 client.
|
135
|
+
|
136
|
+
* An `env` is a hash which contains all the information for both request and
|
137
|
+
response. It's mostly seen in `@app.call(env)` See other explanation
|
138
|
+
such as `env[RestCore::REQUEST_METHOD]` for more detail.
|
139
|
+
|
140
|
+
* `env[RestCore::REQUEST_METHOD]` is a symbol representing which HTTP method
|
141
|
+
would be used in the subsequent HTTP request. The possible values are
|
142
|
+
either: `:get`, `:post`, `:put` or `:delete`.
|
143
|
+
|
144
|
+
* `env[RestCore::REQUEST_PATH]` is a string representing which HTTP path
|
145
|
+
would be used in the subsequent HTTP request. This path could also include
|
146
|
+
the protocol, not only the path. e.g. `"http://graph.facebook.com/4"` or
|
147
|
+
simply `"4"`. In the case of built-in Facebook client, the
|
148
|
+
`RestCore::DefaultSite` middleware would take care of the site.
|
149
|
+
|
150
|
+
* `env[RestCore::REQUEST_QUERY]` is a hash which keys are query keys and
|
151
|
+
values are query values. Both keys and values' type should be String, not
|
152
|
+
Symbol. Values with nil or false would be ignored. Both keys and values
|
153
|
+
would be escaped automatically.
|
154
|
+
|
155
|
+
* `env[RestCore::REQUEST_PAYLOAD]` is a hash which keys are payload keys and
|
156
|
+
values are payload values. Both keys and values' type should be String,
|
157
|
+
not Symbol. Values with nil or false would be ignored. Both keys and values
|
158
|
+
would be escaped automatically.
|
159
|
+
|
160
|
+
* `env[RestCore::REQUEST_HEADERS]` is a hash which keys are header names and
|
161
|
+
values are header values. Both keys and values' type should be String,
|
162
|
+
not Symbol. Values with nil or false would be ignored.
|
163
|
+
|
164
|
+
* `env[RestCore::RESPONSE_BODY]` is a string which is returned by the server.
|
165
|
+
Might be nil if there's no response or not yet making HTTP request.
|
166
|
+
|
167
|
+
* `env[RestCore::RESPONSE_STATUS]` is a number which is returned by the
|
168
|
+
server for the HTTP status. Might be nil if there's no response or not
|
169
|
+
yet making HTTP request.
|
170
|
+
|
171
|
+
* `env[RestCore::RESPONSE_HEADERS]` is a hash which is returned by the server
|
172
|
+
for the response headers. Both keys and values' type should be String.
|
173
|
+
|
174
|
+
* `env[RestCore::DRY]` is a boolean (either `true` or `false` or `nil`) which
|
175
|
+
indicates that if we're only asking for modified `env`, instead of making
|
176
|
+
real requests. It's used to ask for the real request URI, etc.
|
177
|
+
|
178
|
+
* `env[RestCore::FAIL]` is an array which contains failing events. Events
|
179
|
+
could be any objects, it's handled by `RestCore::ErrorDetector` or any
|
180
|
+
other custom _middleware_.
|
181
|
+
|
182
|
+
* `env[RestCore::LOG]` is an array which contains logging events. Events
|
183
|
+
could be any objects, it's handled by `RestCore::CommonLogger` or
|
184
|
+
any other custom _middleware_.
|
185
|
+
|
89
186
|
## LICENSE:
|
90
187
|
|
91
188
|
Apache License 2.0
|
data/bin/rib-rest-core
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rib/runner'
|
5
|
+
# create the shell before app to prvent your bundler (if any) kicks in
|
6
|
+
Rib.shell
|
7
|
+
# we need to require anything before loading the app,
|
8
|
+
# and both `rib auto` (true) and `rib-auto` (nil) should work
|
9
|
+
require 'rib/core' if Rib.config.delete(:mimic_irb) != false
|
10
|
+
require 'rib/app/rest-core'
|
11
|
+
# load the app
|
12
|
+
Rib::RestCore.load
|
13
|
+
Rib::Runner.run(ARGV)
|
14
|
+
rescue LoadError => e
|
15
|
+
abort("Error: #{e}\n" \
|
16
|
+
"Please install rib to use interactive rest-core:\n\n" \
|
17
|
+
" gem install rib\n\n" \
|
18
|
+
"Or add rib or rest-core to Gemfile if that's the case")
|
19
|
+
end
|
20
|
+
|
21
|
+
__END__
|
22
|
+
Run as interactive rest-core client
|
@@ -1 +1,2 @@
|
|
1
|
-
<%= rc_facebook.app_id
|
1
|
+
<%= rc_facebook.app_id %>
|
2
|
+
<%= rc_flurry .api_key %>
|
@@ -178,6 +178,8 @@ class ApplicationControllerTest < ActionController::TestCase
|
|
178
178
|
def test_helper
|
179
179
|
get(:helper)
|
180
180
|
assert_response :success
|
181
|
-
assert_equal RestCore::Facebook.default_app_id
|
181
|
+
assert_equal "#{RestCore::Facebook.default_app_id}\n" \
|
182
|
+
"#{RestCore::Flurry .default_api_key}",
|
183
|
+
@response.body.strip
|
182
184
|
end
|
183
185
|
end
|
@@ -1 +1,2 @@
|
|
1
|
-
<%= rc_facebook.app_id
|
1
|
+
<%= rc_facebook.app_id %>
|
2
|
+
<%= rc_flurry .api_key %>
|
@@ -178,6 +178,8 @@ class ApplicationControllerTest < ActionController::TestCase
|
|
178
178
|
def test_helper
|
179
179
|
get(:helper)
|
180
180
|
assert_response :success
|
181
|
-
assert_equal RestCore::Facebook.default_app_id
|
181
|
+
assert_equal "#{RestCore::Facebook.default_app_id}\n" \
|
182
|
+
"#{RestCore::Flurry .default_api_key}",
|
183
|
+
@response.body.strip
|
182
184
|
end
|
183
185
|
end
|
data/lib/rest-core/builder.rb
CHANGED
@@ -6,18 +6,34 @@ class RestCore::Builder
|
|
6
6
|
include RestCore
|
7
7
|
include Wrapper
|
8
8
|
|
9
|
+
class << self
|
10
|
+
attr_writer :default_app
|
11
|
+
end
|
12
|
+
def self.default_app
|
13
|
+
@default_app ||= RestClient
|
14
|
+
end
|
15
|
+
|
9
16
|
def self.client *attrs, &block
|
10
17
|
new(&block).to_client(*attrs)
|
11
18
|
end
|
12
19
|
|
13
20
|
def to_client *attrs
|
14
|
-
|
15
|
-
struct =
|
21
|
+
fields = members + attrs
|
22
|
+
struct = if fields.empty?
|
23
|
+
Struct.new(nil)
|
24
|
+
else
|
25
|
+
Struct.new(*fields)
|
26
|
+
end
|
16
27
|
client = Class.new(struct)
|
17
|
-
client.send(:include, Client)
|
18
28
|
client.const_set('Struct', struct)
|
29
|
+
client.send(:include, Client)
|
19
30
|
class << client; attr_reader :builder; end
|
20
31
|
client.instance_variable_set(:@builder, self)
|
21
32
|
client
|
22
33
|
end
|
34
|
+
|
35
|
+
def initialize &block
|
36
|
+
@middles ||= []
|
37
|
+
instance_eval(&block) if block_given?
|
38
|
+
end
|
23
39
|
end
|
@@ -1,33 +1,27 @@
|
|
1
1
|
|
2
|
+
require 'rest-core/util/rails_util_util'
|
3
|
+
|
2
4
|
require 'cgi'
|
3
5
|
require 'uri'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def default_check_handler ; nil; end
|
17
|
-
end
|
18
|
-
|
19
|
-
module RailsCache
|
20
|
-
def [] key ; read(key) ; end
|
21
|
-
def []= key, value; write(key, value) ; end
|
22
|
-
def store key, value,
|
23
|
-
options={}; write(key, value, options); end
|
24
|
-
end
|
7
|
+
module RestCore::Facebook::DefaultAttributes
|
8
|
+
def default_canvas ; '' ; end
|
9
|
+
def default_iframe ; false; end
|
10
|
+
def default_auto_authorize ; false; end
|
11
|
+
def default_auto_authorize_options; {} ; end
|
12
|
+
def default_auto_authorize_scope ; '' ; end
|
13
|
+
def default_ensure_authorized ; false; end
|
14
|
+
def default_write_session ; false; end
|
15
|
+
def default_write_cookies ; false; end
|
16
|
+
def default_write_handler ; nil; end
|
17
|
+
def default_check_handler ; nil; end
|
25
18
|
end
|
26
19
|
|
27
20
|
module RestCore::Facebook::RailsUtil
|
21
|
+
include RestCore
|
22
|
+
|
28
23
|
def self.init app=Rails
|
29
|
-
|
30
|
-
RestCore::Config.load_for_rails(RestCore::Facebook, 'facebook', app)
|
24
|
+
Config.load_for_rails(Facebook, 'facebook', app)
|
31
25
|
end
|
32
26
|
|
33
27
|
module Helper
|
@@ -40,9 +34,9 @@ module RestCore::Facebook::RailsUtil
|
|
40
34
|
# skip if included already, any better way to detect this?
|
41
35
|
return if controller.respond_to?(:rc_facebook, true)
|
42
36
|
|
43
|
-
controller.rescue_from(
|
37
|
+
controller.rescue_from(Facebook::Error::AccessToken,
|
44
38
|
:with => :rc_facebook_on_access_token_error)
|
45
|
-
controller.helper(
|
39
|
+
controller.helper(Facebook::RailsUtil::Helper)
|
46
40
|
controller.instance_methods.select{ |method|
|
47
41
|
method.to_s =~ /^rc_facebook/
|
48
42
|
}.each{ |method| controller.send(:protected, method) }
|
@@ -50,9 +44,9 @@ module RestCore::Facebook::RailsUtil
|
|
50
44
|
|
51
45
|
def rc_facebook_setup options={}
|
52
46
|
rc_facebook_options_ctl.merge!(
|
53
|
-
|
47
|
+
RailsUtilUtil.extract_options(Facebook.members, options, :reject))
|
54
48
|
rc_facebook_options_new.merge!(
|
55
|
-
|
49
|
+
RailsUtilUtil.extract_options(Facebook.members, options, :select))
|
56
50
|
|
57
51
|
# we'll need to reinitialize rc_facebook with the new options,
|
58
52
|
# otherwise if you're calling rc_facebook before rc_facebook_setup,
|
@@ -84,7 +78,7 @@ module RestCore::Facebook::RailsUtil
|
|
84
78
|
|
85
79
|
# override this if you need different app_id and secret
|
86
80
|
def rc_facebook
|
87
|
-
@rc_facebook ||=
|
81
|
+
@rc_facebook ||= Facebook.new(rc_facebook_options_new)
|
88
82
|
end
|
89
83
|
|
90
84
|
def rc_facebook_on_access_token_error error=nil
|
@@ -157,7 +151,7 @@ module RestCore::Facebook::RailsUtil
|
|
157
151
|
if rc_facebook_options_ctl.has_key?(key)
|
158
152
|
rc_facebook_options_ctl[key]
|
159
153
|
else
|
160
|
-
|
154
|
+
Facebook.send("default_#{key}")
|
161
155
|
end
|
162
156
|
end
|
163
157
|
|
@@ -221,8 +215,10 @@ module RestCore::Facebook::RailsUtil
|
|
221
215
|
def rc_facebook_check_code
|
222
216
|
return if rc_facebook.authorized? || !params[:code]
|
223
217
|
|
224
|
-
rc_facebook.authorize!(
|
225
|
-
|
218
|
+
rc_facebook.authorize!(
|
219
|
+
:code => params[:code],
|
220
|
+
:redirect_uri => rc_facebook_normalized_request_uri)
|
221
|
+
|
226
222
|
logger.debug(
|
227
223
|
"DEBUG: Facebook: detected code with " \
|
228
224
|
"#{rc_facebook_normalized_request_uri}," \
|
@@ -329,13 +325,6 @@ module RestCore::Facebook::RailsUtil
|
|
329
325
|
!rc_facebook_oget(:auto_authorize_options).blank? ||
|
330
326
|
rc_facebook_oget(:auto_authorize)
|
331
327
|
end
|
332
|
-
|
333
|
-
def rc_facebook_extract_options options, method
|
334
|
-
# Hash[] is for ruby 1.8.7
|
335
|
-
# map(&:to_sym) is for ruby 1.8.7
|
336
|
-
Hash[options.send(method){ |(k, v)|
|
337
|
-
RestCore::Facebook.members.map(&:to_sym).member?(k) }]
|
338
|
-
end
|
339
328
|
# ==================== end misc ================================
|
340
329
|
end
|
341
330
|
|
@@ -13,28 +13,24 @@ RestCore::Facebook = RestCore::Builder.client(
|
|
13
13
|
'Accept-Language' => 'en-us'}
|
14
14
|
use s::Oauth2Query , nil
|
15
15
|
|
16
|
-
use s::CommonLogger ,
|
17
|
-
|
16
|
+
use s::CommonLogger , nil
|
18
17
|
use s::Cache , nil, 3600 do
|
19
|
-
use s::ErrorHandler
|
20
|
-
|
21
|
-
use s::ErrorDetector
|
18
|
+
use s::ErrorHandler, lambda{ |env|
|
19
|
+
raise ::RestCore::Facebook::Error.call(env) }
|
20
|
+
use s::ErrorDetector, lambda{ |env|
|
22
21
|
if env[s::RESPONSE_BODY].kind_of?(Hash)
|
23
22
|
env[s::RESPONSE_BODY]['error'] ||
|
24
23
|
env[s::RESPONSE_BODY]['error_code']
|
25
24
|
end}
|
26
25
|
|
27
|
-
use s::JsonDecode
|
28
|
-
run s::Ask
|
26
|
+
use s::JsonDecode , true
|
29
27
|
end
|
30
28
|
|
31
29
|
use s::Defaults , :data => lambda{{}},
|
32
30
|
:old_site => 'https://api.facebook.com/'
|
33
|
-
|
34
|
-
run s::RestClient
|
35
31
|
end
|
36
32
|
|
37
|
-
class RestCore::Facebook::Error <
|
33
|
+
class RestCore::Facebook::Error < RestCore::Error
|
38
34
|
include RestCore
|
39
35
|
class AccessToken < Facebook::Error; end
|
40
36
|
class InvalidAccessToken < AccessToken ; end
|
@@ -91,7 +87,7 @@ module RestCore::Facebook::Client
|
|
91
87
|
|
92
88
|
def next_page hash, opts={}, &cb
|
93
89
|
if hash['paging'].kind_of?(Hash) && hash['paging']['next']
|
94
|
-
|
90
|
+
get(hash['paging']['next'], {}, opts, &cb)
|
95
91
|
else
|
96
92
|
yield(nil) if block_given?
|
97
93
|
end
|
@@ -99,7 +95,7 @@ module RestCore::Facebook::Client
|
|
99
95
|
|
100
96
|
def prev_page hash, opts={}, &cb
|
101
97
|
if hash['paging'].kind_of?(Hash) && hash['paging']['previous']
|
102
|
-
|
98
|
+
get(hash['paging']['previous'], {}, opts, &cb)
|
103
99
|
else
|
104
100
|
yield(nil) if block_given?
|
105
101
|
end
|
@@ -171,8 +167,8 @@ module RestCore::Facebook::Client
|
|
171
167
|
def authorize! opts={}
|
172
168
|
query = {:client_id => app_id, :client_secret => secret}.merge(opts)
|
173
169
|
self.data = Vendor.parse_query(
|
174
|
-
|
175
|
-
|
170
|
+
get(url('oauth/access_token'), query,
|
171
|
+
{:json_decode => false}.merge(opts)))
|
176
172
|
end
|
177
173
|
|
178
174
|
# old rest facebook api, i will definitely love to remove them someday
|
@@ -181,15 +177,14 @@ module RestCore::Facebook::Client
|
|
181
177
|
uri = url("method/#{path}", {:format => 'json'}.merge(query),
|
182
178
|
{:site => old_site}.merge(opts))
|
183
179
|
if opts[:post]
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
&cb)
|
180
|
+
post(url("method/#{path}", {:format => 'json'},
|
181
|
+
{:site => old_site}.merge(opts)),
|
182
|
+
query,
|
183
|
+
{} ,
|
184
|
+
opts.merge('cache.key' => uri, 'cache.post' => true),
|
185
|
+
&cb)
|
191
186
|
else
|
192
|
-
|
187
|
+
get(uri, {}, opts, &cb)
|
193
188
|
end
|
194
189
|
end
|
195
190
|
|
@@ -209,7 +204,8 @@ module RestCore::Facebook::Client
|
|
209
204
|
def exchange_sessions query={}, opts={}, &cb
|
210
205
|
q = {:client_id => app_id, :client_secret => secret,
|
211
206
|
:type => 'client_cred'}.merge(query)
|
212
|
-
|
207
|
+
post(url('oauth/exchange_sessions', q),
|
208
|
+
{}, {}, opts, &cb)
|
213
209
|
end
|
214
210
|
|
215
211
|
protected
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
require 'rest-core/util/rails_util_util'
|
3
|
+
|
4
|
+
module RestCore::Flurry::DefaultAttributes
|
5
|
+
def default_api_key ; nil; end
|
6
|
+
def default_access_code; nil; end
|
7
|
+
end
|
8
|
+
|
9
|
+
module RestCore::Flurry::RailsUtil
|
10
|
+
include RestCore
|
11
|
+
|
12
|
+
def self.init app=Rails
|
13
|
+
Config.load_for_rails(Flurry, 'flurry', app)
|
14
|
+
end
|
15
|
+
|
16
|
+
module Helper
|
17
|
+
def rc_flurry
|
18
|
+
controller.send(:rc_flurry)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.included controller
|
23
|
+
# skip if included already, any better way to detect this?
|
24
|
+
return if controller.respond_to?(:rc_flurry, true)
|
25
|
+
|
26
|
+
controller.helper(Flurry::RailsUtil::Helper)
|
27
|
+
controller.instance_methods.select{ |method|
|
28
|
+
method.to_s =~ /^rc_flurry/
|
29
|
+
}.each{ |method| controller.send(:protected, method) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def rc_flurry_setup options={}
|
33
|
+
rc_flurry_options_ctl.merge!(
|
34
|
+
RailsUtilUtil.extract_options(Flurry.members, options, :reject))
|
35
|
+
rc_flurry_options_new.merge!(
|
36
|
+
RailsUtilUtil.extract_options(Flurry.members, options, :select))
|
37
|
+
|
38
|
+
# we'll need to reinitialize rc_flurry with the new options,
|
39
|
+
# otherwise if you're calling rc_flurry before rc_flurry_setup,
|
40
|
+
# you'll end up with default options without the ones you've passed
|
41
|
+
# into rc_flurry_setup.
|
42
|
+
rc_flurry.send(:initialize, rc_flurry_options_new)
|
43
|
+
|
44
|
+
true # keep going
|
45
|
+
end
|
46
|
+
|
47
|
+
def rc_flurry
|
48
|
+
@rc_flurry ||= Flurry.new(rc_flurry_options_new)
|
49
|
+
end
|
50
|
+
|
51
|
+
module_function
|
52
|
+
|
53
|
+
# ==================== begin options utility =======================
|
54
|
+
def rc_flurry_oget key
|
55
|
+
if rc_flurry_options_ctl.has_key?(key)
|
56
|
+
rc_flurry_options_ctl[key]
|
57
|
+
else
|
58
|
+
Flurry.send("default_#{key}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def rc_flurry_options_ctl
|
63
|
+
@rc_flurry_options_ctl ||= {}
|
64
|
+
end
|
65
|
+
|
66
|
+
def rc_flurry_options_new
|
67
|
+
@rc_flurry_options_new ||= {:log_method => logger.method(:debug)}
|
68
|
+
end
|
69
|
+
# ==================== end options utility =======================
|
70
|
+
end
|
71
|
+
|
72
|
+
RestCore::Flurry::RailsUtil.init(Rails)
|