mogli 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mogli.rb CHANGED
@@ -8,6 +8,7 @@ require "hashie"
8
8
 
9
9
  require "mogli/authenticator"
10
10
  require "mogli/model"
11
+ require "mogli/profile"
11
12
  require "mogli/fetching_array"
12
13
  require "mogli/action"
13
14
  require "mogli/activity"
@@ -25,6 +26,7 @@ require "mogli/note"
25
26
  require "mogli/page"
26
27
  require "mogli/photo"
27
28
  require "mogli/post"
29
+ require "mogli/status"
28
30
  require "mogli/television"
29
31
  require "mogli/video"
30
32
  require "mogli/work"
data/lib/mogli/album.rb CHANGED
@@ -2,6 +2,7 @@ module Mogli
2
2
  class Album < Model
3
3
 
4
4
  define_properties :id, :name, :description, :link, :count, :created_time, :updated_time
5
+ creation_properties :name, :message
5
6
 
6
7
  hash_populating_accessor :from, "User","Page"
7
8
  has_association :photos, "Photo"
data/lib/mogli/client.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "mogli/client/event"
1
2
  require "mogli/client/user"
2
3
  require "ruby-debug"
3
4
 
@@ -8,6 +9,7 @@ module Mogli
8
9
  attr_reader :expiration
9
10
 
10
11
  include HTTParty
12
+ include Mogli::Client::Event
11
13
  include Mogli::Client::User
12
14
  class UnrecognizeableClassError < Exception; end
13
15
 
@@ -17,7 +19,9 @@ module Mogli
17
19
 
18
20
  def initialize(access_token = nil,expiration=nil)
19
21
  @access_token = access_token
20
- @expiration = Time.now + expiration if expiration
22
+ # nil expiration means extended access
23
+ expiration = 10*365*24*60*60 if expiration.nil? or expiration == 0
24
+ @expiration = Time.now + expiration
21
25
  @default_params = @access_token ? {:access_token=>access_token} : {}
22
26
  end
23
27
 
@@ -35,6 +39,15 @@ module Mogli
35
39
  new(hash["access_token"],hash["expires"].to_s.to_i)
36
40
  end
37
41
 
42
+ def post(path,klass,body_args)
43
+ data = self.class.post(api_path(path),:body=>default_params.merge(body_args))
44
+ map_data(data,klass)
45
+ end
46
+
47
+ def delete(path)
48
+ self.class.delete(api_path(path),:query=>default_params)
49
+ end
50
+
38
51
  def get_and_map(path,klass=nil)
39
52
  data = self.class.get(api_path(path),:query=>default_params)
40
53
  map_data(data,klass)
@@ -133,4 +146,4 @@ module Mogli
133
146
  end
134
147
 
135
148
  end
136
- end
149
+ end
@@ -0,0 +1,11 @@
1
+ module Mogli
2
+ class Client
3
+ module Event
4
+
5
+
6
+ def event(id)
7
+ get_and_map(id,Mogli::Event)
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/mogli/comment.rb CHANGED
@@ -2,7 +2,7 @@ module Mogli
2
2
  class Comment < Model
3
3
 
4
4
  define_properties :id, :message, :created_time
5
-
5
+ creation_properties :message
6
6
  hash_populating_accessor :from, "User","Page"
7
7
 
8
8
  end
data/lib/mogli/link.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Mogli
2
+ class Link < Model
3
+ define_properties :link, :message
4
+ creation_properties :link, :message
5
+ end
6
+ end
data/lib/mogli/model.rb CHANGED
@@ -13,6 +13,19 @@ module Mogli
13
13
  super(hash||{})
14
14
  end
15
15
 
16
+ def post_params
17
+ post_params = {}
18
+ self.class.creation_keys.each do |key|
19
+ post_params[key] = self[key]
20
+ end
21
+ post_params
22
+ end
23
+
24
+ def destroy
25
+ client.delete(id)
26
+ freeze
27
+ end
28
+
16
29
  def self.included(other)
17
30
  other.extend(ClassMethods)
18
31
  end
@@ -35,6 +48,14 @@ module Mogli
35
48
  end
36
49
  end
37
50
 
51
+ def self.creation_properties(*args)
52
+ @creation_properties = args
53
+ end
54
+
55
+ def self.creation_keys
56
+ @creation_properties || []
57
+ end
58
+
38
59
  def self.hash_populating_accessor(method_name,*klass)
39
60
  define_method "#{method_name}=" do |hash|
40
61
  instance_variable_set("@#{method_name}",client.map_data(hash,klass))
@@ -42,16 +63,29 @@ module Mogli
42
63
  define_method "#{method_name}" do
43
64
  instance_variable_get "@#{method_name}"
44
65
  end
66
+
67
+ add_creation_method(method_name,klass)
68
+
69
+ end
70
+
71
+ def self.add_creation_method(name,klass)
72
+ define_method "#{name}_create" do |arg|
73
+ params = arg.nil? ? {} : arg.post_params
74
+ klass_to_send = arg.nil? ? nil : klass
75
+ client.post("#{id}/#{name}", klass_to_send, params)
76
+ end
45
77
  end
46
78
 
47
79
  def self.has_association(name,klass)
48
80
  define_method name do
49
81
  if (ret=instance_variable_get("@#{name}")).nil?
50
- ret = client.get_and_map("/#{id}/#{name}",klass)
82
+ ret = client.get_and_map("#{id}/#{name}",klass)
51
83
  instance_variable_set("@#{name}",ret)
52
84
  end
53
85
  return ret
54
86
  end
87
+
88
+ add_creation_method(name,klass)
55
89
  end
56
90
 
57
91
  def self.recognize?(data)
data/lib/mogli/note.rb CHANGED
@@ -2,6 +2,7 @@ module Mogli
2
2
  class Note < Model
3
3
 
4
4
  define_properties :id, :subject, :message, :created_time, :updated_time, :icon
5
+ creation_properties :message, :subject
5
6
 
6
7
  hash_populating_accessor :from, "User", "Page"
7
8
 
data/lib/mogli/page.rb CHANGED
@@ -1,21 +1,12 @@
1
1
  module Mogli
2
- class Page < Model
2
+ class Page < Profile
3
3
 
4
4
  define_properties :id, :name, :category
5
5
 
6
- hash_populating_accessor :albums, "Album"
7
- hash_populating_accessor :photos, "Photo"
8
- hash_populating_accessor :feed, "Post"
9
- hash_populating_accessor :posts, "Post"
10
- hash_populating_accessor :events, "Event"
11
- hash_populating_accessor :videos, "Video"
12
6
 
13
7
  def self.recognize?(hash)
14
8
  hash.has_key?("category")
15
9
  end
16
10
 
17
- def to_s
18
- name
19
- end
20
11
  end
21
12
  end
data/lib/mogli/photo.rb CHANGED
@@ -2,6 +2,7 @@ module Mogli
2
2
  class Photo < Model
3
3
  define_properties :id, :name, :picture, :source, :height, :width, :link, :icon,
4
4
  :created_time, :updated_time
5
+ creation_properties :message
5
6
 
6
7
  hash_populating_accessor :from, "User","Page"
7
8
  end
data/lib/mogli/post.rb CHANGED
@@ -5,8 +5,14 @@ module Mogli
5
5
  :description, :source, :icon, :attribution, :actions, :likes,
6
6
  :created_time, :updated_time, :privacy
7
7
 
8
+ creation_properties :message, :picture, :link, :name, :description
9
+
8
10
  hash_populating_accessor :actions, "Action"
9
11
  hash_populating_accessor :comments, "Comment"
10
12
  hash_populating_accessor :from, "User"
13
+
14
+ def likes_create
15
+ client.post("#{id}/likes",nil,{})
16
+ end
11
17
  end
12
18
  end
@@ -0,0 +1,21 @@
1
+ module Mogli
2
+ class Profile < Model
3
+ define_properties :id, :name
4
+
5
+ has_association :feed, "Post"
6
+ has_association :links, "Link"
7
+ has_association :photos, "Photo"
8
+ has_association :groups, "Group"
9
+ has_association :albums,"Album"
10
+ has_association :videos, "Video"
11
+ has_association :notes, "Note"
12
+ has_association :posts, "Post"
13
+ has_association :events, "Event"
14
+ has_association :links, "Link"
15
+ has_association :statuses, "Status"
16
+
17
+ def to_s
18
+ name
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module Mogli
2
+ class Status < Model
3
+ define_properties :id, :message, :updated_time
4
+
5
+ hash_populating_accessor :from, "User", "Page"
6
+ end
7
+ end
data/lib/mogli/user.rb CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  module Mogli
3
- class User < Model
3
+ class User < Profile
4
4
 
5
- define_properties :id, :first_name, :last_name, :name, :link, :about, :birthday,
5
+ define_properties :first_name, :last_name, :link, :about, :birthday,
6
6
  :email, :website, :timezone, :updated_time, :verified
7
7
 
8
8
  def self.recognize?(hash)
@@ -13,14 +13,13 @@ module Mogli
13
13
  hash_populating_accessor :education, "Education"
14
14
 
15
15
  has_association :activities,"Activity"
16
- has_association :albums,"Album"
17
16
  has_association :friends, "User"
18
17
  has_association :interests, "Interest"
19
18
  has_association :music, "Music"
20
19
  has_association :books, "Book"
21
20
  has_association :movies, "Movie"
22
21
  has_association :television, "Television"
23
- has_association :posts, "Post"
24
- has_association :feed, "Post"
22
+ has_association :likes, "Page"
23
+
25
24
  end
26
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Mangino
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-03 00:00:00 -04:00
12
+ date: 2010-05-04 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,6 +47,7 @@ files:
47
47
  - lib/mogli/album.rb
48
48
  - lib/mogli/authenticator.rb
49
49
  - lib/mogli/book.rb
50
+ - lib/mogli/client/event.rb
50
51
  - lib/mogli/client/user.rb
51
52
  - lib/mogli/client.rb
52
53
  - lib/mogli/comment.rb
@@ -55,6 +56,7 @@ files:
55
56
  - lib/mogli/fetching_array.rb
56
57
  - lib/mogli/group.rb
57
58
  - lib/mogli/interest.rb
59
+ - lib/mogli/link.rb
58
60
  - lib/mogli/model.rb
59
61
  - lib/mogli/movie.rb
60
62
  - lib/mogli/music.rb
@@ -62,6 +64,8 @@ files:
62
64
  - lib/mogli/page.rb
63
65
  - lib/mogli/photo.rb
64
66
  - lib/mogli/post.rb
67
+ - lib/mogli/profile.rb
68
+ - lib/mogli/status.rb
65
69
  - lib/mogli/television.rb
66
70
  - lib/mogli/user.rb
67
71
  - lib/mogli/video.rb