infomeme_client 0.1.4 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- metadata +26 -165
- data/.document +0 -5
- data/.gitignore +0 -21
- data/LICENSE +0 -20
- data/README.rdoc +0 -8
- data/Rakefile +0 -55
- data/VERSION +0 -1
- data/lib/infomeme_client.rb +0 -22
- data/lib/infomeme_client/base.rb +0 -77
- data/lib/infomeme_client/communication.rb +0 -75
- data/lib/infomeme_client/entity_hash.rb +0 -66
- data/lib/infomeme_client/entity_hash/comment.rb +0 -2
- data/lib/infomeme_client/entity_hash/invoice.rb +0 -2
- data/lib/infomeme_client/entity_hash/meme.rb +0 -45
- data/lib/infomeme_client/entity_hash/meme_type.rb +0 -2
- data/lib/infomeme_client/entity_hash/transaction.rb +0 -2
- data/lib/infomeme_client/entity_hash/user.rb +0 -2
- data/lib/infomeme_client/errors.rb +0 -22
- data/lib/infomeme_client/functions.rb +0 -16
- data/lib/infomeme_client/functions/meme.rb +0 -23
- data/lib/infomeme_client/functions/user.rb +0 -79
- data/lib/infomeme_client/functions/user_meme.rb +0 -127
- data/lib/infomeme_client/functions/user_order.rb +0 -31
- data/lib/infomeme_client/meme_application.rb +0 -18
- data/lib/infomeme_client/permissions.rb +0 -22
- data/lib/infomeme_client/response.rb +0 -52
- data/test/fixtures/memes/comments.json +0 -1
- data/test/fixtures/memes/meme.json +0 -1
- data/test/fixtures/memes/memes.json +0 -1
- data/test/fixtures/memes/types.json +0 -1
- data/test/fixtures/oauth/access_token.json +0 -1
- data/test/fixtures/oauth/authorize.json +0 -1
- data/test/fixtures/oauth/permissions.json +0 -1
- data/test/fixtures/oauth/request_token.json +0 -1
- data/test/fixtures/oauth/verify_access.json +0 -1
- data/test/fixtures/response/error.json +0 -1
- data/test/fixtures/response/ok.json +0 -1
- data/test/fixtures/response/test.json +0 -1
- data/test/fixtures/response/test_extract.json +0 -1
- data/test/fixtures/users/invoice.json +0 -1
- data/test/fixtures/users/invoices.json +0 -1
- data/test/fixtures/users/memes.json +0 -1
- data/test/fixtures/users/order_paypal.json +0 -1
- data/test/fixtures/users/permissions.json +0 -1
- data/test/fixtures/users/transactions.json +0 -1
- data/test/fixtures/users/user.json +0 -1
- data/test/fixtures/users/user_public.json +0 -1
- data/test/helper.rb +0 -69
- data/test/test_authorization.rb +0 -56
- data/test/test_communication.rb +0 -46
- data/test/test_entity_hash.rb +0 -15
- data/test/test_meme_functions.rb +0 -46
- data/test/test_permissions.rb +0 -25
- data/test/test_user_functions.rb +0 -15
- data/test/test_user_meme_functions.rb +0 -47
- data/test/test_user_order_functions.rb +0 -45
@@ -1,22 +0,0 @@
|
|
1
|
-
module InfomemeClient::Permissions
|
2
|
-
def all_permissions
|
3
|
-
handle_response :get, "/oauth/permissions" do |resp|
|
4
|
-
resp.permissions unless resp.error?
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def has_permission?(perm)
|
9
|
-
authorized? && permissions && permissions.include?(perm)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
attr_accessor :permissions
|
14
|
-
|
15
|
-
def refresh_permissions
|
16
|
-
self.permissions = nil
|
17
|
-
return false unless authorized?
|
18
|
-
response = get "/users/#{verified_user}/permissions"
|
19
|
-
return false if response.error?
|
20
|
-
self.permissions = response.permissions
|
21
|
-
end
|
22
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
class InfomemeClient::Response < InfomemeClient::EntityHash
|
2
|
-
STATUS_FAILED = -1
|
3
|
-
STATUS_OK = 0
|
4
|
-
STATUS_ERROR = 1
|
5
|
-
|
6
|
-
ERRORS = {
|
7
|
-
"request_failed" => InfomemeClient::Error::RequestFailed,
|
8
|
-
"error" => InfomemeClient::Error,
|
9
|
-
"internal_error" => InfomemeClient::Error::InternalError,
|
10
|
-
"no_access" => InfomemeClient::Error::NoAccess,
|
11
|
-
"not_found" => InfomemeClient::Error::NotFound,
|
12
|
-
}.freeze
|
13
|
-
|
14
|
-
def initialize(response)
|
15
|
-
super(response.is_a?(Exception) ? {:status => STATUS_FAILED, :message => "Request failed.", :error_code => "request_failed", :errors => {:base => {response.class.name.to_sym => response.message}}} : response, true)
|
16
|
-
ERRORS.each do |key, val|
|
17
|
-
instance_eval "def #{val.name.split('::').last.sub(/\b\w/) { $&.downcase }}Error?; error_code == #{key}; end"
|
18
|
-
end
|
19
|
-
freeze
|
20
|
-
end
|
21
|
-
|
22
|
-
def failed?
|
23
|
-
status == STATUS_FAILED
|
24
|
-
end
|
25
|
-
|
26
|
-
def error?
|
27
|
-
status != STATUS_OK
|
28
|
-
end
|
29
|
-
|
30
|
-
def raise_error(options = {})
|
31
|
-
return false unless error?
|
32
|
-
return false if options.key?(:only) && ! options[:only].include?(error_code)
|
33
|
-
return false if options.key?(:except) && options[:except].include?(error_code)
|
34
|
-
err = ERRORS.key?(error_code) ? ERRORS[error_code] : InfomemeClient::Error
|
35
|
-
raise err, [(respond_to?(:errors) ? errors.to_hash : nil), message]
|
36
|
-
end
|
37
|
-
|
38
|
-
def extract(key, *extra_args)
|
39
|
-
return nil unless @hsh.key?(key)
|
40
|
-
klass = case key
|
41
|
-
when :comments then InfomemeClient::EntityHash::Comment
|
42
|
-
when :meme, :memes then InfomemeClient::EntityHash::Meme
|
43
|
-
when :meme_types then InfomemeClient::EntityHash::MemeType
|
44
|
-
when :user then InfomemeClient::EntityHash::User
|
45
|
-
when :transactions then InfomemeClient::EntityHash::Transaction
|
46
|
-
when :invoice, :invoices then InfomemeClient::EntityHash::Invoice
|
47
|
-
else InfomemeClient::EntityHash
|
48
|
-
end
|
49
|
-
stored = to_hash[key]
|
50
|
-
stored.is_a?(Array) ? stored.collect {|val| klass.new *[val, extra_args]} : klass.new(*[stored, extra_args])
|
51
|
-
end
|
52
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","comments":[{"comment":"test comment 1","user":{"username":"test_user"},"created_at":"2010-01-01 12:00:00"},{"comment":"test comment 2","user":{"username":"test_user"},"created_at":"2010-01-01 11:00:00"},{"comment":"test comment 3","user":{"username":"test_user"},"created_at":"2010-01-01 10:00:00"}],"pages":1,"count":3}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","meme":{"id":1,"name":"test meme 1"}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","memes":[{"id":1,"name":"test meme 1"},{"id":2,"name":"test meme 2"},{"id":3,"name":"test meme 3"},{"id":4,"name":"test meme 4"}],"pages":1,"count":4}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","meme_types":[{"id":1,"name":"TEST","url":"http://test.url","summary":"test summary","description":"test description"}]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","access_token":{"token":"test_token","secret":"test_secret"}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","verifier":"test_verifier"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","permissions":[{"id":0,"name":"memes","description":"Meme functionality (comment, rate, publish, etc.)."},{"id":1,"name":"private_data","description":"Access to private data (firstname, lastname, cleared and pending balance)."},{"id":2,"name":"order","description":"Order functionality (order, transactions, invoices, etc.)."}]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","request_token":{"token":"test_token","secret":"test_secret"}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","user_id":"test_user"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":1,"message":"Error.","error_code":"error","errors":{"test":{"test":"test error"}}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success."}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","test_message":"test message"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","user":{"username":"test_user","email":"test@email.tld"}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","invoice":{"amount_user":10.0,"meme":{"name":"test meme 1"}}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","invoices":[{"amount_user":10.0,"meme":{"name":"test meme 1"}},{"amount_user":2.0,"meme":{"name":"test meme 2"}},{"amount_user":1.3,"meme":{"name":"test meme 3"}},{"amount_user":14.3,"meme":{"name":"test meme 4"}}],"pages":1,"count":4}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","memes":[{"id":1,"name":"test meme 1"},{"id":2,"name":"test meme 2"},{"id":3,"name":"test meme 3"},{"id":4,"name":"test meme 4"}],"pages":1,"count":4}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","paypal_url":"test_paypal_url"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","permissions":[0,1,2]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","transactions":[{"amount_user":10.0,"meme":{"name":"test meme 1"}},{"amount_user":2.0,"meme":{"name":"test meme 2"}},{"amount_user":1.3,"meme":{"name":"test meme 3"}},{"amount_user":14.3,"meme":{"name":"test meme 4"}}],"pages":1,"count":4}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","user":{"username":"test_user","comments":3,"ratings":3,"language":"en","confirmed":true,"can_publish":true,"language":"en"}}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"status":0,"message":"Success.","user":{"username":"test_user","comments":3,"ratings":3}}
|
data/test/helper.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "test/unit"
|
3
|
-
require "fakeweb"
|
4
|
-
|
5
|
-
FakeWeb.allow_net_connect = false
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
9
|
-
require "infomeme_client"
|
10
|
-
|
11
|
-
class Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
@test_site = "https://test.api.site"
|
14
|
-
@test_api_key = "TEST_API_KEY"
|
15
|
-
@test_api_secret = "TEST_API_KEY"
|
16
|
-
@im_client = InfomemeClient.new :api_key => @test_api_key, :api_secret => @test_api_secret, :site => @test_site
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def fake_request(method, url, options)
|
21
|
-
FakeWeb.register_uri(method, infomeme_url(url), options)
|
22
|
-
end
|
23
|
-
|
24
|
-
def fake_authorize_requests
|
25
|
-
fake_request(:get, "/oauth/verify_access", :body => fixture("oauth/verify_access"), :content_type => "application/json")
|
26
|
-
fake_request(:get, "/users/test_user", :body => fixture("users/user"), :content_type => "application/json")
|
27
|
-
fake_request(:get, "/users/test_user/permissions", :body => fixture("users/permissions"), :content_type => "application/json")
|
28
|
-
end
|
29
|
-
|
30
|
-
def authorize
|
31
|
-
fake_authorize_requests
|
32
|
-
assert_nothing_raised do
|
33
|
-
@im_client.authorize_with_token("test_token", "test_secret")
|
34
|
-
end
|
35
|
-
assert @im_client.authorized?
|
36
|
-
end
|
37
|
-
|
38
|
-
def fixture(filename)
|
39
|
-
File.read(File.dirname(__FILE__) + "/fixtures/#{filename}.json")
|
40
|
-
end
|
41
|
-
|
42
|
-
def infomeme_url(url)
|
43
|
-
url =~ /^http/ ? url : "#{@test_site}#{url}"
|
44
|
-
end
|
45
|
-
|
46
|
-
def check_paged(type, resp, options = {})
|
47
|
-
assert_instance_of InfomemeClient::Response, resp
|
48
|
-
assert_respond_to resp, type.to_sym
|
49
|
-
assert_respond_to resp, :pages
|
50
|
-
assert_respond_to resp, :count
|
51
|
-
check_list(type, resp.extract(type.to_sym))
|
52
|
-
assert_kind_of Integer, resp.pages
|
53
|
-
assert_kind_of Integer, resp.count
|
54
|
-
end
|
55
|
-
|
56
|
-
def check_list(type, list)
|
57
|
-
assert_instance_of Array, list
|
58
|
-
type = type.to_s.sub(/s\z/, "").to_sym
|
59
|
-
list.each do |elm|
|
60
|
-
check_eh(type, elm)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def check_eh(type, obj)
|
65
|
-
klass = InfomemeClient::EntityHash.const_get(type.to_s.split("_").map {|t| t.capitalize}.join.to_sym)
|
66
|
-
assert_instance_of Class, klass, "couldn't determine class from #{type.inspect} (#{klass.inspect})"
|
67
|
-
assert_instance_of klass, obj
|
68
|
-
end
|
69
|
-
end
|
data/test/test_authorization.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestAuthorization < Test::Unit::TestCase
|
4
|
-
def test_request_authorization
|
5
|
-
fake_request(:get, "/oauth/request_token", :body => fixture("oauth/request_token"), :content_type => "application/json")
|
6
|
-
req_token = nil
|
7
|
-
assert_nothing_raised do
|
8
|
-
req_token = @im_client.request_authorization
|
9
|
-
end
|
10
|
-
assert_kind_of InfomemeClient::EntityHash, req_token
|
11
|
-
assert_respond_to req_token, :token, req_token.inspect
|
12
|
-
assert_respond_to req_token, :secret, req_token.inspect
|
13
|
-
assert_equal "test_token", req_token.token, req_token.inspect
|
14
|
-
assert_equal "test_secret", req_token.secret, req_token.inspect
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_authorize_with_verifier
|
18
|
-
fake_request(:get, "/oauth/access_token?oauth_verifier=test_verifier", :body => fixture("oauth/access_token"), :content_type => "application/json")
|
19
|
-
fake_authorize_requests
|
20
|
-
assert_nothing_raised do
|
21
|
-
@im_client.authorize_with_verifier("test_token", "test_secret", "test_verifier")
|
22
|
-
end
|
23
|
-
check_authorized
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_authorize_with_token
|
27
|
-
authorize
|
28
|
-
check_authorized
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_authorize_with_credentials
|
32
|
-
fake_request(:get, "/oauth/request_token", :body => fixture("oauth/request_token"), :content_type => "application/json")
|
33
|
-
fake_request(:get, "/oauth/permissions", :body => fixture("oauth/permissions"), :content_type => "application/json")
|
34
|
-
fake_request(:put, "/oauth/authorize", :body => fixture("oauth/authorize"), :content_type => "application/json")
|
35
|
-
fake_request(:get, "/oauth/access_token?oauth_verifier=test_verifier", :body => fixture("oauth/access_token"), :content_type => "application/json")
|
36
|
-
fake_authorize_requests
|
37
|
-
assert_nothing_raised do
|
38
|
-
@im_client.authorize_with_credentials("test_login", "test_password")
|
39
|
-
end
|
40
|
-
check_authorized
|
41
|
-
assert @im_client.has_permission?(0)
|
42
|
-
assert @im_client.has_permission?(1)
|
43
|
-
assert @im_client.has_permission?(2)
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
def check_authorized
|
48
|
-
assert @im_client.authorized?
|
49
|
-
assert @im_client.confirmed?
|
50
|
-
assert @im_client.can_publish?
|
51
|
-
cred = @im_client.credentials
|
52
|
-
assert_equal "test_user", cred[:login]
|
53
|
-
assert_equal "test_token", cred[:token]
|
54
|
-
assert_equal "test_secret", cred[:secret]
|
55
|
-
end
|
56
|
-
end
|
data/test/test_communication.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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
|
data/test/test_entity_hash.rb
DELETED
@@ -1,15 +0,0 @@
|
|
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
|
data/test/test_meme_functions.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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
|
data/test/test_permissions.rb
DELETED
@@ -1,25 +0,0 @@
|
|
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
|
data/test/test_user_functions.rb
DELETED
@@ -1,15 +0,0 @@
|
|
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
|
@@ -1,47 +0,0 @@
|
|
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
|