Class: Loquor::HttpAction::Get

Inherits:
Loquor::HttpAction show all
Defined in:
lib/loquor/http_actions/get.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Loquor::HttpAction

#execute, #signed_request

Constructor Details

#initialize(url, deps) ⇒ Get

Returns a new instance of Get.



7
8
9
# File 'lib/loquor/http_actions/get.rb', line 7

def initialize(url, deps)
  super
end

Class Method Details

.get(url, deps) ⇒ Object



3
4
5
# File 'lib/loquor/http_actions/get.rb', line 3

def self.get(url, deps)
  new(url, deps).get
end

Instance Method Details

#execute_against_cacheObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/loquor/http_actions/get.rb', line 18

def execute_against_cache
  cache = @config.cache
  if cache
    val = cache.get(request.url)
    unless val
      val = execute
      cache.set(request.url, val)
    end
    val
  else
    execute
  end
end

#getObject



11
12
13
14
15
16
# File 'lib/loquor/http_actions/get.rb', line 11

def get
  @config.logger.info "GET: #{full_url}"
  response = @should_cache ? JSON.parse(execute_against_cache) : JSON.parse(execute)
  @config.logger.info "Response: #{response}"
  response
end