mini_fb 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{README.markdown → README.md} +0 -0
- data/lib/mini_fb.rb +20 -11
- data/lib/version.rb +1 -1
- data/spec/mini_fb_spec.rb +44 -45
- data/spec/test_helper.rb +14 -0
- metadata +6 -5
- data/VERSION.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8e391adab3eb0fcf238f777a85227dd45e654fd
|
4
|
+
data.tar.gz: a2edb60b87d01fd15ac45bbad81ea061d777cdbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c44908e88abd8128bff57b620934b1e9bb50be219883aa3b3ebd4285da632f128e68bcd407c8a842454d0365045a55bb701e9c50b643729234d748b611efeac
|
7
|
+
data.tar.gz: 0d96d4738a20e6a09c8c4e7fdeeabc7c7f71423150bd47183c939495ac258ca5c92779df7453f398849537a5bf417e04412d6820c371b6fd3e3a4132afa449d3
|
File without changes
|
data/lib/mini_fb.rb
CHANGED
@@ -512,7 +512,7 @@ module MiniFB
|
|
512
512
|
resp = @@http.get oauth_url
|
513
513
|
puts 'resp=' + resp.body.to_s if @@logging
|
514
514
|
params = {}
|
515
|
-
params_array = resp.split("&")
|
515
|
+
params_array = resp.body.to_s.split("&")
|
516
516
|
params_array.each do |p|
|
517
517
|
ps = p.split("=")
|
518
518
|
params[ps[0]] = ps[1]
|
@@ -520,17 +520,29 @@ module MiniFB
|
|
520
520
|
return params
|
521
521
|
end
|
522
522
|
|
523
|
+
# Gets long-lived token from the Facebook Graph API
|
524
|
+
# options:
|
525
|
+
# - app_id: your app ID (string)
|
526
|
+
# - secret: your app secret (string)
|
527
|
+
# - access_token: short-lived user token (string)
|
523
528
|
# returns a hash with one value being 'access_token', the other being 'expires'
|
529
|
+
#
|
530
|
+
# Throws MiniFB::FaceBookError if response from Facebook Graph API is not successful
|
524
531
|
def self.fb_exchange_token(app_id, secret, access_token)
|
525
532
|
oauth_url = "#{graph_base}oauth/access_token"
|
526
533
|
oauth_url << "?client_id=#{app_id}"
|
527
534
|
oauth_url << "&client_secret=#{secret}"
|
528
535
|
oauth_url << "&grant_type=fb_exchange_token"
|
529
536
|
oauth_url << "&fb_exchange_token=#{CGI.escape(access_token)}"
|
530
|
-
|
531
|
-
|
537
|
+
response = @@http.get oauth_url
|
538
|
+
body = response.body.to_s
|
539
|
+
puts 'resp=' + body if @@logging
|
540
|
+
unless response.ok?
|
541
|
+
res_hash = JSON.parse(body)
|
542
|
+
raise MiniFB::FaceBookError.new(response.status, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
|
543
|
+
end
|
532
544
|
params = {}
|
533
|
-
params_array =
|
545
|
+
params_array = body.split("&")
|
534
546
|
params_array.each do |p|
|
535
547
|
ps = p.split("=")
|
536
548
|
params[ps[0]] = ps[1]
|
@@ -724,16 +736,10 @@ module MiniFB
|
|
724
736
|
@@log.debug "Response = #{resp}. Status = #{response.status}" if @@logging
|
725
737
|
@@log.debug 'API Version =' + response.headers["Facebook-API-Version"].to_s if @@logging
|
726
738
|
|
727
|
-
res_hash = JSON.parse(resp.to_s.size > 2 ? resp.to_s : {response: resp.to_s}.to_json)
|
728
|
-
|
729
|
-
unless response.ok?
|
730
|
-
raise MiniFB::FaceBookError.new(response.status, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
|
731
|
-
end
|
732
|
-
|
733
739
|
if options[:response_type] == :params
|
734
740
|
# Some methods return a param like string, for example: access_token=11935261234123|rW9JMxbN65v_pFWQl5LmHHABC
|
735
741
|
params = {}
|
736
|
-
params_array = resp.split("&")
|
742
|
+
params_array = resp.to_s.split("&")
|
737
743
|
params_array.each do |p|
|
738
744
|
ps = p.split("=")
|
739
745
|
params[ps[0]] = ps[1]
|
@@ -741,6 +747,9 @@ module MiniFB
|
|
741
747
|
return params
|
742
748
|
else
|
743
749
|
res_hash = JSON.parse(resp.to_s.size > 2 ? resp.to_s : {response: resp.to_s}.to_json)
|
750
|
+
unless response.ok?
|
751
|
+
raise MiniFB::FaceBookError.new(response.status, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
|
752
|
+
end
|
744
753
|
end
|
745
754
|
|
746
755
|
if res_hash.is_a? Array # fql return this
|
data/lib/version.rb
CHANGED
data/spec/mini_fb_spec.rb
CHANGED
@@ -3,65 +3,64 @@ require 'uri'
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
require_relative '../lib/mini_fb'
|
6
|
+
require_relative 'test_helper'
|
6
7
|
|
7
8
|
describe MiniFB do
|
9
|
+
before do
|
10
|
+
MiniFB.log_level = :warn
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@config = File.open(file_path) { |yf| YAML::load(yf) }
|
13
|
-
MiniFB.log_level = :warn
|
14
|
-
|
15
|
-
@oauth_url = MiniFB.oauth_url(@config['fb_app_id'],
|
16
|
-
"http://localhost:3000", # redirect url
|
17
|
-
:scope=>MiniFB.scopes.join(","))
|
18
|
-
end
|
19
|
-
|
13
|
+
let(:app_id){TestHelper.config['app_id']}
|
14
|
+
let(:app_secret){TestHelper.config['app_secret']}
|
15
|
+
let(:access_token){TestHelper.config['access_token']}
|
20
16
|
|
17
|
+
describe '#authenticate_as_app' do
|
21
18
|
|
22
|
-
|
23
|
-
|
19
|
+
it 'authenticates with valid params' do
|
20
|
+
res = MiniFB.authenticate_as_app(app_id, app_secret)
|
21
|
+
expect(res).to include('access_token')
|
22
|
+
expect(res['access_token']).to match(/^#{app_id}/)
|
24
23
|
end
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
describe '#signed_request_params' do
|
27
|
+
let (:req) { 'vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0' }
|
28
|
+
let (:secret) { 'secret' }
|
29
29
|
|
30
|
-
it '
|
31
|
-
|
32
|
-
res.should include("access_token")
|
33
|
-
res["access_token"].should match(/^#{@config['fb_app_id']}/)#starts_with?(@config["fb_app_id"].to_s)
|
30
|
+
it 'decodes params' do
|
31
|
+
expect(MiniFB.signed_request_params(secret, req)).to eq({"0" => "payload"})
|
34
32
|
end
|
33
|
+
end
|
35
34
|
|
35
|
+
describe '#exchange_token' do
|
36
|
+
let(:invalid_app_id) { '12345' }
|
37
|
+
let(:invalid_secret) { 'secret' }
|
38
|
+
let(:invalid_access_token) { 'token' }
|
36
39
|
|
37
|
-
it '
|
38
|
-
|
39
|
-
secret = 'secret'
|
40
|
-
req = 'vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0'
|
41
|
-
expect(MiniFB.signed_request_params(secret, req)).to eq({"0" => "payload"})
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
40
|
+
it 'returns valid long-lived token' do
|
41
|
+
res = MiniFB.fb_exchange_token(app_id, app_secret, access_token)
|
45
42
|
|
43
|
+
expect(res).to include('access_token')
|
44
|
+
expect(res).to include('expires')
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
it 'raises error on request with invalid params' do
|
48
|
+
error_message = 'Facebook error 400: OAuthException: '\
|
49
|
+
'Error validating application. '\
|
50
|
+
'Cannot get application info due to a system error.'
|
50
51
|
|
52
|
+
expect do
|
53
|
+
MiniFB.fb_exchange_token(invalid_app_id, invalid_secret, invalid_access_token)
|
54
|
+
end.to raise_error(MiniFB::FaceBookError, error_message)
|
55
|
+
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
'activities'=> [:name],
|
56
|
-
'music' => [:name],
|
57
|
-
'videos' => [:name],
|
58
|
-
'television'=> [:name],
|
59
|
-
'movies' => [:name],
|
60
|
-
'likes' => [:name],
|
61
|
-
'work' => [:name],
|
62
|
-
'education' => [:name],
|
63
|
-
'books' => [:name]
|
64
|
-
}
|
57
|
+
it 'raise error on request with invalid token' do
|
58
|
+
error_message = 'Facebook error 400: OAuthException: '\
|
59
|
+
'Invalid OAuth access token.'
|
65
60
|
|
66
|
-
|
61
|
+
expect do
|
62
|
+
MiniFB.fb_exchange_token(app_id, app_secret, invalid_access_token)
|
63
|
+
end.to raise_error(MiniFB::FaceBookError, error_message)
|
64
|
+
end
|
65
|
+
end
|
67
66
|
end
|
data/spec/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_fb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -50,13 +50,13 @@ files:
|
|
50
50
|
- Gemfile
|
51
51
|
- Gemfile.lock
|
52
52
|
- LICENSE.txt
|
53
|
-
- README.
|
53
|
+
- README.md
|
54
54
|
- Rakefile
|
55
|
-
- VERSION.yml
|
56
55
|
- lib/mini_fb.rb
|
57
56
|
- lib/version.rb
|
58
57
|
- mini_fb.gemspec
|
59
58
|
- spec/mini_fb_spec.rb
|
59
|
+
- spec/test_helper.rb
|
60
60
|
homepage: http://github.com/appoxy/mini_fb/
|
61
61
|
licenses: []
|
62
62
|
metadata: {}
|
@@ -76,9 +76,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: 1.3.6
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.
|
79
|
+
rubygems_version: 2.6.6
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Tiny facebook library. By http://www.appoxy.com
|
83
83
|
test_files:
|
84
84
|
- spec/mini_fb_spec.rb
|
85
|
+
- spec/test_helper.rb
|