Module: Sinatra::APDM

Defined in:
lib/apdm/sinatra.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/apdm/sinatra.rb', line 44

def self.registered(app)
  app.get '/apdm-design-elements.css' do
    headers('Content-Type' => 'text/css', 'X-Content-Type-Options' => 'nosniff')
    design_elements.css
  end

  app.helpers(Sinatra::APDM::Helpers)
end

Instance Method Details

#apdm_configure(&blk) ⇒ Object



53
54
55
# File 'lib/apdm/sinatra.rb', line 53

def apdm_configure(&blk)
  self.instance_exec(&blk)
end

#enable_apdm_cache_headersObject

Cache headers required/recommended by the apdm proxy



79
80
81
82
83
# File 'lib/apdm/sinatra.rb', line 79

def enable_apdm_cache_headers
  before do
    cache_control :private, :no_cache, :no_store, :must_revalidate
  end
end

#enable_apdm_proxy_workaroundsObject

Here be workarounds for the diabolical evil apdm proxy



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/apdm/sinatra.rb', line 66

def enable_apdm_proxy_workarounds
  before do
    # Enforce a trailing slash for root requests.
    #   i.e. /vis/bandwagon ==redirects to==> /vis/bandwagon/
    # The evil apdm proxy sets cookies on path with trailing slash (e.g. /vis/bandwagon/)
    # so a user entering /vis/bandwagon (without trailing slash) will loose its credentials. This is the workaround.
    if request.path_info == '/' and not request.env['REQUEST_PATH'].match(/\/$/)
      redirect request.env['REQUEST_PATH']+"/"
    end
  end
end

#set_ad_tech_context_prefix(context_prefix) ⇒ Object



61
62
63
# File 'lib/apdm/sinatra.rb', line 61

def set_ad_tech_context_prefix(context_prefix)
  set :ad_tech_context_prefix, context_prefix
end

#set_design_elements_api_key(api_key) ⇒ Object



57
58
59
# File 'lib/apdm/sinatra.rb', line 57

def set_design_elements_api_key(api_key)
  set :design_elements_api_key, api_key
end