fb_graph 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.3.0
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 = "1.2.5"
8
+ s.version = "1.3.0"
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"]
@@ -10,7 +10,7 @@ module FbGraph
10
10
  @longitude = attriutes[:longitude]
11
11
  end
12
12
 
13
- def to_hash
13
+ def to_hash(options = {})
14
14
  {
15
15
  :latitude => self.latitude,
16
16
  :longitude => self.longitude
data/lib/fb_graph/node.rb CHANGED
@@ -33,7 +33,7 @@ module FbGraph
33
33
  protected
34
34
 
35
35
  def get(params = {})
36
- _params_ = stringfy_access_token(params)
36
+ _params_ = stringfy_params(params)
37
37
  _endpoint_ = build_endpoint(_params_.merge!(:method => :get))
38
38
  handle_response do
39
39
  RestClient.get(_endpoint_)
@@ -41,7 +41,7 @@ module FbGraph
41
41
  end
42
42
 
43
43
  def post(params = {})
44
- _params_ = stringfy_access_token(params)
44
+ _params_ = stringfy_params(params)
45
45
  _endpoint_ = build_endpoint(_params_.merge!(:method => :post))
46
46
  handle_response do
47
47
  RestClient.post(_endpoint_, _params_)
@@ -49,7 +49,7 @@ module FbGraph
49
49
  end
50
50
 
51
51
  def delete(params = {})
52
- _params_ = stringfy_access_token(params)
52
+ _params_ = stringfy_params(params)
53
53
  _endpoint_ = build_endpoint(_params_.merge!(:method => :delete))
54
54
  handle_response do
55
55
  RestClient.delete(_endpoint_)
@@ -69,12 +69,17 @@ module FbGraph
69
69
  _endpoint_
70
70
  end
71
71
 
72
- def stringfy_access_token(params)
72
+ def stringfy_params(params)
73
73
  _params_ = params.dup
74
74
  _params_[:access_token] ||= self.access_token
75
75
  if access_token.is_a?(OAuth2::AccessToken)
76
76
  _params_[:access_token] = _params_[:access_token].token
77
77
  end
78
+ _params_.each do |key, value|
79
+ if value.present? && ![Symbol, String, Numeric, IO].any? { |klass| value.is_a? klass }
80
+ _params_[key] = value.to_json
81
+ end
82
+ end
78
83
  _params_
79
84
  end
80
85
 
@@ -17,7 +17,11 @@ module FbGraph
17
17
  @tags = []
18
18
  if attributes[:tags]
19
19
  Collection.new(attributes[:tags]).each do |tag|
20
- @tags << Tag.new(tag)
20
+ @tags << if tag.is_a?(Tag)
21
+ tag
22
+ else
23
+ Tag.new(tag)
24
+ end
21
25
  end
22
26
  end
23
27
  # NOTE:
data/lib/fb_graph/post.rb CHANGED
@@ -37,7 +37,7 @@ module FbGraph
37
37
  @actions = []
38
38
  if attributes[:actions]
39
39
  attributes[:actions].each do |action|
40
- @actions << FbGraph::Action.new(action)
40
+ @actions << Action.new(action)
41
41
  end
42
42
  end
43
43
  @like_count = attributes[:likes]
@@ -14,7 +14,7 @@ module FbGraph
14
14
  @deny = attriutes[:deny]
15
15
  end
16
16
 
17
- def to_hash
17
+ def to_hash(options = {})
18
18
  {
19
19
  :value => self.value,
20
20
  :friends => self.friends,
@@ -18,7 +18,7 @@ module FbGraph
18
18
 
19
19
  ENDPOINT = 'https://api.facebook.com/method/fql.query'
20
20
  def build_endpoint
21
- params = stringfy_access_token(
21
+ params = stringfy_params(
22
22
  :query => self.query,
23
23
  :access_token => self.access_token,
24
24
  :format => :json
@@ -1,15 +1,19 @@
1
1
  module FbGraph
2
2
  module Serialization
3
- def to_hash
3
+ def to_hash(options = {})
4
4
  raise "Define #{self.class}#to_hash!"
5
5
  end
6
6
 
7
- def to_json
8
- hash = self.to_hash
7
+ def as_json(options = {})
8
+ hash = self.to_hash options
9
9
  hash.delete_if do |k, v|
10
10
  v.blank?
11
11
  end
12
- hash.to_json
12
+ hash
13
+ end
14
+
15
+ def to_json(options = {})
16
+ as_json.to_json options
13
17
  end
14
18
  end
15
19
  end
data/lib/fb_graph/tag.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module FbGraph
2
2
  class Tag
3
3
  include Comparison
4
+ include Serialization
4
5
 
5
6
  attr_accessor :user, :name, :x, :y, :created_time
6
7
 
@@ -15,5 +16,15 @@ module FbGraph
15
16
  end
16
17
  @name = attributes[:name]
17
18
  end
19
+
20
+ def to_hash(options = {})
21
+ hash = {
22
+ :tag_text => self.name,
23
+ :x => self.x,
24
+ :y => self.y
25
+ }
26
+ hash[:tag_uid] = self.user.identifier if self.user
27
+ hash
28
+ end
18
29
  end
19
30
  end
@@ -11,7 +11,7 @@ module FbGraph
11
11
  @locale = attriutes[:locale]
12
12
  end
13
13
 
14
- def to_hash
14
+ def to_hash(options = {})
15
15
  {
16
16
  :country => self.country,
17
17
  :city => self.city,
@@ -4,11 +4,11 @@ module FbGraph
4
4
 
5
5
  def initialize(attriutes = {})
6
6
  super
7
- @street = attriutes[:street]
8
- @city = attriutes[:city]
9
- @state = attriutes[:state]
10
- @zip = attriutes[:zip]
11
- @country = attriutes[:country]
7
+ @street = attriutes[:street]
8
+ @city = attriutes[:city]
9
+ @state = attriutes[:state]
10
+ @zip = attriutes[:zip]
11
+ @country = attriutes[:country]
12
12
  end
13
13
  end
14
14
  end
data/lib/fb_graph.rb CHANGED
@@ -2,11 +2,7 @@ require 'rubygems'
2
2
  require 'json'
3
3
  require 'restclient'
4
4
  require 'oauth2'
5
-
6
- # NOTE:
7
- # For some reason, ActiveSupport 3.0.0 doesn'tj load whole code.
8
- # Load needed extention directly for now.
9
- require 'active_support/core_ext'
5
+ require 'active_support/all'
10
6
 
11
7
  module FbGraph
12
8
  ROOT_URL = "https://graph.facebook.com"
@@ -29,4 +29,13 @@ describe FbGraph::Connections::Photos, '#photo!' do
29
29
  photo.name.should == 'Hello, where is photo?'
30
30
  photo.access_token.should == 'valid'
31
31
  end
32
+
33
+ it 'should support Tag' do
34
+ photo = FbGraph::Album.new('12345', :access_token => 'valid').photo!(
35
+ :image => Tempfile.new('image_file'),
36
+ :message => 'Hello, where is photo?',
37
+ :tags => [FbGraph::Tag.new(:id => 12345, :name => 'me', :x => 0, :y => 10)]
38
+ )
39
+ photo.tags.should == [FbGraph::Tag.new(:id => 12345, :name => 'me', :x => 0, :y => 10)]
40
+ end
32
41
  end
@@ -12,11 +12,19 @@ describe FbGraph::Node, '.new' do
12
12
 
13
13
  end
14
14
 
15
- describe FbGraph::Node, '#stringfy_access_token' do
15
+ describe FbGraph::Node, '#stringfy_params' do
16
+ it 'should make all values to JSON' do
17
+ client = OAuth2::Client.new('client_id', 'client_secret')
18
+ node = FbGraph::Node.new('identifier')
19
+ params = node.send :stringfy_params, {:hash => {:a => :b}, :array => [:a, :b]}
20
+ params[:hash].should == '{"a":"b"}'
21
+ params[:array].should == '["a","b"]'
22
+ end
23
+
16
24
  it 'should support OAuth2::AccessToken' do
17
25
  client = OAuth2::Client.new('client_id', 'client_secret')
18
26
  node = FbGraph::Node.new('identifier', :access_token => OAuth2::AccessToken.new(client, 'token', 'secret'))
19
- params = node.send :stringfy_access_token, {}
27
+ params = node.send :stringfy_params, {}
20
28
  params[:access_token].should == 'token'
21
29
  end
22
30
  end
@@ -6,7 +6,7 @@ class Klass1
6
6
  end
7
7
 
8
8
  class Klass2 < Klass1
9
- def to_hash
9
+ def to_hash(options = {})
10
10
  {:att1 => self.att1, :att2 => self.att2}
11
11
  end
12
12
  end
@@ -18,4 +18,17 @@ describe FbGraph::Tag, '.new' do
18
18
  tag.created_time.should == Time.parse("2010-04-22T08:24:26+0000")
19
19
  end
20
20
 
21
+ it 'should not setup user if id is blank' do
22
+ attributes = {
23
+ :id => "",
24
+ :name => "Arjun Banker",
25
+ :x => 32.5,
26
+ :y => 27.7778,
27
+ :created_time => "2010-04-22T08:24:26+0000"
28
+ }
29
+ tag = FbGraph::Tag.new(attributes)
30
+ tag.user.should be_nil
31
+ tag.name.should == 'Arjun Banker'
32
+ end
33
+
21
34
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 5
10
- version: 1.2.5
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - nov matake