joey 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{joey}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
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-07-07}
9
+ s.date = %q{2010-08-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/action.rb", "lib/joey/affiliation.rb", "lib/joey/album.rb", "lib/joey/comment.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/post.rb", "lib/joey/privacy.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"]
@@ -1,5 +1,15 @@
1
1
  module Joey
2
2
  class Action < Model
3
3
  define_properties :name, :link
4
+
5
+ def validate
6
+ errors << { :message => "name should String but is #{name.inspect}" } unless name.is_a?(String)
7
+ errors << { :message => "link should String but is #{link.inspect}" } unless link.is_a?(String)
8
+ end
9
+
10
+ def valid?
11
+ self.validate
12
+ self.errors.empty?
13
+ end
4
14
  end
5
15
  end
@@ -1,5 +1,14 @@
1
1
  module Joey
2
2
  class Affiliation < Model
3
3
  define_properties :type, :year, :name, :nid, :status
4
+
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
4
13
  end
5
14
  end
@@ -7,7 +7,15 @@ module Joey
7
7
  hash_populating_accessor :from, "User", "Page"
8
8
  hash_populating_accessor :comments, "Comment"
9
9
  has_association :photos, "Photo"
10
- #has_association :comments, "Comment"
10
+ has_association :comments, "Comment"
11
11
 
12
+ def validate
13
+ valid = true
14
+ end
15
+
16
+ def valid?
17
+ self.validate
18
+ self.errors.empty?
19
+ end
12
20
  end
13
21
  end
@@ -1,7 +1,19 @@
1
1
  module Joey
2
2
  class Comment < Model
3
- define_properties :id, :message, :created_time
3
+ define_properties :id, :message, :created_time, :count
4
4
  #creation_properties :message
5
5
  hash_populating_accessor :from, "User","Page"
6
+
7
+ def validate
8
+ created_time.to_time rescue errors << { :message => 'created_time is not compatible' }
9
+ updated_time.to_time rescue errors << { :message => 'updated_time is not compatible' }
10
+ errors << { :message => 'id should not be nil' } if id.nil?
11
+ errors << { :message => 'from is not a Joey::User or Joey::Page' } unless from.is_a?(Joey::User) || from.is_a?(Joey::Page)
12
+ end
13
+
14
+ def valid?
15
+ self.validate
16
+ self.errors.empty?
17
+ end
6
18
  end
7
19
  end
@@ -6,5 +6,14 @@ module Joey
6
6
  hash_populating_accessor :school, "Page"
7
7
  hash_populating_accessor :year, "Page"
8
8
  hash_populating_accessor :concentration, "Page"
9
+
10
+ def validate
11
+ valid = true
12
+ end
13
+
14
+ def valid?
15
+ self.validate
16
+ self.errors.empty?
17
+ end
9
18
  end
10
19
  end
@@ -1,5 +1,14 @@
1
1
  module Joey
2
2
  class EducationHistory < Model
3
3
  define_properties :name, :degree, :year, :school_type, :concentrations
4
+
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
4
13
  end
5
14
  end
@@ -1,5 +1,14 @@
1
1
  module Joey
2
2
  class HsInfo < Model
3
3
  define_properties :hs1_name, :hs2_name, :grad_year
4
+
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
4
13
  end
5
14
  end
@@ -1,5 +1,16 @@
1
1
  module Joey
2
2
  class Location < Model
3
3
  define_properties :name, :zip, :country, :id, :state, :city
4
+
5
+ def validate
6
+ valid = true
7
+ errors << { :message => "country should be string but is #{country.inspect}" } unless country.is_a?(String)
8
+ errors << { :message => "city should be string but is #{city.inspect}" } unless city.is_a?(String)
9
+ end
10
+
11
+ def valid?
12
+ self.validate
13
+ self.errors.empty?
14
+ end
4
15
  end
5
16
  end
@@ -3,10 +3,12 @@ module Joey
3
3
 
4
4
  class KoalaClientRequiredError < Exception; end
5
5
 
6
- attr_accessor :client
6
+ attr_accessor :client, :errors
7
7
 
8
8
  def initialize(hash = {}, client = nil)
9
9
  self.client = client
10
+ self.errors = []
11
+
10
12
  super(hash || {})
11
13
  end
12
14
 
@@ -54,8 +56,10 @@ module Joey
54
56
  #add_creation_method(name, klass)
55
57
  end
56
58
 
57
- def self.find(id, client = nil)
58
- client.get_and_map(id, self)
59
+ ##
60
+ # Get some information of a node in the Graph.
61
+ def self.find(id, client = nil, args = {})
62
+ client.get_and_map(id, self, args)
59
63
  end
60
64
 
61
65
  end
@@ -16,5 +16,15 @@ module Joey
16
16
  hash.has_key?("category")
17
17
  end
18
18
 
19
+ def validate
20
+ valid = true
21
+ errors << { :message => 'id should not be nil' } if id.nil?
22
+ errors << { :message => "name should be string but is #{name.inspect}" } unless name.is_a?(String)
23
+ end
24
+
25
+ def valid?
26
+ self.validate
27
+ self.errors.empty?
28
+ end
19
29
  end
20
30
  end
@@ -5,5 +5,17 @@ module Joey
5
5
  #creation_properties :message
6
6
 
7
7
  hash_populating_accessor :from, "User","Page"
8
+ hash_populating_accessor :comments, "Comment"
9
+ hash_populating_accessor :tags, "Tag"
10
+ #has_association :comments, "Comment"
11
+
12
+ def validate
13
+ valid = true
14
+ end
15
+
16
+ def valid?
17
+ self.validate
18
+ self.errors.empty?
19
+ end
8
20
  end
9
21
  end
@@ -1,20 +1,64 @@
1
1
  module Joey
2
2
  class Post < Model
3
-
3
+
4
4
  define_properties :id, :message, :picture, :link, :name, :caption,
5
5
  :description, :source, :icon, :attribution, :actions, :likes,
6
6
  :created_time, :updated_time, :type
7
-
7
+
8
8
  #creation_properties :message, :picture, :link, :name, :description
9
-
9
+
10
10
  hash_populating_accessor :actions, "Action"
11
11
  hash_populating_accessor :comments, "Comment"
12
- hash_populating_accessor :from, "User"
13
- hash_populating_accessor :to, "User"
12
+ hash_populating_accessor :from, "User", "Page"
13
+ hash_populating_accessor :to, "User", "Page"
14
14
  hash_populating_accessor :privacy, "Privacy"
15
-
15
+
16
+ def validate
17
+ created_time.to_time rescue errors << { :message => 'created_time is not compatible' }
18
+ updated_time.to_time rescue errors << { :message => 'updated_time is not compatible' }
19
+ errors << { :message => 'id should not be nil' } if id.nil?
20
+ errors << { :message => "name is neither string nor nil but is #{name.inspect}" } unless name.is_a?(String) || name.nil?
21
+ errors << { :message => "message is neither string nor nil but is #{message.inspect}" } unless message.is_a?(String) || message.nil?
22
+ errors << { :message => "likes is neither string nor nil but is #{likes.inspect}" } unless likes.is_a?(Integer) || likes.nil?
23
+ errors << { :message => "icon is neither string nor nil but is #{icon.inspect}" } unless icon.is_a?(String) || icon.nil?
24
+ errors << { :message => "attribution is neither string nor nil but is #{attribution.inspect}" } unless attribution.is_a?(String) || attribution.nil?
25
+
26
+ unless ['music', 'photo', 'video', 'status', 'link'].include?(type)
27
+ errors << { :message => "type should be one of 'music', 'video', 'status', or 'link' but is #{type}" }
28
+ end
29
+
30
+ if type == 'picture' && !picture.is_a?(String)
31
+ errors << { :message => "picture is not present for picture post and is #{picture.inspect}" }
32
+ end
33
+
34
+ if type == 'link' && !link.is_a?(String)
35
+ errors << { :message => "picture is not present for picture post and is #{picture.inspect}" }
36
+ end
37
+
38
+ errors << { :message => "from is not a Joey::User or Joey::Page and is #{from.inspect}" } unless from.is_a?(Joey::User) || from.is_a?(Joey::Page)
39
+
40
+ errors << { :message => "to is neither an array nor nil and is #{to.inspect}" } unless to.is_a?(Array) || to.nil?
41
+ if to.is_a?(Array) && !(to.collect(&:class).uniq - [Joey::User, Joey::Page]).empty?
42
+ errors << { :message => 'to is not an array of Joey::User or Joey::Page' }
43
+ end
44
+
45
+ # TODO: Explore following approach.
46
+ # errors << { :message => 'Comments is not valid' }, unless comment.nil? || (comments.collect(&:valid?).uniq - [true]).empty?
47
+
48
+ # Sometimes comments is a single Joey::Comment object
49
+ errors << { :message => "comments is not an array nor nil and is #{comments.inspect}" } unless comments.is_a?(Array) || comments.nil?
50
+ if comments.is_a?(Array) && !(comments.collect(&:class).uniq - [Joey::Comment]).empty?
51
+ errors << { :message => 'comments is not an array of Joey::Comment' }
52
+ end
53
+ end
54
+
55
+ def valid?
56
+ self.validate
57
+ self.errors.empty?
58
+ end
59
+
16
60
  #def likes_create
17
- #client.post("#{id}/likes",nil,{})
61
+ #client.post("#{id}/likes",nil,{})
18
62
  #end
19
63
  end
20
64
  end
@@ -1,5 +1,14 @@
1
1
  module Joey
2
2
  class Privacy < Model
3
3
  define_properties :value, :description, :allow, :friends, :deny
4
+
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
4
13
  end
5
14
  end
@@ -17,5 +17,14 @@ module Joey
17
17
  def to_s
18
18
  name
19
19
  end
20
+
21
+ def validate
22
+ valid = true
23
+ end
24
+
25
+ def valid?
26
+ self.validate
27
+ self.errors.empty?
28
+ end
20
29
  end
21
30
  end
@@ -1,5 +1,14 @@
1
1
  module Joey
2
2
  class Relative < Model
3
- define_properties :uid, :relationship
3
+ define_properties :uid, :relationship, :name
4
+
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
4
13
  end
5
14
  end
@@ -21,8 +21,8 @@ module Joey
21
21
 
22
22
  # path can be some node id in the Facebook Graph e.g. 'me', 'me/feed', '1234567890/feed'.
23
23
  # klass is wrapper class for that node.
24
- def get_and_map(path, klass = nil)
25
- data = self.get_object(path)
24
+ def get_and_map(path, klass = nil, args = {})
25
+ data = self.get_object(path, args)
26
26
  map_data(data, klass)
27
27
  end
28
28
 
@@ -37,6 +37,8 @@ module Joey
37
37
  raise_error_if_necessary(data)
38
38
  hash_or_array = extract_hash_or_array(data, klass)
39
39
  hash_or_array = map_to_class(hash_or_array, klass) if klass
40
+ # TODO: Validate an object here.
41
+ #hash_or_array.validate and puts hash_or_array.class.inspect if hash_or_array.is_a?(Model)
40
42
  hash_or_array
41
43
  end
42
44
 
@@ -66,6 +68,7 @@ module Joey
66
68
  else
67
69
  hash_or_array = create_instance(klass, hash_or_array)
68
70
  end
71
+ hash_or_array
69
72
  end
70
73
 
71
74
  def create_instance(klass, data)
@@ -77,7 +80,9 @@ module Joey
77
80
  end
78
81
 
79
82
  def constantize_string(klass)
80
- klass.is_a?(String) ? Joey.const_get(klass) : klass
83
+ # FIXME: cost_get is buggy on some versions of Ruby
84
+ # klass.is_a?(String) ? Joey.const_get(klass) : klass
85
+ klass.is_a?(String) ? (klass =~ /Joey/ ? klass.constantize : ("Joey::"+ klass).constantize) : klass
81
86
  end
82
87
 
83
88
  def determine_class(klass_or_klasses, data)
@@ -1,5 +1,14 @@
1
1
  module Joey
2
2
  class Status < Model
3
3
  define_properties :time, :status_id, :message
4
+
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
4
13
  end
5
14
  end
@@ -2,5 +2,13 @@ module Joey
2
2
  class Television < Model
3
3
  define_properties :name, :category, :id
4
4
 
5
+ def validate
6
+ valid = true
7
+ end
8
+
9
+ def valid?
10
+ self.validate
11
+ self.errors.empty?
12
+ end
5
13
  end
6
14
  end
@@ -1,25 +1,25 @@
1
1
  module Joey
2
2
  class User < Profile
3
3
  include ParserHelpers
4
-
4
+
5
5
  define_properties :first_name, :last_name, :middle_name, :link, :about, :about_me, :birthday, :gender,
6
- :email, :website, :timezone, :updated_time, :verified, :religion, :political
6
+ :email, :website, :timezone, :updated_time, :verified, :religion, :political
7
7
  define_properties :pic_small, :pic_big, :pic_square, :pic, :pic_big_with_logo, :pic_small_with_logo,
8
- :pic_square_with_logo, :pic_with_logo
8
+ :pic_square_with_logo, :pic_with_logo, :picture
9
9
  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 :profile_url, :profile_update_time, :interests, :is_blocked, :quotes
12
-
10
+ define_properties :wall_count, :uid, :movies, :sex, :birthday_date, :notes_count, :activities, :profile_blurb, :music, :locale
11
+ define_properties :profile_url, :profile_update_time, :interests, :is_blocked, :quotes, :interested_in, :bio
12
+
13
13
  def self.recognize?(hash)
14
14
  !hash.has_key?("category")
15
15
  end
16
-
16
+
17
17
  hash_populating_accessor :status, "Status"
18
18
  hash_populating_accessor :work, "Work"
19
19
  hash_populating_accessor :work_history, "WorkHistory"
20
20
  hash_populating_accessor :education, "Education"
21
21
  hash_populating_accessor :education_history, "EducationHistory"
22
-
22
+
23
23
  hash_populating_accessor :location, "Page"
24
24
  hash_populating_accessor :current_location, "Location"
25
25
  hash_populating_accessor :hometown, "Page"
@@ -37,21 +37,41 @@ module Joey
37
37
  #has_association :movies, "Movie"
38
38
  has_association :television, "Television"
39
39
  has_association :likes, "Page"
40
-
40
+
41
41
  def has_app_permission?(ext_perm)
42
42
  boolianize(client.rest_call("users.hasAppPermission", :ext_perm => ext_perm.to_s))
43
43
  end
44
44
 
45
45
  def friends!(ids)
46
46
  data = self.client.rest_call('users.getInfo', :uids => ids, :fields =>
47
- 'about_me,activities,affiliations,books,birthday,birthday_date,current_location,education_history,
47
+ 'about_me,activities,affiliations,books,birthday,birthday_date,current_location,education_history,
48
48
  email,family,first_name,hometown_location,hs_info,interests,is_app_user,is_blocked,last_name,
49
49
  locale,meeting_for,meeting_sex,movies,music,name,notes_count,pic,pic_big,pic_small,pic_square,
50
50
  pic_with_logo,pic_big_with_logo,pic_small_with_logo,pic_square_with_logo,
51
51
  political,profile_blurb,profile_update_time,profile_url,quotes,relationship_status,religion,sex,
52
52
  significant_other_id,status,timezone,tv,username,wall_count,website,work_history')
53
- self.client.map_data(data, self.class)
54
- end
53
+ self.client.map_data(data, self.class)
54
+ end
55
+
56
+ def info(args)
57
+ data = self.client.rest_call('users.getInfo', :uids => self.id, :fields => args.join(','))
58
+ user = self.client.map_data(data, self.class).first
59
+ user.id = user.uid
60
+ user
61
+ end
55
62
 
63
+ def validate
64
+ errors << { :message => 'id should not be nil' } if id.nil?
65
+ errors << { :message => "name should be string but is #{name.inspect}" } unless name.is_a?(String)
66
+ errors << { :message => "gender should be 'male' or 'female' but is #{gender.inspect}" } unless ['male', 'female'].include?(gender)
67
+ errors << { :message => "pic big is neither string nor nil but is #{pic_big.inspect}" } unless pic_big.is_a?(String) || pic_big.nil?
68
+ errors << { :message => "current location is neither Joey::Location nor nil but is #{current_location.inspect}" } unless current_location.is_a?(Joey::Location) || current_location.nil?
69
+ updated_time.to_time rescue errors << { :message => 'updated_time is not compatible' }
70
+ end
71
+
72
+ def valid?
73
+ self.validate
74
+ self.errors.empty?
75
+ end
56
76
  end
57
77
  end
@@ -2,7 +2,7 @@ module Joey #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,10 +1,19 @@
1
1
  module Joey
2
2
  class Work < Model
3
3
 
4
- define_properties :start_date, :end_date
4
+ define_properties :start_date, :end_date, :description
5
5
 
6
6
  hash_populating_accessor :employer, "Page"
7
7
  hash_populating_accessor :location, "Page"
8
8
  hash_populating_accessor :position, "Page"
9
+
10
+ def validate
11
+ valid = true
12
+ end
13
+
14
+ def valid?
15
+ self.validate
16
+ self.errors.empty?
17
+ end
9
18
  end
10
19
  end
@@ -3,5 +3,15 @@ module Joey
3
3
  define_properties :start_date, :position, :company_name, :description, :end_date
4
4
 
5
5
  hash_populating_accessor :location, "Location"
6
+
7
+ def validate
8
+ valid = true
9
+ end
10
+
11
+ def valid?
12
+ self.validate
13
+ self.errors.empty?
14
+ end
15
+
6
16
  end
7
17
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
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-07-07 00:00:00 +05:30
17
+ date: 2010-08-22 00:00:00 +05:30
18
18
  default_executable:
19
19
  dependencies: []
20
20