tracker_api/lib/tracker_api/client.rb in v2gpti-1.2.3 vs tracker_api/lib/tracker_api/client.rb in v2gpti-1.2.4

- old
+ new

@@ -70,10 +70,19 @@ # @return [Faraday::Response] def put(path, options = {}) request(:put, parse_query_and_convenience_headers(path, options)) end + # Make a HTTP DELETE request + # + # @param path [String] The path, relative to api endpoint + # @param options [Hash] Query and header params for request + # @return [Faraday::Response] + def delete(path, options = {}) + request(:delete, parse_query_and_convenience_headers(path, options)) + end + # Make one or more HTTP GET requests, optionally fetching # the next page of results from information passed back in headers # based on value in {#auto_paginate}. # # @param path [String] The path, relative to {#api_endpoint} @@ -191,18 +200,28 @@ headers['Content-Type'] = 'application/json' params = {} end - @last_response = response = connection.send(method) do |req| - req.url(url) - req.headers.merge!(headers) - req.params.merge!(params) - req.body = body + response = nil + sleep 0.5 # Per PT we might be hitting their API too frequently. So adding a 0.5 Sec pause. + begin + tries ||= 3 + @last_response = response = connection.send(method) do |req| + req.url(url) + req.headers.merge!(headers) + req.params.merge!(params) + req.body = body + end + response + + rescue Faraday::Error::ClientError => e + if e.response[:status].between?(500, 520) # retry calling the api if the response is any of 500 errors + sleep 1 + retry unless (tries -= 1).zero? + end + raise TrackerApi::Error.new(e) end - response - rescue Faraday::Error::ClientError => e - raise TrackerApi::Error.new(e) end class Pagination attr_accessor :headers, :total, :limit, :offset, :returned