class Pagelime::Clients::XmlS3Storage

Public Class Methods

new(options = {}) click to toggle source
# File lib/pagelime/clients/xml_s3_storage.rb, line 8
def initialize(options = {})
  @options = {
    :account_key    => ENV['PAGELIME_ACCOUNT_KEY'],
    :account_secret => ENV['PAGELIME_ACCOUNT_SECRET'],
    :api_version    => ENV['PAGELIME_RACK_API_VERSION']
  }.merge(options)
end

Public Instance Methods

fetch_path(page_path) click to toggle source
# File lib/pagelime/clients/xml_s3_storage.rb, line 27
def fetch_path(page_path)
  
  Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: NO '#{page_path}' CACHE... loading XML"
  
  content = request_content("/cms_assets/heroku/#{@options[:account_key]}/pages#{page_path}.xml")
  
  Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Content: #{content.inspect}"
  
  content
end
fetch_shared() click to toggle source
# File lib/pagelime/clients/xml_s3_storage.rb, line 16
def fetch_shared

  Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: NO SHARED CACHE... loading XML"
  
  content = request_content("/cms_assets/heroku/#{@options[:account_key]}/shared-regions.xml")
  
  Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Shared content: #{content.inspect}"
  
  content
end

Private Instance Methods

http() click to toggle source
# File lib/pagelime/clients/xml_s3_storage.rb, line 49
def http
  @http ||= Net::HTTP::new('s3.amazonaws.com', 80)
end
request_content(url) click to toggle source
# File lib/pagelime/clients/xml_s3_storage.rb, line 40
def request_content(url)
  response = http.get(url)
  
  Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: S3 response code: #{response.code.inspect}"
  
  # only return the body if response code 200-399
  response.body if (200...400).include?(response.code.to_f)
end