Sha256: dc6895d0703e4fb74179ddaeea9c1fc5c389c9a6051fa478dc1bfc1dc1baf6a8
Contents?: true
Size: 1.47 KB
Versions: 16
Compression:
Stored size: 1.47 KB
Contents
require_relative 'utils' class Fanforce class Error < StandardError; include ::Fanforce::Utils attr_accessor :path, :query_params, :request, :response, :request_url def initialize(response, request, path, query_params) @query_params = query_params @path = path @request = request begin @response = MultiJson.load(response, :symbolize_keys => true) rescue Exception => e @response = "JSON decode error in Gem: #{e.message}" end @request_url = "#{@path}?#{to_param(@query_params)}" super(@response.is_a?(Hash) ? @response[:msg] : @response) end def curl_command case @request.method when :get "curl \"#{@path}?#{to_param(@query_params)}\"" when :post "curl -X POST -d \"#{to_param(@query_params)}\" #{@path}" when :put "curl -X PUT -d \"#{to_param(@query_params)}\" #{@path.to_json}" when :delete "curl --request DELETE \"#{@path}?#{to_param(@query_params)}\"" else "Could not create curl command because request method was unknown: #{@request.method}" end end def code() end end class BadRequestError < Error; def code() 400 end end class ForbiddenError < Error; def code() 403 end end class NotFoundError < Error; def code() 404 end end class UnprocessableEntityError < Error; def code() 422 end end class UnknownError < Error; def code() 500 end end end
Version data entries
16 entries across 16 versions & 1 rubygems