mini_fb 1.1.7 → 1.1.8
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/README.markdown +1 -1
- data/lib/mini_fb.rb +33 -5
- metadata +79 -59
- data/test/test_mini_fb.rb +0 -69
data/README.markdown
CHANGED
@@ -3,7 +3,7 @@ MiniFB - the simple miniature facebook library
|
|
3
3
|
|
4
4
|
MiniFB is a small, lightweight Ruby library for interacting with the [Facebook API](http://wiki.developers.facebook.com/index.php/API).
|
5
5
|
|
6
|
-
Brought to you by: [](http://www.appoxy.com)
|
7
7
|
|
8
8
|
Support
|
9
9
|
--------
|
data/lib/mini_fb.rb
CHANGED
@@ -321,6 +321,16 @@ module MiniFB
|
|
321
321
|
return sig == expected_sig
|
322
322
|
end
|
323
323
|
|
324
|
+
# This function decodes the data sent by Facebook and returns a Hash.
|
325
|
+
# See: http://developers.facebook.com/docs/authentication/canvas
|
326
|
+
def self.signed_request_params(secret, req)
|
327
|
+
s, p = req.split(".")
|
328
|
+
p = base64_url_decode(p)
|
329
|
+
h = JSON.parse(p)
|
330
|
+
h.delete('algorithm') if h['algorithm'] == 'HMAC-SHA256'
|
331
|
+
h
|
332
|
+
end
|
333
|
+
|
324
334
|
# Ruby's implementation of base64 decoding seems to be reading the string in multiples of 4 and ignoring
|
325
335
|
# any extra characters if there are no white-space characters at the end. Since facebook does not take this
|
326
336
|
# into account, this function fills any string with white spaces up to the point where it becomes divisible
|
@@ -484,7 +494,7 @@ module MiniFB
|
|
484
494
|
def self.oauth_url(app_id, redirect_uri, options={})
|
485
495
|
oauth_url = "#{graph_base}oauth/authorize"
|
486
496
|
oauth_url << "?client_id=#{app_id}"
|
487
|
-
oauth_url << "&redirect_uri=#{
|
497
|
+
oauth_url << "&redirect_uri=#{CGI.escape(redirect_uri)}"
|
488
498
|
# oauth_url << "&scope=#{options[:scope]}" if options[:scope]
|
489
499
|
oauth_url << ("&" + options.map { |k, v| "%s=%s" % [k, v] }.join('&')) unless options.empty?
|
490
500
|
oauth_url
|
@@ -494,9 +504,27 @@ module MiniFB
|
|
494
504
|
def self.oauth_access_token(app_id, redirect_uri, secret, code)
|
495
505
|
oauth_url = "#{graph_base}oauth/access_token"
|
496
506
|
oauth_url << "?client_id=#{app_id}"
|
497
|
-
oauth_url << "&redirect_uri=#{
|
507
|
+
oauth_url << "&redirect_uri=#{CGI.escape(redirect_uri)}"
|
508
|
+
oauth_url << "&client_secret=#{secret}"
|
509
|
+
oauth_url << "&code=#{CGI.escape(code)}"
|
510
|
+
resp = RestClient.get oauth_url
|
511
|
+
puts 'resp=' + resp.body.to_s if @@logging
|
512
|
+
params = {}
|
513
|
+
params_array = resp.split("&")
|
514
|
+
params_array.each do |p|
|
515
|
+
ps = p.split("=")
|
516
|
+
params[ps[0]] = ps[1]
|
517
|
+
end
|
518
|
+
return params
|
519
|
+
end
|
520
|
+
|
521
|
+
# returns a hash with one value being 'access_token', the other being 'expires'
|
522
|
+
def self.fb_exchange_token(app_id, secret, access_token)
|
523
|
+
oauth_url = "#{graph_base}oauth/access_token"
|
524
|
+
oauth_url << "?client_id=#{app_id}"
|
498
525
|
oauth_url << "&client_secret=#{secret}"
|
499
|
-
oauth_url << "&
|
526
|
+
oauth_url << "&grant_type=fb_exchange_token"
|
527
|
+
oauth_url << "&fb_exchange_token=#{CGI.escape(access_token)}"
|
500
528
|
resp = RestClient.get oauth_url
|
501
529
|
puts 'resp=' + resp.body.to_s if @@logging
|
502
530
|
params = {}
|
@@ -627,13 +655,13 @@ module MiniFB
|
|
627
655
|
resp = RestClient.post url, options[:params]
|
628
656
|
else
|
629
657
|
if options[:params] && options[:params].size > 0
|
630
|
-
url += '?' + options[:params].map { |k, v|
|
658
|
+
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
|
631
659
|
end
|
632
660
|
@@log.debug 'url_get=' + url if @@logging
|
633
661
|
resp = RestClient.get url
|
634
662
|
end
|
635
663
|
|
636
|
-
@@log.debug 'resp=' + resp.to_s
|
664
|
+
@@log.debug 'resp=' + resp.to_s if @@log.debug?
|
637
665
|
|
638
666
|
if options[:response_type] == :params
|
639
667
|
# Some methods return a param like string, for example: access_token=11935261234123|rW9JMxbN65v_pFWQl5LmHHABC
|
metadata
CHANGED
@@ -1,93 +1,113 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_fb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 1
|
8
|
-
- 7
|
9
|
-
version: 1.1.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.8
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Travis Reeder
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-10-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rest-client
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
31
22
|
type: :runtime
|
32
|
-
|
33
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
34
31
|
name: hashie
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
35
39
|
prerelease: false
|
36
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rest-client
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
37
49
|
none: false
|
38
|
-
requirements:
|
39
|
-
- -
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
|
42
|
-
- 0
|
43
|
-
version: "0"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
44
54
|
type: :runtime
|
45
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: hashie
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: Tiny facebook library
|
47
79
|
email: travis@appoxy.com
|
48
80
|
executables: []
|
49
|
-
|
50
81
|
extensions: []
|
51
|
-
|
52
|
-
extra_rdoc_files:
|
82
|
+
extra_rdoc_files:
|
53
83
|
- LICENSE.txt
|
54
84
|
- README.markdown
|
55
|
-
files:
|
85
|
+
files:
|
56
86
|
- lib/mini_fb.rb
|
57
87
|
- LICENSE.txt
|
58
88
|
- README.markdown
|
59
|
-
- test/test_mini_fb.rb
|
60
|
-
has_rdoc: true
|
61
89
|
homepage: http://github.com/appoxy/mini_fb
|
62
90
|
licenses: []
|
63
|
-
|
64
91
|
post_install_message:
|
65
92
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
93
|
+
require_paths:
|
68
94
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
96
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
76
|
-
version: "0"
|
77
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
102
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
- 0
|
84
|
-
version: "0"
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
85
107
|
requirements: []
|
86
|
-
|
87
108
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.8.24
|
89
110
|
signing_key:
|
90
111
|
specification_version: 3
|
91
112
|
summary: Tiny facebook library
|
92
|
-
test_files:
|
93
|
-
- test/test_mini_fb.rb
|
113
|
+
test_files: []
|
data/test/test_mini_fb.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'rspec'
|
3
|
-
require 'uri'
|
4
|
-
require 'yaml'
|
5
|
-
require 'active_support/core_ext'
|
6
|
-
require '../lib/mini_fb'
|
7
|
-
|
8
|
-
describe "Some Feature" do
|
9
|
-
|
10
|
-
before :all do
|
11
|
-
@is_setup = true
|
12
|
-
@config = File.open(File.expand_path("~/.test_configs/mini_fb_tests.yml")) { |yf| YAML::load(yf) }
|
13
|
-
puts "@config=" + @config.inspect
|
14
|
-
MiniFB.log_level = :debug
|
15
|
-
|
16
|
-
@oauth_url = MiniFB.oauth_url(@config['fb_app_id'], # your Facebook App ID (NOT API_KEY)
|
17
|
-
"http://localhost:3000", # redirect url
|
18
|
-
:scope=>MiniFB.scopes.join(","))
|
19
|
-
puts "If you need an access token, go here in your browser:"
|
20
|
-
puts "#{@oauth_url}"
|
21
|
-
puts "Then grab the 'code' parameter in the redirect url and add it to mini_fb_tests.yml."
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
before :each do
|
27
|
-
# this code runs once per-test
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should do something useful, rather than just being called test1" do
|
31
|
-
# el code here
|
32
|
-
puts 'whatup'
|
33
|
-
true.should be_true
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'test_uri_escape' do
|
37
|
-
URI.escape("x=y").should eq("x=y")
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'test_authenticate_as_app' do
|
41
|
-
res = MiniFB.authenticate_as_app(@config["fb_api_key"], @config["fb_secret"])
|
42
|
-
puts 'res=' + res.inspect
|
43
|
-
res.should include("access_token")
|
44
|
-
res["access_token"].should match(/^#{@config['fb_app_id']}/)#starts_with?(@config["fb_app_id"].to_s)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
def access_token
|
50
|
-
@config['access_token']
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def test_me_with_fields
|
55
|
-
fields = {
|
56
|
-
'interests' => [:name],
|
57
|
-
'activities'=> [:name],
|
58
|
-
'music' => [:name],
|
59
|
-
'videos' => [:name],
|
60
|
-
'television'=> [:name],
|
61
|
-
'movies' => [:name],
|
62
|
-
'likes' => [:name],
|
63
|
-
'work' => [:name],
|
64
|
-
'education' => [:name],
|
65
|
-
'books' => [:name]
|
66
|
-
}
|
67
|
-
|
68
|
-
snap = MiniFB.get(access_token, 'me', :fields =>fields.keys)
|
69
|
-
end
|