facebook_sdk 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/facebook_sdk.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = FacebookSDK::VERSION
8
8
  s.authors = ["Erick Zetta"]
9
9
  s.email = ["erick.zetta@gmail.com"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/eckz/facebook_sdk"
11
11
  s.summary = %q{Facebook SDK for Graph API}
12
12
  s.description = %q{Facebook SDK for Graph API}
13
13
 
data/lib/facebook_sdk.rb CHANGED
@@ -2,10 +2,14 @@ require "facebook_sdk/version"
2
2
  require "forwardable"
3
3
  require "faraday"
4
4
 
5
+ require "facebook_sdk/apiexception"
5
6
  require "facebook_sdk/configuration"
6
- require "facebook_sdk/api"
7
7
 
8
- require "facebook_sdk/middleware/json_decoder"
8
+ require "facebook_sdk/modules/api"
9
+
10
+ require "facebook_sdk/faraday-middleware/json_decoder"
11
+ require "facebook_sdk/faraday-middleware/hashie_converter"
12
+ require "facebook_sdk/faraday-middleware/raise_api_exception"
9
13
 
10
14
  module FacebookSDK
11
15
  class Session
@@ -24,8 +28,12 @@ module FacebookSDK
24
28
  #builder.use Faraday::Response::Logger # log the request to STDOUT
25
29
 
26
30
  builder.use Faraday::Adapter::NetHttp # make http requests with Net::HTTP
27
- builder.use FacebookSDK::Middleware::JSONDecoder # use own JSONDecoder
28
31
 
32
+ # order inversed (in response)
33
+
34
+ builder.use FacebookSDK::FaradayMiddleware::RaiseApiException
35
+ builder.use FacebookSDK::FaradayMiddleware::HashieConverter
36
+ builder.use FacebookSDK::FaradayMiddleware::JSONDecoder # use own JSONDecoder
29
37
 
30
38
  @config = Configuration.new
31
39
 
@@ -0,0 +1,13 @@
1
+ module FacebookSDK
2
+ class ApiException < StandardError
3
+ attr_accessor :result
4
+
5
+ def initialize(result)
6
+ @result = result
7
+ end
8
+
9
+ def type
10
+ @result.type
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,6 @@
1
1
  module FacebookSDK
2
2
  class Configuration
3
- attr_accessor :app_id, :secret, :faraday
3
+ attr_accessor :app_id, :secret, :faraday,
4
+ :signed_request, :code, :state
4
5
  end
5
6
  end
@@ -0,0 +1,14 @@
1
+
2
+ require 'hashie'
3
+
4
+ module FacebookSDK
5
+ module FaradayMiddleware
6
+ class HashieConverter < Faraday::Response::Middleware
7
+
8
+ def on_complete(env)
9
+ env[:body] = Hashie::Mash.new env[:body]
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -2,7 +2,7 @@
2
2
  require 'json'
3
3
 
4
4
  module FacebookSDK
5
- module Middleware
5
+ module FaradayMiddleware
6
6
  class JSONDecoder < Faraday::Response::Middleware
7
7
 
8
8
  def on_complete(env)
@@ -0,0 +1,16 @@
1
+
2
+
3
+ module FacebookSDK
4
+ module FaradayMiddleware
5
+ class RaiseApiException < Faraday::Response::Middleware
6
+
7
+ def on_complete(env)
8
+ case env[:status]
9
+ when 400...499
10
+ raise FacebookSDK::ApiException, env[:body]
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -1,12 +1,9 @@
1
1
 
2
- require 'hashie'
3
-
4
2
  module FacebookSDK
5
3
  module Api
6
4
  def api(url, &block)
7
5
  result = get url, &block
8
-
9
- Hashie::Mash.new result.body
6
+ result.body
10
7
  end
11
8
 
12
9
  end
@@ -1,3 +1,3 @@
1
1
  module FacebookSDK
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/test/test_basic.rb CHANGED
@@ -17,4 +17,15 @@ class TestBasic < FacebookSDK::TestCase
17
17
  assert_equal "Facebook Platform", p.name
18
18
  assert_equal "http://developers.facebook.com", p.website
19
19
  end
20
+
21
+ def test_exception_without_access_token
22
+ fb = FacebookSDK::Session.new do |config|
23
+
24
+ end
25
+
26
+ assert_raise FacebookSDK::ApiException do
27
+ p = fb.api '/me'
28
+ end
29
+
30
+ end
20
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
16
- requirement: &73638110 !ruby/object:Gem::Requirement
16
+ requirement: &73695500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *73638110
24
+ version_requirements: *73695500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: turn
27
- requirement: &73637760 !ruby/object:Gem::Requirement
27
+ requirement: &73695190 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *73637760
35
+ version_requirements: *73695190
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &73637430 !ruby/object:Gem::Requirement
38
+ requirement: &73694830 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *73637430
46
+ version_requirements: *73694830
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hashie
49
- requirement: &73637060 !ruby/object:Gem::Requirement
49
+ requirement: &73694470 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *73637060
57
+ version_requirements: *73694470
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: faraday
60
- requirement: &73636640 !ruby/object:Gem::Requirement
60
+ requirement: &73694040 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *73636640
68
+ version_requirements: *73694040
69
69
  description: Facebook SDK for Graph API
70
70
  email:
71
71
  - erick.zetta@gmail.com
@@ -78,13 +78,16 @@ files:
78
78
  - Rakefile
79
79
  - facebook_sdk.gemspec
80
80
  - lib/facebook_sdk.rb
81
- - lib/facebook_sdk/api.rb
81
+ - lib/facebook_sdk/apiexception.rb
82
82
  - lib/facebook_sdk/configuration.rb
83
- - lib/facebook_sdk/middleware/json_decoder.rb
83
+ - lib/facebook_sdk/faraday-middleware/hashie_converter.rb
84
+ - lib/facebook_sdk/faraday-middleware/json_decoder.rb
85
+ - lib/facebook_sdk/faraday-middleware/raise_api_exception.rb
86
+ - lib/facebook_sdk/modules/api.rb
84
87
  - lib/facebook_sdk/version.rb
85
88
  - test/helper.rb
86
89
  - test/test_basic.rb
87
- homepage: ''
90
+ homepage: https://github.com/eckz/facebook_sdk
88
91
  licenses: []
89
92
  post_install_message:
90
93
  rdoc_options: []