Module: GithubPivotalFlow::GitHubAPI::HttpMethods::ResponseMethods

Defined in:
lib/github_pivotal_flow/github_api.rb

Overview

Decorator for Net::HTTPResponse

Instance Method Summary collapse

Instance Method Details

#dataObject



72
# File 'lib/github_pivotal_flow/github_api.rb', line 72

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

#data?Boolean

Returns:

  • (Boolean)


71
# File 'lib/github_pivotal_flow/github_api.rb', line 71

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

#error_messageObject



74
# File 'lib/github_pivotal_flow/github_api.rb', line 74

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

#error_message?Boolean

Returns:

  • (Boolean)


73
# File 'lib/github_pivotal_flow/github_api.rb', line 73

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

#error_sentencesObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/github_pivotal_flow/github_api.rb', line 76

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



70
# File 'lib/github_pivotal_flow/github_api.rb', line 70

def status() code.to_i end

#success?Boolean

Returns:

  • (Boolean)


75
# File 'lib/github_pivotal_flow/github_api.rb', line 75

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