Class: ContentfulRedis::Request

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

Instance Method Summary collapse

Constructor Details

#initialize(space, params, action = :get, env = ContentfulRedis.configuration.default_env || :published) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/contentful_redis/request.rb', line 10

def initialize(space, params, action = :get, env = ContentfulRedis.configuration.default_env || :published)
  @space = space
  @action = action

  if env.to_s.downcase == 'published'
    @endpoint = 'cdn'
    @access_token = @space[:access_token]
  else
    @endpoint = 'preview'
    @access_token = @space[:preview_access_token]
  end

  params[:include] = 1

  @parameters = params
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
# File 'lib/contentful_redis/request.rb', line 27

def call
  generated_key = ContentfulRedis::KeyManager.content_model_key(@space, @endpoint, @parameters)

  return fetch_from_origin(generated_key) if @action == :update || !ContentfulRedis.redis.exists(generated_key)

  JSON.parse(ContentfulRedis.redis.get(generated_key))
end