File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change
1
+ 2.2.2
Original file line number Diff line number Diff line change @@ -8,12 +8,14 @@ module Api
8
8
class Request
9
9
def initialize ( attrs = { } )
10
10
@host = 'graph.facebook.com'
11
- @query = attrs [ :params ] if attrs [ :params ]
11
+ @query = attrs [ :username ] if attrs [ :username ]
12
+ @access_token = attrs [ :access_token ] if attrs [ :access_token ]
12
13
@path = attrs . fetch :path , "/v2.3/#{ @query } "
13
14
@method = attrs . fetch :method , :get
14
15
end
15
16
16
17
def run
18
+ print "#{ as_curl } \n "
17
19
case response = run_http_request
18
20
when Net ::HTTPOK
19
21
JSON . parse ( response . body )
@@ -35,15 +37,22 @@ def http_request
35
37
end
36
38
37
39
def uri
40
+ query = @access_token ? facebook_access_token : facebook_app_keys
38
41
@uri ||= URI ::HTTPS . build host : @host , path : @path , query : query
39
42
end
40
43
41
- def query
44
+ def facebook_app_keys
42
45
{ } . tap do |query |
43
46
query . merge! access_token : "#{ Net ::Facebook . configuration . client_id } |#{ Net ::Facebook . configuration . client_secret } "
44
47
end . to_param
45
48
end
46
49
50
+ def facebook_access_token
51
+ { } . tap do |query |
52
+ query . merge! access_token : @access_token
53
+ end . to_param
54
+ end
55
+
47
56
def as_curl
48
57
'curl' . tap do |curl |
49
58
curl << " -X #{ http_request . method } "
Original file line number Diff line number Diff line change @@ -36,13 +36,7 @@ def self.find_by(params = {})
36
36
# (case-insensitive).
37
37
# @raise [Net::Errors::UnknownUser] if the page cannot be found.
38
38
def self . find_by! ( params = { } )
39
- find_by_username! params [ :username ]
40
- end
41
-
42
- private
43
-
44
- def self . find_by_username! ( username )
45
- request = Api ::Request . new params : username
39
+ request = Api ::Request . new params
46
40
new request . run
47
41
rescue Errors ::ResponseError => error
48
42
case error . response
You can’t perform that action at this time.
0 commit comments