class Kongkit::Client::Resource

Attributes

client[R]
data[R]
status_code[R]

Public Class Methods

new(client, data, status_code) click to toggle source
# File lib/kongkit/client/resource.rb, line 6
def initialize(client, data, status_code)
  @client      = client
  @data        = data
  @status_code = status_code
end

Public Instance Methods

[](key) click to toggle source

Allow fields to be retrieved via Hash notation

@param key [Symbol] A symbol key @return [Object] from data if exists

# File lib/kongkit/client/resource.rb, line 16
def [](key)
  data[key]
rescue NoMethodError
  nil
end
each(&block) click to toggle source

Calls block once for each key in the data hash, passing the key-value pair as parameters

@return [Enumerator] Enumerator

# File lib/kongkit/client/resource.rb, line 25
def each(&block)
  data.each(&block)
end
error?() click to toggle source

Returns true if there is any error

@return [Boolean] `true` if the response was an error

# File lib/kongkit/client/resource.rb, line 47
def error?
  status_code >= 400
end
inspect() click to toggle source

Returns a string containing a human-readable representation of this object

@return [String] human-readable representation of this object

# File lib/kongkit/client/resource.rb, line 40
def inspect
  data.inspect
end
next() click to toggle source

Retrieves the next resource

@return [Kongkit::Client::Resource] Resource

# File lib/kongkit/client/resource.rb, line 32
def next
  return nil if data[:next].nil?
  client.get(data[:next])
end
to_json() click to toggle source

Return the JSON representation of the resource

@return [Hash] JSON representation

# File lib/kongkit/client/resource.rb, line 54
def to_json
  data.merge({status_code: status_code}).to_json
end