mini_fb 2.2.0 → 2.2.1
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.
- checksums.yaml +4 -4
- data/README.markdown +12 -5
- data/VERSION.yml +5 -0
- data/lib/mini_fb.rb +55 -57
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 396b01082b7673dbdbb00ef7846c28c9054d8b54
|
4
|
+
data.tar.gz: 1cb737e842fbdf953ca170215150675a6eeba7c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0732ea1d42dee9bfa7c32a4e75f2e11f13d9da4cd76148e6e3fb2010d41be0c90184b012d4830a6b158ebf338fb56fa02f6784dd80ebf826d786021f0daebf60
|
7
|
+
data.tar.gz: 75a06e1d0bbe858045f747e80ca4f03c9f934b8b6159b17d1f8697e71d5bb9987e2307d3d74b748b6c8ff297382a6b5e6a74269ef345c8cddf5d2bd460ae744c
|
data/README.markdown
CHANGED
@@ -47,14 +47,21 @@ Facebook now uses Oauth 2 for authentication, but don't worry, this part is easy
|
|
47
47
|
That's it. You now need to hold onto this access_token. We've put it in a cookie for now, but you probably
|
48
48
|
want to store it in your database or something.
|
49
49
|
|
50
|
-
|
50
|
+
General Use
|
51
51
|
--------------------------
|
52
52
|
|
53
|
+
@response_hash = MiniFB.get(@access_token, @id, @options = {})
|
54
|
+
|
55
|
+
|
53
56
|
It's very simple:
|
54
57
|
|
55
58
|
@id = {some ID of something in facebook} || "me"
|
56
|
-
@
|
57
|
-
|
59
|
+
@options:
|
60
|
+
type = {some facebook type like feed, friends, or photos}
|
61
|
+
version = {version of the graph api}. Example: "2.5"
|
62
|
+
fields = {array of fields to explicit fetch}
|
63
|
+
params = {optional params}
|
64
|
+
|
58
65
|
# @response_hash is a hash, but also allows object like syntax for instance, the following is true:
|
59
66
|
@response_hash["user"] == @response_hash.user
|
60
67
|
|
@@ -112,7 +119,7 @@ eg:
|
|
112
119
|
:uid => @user_id, :target_id => @target_user_id,
|
113
120
|
:message => "Hello other user!"
|
114
121
|
})
|
115
|
-
|
122
|
+
|
116
123
|
all responses will be json. In the instance of 'bad json' methods, the response will formatted {'response': '#{bad_response_string}'}
|
117
124
|
|
118
125
|
|
@@ -194,7 +201,7 @@ Define an fb_connect method in your login/sessions controller like so:
|
|
194
201
|
@fb_info = MiniFB.parse_cookie_information(FB_APP_ID, cookies) # some users may have to use their API rather than the app. ID.
|
195
202
|
puts "uid=#{@fb_info['uid']}"
|
196
203
|
puts "session=#{@fb_info['session_key']}"
|
197
|
-
|
204
|
+
|
198
205
|
if MiniFB.verify_cookie_signature(FB_APP_ID, FB_SECRET, cookies)
|
199
206
|
# And here you would create the user if it doesn't already exist, then redirect them to wherever you want.
|
200
207
|
else
|
data/VERSION.yml
ADDED
data/lib/mini_fb.rb
CHANGED
@@ -573,7 +573,9 @@ module MiniFB
|
|
573
573
|
# - metadata: to include metadata in response. true/false
|
574
574
|
# - params: Any additional parameters you would like to submit
|
575
575
|
def self.get(access_token, id, options={})
|
576
|
-
url =
|
576
|
+
url = graph_base
|
577
|
+
url << "v#{options[:version]}/" if options[:version]
|
578
|
+
url << id
|
577
579
|
url << "/#{options[:type]}" if options[:type]
|
578
580
|
params = options[:params] || {}
|
579
581
|
params["access_token"] = "#{(access_token)}"
|
@@ -594,7 +596,8 @@ module MiniFB
|
|
594
596
|
#
|
595
597
|
# Can throw a connection Timeout if there is too many items
|
596
598
|
def self.multiget(access_token, ids, options={})
|
597
|
-
url =
|
599
|
+
url = graph_base
|
600
|
+
url << "v#{options[:version]}/" if options[:version]
|
598
601
|
url << "#{options[:type]}" if options[:type]
|
599
602
|
params = options[:params] || {}
|
600
603
|
params["ids"] = ids.join(',')
|
@@ -611,7 +614,9 @@ module MiniFB
|
|
611
614
|
# - metadata: to include metadata in response. true/false
|
612
615
|
# - params: Any additional parameters you would like to submit
|
613
616
|
def self.post(access_token, id, options={})
|
614
|
-
url =
|
617
|
+
url = graph_base
|
618
|
+
url << "v#{options[:version]}/" if options[:version]
|
619
|
+
url << id
|
615
620
|
url << "/#{options[:type]}" if options[:type]
|
616
621
|
options.delete(:type)
|
617
622
|
params = options[:params] || {}
|
@@ -636,7 +641,8 @@ module MiniFB
|
|
636
641
|
# - metadata: to include metadata in response. true/false
|
637
642
|
# - params: Any additional parameters you would like to submit
|
638
643
|
def self.delete(access_token, ids, options={})
|
639
|
-
url =
|
644
|
+
url = graph_base
|
645
|
+
url << "v#{options[:version]}/" if options[:version]
|
640
646
|
params = options[:params] || {}
|
641
647
|
if ids.is_a?(Array)
|
642
648
|
params["ids"] = ids.join(',')
|
@@ -696,67 +702,59 @@ module MiniFB
|
|
696
702
|
end
|
697
703
|
|
698
704
|
def self.fetch(url, options={})
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
if options[:params] && options[:params].size > 0
|
707
|
-
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
|
708
|
-
end
|
709
|
-
@@log.debug 'url_delete=' + url if @@logging
|
710
|
-
response = @@http.delete url
|
711
|
-
else
|
712
|
-
if options[:params] && options[:params].size > 0
|
713
|
-
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
|
714
|
-
end
|
715
|
-
@@log.debug 'url_get=' + url if @@logging
|
716
|
-
response = @@http.get url
|
705
|
+
case options[:method]
|
706
|
+
when :post
|
707
|
+
@@log.debug 'url_post=' + url if @@logging
|
708
|
+
response = @@http.post url, options[:params]
|
709
|
+
when :delete
|
710
|
+
if options[:params] && options[:params].size > 0
|
711
|
+
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
|
717
712
|
end
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
if options[:response_type] == :params
|
724
|
-
# Some methods return a param like string, for example: access_token=11935261234123|rW9JMxbN65v_pFWQl5LmHHABC
|
725
|
-
params = {}
|
726
|
-
params_array = resp.split("&")
|
727
|
-
params_array.each do |p|
|
728
|
-
ps = p.split("=")
|
729
|
-
params[ps[0]] = ps[1]
|
730
|
-
end
|
731
|
-
return params
|
732
|
-
else
|
733
|
-
begin
|
734
|
-
res_hash = JSON.parse(resp.to_s)
|
735
|
-
rescue
|
736
|
-
# quick fix for things like stream.publish that don't return json
|
737
|
-
res_hash = JSON.parse("{\"response\": #{resp.to_s}}")
|
738
|
-
end
|
713
|
+
@@log.debug 'url_delete=' + url if @@logging
|
714
|
+
response = @@http.delete url
|
715
|
+
else
|
716
|
+
if options[:params] && options[:params].size > 0
|
717
|
+
url += '?' + options[:params].map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) }.join('&')
|
739
718
|
end
|
719
|
+
@@log.debug 'url_get=' + url if @@logging
|
720
|
+
response = @@http.get url
|
721
|
+
end
|
740
722
|
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
res_hash = { response: res_hash } unless res_hash.is_a? Hash
|
745
|
-
res_hash = Hashie::Mash.new(res_hash)
|
746
|
-
end
|
723
|
+
resp = response.body
|
724
|
+
@@log.debug "Response = #{resp}. Status = #{response.status}" if @@logging
|
725
|
+
@@log.debug 'API Version =' + response.headers["Facebook-API-Version"].to_s if @@logging
|
747
726
|
|
748
|
-
|
749
|
-
raise FaceBookError.new(res_hash["error_code"] || 1, res_hash["error_msg"])
|
750
|
-
end
|
727
|
+
res_hash = JSON.parse(resp.to_s.size > 2 ? resp.to_s : {response: resp.to_s}.to_json)
|
751
728
|
|
752
|
-
|
753
|
-
rescue Exception => ex
|
754
|
-
puts "ex.http_code=" + response.status if @@logging
|
755
|
-
puts 'ex.http_body=' + resp if @@logging
|
756
|
-
res_hash = JSON.parse(resp) # probably should ensure it has a good response
|
729
|
+
unless response.ok?
|
757
730
|
raise MiniFB::FaceBookError.new(response.status, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
|
758
731
|
end
|
759
732
|
|
733
|
+
if options[:response_type] == :params
|
734
|
+
# Some methods return a param like string, for example: access_token=11935261234123|rW9JMxbN65v_pFWQl5LmHHABC
|
735
|
+
params = {}
|
736
|
+
params_array = resp.split("&")
|
737
|
+
params_array.each do |p|
|
738
|
+
ps = p.split("=")
|
739
|
+
params[ps[0]] = ps[1]
|
740
|
+
end
|
741
|
+
return params
|
742
|
+
else
|
743
|
+
res_hash = JSON.parse(resp.to_s.size > 2 ? resp.to_s : {response: resp.to_s}.to_json)
|
744
|
+
end
|
745
|
+
|
746
|
+
if res_hash.is_a? Array # fql return this
|
747
|
+
res_hash.collect! { |x| x.is_a?(Hash) ? Hashie::Mash.new(x) : x }
|
748
|
+
else
|
749
|
+
res_hash = { response: res_hash } unless res_hash.is_a? Hash
|
750
|
+
res_hash = Hashie::Mash.new(res_hash)
|
751
|
+
end
|
752
|
+
|
753
|
+
if res_hash.include?("error_msg")
|
754
|
+
raise FaceBookError.new(res_hash["error_code"] || 1, res_hash["error_msg"])
|
755
|
+
end
|
756
|
+
|
757
|
+
res_hash
|
760
758
|
end
|
761
759
|
|
762
760
|
# Returns all available scopes.
|
data/lib/version.rb
CHANGED
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.1
|
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-01-
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- LICENSE.txt
|
53
53
|
- README.markdown
|
54
54
|
- Rakefile
|
55
|
+
- VERSION.yml
|
55
56
|
- lib/mini_fb.rb
|
56
57
|
- lib/version.rb
|
57
58
|
- mini_fb.gemspec
|