fb_graph 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -18,7 +18,9 @@ This is a work in progress.
18
18
  Now FbGraph supports all objects listed here: http://developers.facebook.com/docs/reference/api/
19
19
  Almost all connections for each object are also supported. (Private message connections are not supported yet)
20
20
 
21
- === Basic Objects
21
+ === GET
22
+
23
+ ==== Basic Objects
22
24
 
23
25
  user = FbGraph::User.fetch('matake')
24
26
  user.name # => 'Nov Matake'
@@ -33,7 +35,7 @@ Almost all connections for each object are also supported. (Private message co
33
35
 
34
36
  :
35
37
 
36
- === Connections
38
+ ==== Connections
37
39
 
38
40
  # Public connections
39
41
  user = FbGraph::User.fetch('matake')
@@ -57,7 +59,7 @@ Almost all connections for each object are also supported. (Private message co
57
59
  me.home
58
60
  :
59
61
 
60
- === Pagination
62
+ ==== Pagination
61
63
 
62
64
  user = FbGraph::User.new('matake', :access_token => ACCESS_TOKEN)
63
65
  likes = user.likes # => Array of FbGraph::Like
@@ -66,6 +68,19 @@ Almost all connections for each object are also supported. (Private message co
66
68
  user.likes(likes.next) # => Array of FbGraph::Like
67
69
  user.likes(likes.previous) # => Array of FbGraph::Like
68
70
 
71
+ === POST
72
+
73
+ ==== Status Update
74
+
75
+ me = FbGraph::User.me(ACCESS_TOKEN)
76
+ me.feed!(
77
+ :message => 'Updating via FbGraph',
78
+ :picture => 'https://graph.facebook.com/matake/picture',
79
+ :link => 'http://github.com/nov/fb_graph',
80
+ :name => 'FbGraph',
81
+ :description => 'A Ruby wrapper for Facebook Graph API'
82
+ )
83
+
69
84
  == Note on Patches/Pull Requests
70
85
 
71
86
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/fb_graph.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fb_graph}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["nov matake"]
@@ -7,6 +7,11 @@ module FbGraph
7
7
  Post.new(post.delete(:id), post)
8
8
  end
9
9
  end
10
+
11
+ def feed!(options = {})
12
+ post = post(options.merge(:connection => 'feed'))
13
+ Post.new(post.delete(:id), options.merge(post))
14
+ end
10
15
  end
11
16
  end
12
17
  end
data/lib/fb_graph/node.rb CHANGED
@@ -23,8 +23,17 @@ module FbGraph
23
23
  protected
24
24
 
25
25
  def get(options = {})
26
- _endpoint_ = build_endpoint(options)
26
+ _endpoint_ = build_endpoint(options.merge!(:method => :get))
27
27
  handle_response RestClient.get(_endpoint_)
28
+ rescue RestClient::Exception => e
29
+ raise FbGraph::Exception.new(e.http_code, e.message, e.http_body)
30
+ end
31
+
32
+ def post(options = {})
33
+ _endpoint_ = build_endpoint(options.merge!(:method => :post))
34
+ handle_response RestClient.post(_endpoint_, options)
35
+ rescue RestClient::Exception => e
36
+ raise FbGraph::Exception.new(e.http_code, e.message, e.http_body)
28
37
  end
29
38
 
30
39
  private
@@ -36,10 +45,12 @@ module FbGraph
36
45
  self.endpoint
37
46
  end
38
47
  options[:access_token] ||= self.access_token
39
- _options_ = options.reject do |k, v|
48
+ options.delete_if do |k, v|
40
49
  v.blank?
41
50
  end
42
- _endpoint_ << "?#{_options_.to_query}" unless _options_.blank?
51
+ if options.delete(:method) == :get && options.present?
52
+ _endpoint_ << "?#{options.to_query}"
53
+ end
43
54
  _endpoint_
44
55
  end
45
56
 
@@ -48,16 +59,15 @@ module FbGraph
48
59
  if _response_[:error]
49
60
  case _response_[:error][:type]
50
61
  when 'OAuthAccessTokenException'
51
- raise FbGraph::Unauthorized.new(_response_[:error][:message])
62
+ raise FbGraph::Unauthorized.new(401, _response_[:error][:message])
52
63
  when 'QueryParseException'
53
- raise FbGraph::NotFound.new(_response_[:error][:message])
64
+ raise FbGraph::NotFound.new(404, _response_[:error][:message])
54
65
  else
55
- raise FbGraph::Exception.new("#{_response_[:error][:type]} :: #{_response_[:error][:message]}")
66
+ raise FbGraph::Exception.new(400, "#{_response_[:error][:type]} :: #{_response_[:error][:message]}")
56
67
  end
57
68
  else
58
69
  _response_
59
70
  end
60
71
  end
61
-
62
72
  end
63
73
  end
data/lib/fb_graph.rb CHANGED
@@ -6,7 +6,14 @@ require 'restclient'
6
6
  module FbGraph
7
7
  ROOT_URL = "https://graph.facebook.com"
8
8
 
9
- class FbGraph::Exception < StandardError; end
9
+ class FbGraph::Exception < StandardError
10
+ attr_accessor :code, :message, :body
11
+ def initialize(code, message, body = '')
12
+ @code = code
13
+ @message = message
14
+ @body = body
15
+ end
16
+ end
10
17
  class FbGraph::Unauthorized < FbGraph::Exception; end
11
18
  class FbGraph::NotFound < FbGraph::Exception; end
12
19
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - nov matake