mogli 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mogli.rb CHANGED
@@ -35,3 +35,4 @@ require "mogli/video"
35
35
  require "mogli/work"
36
36
  require "mogli/user"
37
37
  require "mogli/client"
38
+ require "mogli/app_client"
@@ -0,0 +1,27 @@
1
+ require "mogli/client/event"
2
+ require "mogli/client/user"
3
+
4
+ module Mogli
5
+ class AppClient < Client
6
+ attr_accessor :application_id
7
+
8
+ def subscription_url
9
+ "https://graph.facebook.com/#{application_id}/subscriptions"
10
+ end
11
+
12
+ def subscribe_to_model(model,options)
13
+ options_to_send = options.dup
14
+ options_to_send[:fields] = Array(options[:fields]).join(",")
15
+ options_to_send[:object] = name_for_class(model)
16
+ self.class.post(subscription_url,:body=>default_params.merge(options_to_send))
17
+ end
18
+
19
+ def name_for_class(klass)
20
+ klass.name.split("::").last.downcase
21
+ end
22
+
23
+ def subscriptions
24
+ get_and_map_url(subscription_url,"Subscription")
25
+ end
26
+ end
27
+ end
@@ -40,7 +40,11 @@ module Mogli
40
40
  :client_secret => secret
41
41
  }
42
42
  )
43
- request.parsed_response.split('=').last
43
+ if (request.respond_to?(:parsed_response))
44
+ request.parsed_response.split('=').last
45
+ else
46
+ request.to_s.split("=").last
47
+ end
44
48
  end
45
49
 
46
50
  end
data/lib/mogli/client.rb CHANGED
@@ -83,7 +83,9 @@ module Mogli
83
83
  def self.create_and_authenticate_as_application(client_id, secret)
84
84
  authenticator = Mogli::Authenticator.new(client_id, secret, nil)
85
85
  access_data = authenticator.get_access_token_for_application
86
- new(access_data)
86
+ client = AppClient.new(access_data)
87
+ client.application_id = client_id
88
+ client
87
89
  end
88
90
 
89
91
  def post(path,klass,body_args)
@@ -95,6 +97,11 @@ module Mogli
95
97
  self.class.delete(api_path(path),:query=>default_params)
96
98
  end
97
99
 
100
+ def subscribe_to_model(model,options)
101
+ options_to_send=options.dup
102
+ self.class.post("http://")
103
+ end
104
+
98
105
  def fql_query(query,klass=nil,format="json")
99
106
  data = self.class.post(fql_path,:body=>default_params.merge({:query=>query,:format=>format}))
100
107
  return data unless format=="json"
@@ -103,12 +110,13 @@ module Mogli
103
110
 
104
111
  def get_and_map(path,klass=nil,body_args = {})
105
112
  data = self.class.get(api_path(path),:query=>default_params.merge(body_args))
113
+ debugger
106
114
  data = data.values if body_args.key?(:ids) && !data.key?('error')
107
115
  map_data(data,klass)
108
116
  end
109
117
 
110
- def get_and_map_url(url,klass=nil)
111
- data = self.class.get(url)
118
+ def get_and_map_url(url,klass=nil,body_args = {})
119
+ data = self.class.get(url,:query=>default_params.merge(body_args))
112
120
  map_data(data,klass)
113
121
  end
114
122
 
data/lib/mogli/model.rb CHANGED
@@ -110,6 +110,9 @@ module Mogli
110
110
  end
111
111
  return ret
112
112
  end
113
+ define_method "#{name}=" do |value|
114
+ instance_variable_set("@#{name}",client.map_to_class(client.extract_hash_or_array(value,klass),klass))
115
+ end
113
116
 
114
117
  add_creation_method(name,klass)
115
118
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 18
10
- version: 0.0.18
9
+ - 19
10
+ version: 0.0.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Mangino
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-12 00:00:00 -05:00
18
+ date: 2011-01-13 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,6 +63,7 @@ files:
63
63
  - lib/mogli/activity.rb
64
64
  - lib/mogli/address.rb
65
65
  - lib/mogli/album.rb
66
+ - lib/mogli/app_client.rb
66
67
  - lib/mogli/application.rb
67
68
  - lib/mogli/authenticator.rb
68
69
  - lib/mogli/book.rb