Class: Fog::CDN::Rackspace::Mock

Inherits:
Rackspace::Service show all
Includes:
Base
Defined in:
lib/fog/rackspace/cdn.rb,
lib/fog/rackspace/requests/cdn/delete_object.rb,
lib/fog/rackspace/requests/cdn/put_container.rb,
lib/fog/rackspace/requests/cdn/get_containers.rb,
lib/fog/rackspace/requests/cdn/head_container.rb,
lib/fog/rackspace/requests/cdn/post_container.rb

Constant Summary

Constants included from Base

Base::URI_HEADERS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#endpoint_uri, #publish_container, #region, #service_name, #urls

Methods inherited from Rackspace::Service

#authenticate, #endpoint_uri, #region, #service_name

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



95
96
97
# File 'lib/fog/rackspace/cdn.rb', line 95

def initialize(options={})
  @rackspace_username = options[:rackspace_username]
end

Class Method Details

.dataObject



85
86
87
88
89
# File 'lib/fog/rackspace/cdn.rb', line 85

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {}
  end
end

.resetObject



91
92
93
# File 'lib/fog/rackspace/cdn.rb', line 91

def self.reset
  @data = nil
end

Instance Method Details

#dataObject



99
100
101
# File 'lib/fog/rackspace/cdn.rb', line 99

def data
  self.class.data[@rackspace_username]
end

#delete_object(container, object) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/rackspace/requests/cdn/delete_object.rb', line 27

def delete_object(container, object)        
  response = Excon::Response.new
  response.status = 204
  response.headers = {
    "Content-Length"=>"0", 
    "Date"=>"Fri, 01 Feb 2013 21:34:33 GMT", 
    "X-Trans-Id"=>"tx860f26bd76284a849384c0a467767b57"
  } 
  response.body = ""
  response
end

#get_containers(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fog/rackspace/requests/cdn/get_containers.rb', line 37

def get_containers(options = {})
  response = Excon::Response.new
  response.status = 200
  response.headers = { 
    "Content-Length"=>"4402", 
    "Date"=>"Fri, 01 Feb 2013 21:16:54 GMT", 
    "Content-Type"=>"application/json", 
    "X-Trans-Id"=>"tx6c79ea47300941c49f2291b4d47d4ef5"
  } 
  response.body = [
    { "log_retention"=>false, 
      "cdn_ios_uri"=>"http://a590286a323fec6aed22-d1e9259b2132e81da48ed3e1e802ef22.iosr.cf1.rackcdn.com", 
      "ttl"=>3600, 
      "cdn_enabled"=>true, 
      "cdn_streaming_uri"=>"http://168e307d41afe64f1a62-d1e9259b2132e81da48ed3e1e802ef22.r2.stream.cf1.rackcdn.com", 
      "name"=>"brown", "cdn_uri"=>"http://6e8f4bf5125c9c2e4e3a-d1e9259b2132e81da48ed3e1e802ef22.r2.cf1.rackcdn.com", 
      "cdn_ssl_uri"=>"https://f83cb7d39e0b9ff9581b-d1e9259b2132e81da48ed3e1e802ef22.ssl.cf1.rackcdn.com"
    }, 
    { "log_retention"=>false, 
      "cdn_ios_uri"=>"http://b141f80caedd02158f10-cf33674d895dc8b8e6e5207fdbd5cae4.iosr.cf1.rackcdn.com", 
      "ttl"=>5000, 
      "cdn_enabled"=>false, 
      "cdn_streaming_uri"=>"http://ea5feee96b8087a3d5e5-cf33674d895dc8b8e6e5207fdbd5cae4.r72.stream.cf1.rackcdn.com", 
      "name"=>"fogcontainertests", "cdn_uri"=>"http://0115a9de56617a5d5473-cf33674d895dc8b8e6e5207fdbd5cae4.r72.cf1.rackcdn.com", 
      "cdn_ssl_uri"=>"https://a5df8bd8a418ca88061e-cf33674d895dc8b8e6e5207fdbd5cae4.ssl.cf1.rackcdn.com"
    }
  ] 
  response
end

#head_container(container) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/rackspace/requests/cdn/head_container.rb', line 39

def head_container(container)
  raise Fog::Storage::Rackspace::NotFound.new "#{container} not found" unless container == 'fogcontainertests'
  response = Excon::Response.new
  response.status = 204
  response.headers = { 
    "X-Cdn-Uri"=>"http://e4bbc22477d80eaf22bd-ca4e4e61e477bbd430e1f5b9dc9a19f5.r53.cf1.rackcdn.com", 
    "X-Cdn-Ios-Uri"=>"http://3c10ef49037f74416445-ca4e4e61e477bbd430e1f5b9dc9a19f5.iosr.cf1.rackcdn.com", 
    "X-Cdn-Ssl-Uri"=>"https://b722b8ee248259c37901-ca4e4e61e477bbd430e1f5b9dc9a19f5.ssl.cf1.rackcdn.com", 
    "X-Log-Retention"=>"False", 
    "X-Cdn-Enabled"=>"True", 
    "Content-Length"=>"0", 
    "Date"=>"Fri, 01 Feb 2013 21:25:57 GMT", 
    "X-Cdn-Streaming-Uri"=>"http://b82027c64cb4dd03670a-ca4e4e61e477bbd430e1f5b9dc9a19f5.r53.stream.cf1.rackcdn.com", 
    "X-Ttl"=>"259200", 
    "X-Trans-Id"=>"txca40ffd0412943608bb3e9656c8b81ef"
  }             
  response.body = "" 
  response
end

#post_container(name, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/rackspace/requests/cdn/post_container.rb', line 36

def post_container(name, options = {})
  raise Fog::Storage::Rackspace::NotFound.new "#{name} not found" unless name == 'fogcontainertests'
  response = Excon::Response.new
  response.status = 202
  response.headers = { 
    "X-Cdn-Uri"=>"http://e4bbc22477d80eaf22bd-ca4e4e61e477bbd430e1f5b9dc9a19f5.r53.cf1.rackcdn.com", 
    "X-Cdn-Ios-Uri"=>"http://3c10ef49037f74416445-ca4e4e61e477bbd430e1f5b9dc9a19f5.iosr.cf1.rackcdn.com", 
    "X-Cdn-Ssl-Uri"=>"https://b722b8ee248259c37901-ca4e4e61e477bbd430e1f5b9dc9a19f5.ssl.cf1.rackcdn.com", 
    "Content-Length"=>"58", "Date"=>"Fri, 01 Feb 2013 21:31:30 GMT", 
    "Content-Type"=>"text/plain; charset=UTF-8", 
    "X-Cdn-Streaming-Uri"=>"http://b82027c64cb4dd03670a-ca4e4e61e477bbd430e1f5b9dc9a19f5.r53.stream.cf1.rackcdn.com", 
    "X-Trans-Id"=>"tx4a3206e63dfc446bb5b60e34a62f749d"
  } 
  response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n   " 
  response
end

#purge(object) ⇒ Object



103
104
105
106
# File 'lib/fog/rackspace/cdn.rb', line 103

def purge(object)
  return true if object.is_a? Fog::Storage::Rackspace::File            
  raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object       
end

#put_container(name, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/rackspace/requests/cdn/put_container.rb', line 36

def put_container(name, options = {})
  response = Excon::Response.new
  response.status = 201
  response.headers = { 
    "X-Cdn-Uri"=>"http://e4bbc22477d80eaf22bd-ca4e4e61e477bbd430e1f5b9dc9a19f5.r53.cf1.rackcdn.com", 
    "X-Cdn-Ios-Uri"=>"http://3c10ef49037f74416445-ca4e4e61e477bbd430e1f5b9dc9a19f5.iosr.cf1.rackcdn.com", 
    "X-Cdn-Ssl-Uri"=>"https://b722b8ee248259c37901-ca4e4e61e477bbd430e1f5b9dc9a19f5.ssl.cf1.rackcdn.com", 
    "Content-Length"=>"18", 
    "Date"=>"Fri, 01 Feb 2013 21:21:45 GMT", 
    "Content-Type"=>"text/plain; charset=UTF-8", 
    "X-Cdn-Streaming-Uri"=>"http://b82027c64cb4dd03670a-ca4e4e61e477bbd430e1f5b9dc9a19f5.r53.stream.cf1.rackcdn.com", 
    "X-Trans-Id"=>"tx1b41ec63189f4862baa65e0c08711772"
  } 
  response.body = "201 Created\n\n\n\n   " 
  response
end

#reset_dataObject



108
109
110
# File 'lib/fog/rackspace/cdn.rb', line 108

def reset_data
  self.class.data.delete(@rackspace_username)
end