lib/adp_client.rb in adp_client-0.1.0 vs lib/adp_client.rb in adp_client-1.0.0

- old
+ new

@@ -118,25 +118,52 @@ *response.values_at('access_token', 'token_type', 'expires_in', 'scope') ) end ## - # Get a resource - # Makes a request for a resource from ADP and returns the response as a - # raw {Hash}. + # Make a delete request. + # Makes a request to delete an existing resource from ADP. # # @param [String] the resource endpoint - # @return [Hash] response data + # @return [HTTParty::Response] the response + def delete(resource) + headers = base_headers.merge('Content-Type' => 'application/json') + url = "#{@base_url}/#{resource}" + + @logger.debug("DELETE request Url: #{url}") + @logger.debug("-- Headers: #{headers}") + + x = HTTParty.delete(url, headers: headers) + puts x.inspect + x + end + + ## + # Make a get request + # Makes a request for a resource from ADP and returns the full response. + # + # @param [String] the resource endpoint + # @return [HTTParty::Response] the response def get(resource) url = "#{@base_url}/#{resource}" @logger.debug("GET request Url: #{url}") @logger.debug("-- Headers: #{base_headers}") + HTTParty.get(url, headers: base_headers) + end + + ## + # Get a resource + # Makes a request for a resource from ADP and returns the response as a + # raw {Hash}. + # + # @param [String] the resource endpoint + # @return [Hash] response data + def get_resource(resource) raises_unless_success do - HTTParty - .get(url, headers: base_headers) + get(resource) end.parsed_response end ## # Post a resource @@ -144,11 +171,11 @@ # response as a raw {Hash}. # # @param [String] the resource endpoint # @param [Hash] the resource data # @return [Hash] response data - def post(resource, data) + def post_resource(resource, data) headers = base_headers .merge('Content-Type' => 'application/json') url = "#{@base_url}/#{resource}" @logger.debug("POST request Url: #{url}") @@ -230,13 +257,13 @@ end class InvalidRequestHandler < BaseErrorHandler def error InvalidRequest.new( - format('%s: %s', - @httparty.parsed_response['error'], - @httparty.parsed_response['error_description']) + format('%<error>s: %<description>s', + error: @httparty.parsed_response['error'], + description: @httparty.parsed_response['error_description']) ) end def fail? @httparty.parsed_response['error'] == 'invalid_request' && @@ -263,12 +290,12 @@ end class UnauthorizedHandler < BaseErrorHandler def error Unauthorized.new( - format('%s: %s', - @httparty.parsed_response['error'], - @httparty.parsed_response['error_description']) + format('%<error>s: %<description>s', + error: @httparty.parsed_response['error'], + description: @httparty.parsed_response['error_description']) ) end def fail? @httparty.code == 401