class Storyblok::Request

This object represents a request that is to be made. It gets initialized by the client with domain specific logic. The client later uses the Request's url and query methods to execute the HTTP request.

Attributes

client[R]
endpoint[R]
id[R]
query[R]
type[R]

Public Class Methods

new(client, endpoint, query = {}, id = nil, bypass_cache = false) click to toggle source
# File lib/storyblok/request.rb, line 8
def initialize(client, endpoint, query = {}, id = nil, bypass_cache = false)
  @client = client
  @endpoint = endpoint
  @query = query
  @bypass_cache = bypass_cache

  if id
    @type = :single
    @id = id
  else
    @type = :multi
    @id = nil
  end
end

Public Instance Methods

copy() click to toggle source

Returns a new Request object with the same data

# File lib/storyblok/request.rb, line 34
def copy
  Marshal.load(Marshal.dump(self))
end
get() click to toggle source

Delegates the actual HTTP work to the client

# File lib/storyblok/request.rb, line 29
def get
  client.cached_get(self, @bypass_cache)
end
url() click to toggle source

Returns the final URL, relative to a storyblok space

# File lib/storyblok/request.rb, line 24
def url
  "#{@endpoint}#{@type == :single ? "/#{id}" : ''}"
end