lib/tracker_api/client.rb in tracker_api-1.7.1 vs lib/tracker_api/client.rb in tracker_api-1.8.0

- old
+ new

@@ -46,46 +46,21 @@ @faraday_block.call(builder) if @faraday_block builder.adapter adapter end end - # Make a HTTP GET request + # HTTP requests methods # # @param path [String] The path, relative to api endpoint # @param options [Hash] Query and header params for request # @return [Faraday::Response] - def get(path, options = {}) - request(:get, parse_query_and_convenience_headers(path, options)) + %i{get post patch put delete}.each do |verb| + define_method verb do |path, options = {}| + request(verb, parse_query_and_convenience_headers(path, options)) + end end - # Make a HTTP POST request - # - # @param path [String] The path, relative to api endpoint - # @param options [Hash] Query and header params for request - # @return [Faraday::Response] - def post(path, options = {}) - request(:post, parse_query_and_convenience_headers(path, options)) - end - - # Make a HTTP PUT request - # - # @param path [String] The path, relative to api endpoint - # @param options [Hash] Query and header params for request - # @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} @@ -246,10 +221,14 @@ req.params.merge!(params) req.body = body end response rescue Faraday::Error::ClientError => e - raise TrackerApi::Error.new(e) + case e.response[:status] + 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" + end end class Pagination attr_accessor :headers, :total, :limit, :offset, :returned