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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 396b01082b7673dbdbb00ef7846c28c9054d8b54
4
- data.tar.gz: 1cb737e842fbdf953ca170215150675a6eeba7c6
3
+ metadata.gz: b8e391adab3eb0fcf238f777a85227dd45e654fd
4
+ data.tar.gz: a2edb60b87d01fd15ac45bbad81ea061d777cdbf
5
5
  SHA512:
6
- metadata.gz: 0732ea1d42dee9bfa7c32a4e75f2e11f13d9da4cd76148e6e3fb2010d41be0c90184b012d4830a6b158ebf338fb56fa02f6784dd80ebf826d786021f0daebf60
7
- data.tar.gz: 75a06e1d0bbe858045f747e80ca4f03c9f934b8b6159b17d1f8697e71d5bb9987e2307d3d74b748b6c8ff297382a6b5e6a74269ef345c8cddf5d2bd460ae744c
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
- resp = @@http.get oauth_url
531
- puts 'resp=' + resp.body.to_s if @@logging
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 = resp.split("&")
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
@@ -1,3 +1,3 @@
1
1
  module MiniFB
2
- VERSION = "2.2.1"
2
+ VERSION = "2.2.2"
3
3
  end
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
- before :all do
10
- @is_setup = true
11
- file_path = File.expand_path("../mini_fb_tests.yml", File.dirname(__FILE__))
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
- before :each do
23
- # this code runs once per-test
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
- it 'test_uri_escape' do
27
- URI.escape("x=y").should eq("x=y")
28
- end
26
+ describe '#signed_request_params' do
27
+ let (:req) { 'vlXgu64BQGFSQrY0ZcJBZASMvYvTHu9GQ0YM9rjPSso.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsIjAiOiJwYXlsb2FkIn0' }
28
+ let (:secret) { 'secret' }
29
29
 
30
- it 'test_authenticate_as_app' do
31
- res = MiniFB.authenticate_as_app(@config["fb_api_key"], @config["fb_secret"])
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 'test_signed_request_params' do
38
- # Example request and secret taken from http://developers.facebook.com/docs/authentication/canvas
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
- def access_token
48
- @config['access_token']
49
- end
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
- def test_me_with_fields
53
- fields = {
54
- 'interests' => [:name],
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
- snap = MiniFB.get(access_token, 'me', :fields =>fields.keys)
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
@@ -0,0 +1,14 @@
1
+ module TestHelper
2
+ class << self
3
+
4
+ def config
5
+ @config ||= File.open(config_path) { |yf| YAML::load(yf) }
6
+ end
7
+
8
+ private
9
+
10
+ def config_path
11
+ File.expand_path("../mini_fb_tests.yml", File.dirname(__FILE__))
12
+ end
13
+ end
14
+ end
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.1
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-01-21 00:00:00.000000000 Z
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.markdown
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.4.8
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
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 2
3
- :minor: 1
4
- :patch: 2
5
- :build: