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.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/skylight/util/http.rb', line 166

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.



164
165
166
# File 'lib/skylight/util/http.rb', line 164

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.



164
165
166
# File 'lib/skylight/util/http.rb', line 164

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.



164
165
166
# File 'lib/skylight/util/http.rb', line 164

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.



164
165
166
# File 'lib/skylight/util/http.rb', line 164

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.



189
190
191
# File 'lib/skylight/util/http.rb', line 189

def get(key)
  body.dig(*key.split(".")) if body.is_a?(Hash)
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)


181
182
183
# File 'lib/skylight/util/http.rb', line 181

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.



185
186
187
# File 'lib/skylight/util/http.rb', line 185

def to_s
  body.to_s
end