lib/tracker_api/client.rb in tracker_api-1.8.0 vs lib/tracker_api/client.rb in tracker_api-1.9.0
- old
+ new
@@ -34,11 +34,11 @@
@faraday_block = block if block_given?
@connection = Faraday.new({ url: @url }.merge(connection_options)) do |builder|
# response
builder.use Faraday::Response::RaiseError
- builder.response :json
+ builder.response :json, content_type: /\bjson/ # e.g., 'application/json; charset=utf-8'
# request
builder.request :multipart
builder.request :json
@@ -188,11 +188,12 @@
opts[:url] = options[:url] || File.join(@url, @api_version, path.to_s)
opts[:method] = options[:method] || :get
opts[:params] = options[:params] || {}
opts[:token] = options[:token] || @token
headers = { 'User-Agent' => USER_AGENT,
- 'X-TrackerToken' => opts.fetch(:token) }.merge(options.fetch(:headers, {}))
+ 'X-TrackerToken' => opts.fetch(:token),
+ 'Accept' => 'application/json' }.merge(options.fetch(:headers, {}))
CONVENIENCE_HEADERS.each do |h|
if header = options[h]
headers[h] = header
end
@@ -221,13 +222,14 @@
req.params.merge!(params)
req.body = body
end
response
rescue Faraday::Error::ClientError => e
- case e.response[:status]
+ status_code = e.response[:status]
+ case status_code
when 400..499 then raise TrackerApi::Errors::ClientError.new(e)
when 500..599 then raise TrackerApi::Errors::ServerError.new(e)
- else raise "Expected 4xx or 5xx HTTP status code"
+ else raise "Expected 4xx or 5xx HTTP status code; got #{status_code} instead."
end
end
class Pagination
attr_accessor :headers, :total, :limit, :offset, :returned