Module: Hub::GitHubAPI::HttpMethods::ResponseMethods

Defined in:
lib/hub/github_api.rb

Overview

Decorator for Net::HTTPResponse

Instance Method Summary collapse

Instance Method Details

#dataObject



125
# File 'lib/hub/github_api.rb', line 125

def data() @data ||= JSON.parse(body) end

#data?Boolean

Returns:

  • (Boolean)


124
# File 'lib/hub/github_api.rb', line 124

def data?() content_type =~ /\bjson\b/ end

#error_messageObject



127
# File 'lib/hub/github_api.rb', line 127

def error_message() error_sentences || data['message'] end

#error_message?Boolean

Returns:

  • (Boolean)


126
# File 'lib/hub/github_api.rb', line 126

def error_message?() data? and data['errors'] || data['message'] end

#error_sentencesObject



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/hub/github_api.rb', line 129

def error_sentences
  data['errors'].map do |err|
    case err['code']
    when 'custom'        then err['message']
    when 'missing_field'
      %(Missing field: "%s") % err['field']
    when 'invalid'
      %(Invalid value for "%s": "%s") % [ err['field'], err['value'] ]
    when 'unauthorized'
      %(Not allowed to change field "%s") % err['field']
    end
  end.compact if data['errors']
end

#statusObject



123
# File 'lib/hub/github_api.rb', line 123

def status() code.to_i end

#success?Boolean

Returns:

  • (Boolean)


128
# File 'lib/hub/github_api.rb', line 128

def success?() Net::HTTPSuccess === self end