infomeme_client 0.1.1
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +8 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/infomeme_client/base.rb +77 -0
- data/lib/infomeme_client/communication.rb +75 -0
- data/lib/infomeme_client/entity_hash/comment.rb +2 -0
- data/lib/infomeme_client/entity_hash/meme.rb +45 -0
- data/lib/infomeme_client/entity_hash/meme_type.rb +2 -0
- data/lib/infomeme_client/entity_hash/transaction.rb +3 -0
- data/lib/infomeme_client/entity_hash/user.rb +2 -0
- data/lib/infomeme_client/entity_hash.rb +65 -0
- data/lib/infomeme_client/errors.rb +22 -0
- data/lib/infomeme_client/functions/meme.rb +23 -0
- data/lib/infomeme_client/functions/user.rb +55 -0
- data/lib/infomeme_client/functions/user_meme.rb +94 -0
- data/lib/infomeme_client/functions/user_transaction.rb +21 -0
- data/lib/infomeme_client/functions.rb +16 -0
- data/lib/infomeme_client/meme_application.rb +18 -0
- data/lib/infomeme_client/permissions.rb +22 -0
- data/lib/infomeme_client/response.rb +51 -0
- data/lib/infomeme_client.rb +21 -0
- data/test/fixtures/memes/comments.json +1 -0
- data/test/fixtures/memes/meme.json +1 -0
- data/test/fixtures/memes/memes.json +1 -0
- data/test/fixtures/memes/types.json +1 -0
- data/test/fixtures/oauth/access_token.json +1 -0
- data/test/fixtures/oauth/authorize.json +1 -0
- data/test/fixtures/oauth/permissions.json +1 -0
- data/test/fixtures/oauth/request_token.json +1 -0
- data/test/fixtures/oauth/verify_access.json +1 -0
- data/test/fixtures/response/error.json +1 -0
- data/test/fixtures/response/ok.json +1 -0
- data/test/fixtures/response/test.json +1 -0
- data/test/fixtures/response/test_extract.json +1 -0
- data/test/fixtures/users/memes.json +1 -0
- data/test/fixtures/users/permissions.json +1 -0
- data/test/fixtures/users/user.json +1 -0
- data/test/fixtures/users/user_public.json +1 -0
- data/test/helper.rb +69 -0
- data/test/test_authorization.rb +56 -0
- data/test/test_communication.rb +46 -0
- data/test/test_entity_hash.rb +15 -0
- data/test/test_meme_functions.rb +46 -0
- data/test/test_permissions.rb +25 -0
- data/test/test_user_functions.rb +15 -0
- data/test/test_user_meme_functions.rb +47 -0
- metadata +164 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestCommunication < Test::Unit::TestCase
|
4
|
+
def test_invalid_url
|
5
|
+
fake_request(:get, "/invalid_url", :body => "Error not found.", :status => ["404", "Not Found"])
|
6
|
+
assert_raise InfomemeClient::Error::RequestFailed do
|
7
|
+
@im_client.handle_response :get, "/invalid_url"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_response_error
|
12
|
+
fake_request(:get, "/test_error", :body => fixture("response/error"), :status => ["400", "Bad Request"], :content_type => "application/json")
|
13
|
+
assert_raises InfomemeClient::Error do
|
14
|
+
resp = @im_client.handle_response :get, "/test_error"
|
15
|
+
end
|
16
|
+
resp = @im_client.get "/test_error"
|
17
|
+
assert resp.error?
|
18
|
+
assert_respond_to resp, :errors
|
19
|
+
assert_kind_of InfomemeClient::EntityHash, resp.errors
|
20
|
+
assert_equal resp.errors.to_hash, {:test => {:test => "test error"}}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_response_ok
|
24
|
+
fake_request(:get, "/test_response", :body => fixture("response/test"), :content_type => "application/json")
|
25
|
+
resp = nil
|
26
|
+
assert_nothing_raised do
|
27
|
+
resp = @im_client.handle_response :get, "/test_response"
|
28
|
+
end
|
29
|
+
assert_instance_of InfomemeClient::Response, resp
|
30
|
+
assert_respond_to resp, :test_message
|
31
|
+
assert_equal resp.test_message, "test message"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_response_extract
|
35
|
+
fake_request(:get, "/test_extract", :body => fixture("response/test_extract"), :content_type => "application/json")
|
36
|
+
resp = nil
|
37
|
+
assert_nothing_raised do
|
38
|
+
resp = @im_client.handle_response :get, "/test_extract"
|
39
|
+
end
|
40
|
+
assert_instance_of InfomemeClient::Response, resp
|
41
|
+
assert_respond_to resp, :extract
|
42
|
+
assert_respond_to resp, :user
|
43
|
+
user = resp.extract(:user)
|
44
|
+
assert_instance_of InfomemeClient::EntityHash::User, user
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestEntityHash < Test::Unit::TestCase
|
4
|
+
def test_entity_hash_attributes_available
|
5
|
+
eh = InfomemeClient::EntityHash.new({:foo => "bar"})
|
6
|
+
assert_respond_to eh, :foo
|
7
|
+
assert_equal "bar", eh.foo
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_entity_hash_retrieve_hash
|
11
|
+
hash = {:foo => "bar", :bar => [{:foo => "bar"}]}
|
12
|
+
eh = InfomemeClient::EntityHash.new(hash)
|
13
|
+
assert_equal hash, eh.to_hash
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestMemeFunctions < Test::Unit::TestCase
|
4
|
+
def test_browse
|
5
|
+
fake_request(:get, "/memes?page=1&pageSize=25&sort=date-asc", :body => fixture("memes/memes"), :content_type => "application/json")
|
6
|
+
check_paged :memes, @im_client.browse(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
|
7
|
+
check_list :memes, @im_client.browse(:page => 1, :pageSize => 25, :sort => "date-asc")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_search
|
11
|
+
fake_request(:get, "/memes/search?search_token=a&page=1&pageSize=25&sort=date-asc", :body => fixture("memes/memes"), :content_type => "application/json")
|
12
|
+
check_paged :memes, @im_client.search("a", :page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
|
13
|
+
check_list :memes, @im_client.search("a", :page => 1, :pageSize => 25, :sort => "date-asc")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_meme_types
|
17
|
+
fake_request(:get, "/memes/types", :body => fixture("memes/types"), :content_type => "application/json")
|
18
|
+
types = @im_client.meme_types
|
19
|
+
check_list :meme_types, types
|
20
|
+
assert types.size > 0
|
21
|
+
assert_respond_to types[0], :id
|
22
|
+
assert_respond_to types[0], :name
|
23
|
+
assert_respond_to types[0], :url
|
24
|
+
assert_respond_to types[0], :summary
|
25
|
+
assert_respond_to types[0], :description
|
26
|
+
assert_equal 1, types[0].id
|
27
|
+
assert_equal "TEST", types[0].name
|
28
|
+
assert_equal "http://test.url", types[0].url
|
29
|
+
assert_equal "test summary", types[0].summary
|
30
|
+
assert_equal "test description", types[0].description
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_meme
|
34
|
+
fake_request(:get, "/memes/1", :body => fixture("memes/meme"), :content_type => "application/json")
|
35
|
+
meme = @im_client.meme(1)
|
36
|
+
check_eh :meme, meme
|
37
|
+
assert_respond_to meme, :name
|
38
|
+
assert_equal "test meme 1", meme.name
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_meme_comments
|
42
|
+
fake_request(:get, "/memes/1/comments?page=1&pageSize=25", :body => fixture("memes/comments"), :content_type => "application/json")
|
43
|
+
check_paged :comments, @im_client.meme_comments(1, :page => 1, :pageSize => 25, :no_extract => true)
|
44
|
+
check_list :comments, @im_client.meme_comments(1, :page => 1, :pageSize => 25)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestPermissions < Test::Unit::TestCase
|
4
|
+
def test_all_permissions
|
5
|
+
fake_request(:get, "/oauth/permissions", :body => fixture("oauth/permissions"), :content_type => "application/json")
|
6
|
+
perms = @im_client.all_permissions
|
7
|
+
assert_instance_of Array, perms
|
8
|
+
all = {0 => "memes", 1 => "private_data", 2 => "order"}
|
9
|
+
perms.each do |perm|
|
10
|
+
assert_instance_of InfomemeClient::EntityHash, perm
|
11
|
+
assert_respond_to perm, :id
|
12
|
+
assert_respond_to perm, :name
|
13
|
+
assert_respond_to perm, :description
|
14
|
+
assert all.key?(perm.id)
|
15
|
+
assert_equal all[perm.id], perm.name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_refresh_permissions
|
20
|
+
authorize
|
21
|
+
(0..2).each do |perm|
|
22
|
+
assert @im_client.has_permission?(perm)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestUserFunctions < Test::Unit::TestCase
|
4
|
+
def test_user
|
5
|
+
fake_request(:get, "/users/test_user", :body => fixture("users/user_public"), :content_type => "application/json")
|
6
|
+
user = @im_client.user("test_user")
|
7
|
+
check_eh :user, user
|
8
|
+
assert_respond_to user, :username
|
9
|
+
assert_equal "test_user", user.username
|
10
|
+
assert_respond_to user, :comments
|
11
|
+
assert_equal 3, user.comments
|
12
|
+
assert_respond_to user, :ratings
|
13
|
+
assert_equal 3, user.ratings
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestUserMemeFunctions < Test::Unit::TestCase
|
4
|
+
def test_library
|
5
|
+
fake_request(:get, "/users/test_user/memes?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
|
6
|
+
authorize
|
7
|
+
check_paged :memes, @im_client.library(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
|
8
|
+
check_list :memes, @im_client.library(:page => 1, :pageSize => 25, :sort => "date-asc")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_published
|
12
|
+
fake_request(:get, "/users/test_user/memes/published?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
|
13
|
+
authorize
|
14
|
+
check_paged :memes, @im_client.published(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
|
15
|
+
check_list :memes, @im_client.published(:page => 1, :pageSize => 25, :sort => "date-asc")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_inactive
|
19
|
+
fake_request(:get, "/users/test_user/memes/inactive?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
|
20
|
+
authorize
|
21
|
+
check_paged :memes, @im_client.inactive(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
|
22
|
+
check_list :memes, @im_client.inactive(:page => 1, :pageSize => 25, :sort => "date-asc")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_incomplete
|
26
|
+
fake_request(:get, "/users/test_user/memes/incomplete?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
|
27
|
+
authorize
|
28
|
+
check_paged :memes, @im_client.incomplete(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
|
29
|
+
check_list :memes, @im_client.incomplete(:page => 1, :pageSize => 25, :sort => "date-asc")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_comment
|
33
|
+
fake_request(:post, "/users/test_user/memes/1/comments", :body => fixture("response/ok"), :content_type => "application/json")
|
34
|
+
authorize
|
35
|
+
assert_nothing_raised do
|
36
|
+
assert @im_client.comment(1, "test comment")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_rate
|
41
|
+
fake_request(:post, "/users/test_user/memes/1/rates", :body => fixture("response/ok"), :content_type => "application/json")
|
42
|
+
authorize
|
43
|
+
assert_nothing_raised do
|
44
|
+
assert @im_client.rate(1, 1)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: infomeme_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Infomeme Ltd.
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-15 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: oauth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: multipart-post
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
description: A RubyGem for implementing both Infomeme client and meme applications.
|
64
|
+
email: infomeme@infomeme.com
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files:
|
70
|
+
- LICENSE
|
71
|
+
- README.rdoc
|
72
|
+
files:
|
73
|
+
- .document
|
74
|
+
- .gitignore
|
75
|
+
- LICENSE
|
76
|
+
- README.rdoc
|
77
|
+
- Rakefile
|
78
|
+
- VERSION
|
79
|
+
- lib/infomeme_client.rb
|
80
|
+
- lib/infomeme_client/base.rb
|
81
|
+
- lib/infomeme_client/communication.rb
|
82
|
+
- lib/infomeme_client/entity_hash.rb
|
83
|
+
- lib/infomeme_client/entity_hash/comment.rb
|
84
|
+
- lib/infomeme_client/entity_hash/meme.rb
|
85
|
+
- lib/infomeme_client/entity_hash/meme_type.rb
|
86
|
+
- lib/infomeme_client/entity_hash/transaction.rb
|
87
|
+
- lib/infomeme_client/entity_hash/user.rb
|
88
|
+
- lib/infomeme_client/errors.rb
|
89
|
+
- lib/infomeme_client/functions.rb
|
90
|
+
- lib/infomeme_client/functions/meme.rb
|
91
|
+
- lib/infomeme_client/functions/user.rb
|
92
|
+
- lib/infomeme_client/functions/user_meme.rb
|
93
|
+
- lib/infomeme_client/functions/user_transaction.rb
|
94
|
+
- lib/infomeme_client/meme_application.rb
|
95
|
+
- lib/infomeme_client/permissions.rb
|
96
|
+
- lib/infomeme_client/response.rb
|
97
|
+
- test/fixtures/memes/comments.json
|
98
|
+
- test/fixtures/memes/meme.json
|
99
|
+
- test/fixtures/memes/memes.json
|
100
|
+
- test/fixtures/memes/types.json
|
101
|
+
- test/fixtures/oauth/access_token.json
|
102
|
+
- test/fixtures/oauth/authorize.json
|
103
|
+
- test/fixtures/oauth/permissions.json
|
104
|
+
- test/fixtures/oauth/request_token.json
|
105
|
+
- test/fixtures/oauth/verify_access.json
|
106
|
+
- test/fixtures/response/error.json
|
107
|
+
- test/fixtures/response/ok.json
|
108
|
+
- test/fixtures/response/test.json
|
109
|
+
- test/fixtures/response/test_extract.json
|
110
|
+
- test/fixtures/users/memes.json
|
111
|
+
- test/fixtures/users/permissions.json
|
112
|
+
- test/fixtures/users/user.json
|
113
|
+
- test/fixtures/users/user_public.json
|
114
|
+
- test/helper.rb
|
115
|
+
- test/test_authorization.rb
|
116
|
+
- test/test_communication.rb
|
117
|
+
- test/test_entity_hash.rb
|
118
|
+
- test/test_meme_functions.rb
|
119
|
+
- test/test_permissions.rb
|
120
|
+
- test/test_user_functions.rb
|
121
|
+
- test/test_user_meme_functions.rb
|
122
|
+
has_rdoc: true
|
123
|
+
homepage: https://api.infomeme.com
|
124
|
+
licenses: []
|
125
|
+
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options:
|
128
|
+
- --charset=UTF-8
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
requirements: []
|
150
|
+
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.3.7
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: A RubyGem for implementing both Infomeme client and meme applications.
|
156
|
+
test_files:
|
157
|
+
- test/helper.rb
|
158
|
+
- test/test_authorization.rb
|
159
|
+
- test/test_communication.rb
|
160
|
+
- test/test_entity_hash.rb
|
161
|
+
- test/test_meme_functions.rb
|
162
|
+
- test/test_permissions.rb
|
163
|
+
- test/test_user_functions.rb
|
164
|
+
- test/test_user_meme_functions.rb
|