Class: CacheWarp

Inherits:
WebService show all
Defined in:
lib/cachewarp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from WebService

#get, #get_uri, #service_request

Constructor Details

#initialize(uri = nil) ⇒ CacheWarp

Returns a new instance of CacheWarp



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cachewarp.rb', line 7

def initialize uri=nil
  @uri = uri
  @headers =
      {
          'Pragma' => 'akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no'
      }
  @expected_response_headers =
      {
          'x-cache' => /TCP(.*)HIT(.*)from(.*)AkamaiGHost(.*)/
      }
  @failures = {}
  @response_headers = {}
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures



5
6
7
# File 'lib/cachewarp.rb', line 5

def failures
  @failures
end

#headersObject (readonly)

Returns the value of attribute headers



5
6
7
# File 'lib/cachewarp.rb', line 5

def headers
  @headers
end

#response_headersObject (readonly)

Returns the value of attribute response_headers



5
6
7
# File 'lib/cachewarp.rb', line 5

def response_headers
  @response_headers
end

#uriObject (readonly)

Returns the value of attribute uri



5
6
7
# File 'lib/cachewarp.rb', line 5

def uri
  @uri
end

Instance Method Details

#fetch(uri = @uri, headers = @headers) ⇒ Object



27
28
29
30
31
32
# File 'lib/cachewarp.rb', line 27

def fetch uri=@uri, headers=@headers
  @url = uri
  @headers= headers
  set_response_headers(get_uri(uri, headers).header)
  self
end

#is_cached?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/cachewarp.rb', line 34

def is_cached?
  fetch if response_headers.empty?
  @expected_response_headers.each do |attr, value|
    @failures[attr] = {expected: value, actual: @response_headers[attr]} unless @response_headers[attr] && @response_headers[attr].match(value.to_s)
  end
  return ((@failures.empty?) ? true : false)
end

#set_response_headers(headers) ⇒ Object



21
22
23
24
25
# File 'lib/cachewarp.rb', line 21

def set_response_headers headers
  headers.each_header do |attr, value|
    @response_headers[attr] = value
  end
end