Sha256: 56646131727f83084fe9c0a23596b09152e4b574700fba5b2bfb4a2dfba9131e

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Storyblok
  # 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.
  class Request
    attr_reader :client, :type, :query, :id, :endpoint

    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 = URI.encode_www_form_component(id)
      else
        @type = :multi
        @id = nil
      end
    end

    # Returns the final URL, relative to a storyblok space
    def url
      "#{@endpoint}#{@type == :single ? "/#{id}" : ''}"
    end

    # Delegates the actual HTTP work to the client
    def get
      client.cached_get(self, @bypass_cache)
    end

    # Returns a new Request object with the same data
    def copy
      Marshal.load(Marshal.dump(self))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
storyblok-2.1.0 lib/storyblok/request.rb