mogli 0.0.32 → 0.0.33
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mogli/album.rb +1 -1
- data/lib/mogli/authenticator.rb +14 -10
- data/lib/mogli/client.rb +3 -3
- data/lib/mogli/fetching_array.rb +5 -5
- data/lib/mogli/page.rb +1 -1
- data/lib/mogli/photo.rb +2 -2
- data/spec/authenticator_spec.rb +32 -16
- metadata +4 -4
data/lib/mogli/album.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Mogli
|
2
2
|
class Album < Model
|
3
3
|
|
4
|
-
define_properties :id, :name, :description, :location, :privacy, :link, :count, :created_time, :updated_time
|
4
|
+
define_properties :id, :name, :description, :location, :cover_photo, :privacy, :link, :count, :created_time, :updated_time
|
5
5
|
creation_properties :name, :description
|
6
6
|
|
7
7
|
hash_populating_accessor :from, "User","Page"
|
data/lib/mogli/authenticator.rb
CHANGED
@@ -17,22 +17,26 @@ module Mogli
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def access_token_url(code)
|
20
|
-
"https://graph.facebook.com/oauth/access_token?client_id=#{client_id}&redirect_uri=#{CGI.escape(callback_url)
|
20
|
+
"https://graph.facebook.com/oauth/access_token?client_id=#{client_id}&redirect_uri=#{CGI.escape(callback_url) unless callback_url.nil? || callback_url.empty?}&client_secret=#{secret}&code=#{CGI.escape(code)}"
|
21
21
|
end
|
22
22
|
|
23
23
|
def get_access_token_for_session_key(session_keys)
|
24
24
|
keystr = session_keys.is_a?(Array) ?
|
25
25
|
session_keys.join(',') : session_keys
|
26
26
|
client = Mogli::Client.new
|
27
|
-
response = client.post("oauth/exchange_sessions",
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
response = client.class.post(client.api_path("oauth/exchange_sessions"),
|
28
|
+
:body => {
|
29
|
+
:type => 'client_cred',
|
30
|
+
:client_id => client_id,
|
31
|
+
:client_secret => secret,
|
32
|
+
:sessions => keystr
|
33
|
+
}
|
34
|
+
)
|
32
35
|
raise_exception_if_required(response)
|
33
|
-
response
|
36
|
+
tokens = response.parsed_response
|
37
|
+
session_keys.is_a?(Array) ? tokens : tokens.first
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
def get_access_token_for_application
|
37
41
|
client = Mogli::Client.new
|
38
42
|
response = client.class.post(client.api_path('oauth/access_token'),
|
@@ -43,9 +47,9 @@ module Mogli
|
|
43
47
|
}
|
44
48
|
)
|
45
49
|
raise_exception_if_required(response)
|
46
|
-
response.
|
50
|
+
response.parsed_response.split("=").last
|
47
51
|
end
|
48
|
-
|
52
|
+
|
49
53
|
def raise_exception_if_required(response)
|
50
54
|
raise Mogli::Client::HTTPException if response.code != 200
|
51
55
|
end
|
data/lib/mogli/client.rb
CHANGED
@@ -84,7 +84,7 @@ module Mogli
|
|
84
84
|
|
85
85
|
def self.response_is_error?(post_data)
|
86
86
|
post_data.kind_of?(Hash) and
|
87
|
-
!post_data["error"].
|
87
|
+
!post_data["error"].empty?
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.create_from_session_key(session_key, client_id, secret)
|
@@ -92,12 +92,12 @@ module Mogli
|
|
92
92
|
access_data = authenticator.get_access_token_for_session_key(session_key)
|
93
93
|
new(access_token_from_access_data(access_data),expiration_from_access_data(access_data))
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def self.access_token_from_access_data(access_data)
|
97
97
|
return nil if access_data.nil?
|
98
98
|
access_data['access_token']
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
def self.expiration_from_access_data(access_data)
|
102
102
|
return nil if access_data.nil? or access_data['expires'].nil?
|
103
103
|
Time.now.to_i + access_data['expires'].to_i
|
data/lib/mogli/fetching_array.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
module Mogli
|
2
2
|
class FetchingArray < Array
|
3
3
|
attr_accessor :next_url, :previous_url, :client, :classes
|
4
|
-
|
4
|
+
|
5
5
|
def fetch_next
|
6
|
-
return [] if next_url.
|
6
|
+
return [] if next_url.nil? || next_url.empty?
|
7
7
|
additions = client.get_and_map_url(next_url,classes)
|
8
8
|
self.next_url = additions.next_url
|
9
9
|
self.concat(additions)
|
10
10
|
additions
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def fetch_previous
|
14
|
-
return [] if previous_url.
|
14
|
+
return [] if previous_url.nil? || previous_url.empty?
|
15
15
|
additions = client.get_and_map_url(previous_url,classes)
|
16
16
|
self.previous_url = additions.previous_url
|
17
17
|
self.unshift(*additions)
|
18
18
|
additions
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
data/lib/mogli/page.rb
CHANGED
@@ -17,7 +17,7 @@ module Mogli
|
|
17
17
|
define_properties :created_time
|
18
18
|
|
19
19
|
def client_for_page
|
20
|
-
if access_token.
|
20
|
+
if access_token.nil? || access_token.empty?
|
21
21
|
raise MissingAccessToken.new("You can only get a client for this page if an access_token has been provided. i.e. via /me/accounts")
|
22
22
|
end
|
23
23
|
Client.new(access_token)
|
data/lib/mogli/photo.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Mogli
|
2
2
|
class Photo < Model
|
3
|
-
define_properties :id, :name, :picture, :source, :height, :width, :link, :icon,
|
4
|
-
:created_time, :updated_time
|
3
|
+
define_properties :id, :name, :tags, :picture, :source, :height, :width, :images, :link, :icon,
|
4
|
+
:created_time, :updated_time, :position, :comments
|
5
5
|
creation_properties :message
|
6
6
|
|
7
7
|
hash_populating_accessor :from, "User","Page"
|
data/spec/authenticator_spec.rb
CHANGED
@@ -30,8 +30,12 @@ describe Mogli::Authenticator do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "can trade session_keys for access_tokens" do
|
33
|
-
response =
|
34
|
-
|
33
|
+
response = mock('HTTParty::Response',
|
34
|
+
:parsed_response => [
|
35
|
+
{"access_token" => "myaccesstoken", "expires" => 5000},
|
36
|
+
{"access_token" => "youraccesstoken", "expires" => 5000}
|
37
|
+
],
|
38
|
+
:code => 200)
|
35
39
|
response.stub!(:code).and_return(200)
|
36
40
|
|
37
41
|
Mogli::Client.should_receive(:post).
|
@@ -47,23 +51,33 @@ describe Mogli::Authenticator do
|
|
47
51
|
{"access_token" => "youraccesstoken", "expires" => 5000}]
|
48
52
|
end
|
49
53
|
|
50
|
-
it "can trade one session_key for an
|
51
|
-
response =
|
52
|
-
|
54
|
+
it "can trade one session_key for an access_token" do
|
55
|
+
response = mock('HTTParty::Response',
|
56
|
+
:parsed_response => [
|
57
|
+
{"access_token" => "myaccesstoken", "expires" => 5000}
|
58
|
+
],
|
59
|
+
:code => 200)
|
60
|
+
|
53
61
|
Mogli::Client.should_receive(:post).
|
54
62
|
with("https://graph.facebook.com/oauth/exchange_sessions",
|
55
|
-
:body => {
|
56
|
-
|
63
|
+
:body => {
|
64
|
+
:type => "client_cred",
|
65
|
+
:client_id => "123456",
|
66
|
+
:client_secret => "secret",
|
67
|
+
:sessions => "mysessionkey"
|
68
|
+
}).
|
57
69
|
and_return(response)
|
58
70
|
|
59
71
|
authenticator.
|
60
72
|
get_access_token_for_session_key("mysessionkey").
|
61
73
|
should == {"access_token" => "myaccesstoken", "expires" => 5000}
|
62
74
|
end
|
63
|
-
|
75
|
+
|
64
76
|
it "can ask for an application token" do
|
65
|
-
response =
|
66
|
-
|
77
|
+
response = mock('HTTParty::Response',
|
78
|
+
:parsed_response => "access_token=123456|3SDdfgdfgv0bbEvYjBH5tJtl-dcBdsfgo",
|
79
|
+
:code => 200)
|
80
|
+
|
67
81
|
Mogli::Client.should_receive(:post).
|
68
82
|
with("https://graph.facebook.com/oauth/access_token",
|
69
83
|
:body=> {
|
@@ -72,20 +86,22 @@ describe Mogli::Authenticator do
|
|
72
86
|
:client_secret => "secret"
|
73
87
|
}).
|
74
88
|
and_return(response)
|
75
|
-
|
76
|
-
|
89
|
+
|
90
|
+
|
77
91
|
token = authenticator.get_access_token_for_application
|
78
92
|
token.should =="123456|3SDdfgdfgv0bbEvYjBH5tJtl-dcBdsfgo"
|
79
93
|
end
|
80
|
-
|
94
|
+
|
81
95
|
it "raises an error if not a 200" do
|
82
|
-
response =
|
83
|
-
|
96
|
+
response = mock('HTTParty::Response',
|
97
|
+
:parsed_response => "access_token=123456|3SDdfgdfgv0bbEvYjBH5tJtl-dcBdsfgo",
|
98
|
+
:code => 500)
|
99
|
+
|
84
100
|
Mogli::Client.should_receive(:post).and_return(response)
|
85
101
|
lambda do
|
86
102
|
token = authenticator.get_access_token_for_application
|
87
103
|
end.should raise_error(Mogli::Client::HTTPException)
|
88
|
-
|
104
|
+
|
89
105
|
end
|
90
106
|
|
91
107
|
context "Oauth2" do
|
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:
|
4
|
+
hash: 93
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 33
|
10
|
+
version: 0.0.33
|
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-
|
18
|
+
date: 2011-09-22 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|