class Fluxx::Resource

Base endpoint resources class

Constants

PAGINATION_FIELDS

Public Class Methods

endpoint(value = nil) click to toggle source

Defines the client endpoint, thread-safe

@param value [String] the endpoint URI. @return [String]

Calls superclass method
# File lib/fluxx/resource.rb, line 24
def self.endpoint(value = nil)
  return super(value) unless value.nil?

  Thread.current.thread_variable_get(:FLUXX_INSTANCE_URL) || super
end
objectify(payload) click to toggle source

Resource constructor wrapper

@param payload [Hash] response payload to build a resource. @return [Object] instance or a list of instances.

Calls superclass method
# File lib/fluxx/resource.rb, line 43
def self.objectify(payload)
  filtered = payload.reject { |key, _| PAGINATION_FIELDS.include?(key) }
  data = filtered.values.first if filtered.is_a?(Hash) && filtered.size == 1
  data = data.values.first if data.is_a?(Hash) && data.size == 1

  super(data || payload)
end
request(*args) click to toggle source

Updated request handler with the auto-refreshing token authentication

@param payload [Hash] request payload. @return [HTTP::Response] instance.

Calls superclass method
# File lib/fluxx/resource.rb, line 34
def self.request(*args)
  auth("Bearer #{Token.fresh.access_token}") unless self == Token
  super(*args)
end