class Neows::REST::Request

Attributes

client[RW]
options[RW]
path[RW]

Public Class Methods

new(client, request_method, path, klass, options = {}) click to toggle source

Creates an instance of Request

@param request_method [Symbol] :get @param path [String] @param klass [Class] @param options [Hash] @return [Neows::REST::Request]

# File lib/neows/rest/request.rb, line 15
def initialize(client, request_method, path, klass, options = {})
  @client = client
  @request_method = request_method
  @path = path.gsub @client.base_url, ''
  @options = options
  @klass = klass
end

Public Instance Methods

perform() click to toggle source

Makes the request passing the response into the given class. If a class provides a coerce! method, it will be called to handle custom coercion of data.

@return [Class] instance of Klass

# File lib/neows/rest/request.rb, line 32
def perform
  response = HTTP.with(request_headers).public_send(@request_method, uri, params: @options)
  klass = @klass.new JSON.parse(response.to_s).merge(client: @client)
  klass.coerce! if klass.respond_to?(:coerce!)
  klass
end
uri() click to toggle source

@return [String]

# File lib/neows/rest/request.rb, line 24
def uri
  @client.base_url + @path
end

Private Instance Methods

request_headers() click to toggle source
# File lib/neows/rest/request.rb, line 41
def request_headers
  {
    user_agent: @client.user_agent,
    accept: 'application/json'
  }
end