checkout_ru 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/checkout_ru.gemspec +1 -0
- data/lib/checkout_ru/version.rb +1 -1
- data/lib/checkout_ru.rb +28 -35
- data/test/checkout_ru_test.rb +8 -1
- data/test/test_helper.rb +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24682ee5c93e589612160abcb3f699cd34d1fd84
|
4
|
+
data.tar.gz: ca9124080594ecdbb1640350c8133daf0936103a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c45a9296349bf629a3834ada08a6521e334fdf888df0570ca54e9b39501ffeabcef9af763443e6271ef63e666333e2d8c2b1fd3839d318265251c364f0aebf1
|
7
|
+
data.tar.gz: fac3ed5091be006bcf7ce0ce814818235e62ce573f7657e0045c05a69c800a6bc8cac2be7a94fe13808f4329d7ad00b60184aeb6107509e6187584b6fe5c42c0
|
data/CHANGELOG.md
ADDED
data/checkout_ru.gemspec
CHANGED
data/lib/checkout_ru/version.rb
CHANGED
data/lib/checkout_ru.rb
CHANGED
@@ -18,26 +18,25 @@ module CheckoutRu
|
|
18
18
|
attr_accessor :service_url, :api_key, :adapter
|
19
19
|
|
20
20
|
def get_ticket(options = {})
|
21
|
-
|
22
|
-
make_request("/service/login/ticket/#{
|
21
|
+
key = options[:api_key] || api_key
|
22
|
+
make_request("/service/login/ticket/#{key}")['ticket']
|
23
23
|
end
|
24
24
|
|
25
25
|
def create_order(order, options = {})
|
26
|
-
|
27
|
-
make_request '/service/order/create',
|
26
|
+
make_request_with_key '/service/order/create',
|
28
27
|
:via => :post,
|
29
|
-
:params => { :
|
28
|
+
:params => { :order => order },
|
29
|
+
:api_key => options[:api_key]
|
30
30
|
end
|
31
31
|
|
32
32
|
def update_order(remote_id, order, options = {})
|
33
|
-
|
34
|
-
make_request "/service/order/#{remote_id}",
|
33
|
+
make_request_with_key "/service/order/#{remote_id}",
|
35
34
|
:via => :post,
|
36
|
-
:params => { :
|
35
|
+
:params => { :order => order },
|
36
|
+
:api_key => options[:api_key]
|
37
37
|
end
|
38
38
|
|
39
39
|
def status(remote_id, status, options = {})
|
40
|
-
api_key = options[:api_key] || api_key
|
41
40
|
status_map = Order::Status::MAP
|
42
41
|
|
43
42
|
status_string = if status.is_a?(Symbol)
|
@@ -54,29 +53,23 @@ module CheckoutRu
|
|
54
53
|
status
|
55
54
|
end
|
56
55
|
|
57
|
-
|
56
|
+
make_request_with_key "/service/order/status/#{remote_id}",
|
58
57
|
:via => :post,
|
59
|
-
:params => { :
|
58
|
+
:params => { :status => status_string },
|
59
|
+
:api_key => options[:api_key]
|
60
60
|
end
|
61
61
|
|
62
62
|
def status_history(order_id, options = {})
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
response.order.date = Date.parse(response.order.date)
|
68
|
-
response
|
63
|
+
resp = make_request_with_key "/service/order/statushistory/#{order_id}",
|
64
|
+
:api_key => options[:api_key]
|
65
|
+
resp.order.date = Date.parse(resp.order.date)
|
66
|
+
resp
|
69
67
|
end
|
70
68
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
faraday.request :multi_json
|
76
|
-
faraday.response :raise_error
|
77
|
-
faraday.response :multi_json
|
78
|
-
faraday.adapter options[:adapter] || adapter || Faraday.default_adapter
|
79
|
-
end
|
69
|
+
def make_request_with_key(service, options = {})
|
70
|
+
key = options.delete(:api_key) || api_key
|
71
|
+
params = (options[:params] || {}).merge(:api_key => key)
|
72
|
+
make_request service, options.merge(:params => params)
|
80
73
|
end
|
81
74
|
|
82
75
|
def make_request(service, options = {})
|
@@ -99,16 +92,16 @@ module CheckoutRu
|
|
99
92
|
else
|
100
93
|
body
|
101
94
|
end
|
95
|
+
end
|
102
96
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
raise Error, msg
|
97
|
+
def build_connection(options = {})
|
98
|
+
url = options[:url] || service_url || SERVICE_URL
|
99
|
+
|
100
|
+
Faraday.new(:url => url) do |faraday|
|
101
|
+
faraday.request :multi_json
|
102
|
+
faraday.response :raise_error
|
103
|
+
faraday.response :multi_json
|
104
|
+
faraday.adapter options[:adapter] || adapter || Faraday.default_adapter
|
112
105
|
end
|
113
106
|
end
|
114
107
|
|
data/test/checkout_ru_test.rb
CHANGED
@@ -37,6 +37,13 @@ class CheckoutRuTest < MiniTest::Test
|
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_configured_api_key_is_used_to_make_request
|
41
|
+
CheckoutRu.stubs(:api_key).returns('foobar')
|
42
|
+
CheckoutRu.expects(:make_request).with("/service/login/ticket/foobar").
|
43
|
+
once.returns({})
|
44
|
+
CheckoutRu.get_ticket
|
45
|
+
end
|
46
|
+
|
40
47
|
def test_get_ticket_returns_valid_ticket
|
41
48
|
VCR.use_cassette('get_ticket') do
|
42
49
|
assert_equal 'valid-ticket',
|
@@ -46,7 +53,7 @@ class CheckoutRuTest < MiniTest::Test
|
|
46
53
|
|
47
54
|
def test_get_ticket_with_invalid_api_key_raises_invalid_key_error
|
48
55
|
VCR.use_cassette('get_ticket_invalid_api_key') do
|
49
|
-
assert_raises
|
56
|
+
assert_raises Faraday::Error::ClientError do
|
50
57
|
CheckoutRu.get_ticket(:api_key => 'invalid-api-key')
|
51
58
|
end
|
52
59
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: checkout_ru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxim Chernyak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '2.8'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: mocha
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.0'
|
153
167
|
description: Ruby client for checkout.ru.
|
154
168
|
email:
|
155
169
|
- max@bitsonnet.com
|
@@ -158,6 +172,7 @@ extensions: []
|
|
158
172
|
extra_rdoc_files: []
|
159
173
|
files:
|
160
174
|
- ".gitignore"
|
175
|
+
- CHANGELOG.md
|
161
176
|
- Gemfile
|
162
177
|
- LICENSE.txt
|
163
178
|
- README.md
|