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.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/hp/cdn.rb', line 44 def initialize(={}) # deprecate hp_account_id if [:hp_account_id] Fog::Logger.deprecation(":hp_account_id is deprecated, please use :hp_access_key instead.") @hp_access_key = .delete(:hp_account_id) end @hp_access_key = [:hp_access_key] unless @hp_access_key raise ArgumentError.new("Missing required arguments: hp_access_key. :hp_account_id is deprecated, please use :hp_access_key instead.") end end |
Class Method Details
.data ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fog/hp/cdn.rb', line 32 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :cdn_containers => {} } end end |
.reset ⇒ Object
40 41 42 |
# File 'lib/fog/hp/cdn.rb', line 40 def self.reset @data = nil end |
Instance Method Details
#data ⇒ Object
56 57 58 |
# File 'lib/fog/hp/cdn.rb', line 56 def data self.class.data[@hp_access_key] 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
60 61 62 |
# File 'lib/fog/hp/cdn.rb', line 60 def reset_data self.class.data.delete(@hp_access_key) end |