fb_rails 0.4.0 → 0.5.0
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.
- data/lib/fb_rails/graph.rb +30 -27
- data/lib/fb_rails/log_subscriber.rb +1 -5
- data/lib/fb_rails/mock.rb +4 -5
- data/test/log_subscriber_test.rb +6 -6
- metadata +3 -3
data/lib/fb_rails/graph.rb
CHANGED
@@ -9,45 +9,48 @@ module FbRails
|
|
9
9
|
def facebook_uri
|
10
10
|
@facebook_uri ||= URI.parse('https://graph.facebook.com')
|
11
11
|
end
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :connect
|
15
|
-
def initialize(connect)
|
16
|
-
@connect = connect
|
17
|
-
end
|
18
|
-
|
19
|
-
def post(url, params = {})
|
20
|
-
request(:post, url, params)
|
21
|
-
end
|
22
12
|
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
def http
|
14
|
+
Net::HTTP.new(facebook_uri.host, facebook_uri.port).tap do |result|
|
15
|
+
result.use_ssl = true
|
16
|
+
result.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
17
|
+
end
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
path = build_path(url, params)
|
20
|
+
def request(http_verb, path, params = {})
|
21
|
+
url = build_url(path, params)
|
30
22
|
|
31
23
|
response = ActiveSupport::Notifications.instrument('request.fb_rails') do |payload|
|
32
24
|
payload[:http_verb] = http_verb
|
33
|
-
payload[:request_uri] =
|
34
|
-
http.send(http_verb,
|
25
|
+
payload[:request_uri] = url
|
26
|
+
http.send(http_verb, url)
|
35
27
|
end
|
36
|
-
|
28
|
+
|
37
29
|
ActiveSupport::JSON.decode(response.body)
|
38
30
|
end
|
39
31
|
|
40
|
-
def
|
41
|
-
params = params.merge(:access_token => connect.access_token)
|
32
|
+
def build_url(path, params)
|
42
33
|
param_string = params.map { |key, value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
|
43
|
-
|
34
|
+
"#{path}?#{param_string}"
|
44
35
|
end
|
36
|
+
end
|
45
37
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
attr_reader :connect
|
39
|
+
def initialize(connect)
|
40
|
+
@connect = connect
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(path, params = {})
|
44
|
+
request(:post, path, params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get(path, params = {})
|
48
|
+
request(:get, path, params)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def request(http_verb, path, params)
|
53
|
+
self.class.request(http_verb, path, params.merge(:access_token => connect.access_token))
|
51
54
|
end
|
52
55
|
end
|
53
56
|
end
|
@@ -2,11 +2,7 @@ module FbRails
|
|
2
2
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
3
3
|
def request(event)
|
4
4
|
name = color('FbRails (%.1fms)' % event.duration, CYAN, true)
|
5
|
-
info " #{name}
|
6
|
-
end
|
7
|
-
|
8
|
-
def logger
|
9
|
-
Rails.logger
|
5
|
+
info " #{name} #{event.payload[:http_verb].to_s.upcase} #{event.payload[:request_uri]}"
|
10
6
|
end
|
11
7
|
end
|
12
8
|
end
|
data/lib/fb_rails/mock.rb
CHANGED
@@ -32,7 +32,7 @@ module FbRails
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def find_response(path)
|
35
|
-
path = path.gsub(/\?.*$/, '')
|
35
|
+
path = path.gsub(/\?.*$/, '').gsub(/^\//, '')
|
36
36
|
responses[path]
|
37
37
|
end
|
38
38
|
end
|
@@ -47,9 +47,8 @@ module FbRails
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class Graph
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
50
|
+
def self.http
|
51
|
+
@http ||= Mock.new
|
52
|
+
end
|
54
53
|
end
|
55
54
|
end
|
data/test/log_subscriber_test.rb
CHANGED
@@ -5,22 +5,22 @@ require 'fb_rails/log_subscriber'
|
|
5
5
|
class FbRails::LogSubscriberTest < ActiveSupport::TestCase
|
6
6
|
include ActiveSupport::LogSubscriber::TestHelper
|
7
7
|
|
8
|
-
setup
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
|
9
11
|
FbRails::Mock.respond_to do |mock|
|
10
12
|
mock.add 'test', 'foo' => 'bar'
|
11
13
|
end
|
14
|
+
|
15
|
+
FbRails::LogSubscriber.attach_to :fb_rails
|
12
16
|
end
|
13
17
|
|
14
|
-
def set_logger(logger)
|
15
|
-
# raise 'set logger'
|
16
|
-
Rails.logger = logger
|
17
|
-
end
|
18
|
-
|
19
18
|
test 'request notification' do
|
20
19
|
graph = FbRails::Graph.new(FbRails::Connect.new(fb_cookie))
|
21
20
|
graph.get 'test'
|
22
21
|
|
23
22
|
wait
|
24
23
|
assert_equal 1, @logger.logged(:info).size
|
24
|
+
assert_match /FbRails \(\d+.\d+ms\) GET test/, @logger.logged(:info).first
|
25
25
|
end
|
26
26
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 5
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthew Higgins
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-26 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|