webpay 2.1.1 → 2.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77afac69d89b7df48f6789f19ccd0f27a87f44d8
4
- data.tar.gz: 8fe4aaf18f1278fb012dc1dc5856e569513c9009
3
+ metadata.gz: a7c74b37ee7b237d1f743cc81b96efbf30461e69
4
+ data.tar.gz: 2d1fbb219485d644d317f3d05b85ec979c9ce730
5
5
  SHA512:
6
- metadata.gz: 0f651a31916eb056fbf5fd698a189a07a631726f526c2e463d5c4cf22e9f74e1c2e41e27fd269e982c6e152d5c0069d35c83a47974ffa633c894979182c8e2f8
7
- data.tar.gz: 5042e230ad4a8525eb3cf8f8806f7de18bc9b3c5ff0ef169b5ed40da8edeeee1cb104766818c11eee2a206fbd83ef7c798184b81dc7e893df8c7c4571cc854b6
6
+ metadata.gz: 57fc900f7a509d96913fe41902b7b79d9e10e48a4857e19229aaca8d99c17e42828ef5c21871da3d312744bb0e58db625fe023c1fe29d5fe3df5fe6cc3af329a
7
+ data.tar.gz: 54e6158243f7a2432b86ad3769751dfad61e7bda47efb9a3558417e6f027b5a446b6bbdac28d6981ea1fe5f3e0a7d26a73b4936f5b380374f7c0dedaafca8bbe
data/.travis.yml CHANGED
@@ -8,6 +8,5 @@ gemfile:
8
8
  - gemfiles/no_doc_gems
9
9
  script: "bundle exec rake"
10
10
  notifications:
11
- hipchat:
12
- rooms:
13
- secure: ykLsXlebzR9nnb+9ttpCySOg2hE4Ve699s2Owd7YahcZyVNxnG4q1P8Mps4jFlOgPNQ6JwkcB4A6QLavavtJlX7vXTDj1GD+zVAScjbtN/6ZV94S2eHA7hBUXHUwBmH0Cw5glrFoPEDBsQdOYbrOrJKwFNEhUTHdY0SRgEXv5Wo=
11
+ webhooks:
12
+ secure: Pbqm39Q5UmaN76lEv5xqgrLHgApc+OWsQTFgOAsweBXuIW1fPsoMRq8CwnrZ9Y23XdE1OmK2mi0Y3ncONgptp4yXi+kfaSmMT8LUwJ+Jkk1NWB2teoCYYaRt+da70bjClhSfBdb2+1S300o5NnhdyCdtC1EKP6syakBxgzJkOP0=
data/lib/webpay/client.rb CHANGED
@@ -15,13 +15,14 @@ module WebPay
15
15
  #
16
16
  # @example Client for the default endpoint
17
17
  # Client.new('test_secret_XXXX', 'https://api.webpay.jp', '/v1')
18
- def initialize(api_key, api_base, api_version)
18
+ def initialize(api_key, api_base, api_version, api_proxy = nil, lang = :en)
19
19
  ssl_options = {ca_file: WebPay.ssl_ca_file}
20
20
  default_headers = {
21
21
  'Authorization' => "Bearer #{api_key}",
22
- 'User-Agent' => "WebPay#{api_version} RubyBinding/#{WebPay::VERSION}"
22
+ 'User-Agent' => "WebPay#{api_version} RubyBinding/#{WebPay::VERSION}",
23
+ 'Accept-Language' => lang.to_s
23
24
  }
24
- @conn = Faraday.new(api_base, ssl: ssl_options, headers: default_headers) do |builder|
25
+ @conn = Faraday.new(api_base, ssl: ssl_options, headers: default_headers, proxy: api_proxy) do |builder|
25
26
  builder.request :url_encoded
26
27
  builder.adapter Faraday.default_adapter
27
28
  end
@@ -1,5 +1,5 @@
1
1
  module WebPay
2
2
 
3
3
  # Version of WebPay gem
4
- VERSION = "2.1.1"
4
+ VERSION = "2.2.0"
5
5
  end
data/lib/webpay.rb CHANGED
@@ -25,6 +25,8 @@ module WebPay
25
25
  @api_base = 'https://api.webpay.jp'
26
26
  @api_version = '/v1'
27
27
  @api_key = nil
28
+ @api_proxy = nil
29
+ @language = :en
28
30
 
29
31
  class << self
30
32
  # Absolute path to SSL CA file.
@@ -36,7 +38,7 @@ module WebPay
36
38
  # Current client object.
37
39
  # client is memoized, and nullified when @api_base or @api_key is modified.
38
40
  def client
39
- @client ||= Client.new(@api_key, @api_base, @api_version)
41
+ @client ||= Client.new(@api_key, @api_base, @api_version, @api_proxy, @language)
40
42
  end
41
43
 
42
44
  # Set api_base, the base URL of API.
@@ -54,6 +56,19 @@ module WebPay
54
56
  @client = nil
55
57
  end
56
58
 
59
+ # Set proxy for connecting to @api_base
60
+ def api_proxy=(new_value)
61
+ @api_proxy = new_value
62
+ @client = nil
63
+ end
64
+
65
+ # Set value of accept-language request header
66
+ # Currently WebPay API handles :en and :ja
67
+ def language=(new_value)
68
+ @language = new_value
69
+ @client = nil
70
+ end
71
+
57
72
  # Get current api_base
58
73
  def api_base
59
74
  @api_base
@@ -63,5 +78,15 @@ module WebPay
63
78
  def api_key
64
79
  @api_key
65
80
  end
81
+
82
+ # Get current api_proxy
83
+ def api_proxy
84
+ @api_proxy
85
+ end
86
+
87
+ # Get current language
88
+ def language
89
+ @language
90
+ end
66
91
  end
67
92
  end
@@ -0,0 +1,20 @@
1
+ HTTP/1.1 404 Not Found
2
+ Cache-Control: no-cache, private
3
+ Content-Type: application/json; charset=utf-8
4
+ Date: Sun, 23 Feb 2014 23:53:53 GMT
5
+ Server: nginx/1.4.4
6
+ Status: 404 Not Found
7
+ X-Rack-Cache: miss
8
+ X-Request-Id: b82d843b508fa060a1f1c0bb637e40f6
9
+ X-Runtime: 0.016769
10
+ X-UA-Compatible: IE=Edge,chrome=1
11
+ Content-Length: 151
12
+ Connection: keep-alive
13
+
14
+ {
15
+ "error": {
16
+ "type": "invalid_request_error",
17
+ "message": "該当する顧客がありません: cus_eS6dGfa8BeUlbS",
18
+ "param": "id"
19
+ }
20
+ }
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'uri'
4
+
5
+ describe WebPay do
6
+ it 'should set proxy on Faraday client from api_proxy option' do
7
+ proxy_uri = 'http://test.example.com:8080'
8
+ WebPay.api_proxy = proxy_uri
9
+ expect(WebPay.client.instance_variable_get(:@conn).proxy[:uri])
10
+ .to eq(URI.parse(proxy_uri))
11
+ end
12
+
13
+ describe 'Not Found with Accept-Language: ja' do
14
+ let(:id) { 'cus_eS6dGfa8BeUlbS' }
15
+ before do
16
+ stub_request(:get, 'http://api.example.com/v1/customers/' + id).
17
+ with(headers: { 'Authorization' => 'Bearer fake_apikey', 'Accept-Language' => 'ja' }).
18
+ to_return(response_file('errors/not_found_ja'))
19
+ end
20
+ subject(:error) {
21
+ WebPay.api_base = 'http://api.example.com/v1'
22
+ WebPay.language = :ja
23
+ begin
24
+ WebPay::Customer.retrieve(id)
25
+ rescue => e
26
+ e
27
+ end
28
+ }
29
+ it { should be_instance_of WebPay::InvalidRequestError }
30
+ its(:status) { should eq 404 }
31
+ its(:type) { should eq 'invalid_request_error' }
32
+ its(:param) { should eq 'id' }
33
+ its(:message) { should eq '該当する顧客がありません: cus_eS6dGfa8BeUlbS' }
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - webpay
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-16 00:00:00.000000000 Z
12
+ date: 2014-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -160,6 +160,7 @@ files:
160
160
  - spec/resources/errors/broken_json.txt
161
161
  - spec/resources/errors/card_error.txt
162
162
  - spec/resources/errors/not_found.txt
163
+ - spec/resources/errors/not_found_ja.txt
163
164
  - spec/resources/errors/unauthorized.txt
164
165
  - spec/resources/errors/unknown_api_error.txt
165
166
  - spec/resources/events/all_with_type.txt
@@ -173,6 +174,7 @@ files:
173
174
  - spec/webpay/event_spec.rb
174
175
  - spec/webpay/token_spec.rb
175
176
  - spec/webpay/webpay_error_spec.rb
177
+ - spec/webpay_spec.rb
176
178
  - webpay.gemspec
177
179
  homepage: https://webpay.jp
178
180
  licenses:
@@ -218,6 +220,7 @@ test_files:
218
220
  - spec/resources/errors/broken_json.txt
219
221
  - spec/resources/errors/card_error.txt
220
222
  - spec/resources/errors/not_found.txt
223
+ - spec/resources/errors/not_found_ja.txt
221
224
  - spec/resources/errors/unauthorized.txt
222
225
  - spec/resources/errors/unknown_api_error.txt
223
226
  - spec/resources/events/all_with_type.txt
@@ -231,3 +234,4 @@ test_files:
231
234
  - spec/webpay/event_spec.rb
232
235
  - spec/webpay/token_spec.rb
233
236
  - spec/webpay/webpay_error_spec.rb
237
+ - spec/webpay_spec.rb