recurly 2.4.3 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of recurly might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7da7bb9490b486ad6966ada1a9cc1bc796595830
4
- data.tar.gz: 11fb0f00d9734f02590daa6fe77b13db31247bdc
3
+ metadata.gz: d93db27c0e5a60f14716ebcc41ed9faed1bb1818
4
+ data.tar.gz: 0bfa54bc52c9f79d3a9abf3016ebb56f59428fd6
5
5
  SHA512:
6
- metadata.gz: 5751d6f82a8b8c280ded7beac6077da015333424b67a92a37d636d82a2ce8dd5e048247f3ff341ff0b16ff066501d5803809b27e2a72db5e6195e03858cc8e59
7
- data.tar.gz: 996de0c0f049b92fe4c089b0b8c0f24b3ebdbb81af7865aa3eaebce9a09c1fe4170c02f869acf6dbc7ca02804ceb93cb275cb504922e52d582904c2a3ccd04c7
6
+ metadata.gz: a2a086f1639397b31b532d25b317e578ab1bcdd25c361f169d8a239f84c1e9d56fe22581aa7212143417b84972f4bc378b9a23eb096dd88874b2608a7ed4113c
7
+ data.tar.gz: 997946b21e1068afd78c96fcbd4b43e36c940e67d93b9da0d7360ecb7b6393bb1a144465cfd1a07036b62d20f9060f48e59e9c3f99f477dcc15002b00400460e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Recurly [![Build Status](https://secure.travis-ci.org/recurly/recurly-client-ruby.png)](http://travis-ci.org/recurly/recurly-client-ruby)
1
+ # Recurly [![Build Status](https://secure.travis-ci.org/recurly/recurly-client-ruby.png)](http://travis-ci.org/recurly/recurly-client-ruby) [![Gem Version](https://badge.fury.io/rb/recurly.svg)](http://badge.fury.io/rb/recurly)
2
2
 
3
3
  <https://github.com/recurly/recurly-client-ruby>
4
4
 
@@ -12,7 +12,7 @@ Recurly is packaged as a Ruby gem. We recommend you install it with
12
12
  [Bundler](http://gembundler.com/) by adding the following line to your Gemfile:
13
13
 
14
14
  ``` ruby
15
- gem 'recurly', '~> 2.4.3'
15
+ gem 'recurly', '~> 2.4.4'
16
16
  ```
17
17
 
18
18
  Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
@@ -69,6 +69,21 @@ Recurly::API.net_http = {
69
69
  }
70
70
  ```
71
71
 
72
+ ## Multi-Threaded Configuration
73
+ If you are using the client in a multi-threaded environment and require a different configuration per thread you can use the following within the thread's context:
74
+
75
+ ``` ruby
76
+ Recurly.config({
77
+ subdomain: ENV['RECURLY_SUBDOMAIN']
78
+ api_key: ENV['RECURLY_API_KEY'],
79
+ default_currency: "US",
80
+ private_key: ENV['RECURLY_PUBLIC_API_KEY']
81
+ })
82
+ ```
83
+
84
+ Any configuration items you do not include in the above config call will be defaulted to the standard configuration items. For example if you do not define default_currency then
85
+ Recurly.default_currency will be used.
86
+
72
87
 
73
88
  ## Usage
74
89
 
@@ -89,10 +89,10 @@ module Recurly
89
89
  # refundable.
90
90
  # @raise [Error] If the refund fails.
91
91
  # @param line_items [Array, nil] An array of line items to refund.
92
- def refund line_items = nil
92
+ def refund line_items = nil, refund_apply_order = 'credit'
93
93
  return false unless link? :refund
94
94
  refund = self.class.from_response(
95
- follow_link :refund, :body => refund_line_items_to_xml(line_items)
95
+ follow_link :refund, :body => refund_line_items_to_xml(line_items, refund_apply_order)
96
96
  )
97
97
  refund
98
98
  end
@@ -103,10 +103,10 @@ module Recurly
103
103
  # refundable.
104
104
  # @raise [Error] If the refund fails.
105
105
  # @param amount_in_cents [Integer, nil] The amount (in cents) to refund.
106
- def refund_amount amount_in_cents = nil
106
+ def refund_amount amount_in_cents = nil, refund_apply_order = 'credit'
107
107
  return false unless link? :refund
108
108
  refund = self.class.from_response(
109
- follow_link :refund, :body => refund_amount_to_xml(amount_in_cents)
109
+ follow_link :refund, :body => refund_amount_to_xml(amount_in_cents, refund_apply_order)
110
110
  )
111
111
  refund
112
112
  end
@@ -121,14 +121,17 @@ module Recurly
121
121
  super({ :currency => Recurly.default_currency }.merge attributes)
122
122
  end
123
123
 
124
- def refund_amount_to_xml amount_in_cents=nil
124
+ def refund_amount_to_xml amount_in_cents = nil, refund_apply_order
125
125
  builder = XML.new("<invoice/>")
126
+ builder.add_element 'refund_apply_order', refund_apply_order
126
127
  builder.add_element 'amount_in_cents', amount_in_cents
127
128
  builder.to_s
128
129
  end
129
130
 
130
- def refund_line_items_to_xml line_items = []
131
+ def refund_line_items_to_xml line_items = [], refund_apply_order
131
132
  builder = XML.new("<invoice/>")
133
+ builder.add_element 'refund_apply_order', refund_apply_order
134
+
132
135
  node = builder.add_element 'line_items'
133
136
  line_items.each do |line_item|
134
137
  adj_node = node.add_element 'adjustment'
data/lib/recurly/js.rb CHANGED
@@ -18,6 +18,10 @@ module Recurly
18
18
  # @return [String] A private key for Recurly.js.
19
19
  # @raise [ConfigurationError] No private key has been set.
20
20
  def private_key
21
+ if Thread.current[:recurly_config] && Thread.current[:recurly_config][:private_key]
22
+ return Thread.current[:recurly_config][:private_key]
23
+ end
24
+
21
25
  defined? @private_key and @private_key or raise(
22
26
  ConfigurationError, "private_key not configured"
23
27
  )
@@ -404,15 +404,15 @@ module Recurly
404
404
 
405
405
  if el.children.empty? && href = el.attribute('href')
406
406
  resource_class = Recurly.const_get(
407
- Helper.classify(association_class_name(el.name) ||
407
+ Helper.classify(klass.association_class_name(el.name) ||
408
408
  el.attribute('type') || el.name), false
409
409
  )
410
410
  case el.name
411
- when *associations_for_relation(:has_many)
411
+ when *klass.associations_for_relation(:has_many)
412
412
  record[el.name] = Pager.new(
413
413
  resource_class, :uri => href.value, :parent => record
414
414
  )
415
- when *(associations_for_relation(:has_one) + associations_for_relation(:belongs_to))
415
+ when *(klass.associations_for_relation(:has_one) + klass.associations_for_relation(:belongs_to))
416
416
  record.links[el.name] = {
417
417
  :resource_class => resource_class,
418
418
  :method => :get,
@@ -2,7 +2,7 @@ module Recurly
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 4
5
- PATCH = 3
5
+ PATCH = 4
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
data/lib/recurly.rb CHANGED
@@ -40,8 +40,19 @@ module Recurly
40
40
  end
41
41
 
42
42
  class << self
43
+ # Set a config based on current thread context.
44
+ # Any default set will say in effect unless overwritten in the config_params.
45
+ # Call this method with out any arguments to have it unset the thread context config values.
46
+ # @param config_params - Hash with the following keys: subdomain, api_key, default_currency
47
+ def config(config_params = nil)
48
+ Thread.current[:recurly_config] = config_params
49
+ end
50
+
43
51
  # @return [String] A subdomain.
44
52
  def subdomain
53
+ if Thread.current[:recurly_config] && Thread.current[:recurly_config][:subdomain]
54
+ return Thread.current[:recurly_config][:subdomain]
55
+ end
45
56
  @subdomain || 'api'
46
57
  end
47
58
  attr_writer :subdomain
@@ -49,6 +60,10 @@ module Recurly
49
60
  # @return [String] An API key.
50
61
  # @raise [ConfigurationError] If not configured.
51
62
  def api_key
63
+ if Thread.current[:recurly_config] && Thread.current[:recurly_config][:api_key]
64
+ return Thread.current[:recurly_config][:api_key]
65
+ end
66
+
52
67
  defined? @api_key and @api_key or raise(
53
68
  ConfigurationError, "Recurly.api_key not configured"
54
69
  )
@@ -57,7 +72,11 @@ module Recurly
57
72
 
58
73
  # @return [String, nil] A default currency.
59
74
  def default_currency
60
- return @default_currency if defined? @default_currency
75
+ if Thread.current[:recurly_config] && Thread.current[:recurly_config][:default_currency]
76
+ return Thread.current[:recurly_config][:default_currency]
77
+ end
78
+
79
+ return @default_currency if defined? @default_currency
61
80
  @default_currency = 'USD'
62
81
  end
63
82
  attr_writer :default_currency
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Recurly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 2.4.3
121
+ rubygems_version: 2.4.6
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: Recurly API Client