class AxTrack::Resource
Constants
- ApiError
- ApiRequestsQuotaReachedError
- BadRequestError
- ForbiddenError
- GithubAPIError
- HTTP_BAD_REQUEST_CODE
- HTTP_FORBIDDEN_CODE
- HTTP_NOT_FOUND_CODE
- HTTP_OK_CODE
- HTTP_UNAUTHORIZED_CODE
- HTTP_UNPROCESSABLE_ENTITY_CODE
- NotFoundError
- UnprocessableEntityError
Attributes
client[R]
response[R]
Public Class Methods
new(client)
click to toggle source
# File lib/ax_track/resource.rb, line 23 def initialize(client) @client = client @response = nil end
Public Instance Methods
error_class(status)
click to toggle source
# File lib/ax_track/resource.rb, line 40 def error_class(status) case status when HTTP_BAD_REQUEST_CODE BadRequestError when HTTP_UNAUTHORIZED_CODE UnauthorizedError when HTTP_FORBIDDEN_CODE ForbiddenError when HTTP_NOT_FOUND_CODE NotFoundError when HTTP_UNPROCESSABLE_ENTITY_CODE UnprocessableEntityError else ApiError end end
request(http_method: :get, endpoint:, headers: {}, params: {}, body: {}, result_subset: nil)
click to toggle source
# File lib/ax_track/resource.rb, line 28 def request(http_method: :get, endpoint:, headers: {}, params: {}, body: {}, result_subset: nil) raise "Client not defined" unless defined? @client endpoint = endpoint + "/" unless endpoint[-1] == "/" @response = client.connection.public_send(http_method, endpoint, params.merge(body)) unless response_successful? raise error_class(response.status), "Code: #{response.status}, response: #{response.reason_phrase}" end result_subset ? response[result_subset.to_s] : response end
response_successful?()
click to toggle source
# File lib/ax_track/resource.rb, line 57 def response_successful? response.status == HTTP_OK_CODE end