amiando 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/amiando.rb +30 -12
- data/lib/amiando/payment_type.rb +3 -5
- data/lib/amiando/request.rb +1 -1
- data/lib/amiando/resource.rb +6 -0
- data/lib/amiando/version.rb +1 -1
- data/test/amiando/resource_test.rb +22 -1
- data/test/test_helper.rb +2 -2
- metadata +7 -5
data/.gitignore
CHANGED
data/lib/amiando.rb
CHANGED
@@ -17,22 +17,33 @@ module Amiando
|
|
17
17
|
autoload :TicketShop, 'amiando/ticket_shop'
|
18
18
|
autoload :PaymentType, 'amiando/payment_type'
|
19
19
|
|
20
|
-
|
21
|
-
class ServiceDown <
|
22
|
-
class
|
23
|
-
class
|
24
|
-
class
|
25
|
-
class
|
26
|
-
class
|
27
|
-
class
|
20
|
+
class Error < StandardError
|
21
|
+
class ServiceDown < Error; end
|
22
|
+
class Timeout < Error; end
|
23
|
+
class ApiKeyNeeded < Error; end
|
24
|
+
class NotAuthorized < Error; end
|
25
|
+
class NotFound < Error; end
|
26
|
+
class NotImplemented < Error; end
|
27
|
+
class NotInitialized < Error; end
|
28
|
+
class MissingApiKey < Error; end
|
28
29
|
end
|
29
30
|
|
30
31
|
class << self
|
32
|
+
|
33
|
+
# Api key to be used at all times.
|
31
34
|
attr_accessor :api_key
|
35
|
+
|
36
|
+
# Logger instance. There's no logger by default.
|
32
37
|
attr_accessor :logger
|
38
|
+
|
33
39
|
attr_accessor :verbose
|
40
|
+
|
41
|
+
# If set to true, will run the requests automatically when needed.
|
34
42
|
attr_accessor :autorun
|
35
43
|
|
44
|
+
# Timeout value (in milliseconds). Default: 15 seconds.
|
45
|
+
attr_accessor :timeout
|
46
|
+
|
36
47
|
URL = 'https://amiando.com'
|
37
48
|
TEST_URL = 'https://test.amiando.com'
|
38
49
|
|
@@ -63,10 +74,6 @@ module Amiando
|
|
63
74
|
@requests = []
|
64
75
|
end
|
65
76
|
|
66
|
-
def hydra
|
67
|
-
@hydra ||= Typhoeus::Hydra.new
|
68
|
-
end
|
69
|
-
|
70
77
|
##
|
71
78
|
# Allows to switch temporarily the API key
|
72
79
|
#
|
@@ -81,5 +88,16 @@ module Amiando
|
|
81
88
|
Amiando.api_key = old_key
|
82
89
|
end
|
83
90
|
|
91
|
+
private
|
92
|
+
|
93
|
+
def hydra
|
94
|
+
@hydra ||= Typhoeus::Hydra.new
|
95
|
+
end
|
96
|
+
|
84
97
|
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Default timeout of 15 seconds
|
101
|
+
self.timeout = 15000
|
102
|
+
|
85
103
|
end
|
data/lib/amiando/payment_type.rb
CHANGED
@@ -6,15 +6,13 @@ module Amiando
|
|
6
6
|
#
|
7
7
|
# @param event_id
|
8
8
|
# @param type string or symbol of the following:
|
9
|
-
# * PAYMENT_TYPE_ELV
|
10
|
-
# * PAYMENT_TYPE_CC
|
9
|
+
# * PAYMENT_TYPE_ELV (debit card)
|
10
|
+
# * PAYMENT_TYPE_CC (credit card)
|
11
11
|
# * PAYMENT_TYPE_INVOICE
|
12
12
|
# * PAYMENT_TYPE_PREPAYMENT
|
13
|
-
# * PAYMENT_TYPE_PP
|
13
|
+
# * PAYMENT_TYPE_PP (PayPal)
|
14
14
|
# * PAYMENT_TYPE_ONLOCATION
|
15
15
|
#
|
16
|
-
# [CC = CreditCard, PP = PayPal]
|
17
|
-
#
|
18
16
|
# It will also accept :cc, :invoice, etc and convert them appropriately
|
19
17
|
#
|
20
18
|
def self.create(event_id, type)
|
data/lib/amiando/request.rb
CHANGED
@@ -12,7 +12,7 @@ module Amiando
|
|
12
12
|
params = default_params.merge(params || {})
|
13
13
|
end
|
14
14
|
|
15
|
-
super(path, :method => verb, :params => params, :verbose => Amiando.verbose)
|
15
|
+
super(path, :method => verb, :params => params, :verbose => Amiando.verbose, :timeout => Amiando.timeout)
|
16
16
|
end
|
17
17
|
|
18
18
|
def log_request
|
data/lib/amiando/resource.rb
CHANGED
@@ -65,6 +65,10 @@ module Amiando
|
|
65
65
|
req.on_complete do |response|
|
66
66
|
req.log_response
|
67
67
|
|
68
|
+
if response.timed_out?
|
69
|
+
raise Error::Timeout
|
70
|
+
end
|
71
|
+
|
68
72
|
# Raise different errors depending on the return codes
|
69
73
|
case response.code
|
70
74
|
when 403
|
@@ -73,6 +77,8 @@ module Amiando
|
|
73
77
|
raise Error::NotFound.new(response.body)
|
74
78
|
when 503
|
75
79
|
raise Error::ServiceDown.new(response.body)
|
80
|
+
when 0
|
81
|
+
raise Error.new(response.body)
|
76
82
|
end
|
77
83
|
|
78
84
|
parsed_body = MultiJson.decode(response.body)
|
data/lib/amiando/version.rb
CHANGED
@@ -28,11 +28,32 @@ describe Amiando::Resource do
|
|
28
28
|
it 'raises error when amiando is down' do
|
29
29
|
stub_request(:post, /somewhere/).to_return(:status => 503)
|
30
30
|
lambda {
|
31
|
-
|
31
|
+
Wadus.create
|
32
32
|
Amiando.run
|
33
33
|
}.must_raise Amiando::Error::ServiceDown
|
34
34
|
end
|
35
35
|
|
36
|
+
##
|
37
|
+
# Not working because of issue between webmock and typhoeus
|
38
|
+
#
|
39
|
+
# it 'raises error when the request times out' do
|
40
|
+
# stub_request(:post, /somewhere/).to_timeout
|
41
|
+
# lambda {
|
42
|
+
# Wadus.create
|
43
|
+
# Amiando.run
|
44
|
+
# }.must_raise Amiando::Error::Timeout
|
45
|
+
# end
|
46
|
+
|
47
|
+
it 'raises error when the request returns code 0' do
|
48
|
+
stub_request(:post, /somewhere/).to_return(:status => 0)
|
49
|
+
|
50
|
+
lambda {
|
51
|
+
Wadus.create
|
52
|
+
Amiando.run
|
53
|
+
}.must_raise Amiando::Error
|
54
|
+
end
|
55
|
+
|
56
|
+
|
36
57
|
it 'raises an error if populate method is not implemented' do
|
37
58
|
lambda {
|
38
59
|
Wadus.new.populate(nil)
|
data/test/test_helper.rb
CHANGED
@@ -18,8 +18,8 @@ require 'support/hydra_cache'
|
|
18
18
|
require 'support/factory'
|
19
19
|
require 'support/hydra_monkey_patch'
|
20
20
|
|
21
|
-
Amiando.hydra.cache_setter &HydraCache.method(:setter)
|
22
|
-
Amiando.hydra.cache_getter &HydraCache.method(:getter)
|
21
|
+
Amiando.send(:hydra).cache_setter &HydraCache.method(:setter)
|
22
|
+
Amiando.send(:hydra).cache_getter &HydraCache.method(:getter)
|
23
23
|
HydraCache.revision = 2
|
24
24
|
|
25
25
|
WebMock.allow_net_connect!
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amiando
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 8
|
10
|
+
version: 0.3.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jorge Dias
|
@@ -16,7 +16,8 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2012-01-02 00:00:00 +01:00
|
20
|
+
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: typhoeus
|
@@ -225,6 +226,7 @@ files:
|
|
225
226
|
- test/support/hydra_cache.rb
|
226
227
|
- test/support/hydra_monkey_patch.rb
|
227
228
|
- test/test_helper.rb
|
229
|
+
has_rdoc: true
|
228
230
|
homepage: ""
|
229
231
|
licenses: []
|
230
232
|
|
@@ -254,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
256
|
requirements: []
|
255
257
|
|
256
258
|
rubyforge_project: amiando
|
257
|
-
rubygems_version: 1.
|
259
|
+
rubygems_version: 1.6.2
|
258
260
|
signing_key:
|
259
261
|
specification_version: 3
|
260
262
|
summary: A ruby client for the amiando REST API
|