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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 393f1449eb2aebca42dfeb2c9a24b620f85b6a25
4
- data.tar.gz: ee4988279feb2f27f318964a3303242ef3453248
3
+ metadata.gz: 24682ee5c93e589612160abcb3f699cd34d1fd84
4
+ data.tar.gz: ca9124080594ecdbb1640350c8133daf0936103a
5
5
  SHA512:
6
- metadata.gz: a51d73225f87d9847ab14852cb0a8c080830b03b9879c92a8f2577855507886a6503c06085c3504e123042978098a83a8a8f4987889673b6d1822a7b033f54fa
7
- data.tar.gz: 7609abdbe9bab03b9f325def2b1389b316aba99e0f20cde558a2e4af813047d8e72696186a3698eb0c2b4f92e26b1af3a3167a5a070489248ea65f6e9e686fe2
6
+ metadata.gz: 6c45a9296349bf629a3834ada08a6521e334fdf888df0570ca54e9b39501ffeabcef9af763443e6271ef63e666333e2d8c2b1fd3839d318265251c364f0aebf1
7
+ data.tar.gz: fac3ed5091be006bcf7ce0ce814818235e62ce573f7657e0045c05a69c800a6bc8cac2be7a94fe13808f4329d7ad00b60184aeb6107509e6187584b6fe5c42c0
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.2
2
+
3
+ - Fix Faraday dependency issue
data/checkout_ru.gemspec CHANGED
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rake', '~> 10'
30
30
  spec.add_development_dependency 'minitest', '~> 5.2'
31
31
  spec.add_development_dependency 'vcr', '~> 2.8'
32
+ spec.add_development_dependency 'mocha', '~> 1.0'
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module CheckoutRu
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
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
- api_key = options[:api_key] || api_key
22
- make_request("/service/login/ticket/#{api_key}")['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
- api_key = options[:api_key] || api_key
27
- make_request '/service/order/create',
26
+ make_request_with_key '/service/order/create',
28
27
  :via => :post,
29
- :params => { :api_key => api_key, :order => order }
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
- api_key = options[:api_key] || api_key
34
- make_request "/service/order/#{remote_id}",
33
+ make_request_with_key "/service/order/#{remote_id}",
35
34
  :via => :post,
36
- :params => { :api_key => api_key, :order => order }
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
- make_request "/service/order/status/#{remote_id}",
56
+ make_request_with_key "/service/order/status/#{remote_id}",
58
57
  :via => :post,
59
- :params => { :api_key => api_key, :status => status_string }
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
- api_key = options[:api_key] || api_key
64
- response = make_request "/service/order/statushistory/#{order_id}",
65
- :params => { :api_key => api_key }
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 build_connection(options = {})
72
- url = options[:url] || service_url || SERVICE_URL
73
-
74
- Faraday.new(:url => url) do |faraday|
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
- rescue Faraday::Error::ClientError => e
104
- begin
105
- doc = Nokogiri::HTML(e.response[:body])
106
- doc.css('script, link').each(&:remove)
107
- msg = doc.css('body h1').text
108
- rescue
109
- raise e
110
- else
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
 
@@ -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 CheckoutRu::Error do
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
@@ -1,5 +1,6 @@
1
1
  require 'checkout_ru'
2
2
  require 'minitest/autorun'
3
+ require 'mocha/mini_test'
3
4
  require 'vcr'
4
5
 
5
6
  VCR.configure do |c|
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.2
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-05 00:00:00.000000000 Z
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