fb_graph 0.2.0 → 0.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/fb_graph.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fb_graph}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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"]
12
- s.date = %q{2010-05-21}
12
+ s.date = %q{2010-06-06}
13
13
  s.description = %q{A Ruby wrapper for Facebook Graph API}
14
14
  s.email = %q{nov@matake.jp}
15
15
  s.extra_rdoc_files = [
data/lib/fb_graph.rb CHANGED
@@ -5,8 +5,7 @@ require 'restclient'
5
5
  # NOTE:
6
6
  # For some reason, ActiveSupport 3.0.0 doesn'tj load whole code.
7
7
  # Load needed extention directly for now.
8
- require 'active_support/core_ext/object'
9
- require 'active_support/core_ext/hash'
8
+ require 'active_support/core_ext'
10
9
 
11
10
  module FbGraph
12
11
  ROOT_URL = "https://graph.facebook.com"
data/lib/fb_graph/node.rb CHANGED
@@ -86,10 +86,8 @@ module FbGraph
86
86
  _response_ = JSON.parse(response.body).with_indifferent_access
87
87
  if _response_[:error]
88
88
  case _response_[:error][:type]
89
- when 'OAuthAccessTokenException'
89
+ when 'OAuthAccessTokenException', 'QueryParseException'
90
90
  raise FbGraph::Unauthorized.new(401, _response_[:error][:message])
91
- when 'QueryParseException'
92
- raise FbGraph::NotFound.new(404, _response_[:error][:message])
93
91
  else
94
92
  raise FbGraph::Exception.new(400, "#{_response_[:error][:type]} :: #{_response_[:error][:message]}")
95
93
  end
data/lib/fb_graph/user.rb CHANGED
@@ -27,16 +27,15 @@ module FbGraph
27
27
  # include Connections::Outbox
28
28
  # include Connections::Updates
29
29
 
30
- attr_accessor :name, :last_name, :first_name, :link, :about, :birthday, :work, :education, :email, :website
30
+ attr_accessor :first_name, :last_name, :name, :link, :about, :birthday, :work, :education, :email, :website, :hometown, :location, :gender, :interested_in, :meeting_for, :relationship_status, :religion, :political, :verified, :significant_other, :timezone, :updated_time
31
31
 
32
32
  def initialize(identifier, options = {})
33
33
  super
34
- @name = options[:name]
35
- @last_name = options[:last_name]
36
34
  @first_name = options[:first_name]
35
+ @last_name = options[:last_name]
36
+ @name = options[:name]
37
37
  @link = options[:link]
38
38
  @about = options[:about]
39
- @email = options[:email]
40
39
  if options[:birthday]
41
40
  month, day, year = options[:birthday].split('/').collect(&:to_i)
42
41
  year ||= 0
@@ -54,7 +53,26 @@ module FbGraph
54
53
  @education << FbGraph::Education.new(education)
55
54
  end
56
55
  end
56
+ @email = options[:email]
57
57
  @website = options[:website].to_s.split("\n")
58
+ if (hometown = options[:hometown])
59
+ @hometown = FbGraph::Page.new(hometown.delete(:id), hometown)
60
+ end
61
+ if (location = options[:location])
62
+ @location = FbGraph::Page.new(location.delete(:id), location)
63
+ end
64
+ @gender = options[:gender]
65
+ @interested_in = Array(options[:interested_in])
66
+ @meeting_for = Array(options[:meeting_for])
67
+ @relationship_status = options[:relationship_status]
68
+ @religion = options[:religion]
69
+ @political = options[:political]
70
+ @verified = options[:verified]
71
+ @significant_other = options[:significant_other] # What's this??
72
+ @timezone = options[:timezone]
73
+ if options[:updated_time]
74
+ @updated_time = Time.parse(options[:updated_time]).utc
75
+ end
58
76
  end
59
77
 
60
78
  def self.me(access_token)
@@ -4,8 +4,16 @@
4
4
  "first_name": "Arjun",
5
5
  "last_name": "Banker",
6
6
  "link": "http://www.facebook.com/Arjun",
7
- "about": "squish squash\npip pop\nfizz bang",
7
+ "about": "daydrea",
8
8
  "birthday": "04/15/1984",
9
+ "hometown": {
10
+ "id": 109533479072558,
11
+ "name": "Minnetonka, Minnesota"
12
+ },
13
+ "location": {
14
+ "id": 114952118516947,
15
+ "name": "San Francisco, California"
16
+ },
9
17
  "work": [
10
18
  {
11
19
  "employer": {
@@ -87,13 +95,15 @@
87
95
  ]
88
96
  }
89
97
  ],
98
+ "gender": "male",
90
99
  "interested_in": [
91
- "\\u5973\\u6027"
100
+ "female"
92
101
  ],
93
102
  "meeting_for": [
94
- "\\u53cb\\u60c5"
103
+ "Friendship"
95
104
  ],
105
+ "relationship_status": "In a Relationship",
96
106
  "religion": "zorp",
97
- "timezone": -7,
98
- "updated_time": "2010-04-22T18:23:22+0000"
107
+ "political": "Liberal",
108
+ "updated_time": "2010-05-29T04:29:23+0000"
99
109
  }
@@ -3,5 +3,10 @@
3
3
  "name": "Arjun Banker",
4
4
  "first_name": "Arjun",
5
5
  "last_name": "Banker",
6
- "link": "http://www.facebook.com/Arjun"
6
+ "link": "http://www.facebook.com/Arjun",
7
+ "location": {
8
+ "id": 114952118516947,
9
+ "name": "San Francisco, California"
10
+ },
11
+ "gender": "male"
7
12
  }
@@ -6,18 +6,123 @@
6
6
  "link": "http://www.facebook.com/matake",
7
7
  "about": "I'm a Ruby on Rails Developer on smart.fm",
8
8
  "birthday": "12/13/1981",
9
+ "hometown": {
10
+ "id": 112359252112966,
11
+ "name": "Hirakata, Osaka"
12
+ },
13
+ "location": {
14
+ "id": 108449982512946,
15
+ "name": "Kawasaki, Kanagawa"
16
+ },
17
+ "work": [
18
+ {
19
+ "employer": {
20
+ "id": 105612642807396,
21
+ "name": "Cerego Japan Inc."
22
+ },
23
+ "location": {
24
+ "id": 114600441890814,
25
+ "name": "Shibuya"
26
+ },
27
+ "position": {
28
+ "id": 112075768810308,
29
+ "name": "Web Engineer"
30
+ },
31
+ "start_date": "2008-00",
32
+ "end_date": "0000-00"
33
+ },
34
+ {
35
+ "employer": {
36
+ "id": 107722015925937,
37
+ "name": "Drecom Co., Ltd."
38
+ },
39
+ "location": {
40
+ "id": 111736052177472,
41
+ "name": "Tokyo, Tokyo"
42
+ },
43
+ "position": {
44
+ "id": 111091815582753,
45
+ "name": "Web Engineer"
46
+ },
47
+ "start_date": "2007-04",
48
+ "end_date": "2008-09"
49
+ }
50
+ ],
51
+ "education": [
52
+ {
53
+ "school": {
54
+ "id": 110149592341159,
55
+ "name": "\u540c\u5fd7\u793e\u5927\u5b66"
56
+ },
57
+ "degree": {
58
+ "id": 110616875633830,
59
+ "name": "Master of Engineering"
60
+ },
61
+ "year": {
62
+ "id": 104926492884272,
63
+ "name": "2007"
64
+ },
65
+ "concentration": [
66
+ {
67
+ "id": 112303688789448,
68
+ "name": "Engineering"
69
+ },
70
+ {
71
+ "id": 102358546472290,
72
+ "name": "Intelligent Information"
73
+ },
74
+ {
75
+ "id": 108311762535367,
76
+ "name": "Intelligent Systems Design Laboratory"
77
+ }
78
+ ]
79
+ },
80
+ {
81
+ "school": {
82
+ "id": 110149592341159,
83
+ "name": "\u540c\u5fd7\u793e\u5927\u5b66"
84
+ },
85
+ "year": {
86
+ "id": 117078804987252,
87
+ "name": "2004"
88
+ },
89
+ "concentration": [
90
+ {
91
+ "id": 108311762535367,
92
+ "name": "Intelligent Systems Design Laboratory"
93
+ },
94
+ {
95
+ "id": 120973077930419,
96
+ "name": "Engineering"
97
+ },
98
+ {
99
+ "id": 114592028573050,
100
+ "name": "Intelligent Information"
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "school": {
106
+ "id": 114666815212021,
107
+ "name": "Doshisha H.S."
108
+ },
109
+ "year": {
110
+ "id": 125827317431375,
111
+ "name": "2000"
112
+ }
113
+ }
114
+ ],
115
+ "gender": "male",
9
116
  "interested_in": [
10
- "\u5973\u6027"
117
+ "female"
11
118
  ],
12
119
  "meeting_for": [
13
- "\u53cb\u60c5",
14
- "\u30c7\u30fc\u30c8",
15
- "\u604b\u611b",
16
- "\u60c5\u5831\u4ea4\u63db"
120
+ "Friendship",
121
+ "Networking"
17
122
  ],
18
- "relationship_status": "\u65e2\u5a5a",
19
- "website": "http://matake.jp\nhttp://blog.matake.jp\nhttp://railspress.matake.jp",
123
+ "relationship_status": "Married",
124
+ "website": "http://matake.jp",
20
125
  "timezone": 9,
21
126
  "verified": true,
22
- "updated_time": "2009-10-01T06:57:02+0000"
127
+ "updated_time": "2010-05-20T06:50:04+0000"
23
128
  }
@@ -26,10 +26,10 @@ describe FbGraph::Connections::Friends, '#friends' do
26
26
  end
27
27
 
28
28
  context 'when identifier is me and no access_token is given' do
29
- it 'should raise FbGraph::NotFound' do
29
+ it 'should raise FbGraph::Unauthorized' do
30
30
  lambda do
31
31
  FbGraph::User.new('me').friends
32
- end.should raise_exception(FbGraph::NotFound)
32
+ end.should raise_exception(FbGraph::Unauthorized)
33
33
  end
34
34
  end
35
35
 
@@ -26,10 +26,10 @@ describe FbGraph::Connections::Home, '#home' do
26
26
  end
27
27
 
28
28
  context 'when identifier is me and no access_token is given' do
29
- it 'should raise FbGraph::NotFound' do
29
+ it 'should raise FbGraph::Unauthorized' do
30
30
  lambda do
31
31
  FbGraph::User.new('me').home
32
- end.should raise_exception(FbGraph::NotFound)
32
+ end.should raise_exception(FbGraph::Unauthorized)
33
33
  end
34
34
  end
35
35
 
@@ -15,7 +15,6 @@ describe FbGraph::Tag, '.new' do
15
15
  tag.x.should == 32.5
16
16
  tag.y.should == 27.7778
17
17
  tag.created_time.should == Time.parse("2010-04-22T08:24:26+0000")
18
-
19
18
  end
20
19
 
21
20
  end
@@ -17,10 +17,38 @@ end
17
17
 
18
18
  describe FbGraph::User, '.fetch' do
19
19
  before(:all) do
20
+ fake_json(:get, 'me', 'users/me_public')
21
+ fake_json(:get, 'me?access_token=access_token', 'users/me_private')
20
22
  fake_json(:get, 'arjun', 'users/arjun_public')
21
23
  fake_json(:get, 'arjun?access_token=access_token', 'users/arjun_private')
22
24
  end
23
25
 
26
+ context 'with me context' do
27
+
28
+ context 'when no access_token given' do
29
+ it 'should raise FbGraph::Unauthorized' do
30
+ lambda do
31
+ FbGraph::User.fetch('me')
32
+ end.should raise_exception(FbGraph::Unauthorized)
33
+ end
34
+ end
35
+
36
+ context 'when access_token given' do
37
+ it 'should get current user profile' do
38
+ user = FbGraph::User.me('access_token').fetch
39
+ user.interested_in.should == ['female']
40
+ user.meeting_for.should == ['Friendship', 'Networking']
41
+ user.relationship_status.should == 'Married'
42
+ user.website.should == ['http://matake.jp']
43
+ user.religion.should be_nil
44
+ user.political.should be_nil
45
+ user.timezone.should == 9
46
+ user.verified.should be_true
47
+ end
48
+ end
49
+
50
+ end
51
+
24
52
  context 'when no access_token given' do
25
53
  it 'should get only public profile' do
26
54
  user = FbGraph::User.fetch('arjun')
@@ -29,6 +57,8 @@ describe FbGraph::User, '.fetch' do
29
57
  user.last_name.should == 'Banker'
30
58
  user.identifier.should == '7901103'
31
59
  user.link.should == 'http://www.facebook.com/Arjun'
60
+ user.location.should == FbGraph::Page.new(114952118516947, :name => 'San Francisco, California')
61
+ user.gender.should == 'male'
32
62
  end
33
63
  end
34
64
 
@@ -42,9 +72,11 @@ describe FbGraph::User, '.fetch' do
42
72
  user.last_name.should == 'Banker'
43
73
  user.identifier.should == '7901103'
44
74
  user.link.should == 'http://www.facebook.com/Arjun'
75
+ user.location.should == FbGraph::Page.new(114952118516947, :name => 'San Francisco, California')
76
+ user.gender.should == 'male'
45
77
 
46
78
  # private
47
- user.about.should == "squish squash\npip pop\nfizz bang"
79
+ user.about.should == 'daydrea'
48
80
  user.birthday.should == Date.parse('04/15/1984')
49
81
  user.work.should == [
50
82
  FbGraph::Work.new({
@@ -85,8 +117,19 @@ describe FbGraph::User, '.fetch' do
85
117
  ]
86
118
  })
87
119
  ]
88
- user.email.should == nil
89
- user.website.should == []
120
+ user.email.should == nil
121
+ user.website.should == []
122
+ user.hometown.should == FbGraph::Page.new(109533479072558, :name => 'Minnetonka, Minnesota')
123
+ user.interested_in.should == ['female']
124
+ user.meeting_for.should == ['Friendship']
125
+ user.relationship_status.should == 'In a Relationship'
126
+ user.religion.should == 'zorp'
127
+ user.political.should == 'Liberal'
128
+ user.verified.should be_nil
129
+ # What's this?
130
+ # user.significant_other
131
+ user.timezone.should be_nil
132
+ user.updated_time.should == Time.parse('2010-05-29T04:29:23+0000')
90
133
  end
91
134
  end
92
135
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - nov matake
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-21 00:00:00 +09:00
17
+ date: 2010-06-06 00:00:00 +09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency