joey 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Waseem Ahmad
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest CHANGED
@@ -1,7 +1,9 @@
1
+ COPYING.txt
1
2
  README.md
2
3
  Rakefile
3
4
  devel.vim
4
5
  init.rb
6
+ joey.gemspec
5
7
  lib/joey.rb
6
8
  lib/joey/affiliation.rb
7
9
  lib/joey/album.rb
data/README.md CHANGED
@@ -1,3 +1,77 @@
1
1
  Joey
2
2
  ====
3
- Joey(<a href="http://github.com/waseem/joey">http://github.com/waseem/joey</a>) is object wrappers for nodes in the Facebook OpenGraph. It also provides wrapper for the data returned by requesting the facebook REST api. This gem depends upon Koala(<a href="http://github.com/arsduo/koala">http://github.com/arsduo/koala</a>).
3
+ Joey(<a href="http://github.com/waseem/joey">http://github.com/waseem/joey</a>) provides object wrappers for nodes in the Facebook OpenGraph. It also provides wrappers for the data returned from facebook REST api. This gem depends upon Koala(<a href="http://github.com/arsduo/koala">http://github.com/arsduo/koala</a>).
4
+
5
+ This discussion(<a href="http://groups.google.com/group/koala-users/browse_thread/thread/650be4f3377aef48">http://groups.google.com/group/koala-users/browse_thread/thread/650be4f3377aef48</a>) sums up the motivation to create Joey and what it intends to accomplish.
6
+
7
+ Wrappers
8
+ ----
9
+
10
+ Koala is a lightweight Ruby library which provides an interface to access Facebook Open Graph and REST API.
11
+
12
+ Facebook servers return data in the form of Json or XML. When you use Koala to make requests to the Graph, it converts the returned Json into ready to be used Ruby hashes. e.g.
13
+
14
+ koala_client = Koala::Facebook::GraphAndRestAPI.new(access_token)
15
+ # http://graph.facebook.com/me
16
+ me = koala_client.get_object('me')
17
+ # => {"name"=>"Phuddu Bandar", "timezone"=>5.5, "gender"=>"male", "id"=>"100000654222309", "birthday"=>"12/01/1986", "last_name"=>"Bandar", "updated_time"=>"2010-01-10T16:35:06+0000", "hometown"=>{"name"=>nil, "id"=>nil}, "link"=>"http://www.facebook.com/profile.php?id=100000654222309", "email"=>"phuddu.bandar@gmail.com", "first_name"=>"Phuddu"}
18
+
19
+ me['name'] # => 'Phuddu Bandar'
20
+ me['gender'] # => 'male'
21
+ me['hometown']['name'] # => nil
22
+
23
+ Above when tried with joey returns a Joey::User object. We can access different information associated with a user using accessor methods instead of hash keys.
24
+
25
+ koala_client = Koala::Facebook::GraphAndRestAPI.new(access_token)
26
+ # http://graph.facebook.com/me
27
+ me = koala_client.me
28
+ # => <#Joey::User about=nil about_me=nil activities=nil birthday="12/01/1986" birthday_date=nil books=nil email="phuddu.bandar@gmail.com" first_name="Phuddu" gender="male" id="100000654222309" interests=nil is_app_user=nil is_blocked=nil last_name="Bandar" link="http://www.facebook.com/profile.php?id=100000654222309" locale=nil meeting_for=nil meeting_sex=nil middle_name=nil movies=nil music=nil name="Phuddu Bandar" notes_count=nil pic=nil pic_big=nil pic_big_with_logo=nil pic_small=nil pic_small_with_logo=nil pic_square=nil pic_square_with_logo=nil pic_with_logo=nil political=nil profile_blurb=nil profile_update_time=nil profile_url=nil quotes=nil relationship_status=nil religion=nil sex=nil significant_other_id=nil timezone=5.5 tv=nil uid=nil updated_time="2010-01-10T16:35:06+0000" username=nil verified=nil wall_count=nil website=nil>
29
+
30
+ me.name # => 'Phuddu Bandar'
31
+ me.gender # => 'male'
32
+ me.hometown.name # => nil
33
+
34
+
35
+ The main advantage of creating wrapper classes for different nodes in the Graph is that one can add custom methods to different objects. e.g.
36
+
37
+ In Open Graph there is no method to know if a user has given some particular extended permission to your application. However in old REST api there is <a href="http://developers.facebook.com/docs/reference/rest/users.hasAppPermission">users.hasAppPermission</a> for the same.
38
+
39
+ If we use plain Koala, we can implement it in following way:
40
+
41
+ !koala_client.rest_call('users.hasAppPermission', :ext_perm => 'email').zero? # => true or false
42
+
43
+ In Joey, call to users.hasAppPermission is sheilded behind a Joey::User#has_app_permission?(ext_perm)
44
+
45
+ me = koala_client.me
46
+ me.has_app_permission?(:email) # => true or false
47
+
48
+ A more complex use case arises when someone intends to add application specific methods to different nodes. e.g.
49
+
50
+ An application intends to know if a user has given his proxy email while giving the email extended permission. One can include a module with custom methods.
51
+
52
+ module FacebookUser
53
+
54
+ def self.included(base)
55
+ base.extend(ClassMethods)
56
+ end
57
+
58
+ module ClassMethods
59
+ end
60
+
61
+ def has_proxy_email?
62
+ if self.has_app_permission?(:email)
63
+ return self.email =~ /@proxymail\.facebook\.com/
64
+ else
65
+ return true
66
+ end
67
+ end
68
+ end
69
+
70
+ and somewhere when you intialize your application like 'config/initializers/joey_patch.rb' in Rails
71
+
72
+ Joey::User.send(:include, FacebookUser)
73
+
74
+ Now one can do
75
+
76
+ me = koala_client.me
77
+ me.has_proxy_email? # => true or false
data/joey.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{joey}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Waseem Ahmad"]
9
- s.date = %q{2010-06-16}
9
+ s.date = %q{2010-06-22}
10
10
  s.description = %q{Object wrappers for nodes in the Facebook OpenGraph}
11
11
  s.email = %q{talk.to.waseem@gmail.com}
12
12
  s.extra_rdoc_files = ["README.md", "lib/joey.rb", "lib/joey/affiliation.rb", "lib/joey/album.rb", "lib/joey/education.rb", "lib/joey/education_history.rb", "lib/joey/fetching_array.rb", "lib/joey/hs_info.rb", "lib/joey/location.rb", "lib/joey/model.rb", "lib/joey/page.rb", "lib/joey/parser_helpers.rb", "lib/joey/photo.rb", "lib/joey/profile.rb", "lib/joey/relative.rb", "lib/joey/rest_api.rb", "lib/joey/status.rb", "lib/joey/television.rb", "lib/joey/user.rb", "lib/joey/version.rb", "lib/joey/work.rb", "lib/joey/work_history.rb"]
13
- s.files = ["README.md", "Rakefile", "devel.vim", "init.rb", "lib/joey.rb", "lib/joey/affiliation.rb", "lib/joey/album.rb", "lib/joey/education.rb", "lib/joey/education_history.rb", "lib/joey/fetching_array.rb", "lib/joey/hs_info.rb", "lib/joey/location.rb", "lib/joey/model.rb", "lib/joey/page.rb", "lib/joey/parser_helpers.rb", "lib/joey/photo.rb", "lib/joey/profile.rb", "lib/joey/relative.rb", "lib/joey/rest_api.rb", "lib/joey/status.rb", "lib/joey/television.rb", "lib/joey/user.rb", "lib/joey/version.rb", "lib/joey/work.rb", "lib/joey/work_history.rb", "Manifest", "joey.gemspec"]
13
+ s.files = ["COPYING.txt", "README.md", "Rakefile", "devel.vim", "init.rb", "joey.gemspec", "lib/joey.rb", "lib/joey/affiliation.rb", "lib/joey/album.rb", "lib/joey/education.rb", "lib/joey/education_history.rb", "lib/joey/fetching_array.rb", "lib/joey/hs_info.rb", "lib/joey/location.rb", "lib/joey/model.rb", "lib/joey/page.rb", "lib/joey/parser_helpers.rb", "lib/joey/photo.rb", "lib/joey/profile.rb", "lib/joey/relative.rb", "lib/joey/rest_api.rb", "lib/joey/status.rb", "lib/joey/television.rb", "lib/joey/user.rb", "lib/joey/version.rb", "lib/joey/work.rb", "lib/joey/work_history.rb", "Manifest"]
14
14
  s.homepage = %q{http://github.com/waseem/joey}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Joey", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
data/lib/joey/rest_api.rb CHANGED
@@ -10,10 +10,12 @@ module Joey
10
10
  module ClassMethods
11
11
  end
12
12
 
13
+ # return the currently connected user
13
14
  def me
14
15
  get_and_map('me', Joey::User)
15
16
  end
16
17
 
18
+ # revoke an extended permissions granted by current connected user
17
19
  def revoke_app_permission(ext_perm)
18
20
  # no need to boolianize. It returns true/false.
19
21
  self.rest_call("auth.revokeExtendedPermission", :perm => ext_perm.to_s)
@@ -33,6 +35,7 @@ module Joey
33
35
  map_data(data,klass)
34
36
  end
35
37
 
38
+ # map the returned data to a node class
36
39
  def map_data(data, klass = nil)
37
40
  raise_error_if_necessary(data)
38
41
  hash_or_array = extract_hash_or_array(data, klass)
data/lib/joey/user.rb CHANGED
@@ -2,12 +2,13 @@ module Joey
2
2
  class User < Profile
3
3
  include ParserHelpers
4
4
 
5
- define_properties :first_name, :last_name, :middle_name, :link, :about, :about_me, :birthday, :gender,
5
+ # New Graph API has gender while old REST api has sex. I don't know why facebook does these kind of things.
6
+ define_properties :first_name, :last_name, :middle_name, :link, :about, :about_me, :birthday, :gender, :sex,
6
7
  :email, :website, :timezone, :updated_time, :verified, :religion, :political
7
8
  define_properties :pic_small, :pic_big, :pic_square, :pic, :pic_big_with_logo, :pic_small_with_logo,
8
9
  :pic_square_with_logo, :pic_with_logo
9
10
  define_properties :is_app_user, :books, :username, :significant_other_id, :meeting_for, :tv, :meeting_sex, :relationship_status
10
- define_properties :wall_count, :uid, :movies, :sex, :birthday_date, :notes_count, :activities, :profile_blurb, :music, :music, :locale
11
+ define_properties :wall_count, :uid, :movies, :birthday_date, :notes_count, :activities, :profile_blurb, :music, :music, :locale
11
12
  define_properties :profile_url, :profile_update_time, :interests, :is_blocked, :quotes
12
13
 
13
14
  def self.recognize?(hash)
@@ -29,18 +30,22 @@ module Joey
29
30
  hash_populating_accessor :family, "Relative"
30
31
 
31
32
  #has_association :activities,"Activity"
32
- has_association :friends, "User"
33
33
  #has_association :interests, "Interest"
34
34
  #has_association :music, "Music"
35
35
  #has_association :books, "Book"
36
36
  #has_association :movies, "Movie"
37
37
  has_association :television, "Television"
38
38
  has_association :likes, "Page"
39
+ has_association :friends, "User"
39
40
 
41
+ # Does the current user has an extender permission
40
42
  def has_app_permission?(ext_perm)
41
43
  boolianize(client.rest_call("users.hasAppPermission", :ext_perm => ext_perm.to_s))
42
44
  end
43
45
 
46
+ # Get information about current user's friends.
47
+ # A lot of information is not available in Graph api or is available but
48
+ # only after making several requests to Facebook.
44
49
  def friends!(ids)
45
50
  data = self.client.rest_call('users.getInfo', :uids => ids, :fields =>
46
51
  'about_me,activities,affiliations,books,birthday,birthday_date,current_location,education_history,
data/lib/joey/version.rb CHANGED
@@ -2,7 +2,7 @@ module Joey #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Waseem Ahmad
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-16 00:00:00 +05:30
17
+ date: 2010-06-22 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -48,10 +48,12 @@ extra_rdoc_files:
48
48
  - lib/joey/work.rb
49
49
  - lib/joey/work_history.rb
50
50
  files:
51
+ - COPYING.txt
51
52
  - README.md
52
53
  - Rakefile
53
54
  - devel.vim
54
55
  - init.rb
56
+ - joey.gemspec
55
57
  - lib/joey.rb
56
58
  - lib/joey/affiliation.rb
57
59
  - lib/joey/album.rb
@@ -74,7 +76,6 @@ files:
74
76
  - lib/joey/work.rb
75
77
  - lib/joey/work_history.rb
76
78
  - Manifest
77
- - joey.gemspec
78
79
  has_rdoc: true
79
80
  homepage: http://github.com/waseem/joey
80
81
  licenses: []