Class: Fog::CDN::HP::Mock
- Inherits:
-
Object
- Object
- Fog::CDN::HP::Mock
- Includes:
- Utils
- Defined in:
- lib/fog/hp/requests/cdn/put_container.rb,
lib/fog/hp/cdn.rb,
lib/fog/hp/requests/cdn/get_containers.rb,
lib/fog/hp/requests/cdn/head_container.rb,
lib/fog/hp/requests/cdn/post_container.rb,
lib/fog/hp/requests/cdn/delete_container.rb
Overview
:nodoc:all
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
- #delete_container(name) ⇒ Object
- #get_containers(options = {}) ⇒ Object
- #head_container(name) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #post_container(name, options = {}) ⇒ Object
- #put_container(name, options = {}) ⇒ Object
- #reset_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
41 42 43 |
# File 'lib/fog/hp/cdn.rb', line 41 def initialize(={}) @hp_account_id = [:hp_account_id] end |
Class Method Details
.data ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/fog/hp/cdn.rb', line 29 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :cdn_containers => {} } end end |
.reset ⇒ Object
37 38 39 |
# File 'lib/fog/hp/cdn.rb', line 37 def self.reset @data = nil end |
Instance Method Details
#data ⇒ Object
45 46 47 |
# File 'lib/fog/hp/cdn.rb', line 45 def data self.class.data[@hp_account_id] end |
#delete_container(name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fog/hp/requests/cdn/delete_container.rb', line 23 def delete_container(name) response = Excon::Response.new if self.data[:cdn_containers][name] self.data[:cdn_containers].delete(name) response.status = 204 response.body = "" response else raise Fog::CDN::HP::NotFound end end |
#get_containers(options = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fog/hp/requests/cdn/get_containers.rb', line 32 def get_containers( = {}) response = Excon::Response.new data = self.data[:cdn_containers].map {|_,v| v} response.body = data response.status = 200 response end |
#head_container(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/hp/requests/cdn/head_container.rb', line 31 def head_container(name) response = Excon::Response.new headers = {} if data = self.data[:cdn_containers][name] data.each do |k,_| headers[k] = data[k] if data[k] end response.headers = headers response.status = 204 response.body = "" response else raise Fog::CDN::HP::NotFound end end |
#post_container(name, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/hp/requests/cdn/post_container.rb', line 28 def post_container(name, = {}) response = Excon::Response.new container_id = Fog::Mock.random_hex(33) if data = self.data[:cdn_containers][name] .each do |k,v| data[k] = [k] if [k] end response.headers = { "X-Cdn-Ssl-Uri" => "https://a111.cdn.net/cdn-test.net/#{container_id}/abc", "X-Cdn-Uri" => "http://#{container_id}.cdn-test.net", "X-Trans-Id" => Fog::Mock.random_hex(34) } response.status = 202 response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " self.data[:cdn_containers][name] = data response else raise Fog::CDN::HP::NotFound end end |
#put_container(name, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/hp/requests/cdn/put_container.rb', line 28 def put_container(name, = {}) response = Excon::Response.new container_id = Fog::Mock.random_hex(33) data = { 'x-cdn-ssl-uri' => "https://a111.cdn.net/cdn-test.net/#{container_id}/abc", 'cdn_enabled' => true, 'name' => name, 'x-cdn-uri' => "http://#{container_id}.cdn-test.net", 'ttl' => 86400, 'log_retention' => false } response.headers = { "X-Cdn-Ssl-Uri" => "https://a111.cdn.net/cdn-test.net/#{container_id}/abc", "X-Cdn-Uri" => "http://#{container_id}.cdn-test.net", "X-Trans-Id" => Fog::Mock.random_hex(34) } response.status = 201 response.body = "201 Created\n\n\n\n " self.data[:cdn_containers][name] = data response end |
#reset_data ⇒ Object
49 50 51 |
# File 'lib/fog/hp/cdn.rb', line 49 def reset_data self.class.data.delete(@hp_account_id) end |