Class: Unfuddle::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/unfuddle/response.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response) ⇒ Response

Returns a new instance of Response.



8
9
10
# File 'lib/unfuddle/response.rb', line 8

def initialize(faraday_response)
  @faraday_response = faraday_response
end

Class Method Details

.normalized_body(body) ⇒ Object



39
40
41
# File 'lib/unfuddle/response.rb', line 39

def self.normalized_body(body)
  body.gsub(/\u0000/, "").strip
end

Instance Method Details

#bodyObject



24
25
26
# File 'lib/unfuddle/response.rb', line 24

def body
  faraday_response.body
end

#jsonObject



32
33
34
35
36
37
# File 'lib/unfuddle/response.rb', line 32

def json
  @json ||= begin
    json = self.class.normalized_body(body)
    json.empty? ? {} : JSON.load(json)
  end
end

#locationObject



28
29
30
# File 'lib/unfuddle/response.rb', line 28

def location
  faraday_response["location"]
end

#server_error?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/unfuddle/response.rb', line 16

def server_error?
  status == 500
end

#statusObject



12
13
14
# File 'lib/unfuddle/response.rb', line 12

def status
  faraday_response.status
end

#unauthorized?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/unfuddle/response.rb', line 20

def unauthorized?
  status == 401
end