Class: GitMarkdown::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/git/markdown/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



8
9
10
# File 'lib/git/markdown/api/response.rb', line 8

def initialize(response)
  @raw_response = response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



6
7
8
# File 'lib/git/markdown/api/response.rb', line 6

def raw_response
  @raw_response
end

Instance Method Details

#dataObject



24
25
26
27
28
29
30
# File 'lib/git/markdown/api/response.rb', line 24

def data
  return nil unless @raw_response.body

  JSON.parse(@raw_response.body)
rescue JSON::ParserError
  nil
end

#error_messageObject



32
33
34
35
36
37
38
39
40
# File 'lib/git/markdown/api/response.rb', line 32

def error_message
  return nil if success?

  if data && data["message"]
    data["message"]
  else
    "HTTP #{@raw_response.code}: #{@raw_response.message}"
  end
end

#not_found?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/git/markdown/api/response.rb', line 16

def not_found?
  @raw_response.is_a?(Net::HTTPNotFound)
end

#success?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/git/markdown/api/response.rb', line 12

def success?
  @raw_response.is_a?(Net::HTTPSuccess)
end

#unauthorized?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/git/markdown/api/response.rb', line 20

def unauthorized?
  @raw_response.is_a?(Net::HTTPUnauthorized)
end