recurly 2.3.11 → 2.4.0
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 +5 -5
- data/README.md +1 -1
- data/lib/recurly.rb +0 -18
- data/lib/recurly/api.rb +0 -8
- data/lib/recurly/api/net_http_adapter.rb +0 -1
- data/lib/recurly/invoice.rb +2 -0
- data/lib/recurly/resource.rb +51 -25
- data/lib/recurly/resource/association.rb +16 -0
- data/lib/recurly/version.rb +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39d29efdd5130af37d30fed7585a480ddd295dcb
|
4
|
+
data.tar.gz: 6d5f1620ff648319c552eb70249b39e8dd6cd678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8fc77aced05652c1691ba483954b35fcfe4e8052286469ee3b641d02b5e5de3fc2bbbb2c71969fd65991f1bdbd135bdbe8f123cb8383ff02ac1f58e5d51b869
|
7
|
+
data.tar.gz: 25f9aa18dc272ef1befb71692e0807e0f81f8f95b9a9265308dc058b6a7f473f93c159e99eb55f40f722e1d43c28de26640b9c6dc8a7737c3870671545bd5da2
|
data/README.md
CHANGED
@@ -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.
|
15
|
+
gem 'recurly', '~> 2.4.0'
|
16
16
|
```
|
17
17
|
|
18
18
|
Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
|
data/lib/recurly.rb
CHANGED
@@ -68,8 +68,6 @@ module Recurly
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Assigns a logger to log requests/responses and more.
|
71
|
-
# The logger can only be set if the environment variable
|
72
|
-
# `RECURLY_INSECURE_DEBUG` equals `true`.
|
73
71
|
#
|
74
72
|
# @return [Logger, nil]
|
75
73
|
# @example
|
@@ -81,22 +79,6 @@ module Recurly
|
|
81
79
|
# Recurly.logger = nil # Or Recurly.logger = Logger.new nil
|
82
80
|
attr_accessor :logger
|
83
81
|
|
84
|
-
def logger=(logger)
|
85
|
-
if ENV['RECURLY_INSECURE_DEBUG'].to_s.downcase == 'true'
|
86
|
-
@logger = logger
|
87
|
-
puts <<-MSG
|
88
|
-
[WARNING] Recurly logger enabled. The logger has the potential to leak
|
89
|
-
PII and should never be used in production environments.
|
90
|
-
MSG
|
91
|
-
else
|
92
|
-
puts <<-MSG
|
93
|
-
[WARNING] Recurly logger has been disabled. If you wish to use it,
|
94
|
-
only do so in a non-production environment and make sure
|
95
|
-
the `RECURLY_INSECURE_DEBUG` environment variable is set to `true`.
|
96
|
-
MSG
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
82
|
# Convenience logging method includes a Logger#progname dynamically.
|
101
83
|
# @return [true, nil]
|
102
84
|
def log level, message
|
data/lib/recurly/api.rb
CHANGED
@@ -15,7 +15,6 @@ module Recurly
|
|
15
15
|
require 'recurly/api/errors'
|
16
16
|
|
17
17
|
@@base_uri = "https://api.recurly.com/v2/"
|
18
|
-
@@valid_domains = [".recurly.com"]
|
19
18
|
|
20
19
|
FORMATS = Helper.hash_with_indifferent_read_access(
|
21
20
|
'pdf' => 'application/pdf',
|
@@ -74,13 +73,6 @@ module Recurly
|
|
74
73
|
URI.parse @@base_uri.sub('api', Recurly.subdomain)
|
75
74
|
end
|
76
75
|
|
77
|
-
def validate_uri!(uri)
|
78
|
-
domain = @@valid_domains.detect { |d| uri.host.end_with?(d) }
|
79
|
-
unless domain
|
80
|
-
raise ArgumentError, "URI #{uri} is invalid. You may only make requests to a Recurly domain."
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
76
|
# @return [String]
|
85
77
|
def user_agent
|
86
78
|
"Recurly/#{Version}; #{RUBY_DESCRIPTION}"
|
data/lib/recurly/invoice.rb
CHANGED
data/lib/recurly/resource.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'erb'
|
3
|
+
require 'recurly/resource/association'
|
3
4
|
|
4
5
|
module Recurly
|
5
6
|
# The base class for all Recurly resources (e.g. {Account}, {Subscription},
|
@@ -321,8 +322,9 @@ module Recurly
|
|
321
322
|
raise NotFound, "can't find a record with nil identifier"
|
322
323
|
end
|
323
324
|
|
325
|
+
uri = uuid =~ /^http/ ? uuid : member_path(uuid)
|
324
326
|
begin
|
325
|
-
from_response API.get(
|
327
|
+
from_response API.get(uri, {}, options)
|
326
328
|
rescue API::NotFound => e
|
327
329
|
raise NotFound, e.description
|
328
330
|
end
|
@@ -403,14 +405,15 @@ module Recurly
|
|
403
405
|
|
404
406
|
if el.children.empty? && href = el.attribute('href')
|
405
407
|
resource_class = Recurly.const_get(
|
406
|
-
Helper.classify(
|
408
|
+
Helper.classify(association_class_name(el.name) ||
|
409
|
+
el.attribute('type') || el.name), false
|
407
410
|
)
|
408
411
|
case el.name
|
409
|
-
when *
|
412
|
+
when *associations_for_relation(:has_many)
|
410
413
|
record[el.name] = Pager.new(
|
411
414
|
resource_class, :uri => href.value, :parent => record
|
412
415
|
)
|
413
|
-
when *(
|
416
|
+
when *(associations_for_relation(:has_one) + associations_for_relation(:belongs_to))
|
414
417
|
record.links[el.name] = {
|
415
418
|
:resource_class => resource_class,
|
416
419
|
:method => :get,
|
@@ -431,11 +434,29 @@ module Recurly
|
|
431
434
|
record
|
432
435
|
end
|
433
436
|
|
434
|
-
# @return [
|
437
|
+
# @return [Array] A list of associations for the current class.
|
435
438
|
def associations
|
436
|
-
@associations ||=
|
437
|
-
|
438
|
-
|
439
|
+
@associations ||= []
|
440
|
+
end
|
441
|
+
|
442
|
+
# @return [Array] A list of associated resource classes with
|
443
|
+
# the relation [:has_many, :has_one, :belongs_to] for the current class.
|
444
|
+
def associations_for_relation(relation)
|
445
|
+
associations.select{ |a| a.relation == relation }.map(&:resource_class)
|
446
|
+
end
|
447
|
+
|
448
|
+
# @return [String, nil] The actual associated resource class name
|
449
|
+
# for the current class if the resource class does not match the
|
450
|
+
# actual class.
|
451
|
+
def association_class_name(resource_class)
|
452
|
+
association = find_association(resource_class)
|
453
|
+
association.class_name if association
|
454
|
+
end
|
455
|
+
|
456
|
+
# @return [Association, nil] Find association for the current class
|
457
|
+
# with resource class name.
|
458
|
+
def find_association(resource_class)
|
459
|
+
associations.find{ |a| a.resource_class == resource_class }
|
439
460
|
end
|
440
461
|
|
441
462
|
def associations_helper
|
@@ -448,8 +469,10 @@ module Recurly
|
|
448
469
|
# @param collection_name [Symbol] Association name.
|
449
470
|
# @param options [Hash] A hash of association options.
|
450
471
|
# @option options [true, false] :readonly Don't define a setter.
|
472
|
+
# [String] :class_name Actual associated resource class name
|
473
|
+
# if not same as collection_name.
|
451
474
|
def has_many collection_name, options = {}
|
452
|
-
associations
|
475
|
+
associations << Association.new(:has_many, collection_name.to_s, options)
|
453
476
|
associations_helper.module_eval do
|
454
477
|
define_method collection_name do
|
455
478
|
self[collection_name] ||= []
|
@@ -468,8 +491,10 @@ module Recurly
|
|
468
491
|
# @param member_name [Symbol] Association name.
|
469
492
|
# @param options [Hash] A hash of association options.
|
470
493
|
# @option options [true, false] :readonly Don't define a setter.
|
494
|
+
# [String] :class_name Actual associated resource class name
|
495
|
+
# if not same as member_name.
|
471
496
|
def has_one member_name, options = {}
|
472
|
-
associations
|
497
|
+
associations << Association.new(:has_one, member_name.to_s, options)
|
473
498
|
associations_helper.module_eval do
|
474
499
|
define_method(member_name) { self[member_name] }
|
475
500
|
if options.key?(:readonly) && options[:readonly] == false
|
@@ -501,8 +526,13 @@ module Recurly
|
|
501
526
|
# Establishes a belongs_to association.
|
502
527
|
#
|
503
528
|
# @return [Proc]
|
529
|
+
# @param parent_name [Symbol] Association name.
|
530
|
+
# @param options [Hash] A hash of association options.
|
531
|
+
# @option options [true, false] :readonly Don't define a setter.
|
532
|
+
# [String] :class_name Actual associated resource class name
|
533
|
+
# if not same as parent_name.
|
504
534
|
def belongs_to parent_name, options = {}
|
505
|
-
associations
|
535
|
+
associations << Association.new(:belongs_to, parent_name.to_s, options)
|
506
536
|
associations_helper.module_eval do
|
507
537
|
define_method(parent_name) { self[parent_name] }
|
508
538
|
if options.key?(:readonly) && options[:readonly] == false
|
@@ -515,7 +545,8 @@ module Recurly
|
|
515
545
|
|
516
546
|
# @return [:has_many, :has_one, :belongs_to, nil] An association type.
|
517
547
|
def reflect_on_association name
|
518
|
-
a =
|
548
|
+
a = find_association name.to_s
|
549
|
+
a.relation if a
|
519
550
|
end
|
520
551
|
|
521
552
|
def embedded! root_index = false
|
@@ -559,12 +590,9 @@ module Recurly
|
|
559
590
|
return if response.body.to_s.length.zero?
|
560
591
|
fresh = self.class.from_response response
|
561
592
|
else
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
else
|
566
|
-
self.class.find(to_param, options)
|
567
|
-
end
|
593
|
+
fresh = self.class.find(
|
594
|
+
@href || to_param, :etag => (etag unless changed?)
|
595
|
+
)
|
568
596
|
end
|
569
597
|
fresh and copy_from fresh
|
570
598
|
persist! true
|
@@ -663,7 +691,7 @@ module Recurly
|
|
663
691
|
changed_attributes[key] = self[key]
|
664
692
|
end
|
665
693
|
|
666
|
-
if self.class.
|
694
|
+
if self.class.find_association key
|
667
695
|
value = fetch_association key, value
|
668
696
|
# FIXME: More explicit; less magic.
|
669
697
|
elsif value && key.end_with?('_in_cents') && !respond_to?(:currency)
|
@@ -960,12 +988,10 @@ module Recurly
|
|
960
988
|
|
961
989
|
def clear_errors
|
962
990
|
errors.clear
|
963
|
-
self.class.associations
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
associated.clear_errors if associated.respond_to? :clear_errors
|
968
|
-
end
|
991
|
+
self.class.associations do |association|
|
992
|
+
next unless respond_to? "#{association}=" # Clear writable only.
|
993
|
+
[*self[association]].each do |associated|
|
994
|
+
associated.clear_errors if associated.respond_to? :clear_errors
|
969
995
|
end
|
970
996
|
end
|
971
997
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Recurly
|
2
|
+
class Resource
|
3
|
+
class Association
|
4
|
+
attr_reader :relation, :resource_class
|
5
|
+
|
6
|
+
def initialize relation, resource_class, options = {}
|
7
|
+
@relation, @resource_class, @options = relation, resource_class, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def class_name
|
11
|
+
return @class_name if defined? @class_name
|
12
|
+
@class_name = @options[:class_name]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/recurly/version.rb
CHANGED
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
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Recurly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- lib/recurly/plan.rb
|
84
84
|
- lib/recurly/redemption.rb
|
85
85
|
- lib/recurly/resource.rb
|
86
|
+
- lib/recurly/resource/association.rb
|
86
87
|
- lib/recurly/resource/errors.rb
|
87
88
|
- lib/recurly/resource/pager.rb
|
88
89
|
- lib/recurly/subscription.rb
|
@@ -117,8 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
120
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.2.2
|
121
122
|
signing_key:
|
122
123
|
specification_version: 4
|
123
124
|
summary: Recurly API Client
|
124
125
|
test_files: []
|
126
|
+
has_rdoc: true
|