recurly 2.1.0 → 2.1.1

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.

@@ -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.1.0'
15
+ gem 'recurly', '~> 2.1.1'
16
16
  ```
17
17
 
18
18
  Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
@@ -16,9 +16,27 @@ module Recurly
16
16
 
17
17
  @@base_uri = "https://api.recurly.com/v2/"
18
18
 
19
+ FORMATS = Helper.hash_with_indifferent_read_access(
20
+ 'pdf' => 'application/pdf',
21
+ 'xml' => 'application/xml'
22
+ )
23
+
19
24
  class << self
20
- # @return [String]
21
- attr_accessor :accept_language
25
+ # Additional HTTP headers sent with each API call
26
+ # @return [Hash{String => String}]
27
+ def headers
28
+ @headers ||= { 'Accept' => accept, 'User-Agent' => user_agent }
29
+ end
30
+
31
+ # @return [String, nil] Accept-Language header value
32
+ def accept_language
33
+ headers['Accept-Language']
34
+ end
35
+
36
+ # @param [String] language Accept-Language header value
37
+ def accept_language=(language)
38
+ headers['Accept-Language'] = language
39
+ end
22
40
 
23
41
  # @return [Net::HTTPOK, Net::HTTPResponse]
24
42
  # @raise [ResponseError] With a non-2xx status code.
@@ -63,7 +81,7 @@ module Recurly
63
81
  private
64
82
 
65
83
  def accept
66
- 'application/xml'
84
+ FORMATS['xml']
67
85
  end
68
86
  alias content_type accept
69
87
  end
@@ -32,8 +32,7 @@ module Recurly
32
32
  }
33
33
 
34
34
  def request method, uri, options = {}
35
- head = { 'Accept' => accept, 'User-Agent' => user_agent }
36
- accept_language and head['Accept-Language'] ||= accept_language
35
+ head = headers.dup
37
36
  head.update options[:head] if options[:head]
38
37
  uri = base_uri + uri
39
38
  if options[:params] && !options[:params].empty?
@@ -42,9 +41,18 @@ module Recurly
42
41
  request = METHODS[method].new uri.request_uri, head
43
42
  request.basic_auth(*[Recurly.api_key, nil].flatten[0, 2])
44
43
  if options[:body]
45
- head['Content-Type'] = content_type
44
+ request['Content-Type'] = content_type
46
45
  request.body = options[:body]
47
46
  end
47
+ if options[:etag]
48
+ request['If-None-Match'] = options[:etag]
49
+ end
50
+ if options[:format]
51
+ request['Accept'] = FORMATS[options[:format]]
52
+ end
53
+ if options[:locale]
54
+ request['Accept-Language'] = options[:locale]
55
+ end
48
56
  http = ::Net::HTTP.new uri.host, uri.port
49
57
  http.use_ssl = uri.scheme == 'https'
50
58
  net_http.each_pair { |key, value| http.send "#{key}=", value }
@@ -32,6 +32,10 @@ module Recurly
32
32
  )
33
33
  alias to_param invoice_number
34
34
 
35
+ def pdf
36
+ find to_param, :format => 'pdf'
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def initialize attributes = {}
@@ -37,7 +37,9 @@ module Recurly
37
37
  ).gsub(/\W/, '')
38
38
  unsigned = to_query data
39
39
  signed = OpenSSL::HMAC.hexdigest 'sha1', private_key, unsigned
40
- [signed, unsigned].join '|'
40
+ signature = [signed, unsigned].join '|'
41
+ signature = signature.html_safe if signature.respond_to? :html_safe
42
+ signature
41
43
  end
42
44
 
43
45
  # Fetches a record using a token provided by Recurly.js.
@@ -314,14 +314,9 @@ module Recurly
314
314
  raise NotFound, "can't find a record with nil identifier"
315
315
  end
316
316
 
317
- request_options = {}
318
- if etag = options[:etag]
319
- request_options[:head] = { 'If-None-Match' => etag }
320
- end
321
-
322
317
  uri = uuid =~ /^http/ ? uuid : member_path(uuid)
323
318
  begin
324
- from_response API.get(uri, {}, request_options)
319
+ from_response API.get(uri, {}, options)
325
320
  rescue API::NotFound => e
326
321
  raise NotFound, e.description
327
322
  end
@@ -352,9 +347,14 @@ module Recurly
352
347
  # @return [Resource]
353
348
  # @param response [Net::HTTPResponse]
354
349
  def from_response response
355
- record = from_xml response.body
356
- record.instance_eval { @etag, @response = response['ETag'], response }
357
- record
350
+ case response['Content-Type']
351
+ when %r{application/pdf}
352
+ response.body
353
+ else # when %r{application/xml}
354
+ record = from_xml response.body
355
+ record.instance_eval { @etag, @response = response['ETag'], response }
356
+ record
357
+ end
358
358
  end
359
359
 
360
360
  # Instantiates a record from an XML blob: either a String or XML element.
@@ -370,12 +370,15 @@ module Recurly
370
370
  if xml.name == member_name
371
371
  record = new
372
372
  elsif Recurly.const_defined?(class_name = Helper.classify(xml.name))
373
- record = Recurly.const_get(class_name).send :new
373
+ klass = Recurly.const_get class_name
374
+ record = klass.send :new
374
375
  elsif root = xml.root and root.elements.empty?
375
376
  return XML.cast root
376
377
  else
377
378
  record = {}
378
379
  end
380
+ klass ||= self
381
+ associations = klass.associations
379
382
 
380
383
  xml.root.attributes.each do |name, value|
381
384
  record.instance_variable_set "@#{name}", value.to_s
@@ -2,7 +2,7 @@ module Recurly
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-12 00:00:00.000000000 Z
12
+ date: 2012-04-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70249525629500 !ruby/object:Gem::Requirement
16
+ requirement: &70288709160800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70249525629500
24
+ version_requirements: *70288709160800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: minitest
27
- requirement: &70249525628300 !ruby/object:Gem::Requirement
27
+ requirement: &70288709158920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.6.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70249525628300
35
+ version_requirements: *70288709158920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: webmock
38
- requirement: &70249525627820 !ruby/object:Gem::Requirement
38
+ requirement: &70288709156520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.7.6
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70249525627820
46
+ version_requirements: *70288709156520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-minitest
49
- requirement: &70249525627320 !ruby/object:Gem::Requirement
49
+ requirement: &70288709153760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.4.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70249525627320
57
+ version_requirements: *70288709153760
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rb-fsevent
60
- requirement: &70249525626760 !ruby/object:Gem::Requirement
60
+ requirement: &70288709148540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.4.3.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70249525626760
68
+ version_requirements: *70288709148540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: growl_notify
71
- requirement: &70249525626280 !ruby/object:Gem::Requirement
71
+ requirement: &70288709147340 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 0.0.1
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70249525626280
79
+ version_requirements: *70288709147340
80
80
  description: ! 'An API client library for Recurly: http://recurly.com'
81
81
  email: support@recurly.com
82
82
  executables:
@@ -114,8 +114,7 @@ files:
114
114
  - lib/recurly/xml.rb
115
115
  - lib/recurly.rb
116
116
  - README.markdown
117
- - !binary |-
118
- YmluL3JlY3VybHk=
117
+ - bin/recurly
119
118
  homepage: http://github.com/recurly/recurly-client-ruby
120
119
  licenses:
121
120
  - MIT
@@ -139,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
138
  version: '0'
140
139
  requirements: []
141
140
  rubyforge_project:
142
- rubygems_version: 1.8.11
141
+ rubygems_version: 1.8.10
143
142
  signing_key:
144
143
  specification_version: 3
145
144
  summary: Recurly API Client