mogli 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mogli.rb +2 -0
- data/lib/mogli/action.rb +2 -2
- data/lib/mogli/activity.rb +2 -3
- data/lib/mogli/address.rb +1 -2
- data/lib/mogli/album.rb +1 -2
- data/lib/mogli/authenticator.rb +4 -2
- data/lib/mogli/book.rb +3 -2
- data/lib/mogli/client.rb +36 -8
- data/lib/mogli/comment.rb +1 -2
- data/lib/mogli/education.rb +10 -0
- data/lib/mogli/event.rb +1 -2
- data/lib/mogli/group.rb +1 -2
- data/lib/mogli/interest.rb +2 -3
- data/lib/mogli/model.rb +40 -33
- data/lib/mogli/movie.rb +2 -2
- data/lib/mogli/music.rb +2 -2
- data/lib/mogli/note.rb +1 -2
- data/lib/mogli/page.rb +8 -2
- data/lib/mogli/photo.rb +1 -2
- data/lib/mogli/post.rb +2 -3
- data/lib/mogli/television.rb +2 -2
- data/lib/mogli/user.rb +8 -2
- data/lib/mogli/video.rb +1 -2
- data/lib/mogli/work.rb +10 -0
- metadata +3 -1
data/lib/mogli.rb
CHANGED
@@ -15,6 +15,7 @@ require "mogli/address"
|
|
15
15
|
require "mogli/album"
|
16
16
|
require "mogli/book"
|
17
17
|
require "mogli/comment"
|
18
|
+
require "mogli/education"
|
18
19
|
require "mogli/event"
|
19
20
|
require "mogli/group"
|
20
21
|
require "mogli/interest"
|
@@ -26,5 +27,6 @@ require "mogli/photo"
|
|
26
27
|
require "mogli/post"
|
27
28
|
require "mogli/television"
|
28
29
|
require "mogli/video"
|
30
|
+
require "mogli/work"
|
29
31
|
require "mogli/user"
|
30
32
|
require "mogli/client"
|
data/lib/mogli/action.rb
CHANGED
data/lib/mogli/activity.rb
CHANGED
data/lib/mogli/address.rb
CHANGED
data/lib/mogli/album.rb
CHANGED
data/lib/mogli/authenticator.rb
CHANGED
@@ -9,8 +9,10 @@ module Mogli
|
|
9
9
|
@callback_url = callback_url
|
10
10
|
end
|
11
11
|
|
12
|
-
def authorize_url
|
13
|
-
|
12
|
+
def authorize_url(*scopes)
|
13
|
+
scopes = scopes.flatten
|
14
|
+
scope_part = "&scope=#{scopes.join(",")}" unless scopes.blank?
|
15
|
+
"https://graph.facebook.com/oauth/authorize?client_id=#{client_id}&redirect_uri=#{CGI.escape(callback_url)}#{scope_part}"
|
14
16
|
end
|
15
17
|
|
16
18
|
def access_token_url(code)
|
data/lib/mogli/book.rb
CHANGED
data/lib/mogli/client.rb
CHANGED
@@ -5,6 +5,7 @@ module Mogli
|
|
5
5
|
class Client
|
6
6
|
attr_reader :access_token
|
7
7
|
attr_reader :default_params
|
8
|
+
attr_reader :expiration
|
8
9
|
|
9
10
|
include HTTParty
|
10
11
|
include Mogli::Client::User
|
@@ -14,23 +15,24 @@ module Mogli
|
|
14
15
|
"http://graph.facebook.com/#{path}"
|
15
16
|
end
|
16
17
|
|
17
|
-
def initialize(access_token = nil)
|
18
|
+
def initialize(access_token = nil,expiration=nil)
|
18
19
|
@access_token = access_token
|
20
|
+
@expiration = Time.now + expiration if expiration
|
19
21
|
@default_params = @access_token ? {:access_token=>access_token} : {}
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
24
|
+
def expired?
|
25
|
+
expiration and expiration < Time.now
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.create_from_code_and_authenticator(code,authenticator)
|
23
29
|
post_data = get(authenticator.access_token_url(code))
|
24
30
|
parts = post_data.split("&")
|
25
31
|
hash = {}
|
26
32
|
parts.each do |p| (k,v) = p.split("=")
|
27
33
|
hash[k]=v
|
28
34
|
end
|
29
|
-
hash["access_token"]
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.create_from_code_and_authenticator(code,authenticator)
|
33
|
-
new(get_access_token_for_code_and_authenticator(code,authenticator))
|
35
|
+
new(hash["access_token"],hash["expires"].to_s.to_i)
|
34
36
|
end
|
35
37
|
|
36
38
|
def get_and_map(path,klass=nil)
|
@@ -92,7 +94,7 @@ module Mogli
|
|
92
94
|
|
93
95
|
def determine_class(klass_or_klasses,data)
|
94
96
|
klasses = Array(klass_or_klasses).map { |k| constantize_string(k)}
|
95
|
-
klasses.detect {|klass| klass.recognize?(data)}
|
97
|
+
klasses.detect {|klass| klass.recognize?(data)} || klasses.first
|
96
98
|
end
|
97
99
|
|
98
100
|
def raise_error_if_necessary(data)
|
@@ -104,5 +106,31 @@ module Mogli
|
|
104
106
|
end
|
105
107
|
end
|
106
108
|
end
|
109
|
+
|
110
|
+
def fields_to_serialize
|
111
|
+
[:access_token,:default_params,:expiration]
|
112
|
+
end
|
113
|
+
|
114
|
+
# Only serialize the bare minimum to recreate the session.
|
115
|
+
def marshal_load(variables)#:nodoc:
|
116
|
+
fields_to_serialize.each_with_index{|field, index| instance_variable_set("@#{field}", variables[index])}
|
117
|
+
end
|
118
|
+
|
119
|
+
# Only serialize the bare minimum to recreate the session.
|
120
|
+
def marshal_dump#:nodoc:
|
121
|
+
fields_to_serialize.map{|field| send(field)}
|
122
|
+
end
|
123
|
+
|
124
|
+
# Only serialize the bare minimum to recreate the session.
|
125
|
+
def to_yaml( opts = {} )#nodoc
|
126
|
+
YAML::quick_emit(self.object_id, opts) do |out|
|
127
|
+
out.map(taguri) do |map|
|
128
|
+
fields_to_serialize.each do |field|
|
129
|
+
map.add(field, send(field))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
107
135
|
end
|
108
136
|
end
|
data/lib/mogli/comment.rb
CHANGED
data/lib/mogli/event.rb
CHANGED
data/lib/mogli/group.rb
CHANGED
data/lib/mogli/interest.rb
CHANGED
data/lib/mogli/model.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Mogli
|
2
|
-
|
2
|
+
class Model < Hashie::Dash
|
3
3
|
def client=(val)
|
4
4
|
@client=val
|
5
5
|
end
|
@@ -10,49 +10,56 @@ module Mogli
|
|
10
10
|
|
11
11
|
def initialize(hash={},client=nil)
|
12
12
|
self.client=client
|
13
|
-
super(hash)
|
13
|
+
super(hash||{})
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.included(other)
|
17
17
|
other.extend(ClassMethods)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
property arg
|
27
|
-
end
|
20
|
+
def method_missing(method, *args)
|
21
|
+
method_as_s = method.to_s
|
22
|
+
if method_as_s.to_s[-1].chr == "="
|
23
|
+
warn_about_invalid_property(method_as_s.chop)
|
24
|
+
else
|
25
|
+
super
|
28
26
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
end
|
28
|
+
def warn_about_invalid_property(property)
|
29
|
+
puts "Warning: property #{property} doesn't exist for class #{self.class.name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.define_properties(*args)
|
33
|
+
args.each do |arg|
|
34
|
+
property arg
|
37
35
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
instance_variable_set("@#{name}",ret)
|
44
|
-
end
|
45
|
-
return ret
|
46
|
-
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.hash_populating_accessor(method_name,*klass)
|
39
|
+
define_method "#{method_name}=" do |hash|
|
40
|
+
instance_variable_set("@#{method_name}",client.map_data(hash,klass))
|
47
41
|
end
|
48
|
-
|
49
|
-
|
50
|
-
true
|
42
|
+
define_method "#{method_name}" do
|
43
|
+
instance_variable_get "@#{method_name}"
|
51
44
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.has_association(name,klass)
|
48
|
+
define_method name do
|
49
|
+
if (ret=instance_variable_get("@#{name}")).nil?
|
50
|
+
ret = client.get_and_map("/#{id}/#{name}",klass)
|
51
|
+
instance_variable_set("@#{name}",ret)
|
52
|
+
end
|
53
|
+
return ret
|
55
54
|
end
|
56
55
|
end
|
56
|
+
|
57
|
+
def self.recognize?(data)
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.find(id,client=nil)
|
62
|
+
(client||Mogli::Client.new).get_and_map(id,self)
|
63
|
+
end
|
57
64
|
end
|
58
65
|
end
|
data/lib/mogli/movie.rb
CHANGED
data/lib/mogli/music.rb
CHANGED
data/lib/mogli/note.rb
CHANGED
data/lib/mogli/page.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module Mogli
|
2
|
-
class Page <
|
2
|
+
class Page < Model
|
3
3
|
|
4
|
-
include Model
|
5
4
|
define_properties :id, :name, :category
|
6
5
|
|
7
6
|
hash_populating_accessor :albums, "Album"
|
8
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"
|
9
12
|
|
10
13
|
def self.recognize?(hash)
|
11
14
|
hash.has_key?("category")
|
12
15
|
end
|
13
16
|
|
17
|
+
def to_s
|
18
|
+
name
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/mogli/photo.rb
CHANGED
data/lib/mogli/post.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
module Mogli
|
2
|
-
class Post <
|
2
|
+
class Post < Model
|
3
3
|
|
4
|
-
include Model
|
5
4
|
define_properties :id, :to, :message, :picture, :link, :name, :caption,
|
6
5
|
:description, :source, :icon, :attribution, :actions, :likes,
|
7
|
-
:created_time, :updated_time
|
6
|
+
:created_time, :updated_time, :privacy
|
8
7
|
|
9
8
|
hash_populating_accessor :actions, "Action"
|
10
9
|
hash_populating_accessor :comments, "Comment"
|
data/lib/mogli/television.rb
CHANGED
data/lib/mogli/user.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
|
2
2
|
module Mogli
|
3
|
-
class User <
|
4
|
-
|
3
|
+
class User < Model
|
4
|
+
|
5
|
+
define_properties :id, :first_name, :last_name, :name, :link, :about, :birthday,
|
6
|
+
:email, :website, :timezone, :updated_time, :verified
|
5
7
|
|
6
8
|
def self.recognize?(hash)
|
7
9
|
!hash.has_key?("category")
|
8
10
|
end
|
9
11
|
|
12
|
+
hash_populating_accessor :work, "Work"
|
13
|
+
hash_populating_accessor :education, "Education"
|
14
|
+
|
10
15
|
has_association :activities,"Activity"
|
11
16
|
has_association :albums,"Album"
|
12
17
|
has_association :friends, "User"
|
@@ -16,5 +21,6 @@ module Mogli
|
|
16
21
|
has_association :movies, "Movie"
|
17
22
|
has_association :television, "Television"
|
18
23
|
has_association :posts, "Post"
|
24
|
+
has_association :feed, "Post"
|
19
25
|
end
|
20
26
|
end
|
data/lib/mogli/video.rb
CHANGED
data/lib/mogli/work.rb
ADDED
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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Mangino
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/mogli/client/user.rb
|
51
51
|
- lib/mogli/client.rb
|
52
52
|
- lib/mogli/comment.rb
|
53
|
+
- lib/mogli/education.rb
|
53
54
|
- lib/mogli/event.rb
|
54
55
|
- lib/mogli/fetching_array.rb
|
55
56
|
- lib/mogli/group.rb
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- lib/mogli/television.rb
|
65
66
|
- lib/mogli/user.rb
|
66
67
|
- lib/mogli/video.rb
|
68
|
+
- lib/mogli/work.rb
|
67
69
|
- lib/mogli.rb
|
68
70
|
has_rdoc: true
|
69
71
|
homepage: http://developers.facebook.com/docs/api
|