Class: Skylight::Util::HTTP::Response Private

Inherits:
Object
  • Object
show all
Defined in:
lib/skylight/util/http.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, headers, body) ⇒ Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Response.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/skylight/util/http.rb', line 160

def initialize(status, headers, body)
  @status  = status
  @headers = headers

  if (headers[CONTENT_TYPE] || "").include?(APPLICATION_JSON)
    begin
      @body = JSON.parse(body)
    rescue JSON::ParserError
      @body = body # not really JSON I guess
    end
  else
    @body = body
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



197
198
199
200
201
202
203
# File 'lib/skylight/util/http.rb', line 197

def method_missing(name, *args, &blk)
  if respond_to_missing?(name)
    body.send(name, *args, &blk)
  else
    super
  end
end

Instance Attribute Details

#bodyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/skylight/util/http.rb', line 158

def body
  @body
end

#exceptionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/skylight/util/http.rb', line 158

def exception
  @exception
end

#headersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/skylight/util/http.rb', line 158

def headers
  @headers
end

#statusObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/skylight/util/http.rb', line 158

def status
  @status
end

Instance Method Details

#get(key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



183
184
185
186
187
188
189
190
191
# File 'lib/skylight/util/http.rb', line 183

def get(key)
  return nil unless Hash === body

  res = body
  key.split('.').each do |part|
    return unless res = res[part]
  end
  res
end

#respond_to_missing?(name, include_all = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


193
194
195
# File 'lib/skylight/util/http.rb', line 193

def respond_to_missing?(name, include_all=false)
  super || body.respond_to?(name, include_all)
end

#success?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


175
176
177
# File 'lib/skylight/util/http.rb', line 175

def success?
  status >= 200 && status < 300
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



179
180
181
# File 'lib/skylight/util/http.rb', line 179

def to_s
  body.to_s
end