infomeme_client 0.1.3 → 0.1.4
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/VERSION +1 -1
- data/lib/infomeme_client/base.rb +2 -2
- data/lib/infomeme_client/entity_hash.rb +1 -0
- data/lib/infomeme_client/functions/user.rb +1 -2
- data/lib/infomeme_client/functions/{user_transaction.rb → user_order.rb} +16 -1
- data/lib/infomeme_client/functions.rb +2 -2
- data/test/fixtures/users/invoice.json +1 -0
- data/test/fixtures/users/invoices.json +1 -0
- data/test/fixtures/users/order_paypal.json +1 -0
- data/test/fixtures/users/transactions.json +1 -0
- data/test/test_user_order_functions.rb +45 -0
- metadata +11 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/infomeme_client/base.rb
CHANGED
@@ -2,7 +2,6 @@ module InfomemeClient::Base
|
|
2
2
|
def initialize(options = {})
|
3
3
|
self.consumer = OAuth::Consumer.new(options[:api_key] || ::INFOMEME_API_KEY, options[:api_secret] || ::INFOMEME_API_SECRET, :site => options[:site] || ::INFOMEME_API_SITE)
|
4
4
|
self.default_language = options[:language] || "en"
|
5
|
-
self.default_currency = options[:currency] || "usd"
|
6
5
|
case
|
7
6
|
when options.key?(:token) && options.key?(:secret) then authorize_with_token(options[:token], options[:secret])
|
8
7
|
when options.key?(:login) && options.key?(:password) then authorize_with_credentials(options[:login], options[:password])
|
@@ -64,7 +63,8 @@ module InfomemeClient::Base
|
|
64
63
|
end
|
65
64
|
|
66
65
|
def inspect
|
67
|
-
|
66
|
+
@all_permissions ||= all_permissions
|
67
|
+
"#<#{self.class.name}: #{authorized? ? credentials.merge({:permissions => (@all_permissions || []).select {|perm| has_permission?(perm.id)}.collect {|perm| perm.name}}).inspect : 'not authorized'}>"
|
68
68
|
end
|
69
69
|
|
70
70
|
private
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class InfomemeClient::EntityHash
|
2
2
|
autoload :Comment, "infomeme_client/entity_hash/comment"
|
3
|
+
autoload :Invoice, "infomeme_client/entity_hash/invoice"
|
3
4
|
autoload :Meme, "infomeme_client/entity_hash/meme"
|
4
5
|
autoload :MemeType, "infomeme_client/entity_hash/meme_type"
|
5
6
|
autoload :Transaction, "infomeme_client/entity_hash/transaction"
|
@@ -1,9 +1,8 @@
|
|
1
1
|
module InfomemeClient::Functions::User
|
2
|
-
attr_accessor :default_language
|
2
|
+
attr_accessor :default_language
|
3
3
|
|
4
4
|
def register(email, username, password, firstname, lastname, optional_fields = {})
|
5
5
|
optional_fields.store(:language_code, optional_fields.key?(:language) ? optional_fields.delete(:language) : default_language) #language is mandatory
|
6
|
-
optional_fields.store(:currency_code, optional_fields.key?(:currency) ? optional_fields.delete(:currency) : default_currency) #currency is mandatory
|
7
6
|
handle_response :post, "/users/register", optional_fields.merge({:email => email, :username => username, :password => password, :firstname => firstname, :lastname => lastname}) do
|
8
7
|
authorize_with_credentials username, password and return true
|
9
8
|
end
|
@@ -1,4 +1,19 @@
|
|
1
|
-
module InfomemeClient::Functions::
|
1
|
+
module InfomemeClient::Functions::UserOrder
|
2
|
+
def order(meme_id, source, options = {})
|
3
|
+
return false unless authorized?
|
4
|
+
handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/order", options.merge(:source => source)
|
5
|
+
end
|
6
|
+
|
7
|
+
def order_with_balance(meme_id, options = {})
|
8
|
+
order(meme_id, 1, options)
|
9
|
+
refresh_settings
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def order_with_paypal(meme_id, options = {})
|
14
|
+
order(meme_id, 3, options).paypal_url
|
15
|
+
end
|
16
|
+
|
2
17
|
def transactions(options = {})
|
3
18
|
return false unless authorized?
|
4
19
|
extract_or_response :transactions, :get, "/users/#{verified_user}/transactions", options
|
@@ -2,12 +2,12 @@ module InfomemeClient::Functions
|
|
2
2
|
autoload :Meme, "infomeme_client/functions/meme"
|
3
3
|
autoload :User, "infomeme_client/functions/user"
|
4
4
|
autoload :UserMeme, "infomeme_client/functions/user_meme"
|
5
|
-
autoload :
|
5
|
+
autoload :UserOrder, "infomeme_client/functions/user_order"
|
6
6
|
|
7
7
|
include Meme
|
8
8
|
include User
|
9
9
|
include UserMeme
|
10
|
-
include
|
10
|
+
include UserOrder
|
11
11
|
|
12
12
|
private
|
13
13
|
def get_memes(path, options = {}, headers = {})
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":0,"message":"Success.","invoice":{"amount_user":10.0,"meme":{"name":"test meme 1"}}}
|
@@ -0,0 +1 @@
|
|
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}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"status":0,"message":"Success.","paypal_url":"test_paypal_url"}
|
@@ -0,0 +1 @@
|
|
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}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class TestUserOrderFunctions < Test::Unit::TestCase
|
4
|
+
def test_order_with_balance
|
5
|
+
fake_request(:post, "/users/test_user/memes/1/order", :body => fixture("response/ok"), :content_type => "application/json")
|
6
|
+
authorize
|
7
|
+
assert_nothing_raised do
|
8
|
+
assert @im_client.order_with_balance(1)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_order_with_paypal
|
13
|
+
fake_request(:post, "/users/test_user/memes/1/order", :body => fixture("users/order_paypal"), :content_type => "application/json")
|
14
|
+
authorize
|
15
|
+
assert_nothing_raised do
|
16
|
+
assert_equal "test_paypal_url", @im_client.order_with_paypal(1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_transactions
|
21
|
+
fake_request(:get, "/users/test_user/transactions?page=1&pageSize=25", :body => fixture("users/transactions"), :content_type => "application/json")
|
22
|
+
authorize
|
23
|
+
check_paged :transactions, @im_client.transactions(:page => 1, :pageSize => 25, :no_extract => true)
|
24
|
+
check_list :transactions, @im_client.transactions(:page => 1, :pageSize => 25)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_invoices
|
28
|
+
fake_request(:get, "/users/test_user/invoices?page=1&pageSize=25", :body => fixture("users/invoices"), :content_type => "application/json")
|
29
|
+
authorize
|
30
|
+
check_paged :invoices, @im_client.invoices(:page => 1, :pageSize => 25, :no_extract => true)
|
31
|
+
check_list :invoices, @im_client.invoices(:page => 1, :pageSize => 25)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_invoice
|
35
|
+
fake_request(:get, "/users/test_user/invoices/1", :body => fixture("users/invoice"), :content_type => "application/json")
|
36
|
+
authorize
|
37
|
+
invoice = @im_client.invoice(1)
|
38
|
+
check_eh :invoice, invoice
|
39
|
+
assert_respond_to invoice, :amount_user
|
40
|
+
assert_equal 10.0, invoice.amount_user
|
41
|
+
assert_respond_to invoice, :meme
|
42
|
+
assert_respond_to invoice.meme, :name
|
43
|
+
assert_equal "test meme 1", invoice.meme.name
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infomeme_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Infomeme Ltd.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-04 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -105,7 +105,7 @@ files:
|
|
105
105
|
- lib/infomeme_client/functions/meme.rb
|
106
106
|
- lib/infomeme_client/functions/user.rb
|
107
107
|
- lib/infomeme_client/functions/user_meme.rb
|
108
|
-
- lib/infomeme_client/functions/
|
108
|
+
- lib/infomeme_client/functions/user_order.rb
|
109
109
|
- lib/infomeme_client/meme_application.rb
|
110
110
|
- lib/infomeme_client/permissions.rb
|
111
111
|
- lib/infomeme_client/response.rb
|
@@ -122,8 +122,12 @@ files:
|
|
122
122
|
- test/fixtures/response/ok.json
|
123
123
|
- test/fixtures/response/test.json
|
124
124
|
- test/fixtures/response/test_extract.json
|
125
|
+
- test/fixtures/users/invoice.json
|
126
|
+
- test/fixtures/users/invoices.json
|
125
127
|
- test/fixtures/users/memes.json
|
128
|
+
- test/fixtures/users/order_paypal.json
|
126
129
|
- test/fixtures/users/permissions.json
|
130
|
+
- test/fixtures/users/transactions.json
|
127
131
|
- test/fixtures/users/user.json
|
128
132
|
- test/fixtures/users/user_public.json
|
129
133
|
- test/helper.rb
|
@@ -134,6 +138,7 @@ files:
|
|
134
138
|
- test/test_permissions.rb
|
135
139
|
- test/test_user_functions.rb
|
136
140
|
- test/test_user_meme_functions.rb
|
141
|
+
- test/test_user_order_functions.rb
|
137
142
|
has_rdoc: true
|
138
143
|
homepage: https://api.infomeme.com
|
139
144
|
licenses: []
|
@@ -177,3 +182,4 @@ test_files:
|
|
177
182
|
- test/test_permissions.rb
|
178
183
|
- test/test_user_functions.rb
|
179
184
|
- test/test_user_meme_functions.rb
|
185
|
+
- test/test_user_order_functions.rb
|