fogli 0.1.0
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/.gitignore +5 -0
- data/Gemfile +14 -0
- data/LICENSE +21 -0
- data/README.md +168 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/examples/README.md +6 -0
- data/examples/me/README.md +18 -0
- data/examples/me/me.rb +30 -0
- data/lib/fogli.rb +46 -0
- data/lib/fogli/album.rb +8 -0
- data/lib/fogli/categorized_object.rb +9 -0
- data/lib/fogli/comment.rb +5 -0
- data/lib/fogli/event.rb +9 -0
- data/lib/fogli/exception.rb +15 -0
- data/lib/fogli/facebook_graph.rb +125 -0
- data/lib/fogli/facebook_object.rb +225 -0
- data/lib/fogli/facebook_object/connection_proxy.rb +80 -0
- data/lib/fogli/facebook_object/connection_scope.rb +123 -0
- data/lib/fogli/facebook_object/connections.rb +56 -0
- data/lib/fogli/facebook_object/properties.rb +81 -0
- data/lib/fogli/facebook_object/scope_methods.rb +49 -0
- data/lib/fogli/group.rb +8 -0
- data/lib/fogli/link.rb +8 -0
- data/lib/fogli/named_object.rb +8 -0
- data/lib/fogli/note.rb +7 -0
- data/lib/fogli/oauth.rb +167 -0
- data/lib/fogli/page.rb +15 -0
- data/lib/fogli/photo.rb +8 -0
- data/lib/fogli/post.rb +18 -0
- data/lib/fogli/status.rb +7 -0
- data/lib/fogli/user.rb +36 -0
- data/lib/fogli/util/module_attributes.rb +61 -0
- data/lib/fogli/util/options.rb +32 -0
- data/lib/fogli/video.rb +7 -0
- data/test/fogli/facebook_graph_test.rb +124 -0
- data/test/fogli/facebook_object/connection_proxy_test.rb +42 -0
- data/test/fogli/facebook_object/connection_scope_test.rb +91 -0
- data/test/fogli/facebook_object/connections_test.rb +50 -0
- data/test/fogli/facebook_object/properties_test.rb +79 -0
- data/test/fogli/facebook_object/scope_methods_test.rb +69 -0
- data/test/fogli/facebook_object_test.rb +178 -0
- data/test/fogli/oauth_test.rb +56 -0
- data/test/fogli/post_test.rb +18 -0
- data/test/fogli/user_test.rb +25 -0
- data/test/fogli/util/options_test.rb +38 -0
- data/test/fogli_test.rb +16 -0
- data/test/test_helper.rb +14 -0
- metadata +150 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class FacebookObjectTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Fogli::FacebookObject
|
6
|
+
end
|
7
|
+
|
8
|
+
context "class methods" do
|
9
|
+
context "properties and connections" do
|
10
|
+
should "include the properties module" do
|
11
|
+
assert @klass.included_modules.include?(Fogli::FacebookObject::Properties)
|
12
|
+
end
|
13
|
+
|
14
|
+
should "have an id property" do
|
15
|
+
assert @klass.properties.keys.include?(:id)
|
16
|
+
end
|
17
|
+
|
18
|
+
should "have a updated_time property" do
|
19
|
+
assert @klass.properties.keys.include?(:updated_time)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "propagate properties to subclasses" do
|
23
|
+
@subklass = Class.new(@klass)
|
24
|
+
assert @subklass.properties.keys.include?(:id)
|
25
|
+
end
|
26
|
+
|
27
|
+
should "propagate connections to subclasses" do
|
28
|
+
@klass.connection(:foo, :class => :bar)
|
29
|
+
@subklass = Class.new(@klass)
|
30
|
+
assert @subklass.connections.keys.include?(:foo)
|
31
|
+
@klass.connections.clear
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "finding" do
|
36
|
+
setup do
|
37
|
+
@klass.stubs(:get)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "return an unloaded object immediately" do
|
41
|
+
result = @klass.find(:foo)
|
42
|
+
assert !result.loaded?
|
43
|
+
assert_equal :foo, result.id
|
44
|
+
end
|
45
|
+
|
46
|
+
should "be able to limit by fields" do
|
47
|
+
result = @klass.find(:foo, :fields => "name")
|
48
|
+
assert_equal [:name], result.instance_variable_get(:@_fields)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "existence checking" do
|
53
|
+
should "only get the 'id' field" do
|
54
|
+
id = :foo
|
55
|
+
@klass.expects(:get).with("/#{id}", :fields => "id").once
|
56
|
+
assert @klass.exist?(id)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "return false if an exception is raised" do
|
60
|
+
@klass.expects(:get).raises(Fogli::Exception.new("foo", "bar"))
|
61
|
+
assert !@klass.exist?(:foo)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "initialization" do
|
66
|
+
should "be okay without any arguments" do
|
67
|
+
assert_nothing_raised {
|
68
|
+
@klass.new
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
should "populate properties if data is given" do
|
73
|
+
data = { "id" => "42" }
|
74
|
+
instance = @klass.new(data)
|
75
|
+
assert_equal data["id"], instance.id
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with an instance" do
|
81
|
+
setup do
|
82
|
+
@instance = @klass.new
|
83
|
+
end
|
84
|
+
|
85
|
+
[:get, :post].each do |method|
|
86
|
+
should "prepend any #{method} requests with the ID" do
|
87
|
+
id = "foo"
|
88
|
+
RestClient.expects(method).with() do |url, other|
|
89
|
+
assert url =~ /\/foo\/bar$/, "Invalid URL: #{url}"
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
@instance.stubs(:id).returns(id)
|
94
|
+
@instance.send(method, "/bar")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "deleting" do
|
99
|
+
should "post with the delete method" do
|
100
|
+
@instance.expects(:post).with(:method => :delete).once
|
101
|
+
@instance.delete
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "loading" do
|
106
|
+
setup do
|
107
|
+
@id = "foobar"
|
108
|
+
@data = {:id => @id}
|
109
|
+
@instance.stubs(:get).returns(@data)
|
110
|
+
end
|
111
|
+
|
112
|
+
should "store the raw data" do
|
113
|
+
@instance.load!
|
114
|
+
assert_equal @data, @instance._raw
|
115
|
+
end
|
116
|
+
|
117
|
+
should "get only the fields specified, if specified" do
|
118
|
+
instance = @klass.find(@id, :fields => [:a, :b, :c])
|
119
|
+
instance.stubs(:get).returns({})
|
120
|
+
instance.expects(:get).with(:fields => "a,b,c").once.returns({})
|
121
|
+
instance.load!
|
122
|
+
end
|
123
|
+
|
124
|
+
should "populate properties with the data" do
|
125
|
+
@instance.load!
|
126
|
+
assert_equal @id, @instance.id
|
127
|
+
end
|
128
|
+
|
129
|
+
should "mark as loaded" do
|
130
|
+
@instance.load!
|
131
|
+
assert @instance.loaded?
|
132
|
+
end
|
133
|
+
|
134
|
+
should "return the instance" do
|
135
|
+
assert_equal @instance, @instance.load!
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "existence checking" do
|
140
|
+
setup do
|
141
|
+
@instance.stubs(:load!)
|
142
|
+
end
|
143
|
+
|
144
|
+
should "return true if the load succeeded" do
|
145
|
+
assert @instance.exist?
|
146
|
+
end
|
147
|
+
|
148
|
+
should "return false if an exception is raised" do
|
149
|
+
@instance.expects(:load!).raises(Fogli::Exception.new(:foo, :bar))
|
150
|
+
assert !@instance.exist?
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "reading properties" do
|
155
|
+
setup do
|
156
|
+
@instance.stubs(:get).returns({})
|
157
|
+
end
|
158
|
+
|
159
|
+
should "not load if accessing id" do
|
160
|
+
assert !@instance.loaded?
|
161
|
+
@instance.expects(:load!).never
|
162
|
+
@instance.id
|
163
|
+
end
|
164
|
+
|
165
|
+
should "load on first property access" do
|
166
|
+
@instance.expects(:load!).once
|
167
|
+
@instance.updated_time
|
168
|
+
end
|
169
|
+
|
170
|
+
should "not load if loaded" do
|
171
|
+
@instance.load!
|
172
|
+
assert @instance.loaded?
|
173
|
+
@instance.expects(:load!).never
|
174
|
+
@instance.updated_time
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class OAuthObjectTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Fogli::OAuth
|
6
|
+
end
|
7
|
+
|
8
|
+
context "authorization URL" do
|
9
|
+
teardown do
|
10
|
+
Fogli.client_id = nil
|
11
|
+
Fogli.redirect_uri = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return the URL escape the URI" do
|
15
|
+
options = { :client_id => "foo", :redirect_uri => "bar baz" }
|
16
|
+
expected = @klass::AUTHORIZE_URI % ["foo", "bar+baz"]
|
17
|
+
assert_equal expected, @klass.authorize(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "by default use the global client id and redirect uri" do
|
21
|
+
Fogli.client_id = "foo"
|
22
|
+
Fogli.redirect_uri = "bar"
|
23
|
+
expected = @klass::AUTHORIZE_URI % ["foo", "bar"]
|
24
|
+
assert_equal expected, @klass.authorize
|
25
|
+
end
|
26
|
+
|
27
|
+
should "allow scopes to be added to the authorization" do
|
28
|
+
options = {
|
29
|
+
:client_id => "foo",
|
30
|
+
:redirect_uri => "bar",
|
31
|
+
:scope => %w{a b c}
|
32
|
+
}
|
33
|
+
expected = @klass::AUTHORIZE_URI % ["foo", "bar"]
|
34
|
+
expected += "&scope=a,b,c"
|
35
|
+
|
36
|
+
assert_equal expected, @klass.authorize(options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "access token" do
|
41
|
+
teardown do
|
42
|
+
Fogli.client_id = nil
|
43
|
+
Fogli.client_secret = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
should "by default use the global client ID and secret" do
|
47
|
+
Fogli.client_id = "foo"
|
48
|
+
Fogli.client_secret = "bar"
|
49
|
+
options = { :redirect_uri => "bar", :code => "baz" }
|
50
|
+
merged = options.merge({ :client_id => Fogli.client_id,
|
51
|
+
:client_secret => Fogli.client_secret })
|
52
|
+
@klass.expects(:get).with("/oauth/access_token", merged).returns("")
|
53
|
+
@klass.access_token(options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class PostTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Fogli::Post
|
6
|
+
@instance = @klass.new
|
7
|
+
end
|
8
|
+
|
9
|
+
should "be able to like a post" do
|
10
|
+
@instance.expects(:post).with("/likes").once
|
11
|
+
@instance.like!
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be able to unlike a post" do
|
15
|
+
@instance.expects(:post).with("/likes", :method => :delete).once
|
16
|
+
@instance.unlike!
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class UserTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@klass = Fogli::User
|
6
|
+
end
|
7
|
+
|
8
|
+
context "checking authorization" do
|
9
|
+
setup do
|
10
|
+
# Don't want any HTTP calls going out
|
11
|
+
@object = Fogli::FacebookObject.new
|
12
|
+
@object.stubs(:load!)
|
13
|
+
@klass.stubs(:find).returns(@object)
|
14
|
+
end
|
15
|
+
|
16
|
+
should "return true if nothing is raised" do
|
17
|
+
assert @klass.authorized?
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return false if an exception is raised" do
|
21
|
+
@object.expects(:load!).raises(Fogli::Exception.new("foo", "bar"))
|
22
|
+
assert !@klass.authorized?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class OptionsUtilTest < Test::Unit::TestCase
|
4
|
+
class OptionsUtilTestClass
|
5
|
+
include Fogli::Util::Options
|
6
|
+
end
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@klass = OptionsUtilTestClass
|
10
|
+
@instance = @klass.new
|
11
|
+
end
|
12
|
+
|
13
|
+
should "remove unused keys" do
|
14
|
+
defaults = { :foo => :bar }
|
15
|
+
options = { :bar => :baz }
|
16
|
+
assert_equal Hash.new, @instance.verify_options(options, :valid_keys => [:foo])
|
17
|
+
end
|
18
|
+
|
19
|
+
should "merge in the defaults" do
|
20
|
+
defaults = { :foo => :bar, :bar => nil }
|
21
|
+
options = { :bar => :baz }
|
22
|
+
assert_equal defaults.merge(options), @instance.verify_options(options, :default => defaults)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "error if required keys are missing" do
|
26
|
+
options = { :foo => :bar }
|
27
|
+
assert_raises(ArgumentError) {
|
28
|
+
@instance.verify_options(options, :required_keys => [:foo, :bar])
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
should "not error if the required keys aren't missing" do
|
33
|
+
options = { :foo => :bar }
|
34
|
+
assert_nothing_raised {
|
35
|
+
@instance.verify_options(options, :required_keys => [:foo])
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
data/test/fogli_test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FogliTest < Test::Unit::TestCase
|
4
|
+
context "config accessors" do
|
5
|
+
[:client_id, :client_secret, :access_token, :redirect_uri, :logger].each do |key|
|
6
|
+
should "be able to access and read #{key}" do
|
7
|
+
value = "foo#{key}"
|
8
|
+
Fogli.send("#{key}=", value)
|
9
|
+
assert_equal value, Fogli.send(key)
|
10
|
+
|
11
|
+
# Reset the value
|
12
|
+
Fogli.send("#{key}=", nil)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require File.expand_path('../.bundle/environment', __FILE__)
|
3
|
+
rescue LoadError
|
4
|
+
# Fallback on doing the resolve at runtime.
|
5
|
+
require "rubygems"
|
6
|
+
end
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'fogli')
|
9
|
+
require 'contest'
|
10
|
+
require 'mocha'
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
# For any global helpers.
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fogli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mitchell Hashimoto
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-08 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rest-client
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 5
|
30
|
+
- 1
|
31
|
+
version: 1.5.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: json_pure
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 2
|
44
|
+
- 0
|
45
|
+
version: 1.2.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: An efficient, simple, and intuitive Facebook Open Graph library.
|
49
|
+
email: mitchell.hashimoto@gmail.com
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- VERSION
|
64
|
+
- examples/README.md
|
65
|
+
- examples/me/README.md
|
66
|
+
- examples/me/me.rb
|
67
|
+
- lib/fogli.rb
|
68
|
+
- lib/fogli/album.rb
|
69
|
+
- lib/fogli/categorized_object.rb
|
70
|
+
- lib/fogli/comment.rb
|
71
|
+
- lib/fogli/event.rb
|
72
|
+
- lib/fogli/exception.rb
|
73
|
+
- lib/fogli/facebook_graph.rb
|
74
|
+
- lib/fogli/facebook_object.rb
|
75
|
+
- lib/fogli/facebook_object/connection_proxy.rb
|
76
|
+
- lib/fogli/facebook_object/connection_scope.rb
|
77
|
+
- lib/fogli/facebook_object/connections.rb
|
78
|
+
- lib/fogli/facebook_object/properties.rb
|
79
|
+
- lib/fogli/facebook_object/scope_methods.rb
|
80
|
+
- lib/fogli/group.rb
|
81
|
+
- lib/fogli/link.rb
|
82
|
+
- lib/fogli/named_object.rb
|
83
|
+
- lib/fogli/note.rb
|
84
|
+
- lib/fogli/oauth.rb
|
85
|
+
- lib/fogli/page.rb
|
86
|
+
- lib/fogli/photo.rb
|
87
|
+
- lib/fogli/post.rb
|
88
|
+
- lib/fogli/status.rb
|
89
|
+
- lib/fogli/user.rb
|
90
|
+
- lib/fogli/util/module_attributes.rb
|
91
|
+
- lib/fogli/util/options.rb
|
92
|
+
- lib/fogli/video.rb
|
93
|
+
- test/fogli/facebook_graph_test.rb
|
94
|
+
- test/fogli/facebook_object/connection_proxy_test.rb
|
95
|
+
- test/fogli/facebook_object/connection_scope_test.rb
|
96
|
+
- test/fogli/facebook_object/connections_test.rb
|
97
|
+
- test/fogli/facebook_object/properties_test.rb
|
98
|
+
- test/fogli/facebook_object/scope_methods_test.rb
|
99
|
+
- test/fogli/facebook_object_test.rb
|
100
|
+
- test/fogli/oauth_test.rb
|
101
|
+
- test/fogli/post_test.rb
|
102
|
+
- test/fogli/user_test.rb
|
103
|
+
- test/fogli/util/options_test.rb
|
104
|
+
- test/fogli_test.rb
|
105
|
+
- test/test_helper.rb
|
106
|
+
has_rdoc: true
|
107
|
+
homepage: http://github.com/mitchellh/fogli
|
108
|
+
licenses: []
|
109
|
+
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options:
|
112
|
+
- --charset=UTF-8
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
requirements: []
|
130
|
+
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 1.3.6
|
133
|
+
signing_key:
|
134
|
+
specification_version: 3
|
135
|
+
summary: An efficient, simple, and intuitive Facebook Open Graph library.
|
136
|
+
test_files:
|
137
|
+
- test/fogli/facebook_object/connection_proxy_test.rb
|
138
|
+
- test/fogli/facebook_object/scope_methods_test.rb
|
139
|
+
- test/fogli/facebook_object/connections_test.rb
|
140
|
+
- test/fogli/facebook_object/connection_scope_test.rb
|
141
|
+
- test/fogli/facebook_object/properties_test.rb
|
142
|
+
- test/fogli/user_test.rb
|
143
|
+
- test/fogli/oauth_test.rb
|
144
|
+
- test/fogli/post_test.rb
|
145
|
+
- test/fogli/facebook_graph_test.rb
|
146
|
+
- test/fogli/util/options_test.rb
|
147
|
+
- test/fogli/facebook_object_test.rb
|
148
|
+
- test/test_helper.rb
|
149
|
+
- test/fogli_test.rb
|
150
|
+
- examples/me/me.rb
|