Class: Storyblok::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/storyblok/request.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, endpoint, query = {}, id = nil, bypass_cache = false) ⇒ Request

Returns a new instance of Request.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/storyblok/request.rb', line 6

def client
  @client
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



6
7
8
# File 'lib/storyblok/request.rb', line 6

def endpoint
  @endpoint
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/storyblok/request.rb', line 6

def id
  @id
end

#queryObject (readonly)

Returns the value of attribute query.



6
7
8
# File 'lib/storyblok/request.rb', line 6

def query
  @query
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/storyblok/request.rb', line 6

def type
  @type
end

Instance Method Details

#copyObject

Returns a new Request object with the same data



34
35
36
# File 'lib/storyblok/request.rb', line 34

def copy
  Marshal.load(Marshal.dump(self))
end

#getObject

Delegates the actual HTTP work to the client



29
30
31
# File 'lib/storyblok/request.rb', line 29

def get
  client.cached_get(self, @bypass_cache)
end

#urlObject

Returns the final URL, relative to a storyblok space



24
25
26
# File 'lib/storyblok/request.rb', line 24

def url
  "#{@endpoint}#{@type == :single ? "/#{id}" : ''}"
end