Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Expose API headers

Allows callers to globally set custom headers on Recurly API calls.
  • Loading branch information...
commit 0a9c73e8cd1376dec6174eb504713512b41ca6d5 1 parent 31b81ce
Dave Lee authored
Showing with 16 additions and 4 deletions.
  1. +15 −2 lib/recurly/api.rb
  2. +1 −2  lib/recurly/api/net_http_adapter.rb
View
17 lib/recurly/api.rb
@@ -22,8 +22,21 @@ class API
)
class << self
- # @return [String]
- attr_accessor :accept_language
+ # Additional HTTP headers sent with each API call
+ # @return [Hash{String => String}]
+ def headers
+ @headers ||= { 'Accept' => accept, 'User-Agent' => user_agent }
+ end
+
+ # @return [String, nil] Accept-Language header value
+ def accept_language
+ headers['Accept-Language']
+ end
+
+ # @param [String] language Accept-Language header value
+ def accept_language=(language)
+ headers['Accept-Language'] = language
+ end
# @return [Net::HTTPOK, Net::HTTPResponse]
# @raise [ResponseError] With a non-2xx status code.
View
3  lib/recurly/api/net_http_adapter.rb
@@ -32,8 +32,7 @@ def net_http
}
def request method, uri, options = {}
- head = { 'Accept' => accept, 'User-Agent' => user_agent }
- accept_language and head['Accept-Language'] ||= accept_language
+ head = headers.dup
head.update options[:head] if options[:head]
uri = base_uri + uri
if options[:params] && !options[:params].empty?
Please sign in to comment.
Something went wrong with that request. Please try again.