mogli 0.0.15 → 0.0.16

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/lib/mogli/action.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  module Mogli
2
2
  class Action < Model
3
3
  define_properties :name, :link
4
-
4
+
5
+ # simple implementation of to_json, ignoring options like :only, :except,
6
+ # :include, :methods because this is primarily intended for being submitted
7
+ # to facebook
8
+ def to_json(options = nil)
9
+ "{\"name\":\"#{name}\",\"link\":\"#{link}\"}"
10
+ end
5
11
  end
6
- end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Mogli
2
+ class Application < Model
3
+
4
+ define_properties :id, :name, :description, :category, :subcategory, :link
5
+
6
+ has_association :feed, "Post"
7
+ has_association :posts, "Post"
8
+ has_association :albums, "Album"
9
+ has_association :insights, "Insight"
10
+
11
+
12
+ end
13
+ end
data/lib/mogli/client.rb CHANGED
@@ -11,10 +11,12 @@ module Mogli
11
11
  include Mogli::Client::Event
12
12
  include Mogli::Client::User
13
13
 
14
- class UnrecognizeableClassError < Exception; end
15
- class QueryParseException < Exception; end
16
- class OAuthAccessTokenException < Exception; end
17
- class OAuthUnauthorizedClientException < Exception; end
14
+ class ClientException < Exception; end
15
+ class UnrecognizeableClassError < ClientException; end
16
+ class QueryParseException < ClientException; end
17
+ class OAuthAccessTokenException < ClientException; end
18
+ class OAuthUnauthorizedClientException < ClientException; end
19
+ class OAuthException < ClientException; end
18
20
 
19
21
  def api_path(path)
20
22
  "https://graph.facebook.com/#{path}"
@@ -38,6 +40,9 @@ module Mogli
38
40
 
39
41
  def self.create_from_code_and_authenticator(code,authenticator)
40
42
  post_data = get(authenticator.access_token_url(code))
43
+ if (response_is_error?(post_data))
44
+ raise_client_exception(post_data)
45
+ end
41
46
  parts = post_data.split("&")
42
47
  hash = {}
43
48
  parts.each do |p| (k,v) = p.split("=")
@@ -45,6 +50,22 @@ module Mogli
45
50
  end
46
51
  new(hash["access_token"],hash["expires"].to_s.to_i)
47
52
  end
53
+
54
+ def self.raise_client_exception(post_data)
55
+ type=post_data["error"]["type"]
56
+ message=post_data["error"]["message"]
57
+ if Mogli::Client.const_defined?(type)
58
+ raise Mogli::Client.const_get(type).new(message)
59
+ else
60
+ raise ClientException.new("#{type}: #{message}")
61
+ end
62
+ end
63
+
64
+ def self.response_is_error?(post_data)
65
+ post_data.is_a?(HTTParty::Response) and
66
+ post_data.parsed_response.kind_of?(Hash) and
67
+ !post_data.parsed_response["error"].blank?
68
+ end
48
69
 
49
70
  def self.create_from_session_key(session_key, client_id, secret)
50
71
  authenticator = Mogli::Authenticator.new(client_id, secret, nil)
@@ -140,7 +161,7 @@ module Mogli
140
161
  type = data["error"]["type"]
141
162
  message = data["error"]["message"]
142
163
  raise Mogli::Client.const_get(type).new(message) if Mogli::Client.const_defined?(type)
143
- raise Exception.new("#{type}: #{message}")
164
+ raise ClientException.new("#{type}: #{message}")
144
165
  end
145
166
  end
146
167
  end
data/lib/mogli/group.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Mogli
2
2
  class Group < Model
3
3
  set_search_type
4
- define_properties :id, :name, :description, :link, :privacy, :updated_time
4
+ define_properties :id, :name, :description, :link, :privacy, :updated_time, :version, :administrator
5
5
 
6
6
  hash_populating_accessor :owner, "User", "Page"
7
7
  hash_populating_accessor :venue, "Address"
@@ -0,0 +1,6 @@
1
+ module Mogli
2
+ class Insight < Model
3
+ define_properties :id, :name
4
+
5
+ end
6
+ end
data/lib/mogli/model.rb CHANGED
@@ -25,7 +25,23 @@ module Mogli
25
25
  post_params = {}
26
26
  self.class.creation_keys.each do |key|
27
27
  post_params[key] = self[key]
28
+
29
+ # make sure actions and any other creation_properties that aren't just
30
+ # hash entries get added...
31
+ if post_params[key].nil? &&
32
+ self.respond_to?(key.to_sym) && !self.send(key.to_sym).nil?
33
+
34
+ val = self.send(key.to_sym)
35
+ post_params[key] = if val.respond_to?(:to_json)
36
+ val.to_json
37
+ elsif val.is_a?(Array)
38
+ "[#{val.map { |v| v.respond_to?(:to_json) ? v.to_json : nil }.compact.join(',')}]"
39
+ else
40
+ nil
41
+ end
42
+ end
28
43
  end
44
+
29
45
  post_params
30
46
  end
31
47
 
@@ -100,7 +116,7 @@ module Mogli
100
116
 
101
117
  def fetch()
102
118
  raise ArgumentError.new("You cannot fetch models without a populated id attribute") if id.nil?
103
- other = self.class.find(id,client)
119
+ other = self.class.find(id,client)
104
120
  merge!(other) if other
105
121
  end
106
122
 
@@ -116,5 +132,3 @@ module Mogli
116
132
 
117
133
  end
118
134
  end
119
-
120
-
data/lib/mogli/movie.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Mogli
2
2
  class Movie < Model
3
- define_properties :name, :category, :id
3
+ define_properties :name, :category, :id, :created_time
4
4
 
5
5
  end
6
6
  end
data/lib/mogli/post.rb CHANGED
@@ -1,16 +1,18 @@
1
+ require 'json'
2
+
1
3
  module Mogli
2
4
  class Post < Model
3
-
4
- define_properties :id, :to, :message, :picture, :link, :name, :caption,
5
+
6
+ define_properties :id, :to, :message, :picture, :link, :name, :caption,
5
7
  :description, :source, :icon, :attribution, :actions, :likes,
6
8
  :created_time, :updated_time, :privacy, :type
7
-
8
- creation_properties :message, :picture, :link, :name, :description, :caption, :source
9
-
9
+
10
+ creation_properties :message, :picture, :link, :name, :description, :caption, :source, :actions
11
+
10
12
  hash_populating_accessor :actions, "Action"
11
13
  has_association :comments, "Comment"
12
14
  hash_populating_accessor :from, "User"
13
-
15
+
14
16
  def likes_create
15
17
  client.post("#{id}/likes",nil,{})
16
18
  end
data/lib/mogli/profile.rb CHANGED
@@ -14,14 +14,31 @@ module Mogli
14
14
  has_association :links, "Link"
15
15
  has_association :statuses, "Status"
16
16
  has_association :checkins, "Checkin"
17
-
17
+
18
18
  hash_populating_accessor :location, "Location"
19
+
20
+ # Facebook's defaults image url, which seems to be the same as square_image_url at this time
19
21
  def image_url
20
22
  "https://graph.facebook.com/#{id}/picture"
21
23
  end
22
24
 
25
+ # 50x50 pixel image url
26
+ def square_image_url
27
+ "#{image_url}?type=square"
28
+ end
29
+
30
+ # 50 pixels wide, variable height image url
31
+ def small_image_url
32
+ "#{image_url}?type=small"
33
+ end
34
+
35
+ # About 200 pixels wide, variable height image url
36
+ def large_image_url
37
+ "#{image_url}?type=large"
38
+ end
39
+
23
40
  def to_s
24
41
  name
25
42
  end
26
43
  end
27
- end
44
+ end
@@ -1,6 +1,6 @@
1
1
  module Mogli
2
2
  class Television < Model
3
- define_properties :name, :category, :id
3
+ define_properties :name, :category, :id, :created_time
4
4
 
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 16
10
+ version: 0.0.16
5
11
  platform: ruby
6
12
  authors:
7
13
  - Mike Mangino
@@ -9,29 +15,41 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-10-05 00:00:00 -04:00
18
+ date: 2010-11-08 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: hashie
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 0
23
34
  version: 0.2.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: httparty
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
45
+ hash: 9
46
+ segments:
47
+ - 0
48
+ - 4
49
+ - 3
33
50
  version: 0.4.3
34
- version:
51
+ type: :runtime
52
+ version_requirements: *id002
35
53
  description: Simple library for accessing the facebook Open Graph API
36
54
  email: mmangino@elevatedrails.com
37
55
  executables: []
@@ -45,6 +63,7 @@ files:
45
63
  - lib/mogli/activity.rb
46
64
  - lib/mogli/address.rb
47
65
  - lib/mogli/album.rb
66
+ - lib/mogli/application.rb
48
67
  - lib/mogli/authenticator.rb
49
68
  - lib/mogli/book.rb
50
69
  - lib/mogli/checkin.rb
@@ -56,6 +75,7 @@ files:
56
75
  - lib/mogli/event.rb
57
76
  - lib/mogli/fetching_array.rb
58
77
  - lib/mogli/group.rb
78
+ - lib/mogli/insight.rb
59
79
  - lib/mogli/interest.rb
60
80
  - lib/mogli/link.rb
61
81
  - lib/mogli/location.rb
@@ -84,21 +104,27 @@ rdoc_options: []
84
104
  require_paths:
85
105
  - lib
86
106
  required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
87
108
  requirements:
88
109
  - - ">="
89
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
90
114
  version: "0"
91
- version:
92
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
93
117
  requirements:
94
118
  - - ">="
95
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
96
123
  version: "0"
97
- version:
98
124
  requirements: []
99
125
 
100
126
  rubyforge_project:
101
- rubygems_version: 1.3.5
127
+ rubygems_version: 1.3.7
102
128
  signing_key:
103
129
  specification_version: 3
104
130
  summary: Open Graph Library for Ruby