Class: Github::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/github/client.rb

Constant Summary collapse

SUCCESS_CODES =
[200, 201]
FAILURE_CODES =
[400, 401, 422]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



61
62
63
# File 'lib/github/client.rb', line 61

def initialize(response)
  @response = response
end

Class Method Details

.can_handle?(response) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/github/client.rb', line 65

def self.can_handle?(response)
  (SUCCESS_CODES + FAILURE_CODES).include?(response.code)
end

Instance Method Details

#dataObject



101
102
103
# File 'lib/github/client.rb', line 101

def data
  parsed_response
end

#error?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/github/client.rb', line 77

def error?
  when_statuses_are *FAILURE_CODES
end

#error_messageObject



81
82
83
# File 'lib/github/client.rb', line 81

def error_message
  parsed_response["message"]
end

#errorsObject



85
86
87
# File 'lib/github/client.rb', line 85

def errors
  parsed_response["errors"].map { |hash| EntityError.new(hash) }
end

#locationObject



97
98
99
# File 'lib/github/client.rb', line 97

def location
  @response.headers[:location]
end

#rate_limitObject



89
90
91
# File 'lib/github/client.rb', line 89

def rate_limit
  @response.headers[:x_ratelimit_limit].to_i
end

#rate_limit_remainingObject



93
94
95
# File 'lib/github/client.rb', line 93

def rate_limit_remaining
  @response.headers[:x_ratelimit_remaining].to_i
end

#success?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/github/client.rb', line 73

def success?
  when_statuses_are *SUCCESS_CODES
end

#to_sObject



69
70
71
# File 'lib/github/client.rb', line 69

def to_s
  "#{@response.description.strip} | Rate limit: #{rate_limit_remaining} / #{rate_limit_remaining}"
end