Class: Fog::Rackspace::CDNV2::Real

Inherits:
Service
  • Object
show all
Defined in:
lib/fog/rackspace/cdn_v2.rb,
lib/fog/rackspace/requests/cdn_v2/get_ping.rb,
lib/fog/rackspace/requests/cdn_v2/get_flavor.rb,
lib/fog/rackspace/requests/cdn_v2/get_service.rb,
lib/fog/rackspace/requests/cdn_v2/list_flavors.rb,
lib/fog/rackspace/requests/cdn_v2/delete_assets.rb,
lib/fog/rackspace/requests/cdn_v2/list_services.rb,
lib/fog/rackspace/requests/cdn_v2/create_service.rb,
lib/fog/rackspace/requests/cdn_v2/delete_service.rb,
lib/fog/rackspace/requests/cdn_v2/update_service.rb,
lib/fog/rackspace/requests/cdn_v2/get_home_document.rb

Instance Method Summary collapse

Methods inherited from Service

#request_without_retry, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/rackspace/cdn_v2.rb', line 57

def initialize(options = {})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
  @rackspace_must_reauthenticate = false
  @connection_options = options[:connection_options] || {}

  authenticate

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Instance Method Details

#authenticate(options = {}) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/fog/rackspace/cdn_v2.rb', line 96

def authenticate(options={})
  super({
    :rackspace_api_key => @rackspace_api_key,
    :rackspace_username => @rackspace_username,
    :rackspace_auth_url => @rackspace_auth_url,
    :connection_options => @connection_options
  })
end

#create_service(service) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/fog/rackspace/requests/cdn_v2/create_service.rb', line 2

def create_service(service)
  request(
    :expects => [201, 202],
    :method  => 'POST',
    :body    => Fog::JSON.encode(service),
    :path    => "services"
  )
end

#delete_assets(service, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/fog/rackspace/requests/cdn_v2/delete_assets.rb', line 2

def delete_assets(service, options={})
  uri = request_uri("services/#{service.id}/assets", options)

  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => uri,
    :headers => { :accept => "*/*" }
  )
end

#delete_service(service) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/fog/rackspace/requests/cdn_v2/delete_service.rb', line 2

def delete_service(service)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "services/#{service.id}"
  )
end

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



117
118
119
# File 'lib/fog/rackspace/cdn_v2.rb', line 117

def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@rackspace_endpoint || service_endpoint_url)
end

#get_flavor(id) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/fog/rackspace/requests/cdn_v2/get_flavor.rb', line 2

def get_flavor(id)
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "flavors/#{id}"
  )
end

#get_home_documentObject



2
3
4
5
6
7
8
# File 'lib/fog/rackspace/requests/cdn_v2/get_home_document.rb', line 2

def get_home_document
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => ""
  )
end

#get_pingObject



2
3
4
5
6
7
8
9
# File 'lib/fog/rackspace/requests/cdn_v2/get_ping.rb', line 2

def get_ping
  request(
    :expects => [204],
    :method  => 'GET',
    :path    => "ping",
    :headers => { :accept => "*/*" }
  )
end

#get_service(id) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/fog/rackspace/requests/cdn_v2/get_service.rb', line 2

def get_service(id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "services/#{id}"
  )
end

#home_documentObject



92
93
94
# File 'lib/fog/rackspace/cdn_v2.rb', line 92

def home_document
  self.get_home_document.body
end

#list_flavorsObject



2
3
4
5
6
7
8
# File 'lib/fog/rackspace/requests/cdn_v2/list_flavors.rb', line 2

def list_flavors
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => "flavors"
  )
end

#list_services(options = {}) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/fog/rackspace/requests/cdn_v2/list_services.rb', line 2

def list_services(options={})
  request(
    :expects => [200],
    :method  => 'GET',
    :path    => request_uri("services", options)
  )
end

#pingObject



88
89
90
# File 'lib/fog/rackspace/cdn_v2.rb', line 88

def ping
  self.get_ping.status == 204
end

#regionObject



113
114
115
# File 'lib/fog/rackspace/cdn_v2.rb', line 113

def region
  @rackspace_region
end

#request(params, parse_json = true) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/rackspace/cdn_v2.rb', line 70

def request(params, parse_json = true)
  super
rescue Excon::Errors::NotFound => error
  raise NotFound.slurp(error, self)
rescue Excon::Errors::BadRequest => error
  raise BadRequest.slurp(error, self)
rescue Excon::Errors::InternalServerError => error
  raise InternalServerError.slurp(error, self)
rescue Excon::Errors::HTTPStatusError => error
  raise ServiceError.slurp(error, self)
end

#request_id_headerObject



109
110
111
# File 'lib/fog/rackspace/cdn_v2.rb', line 109

def request_id_header
  "x-raxcdn-id"
end

#request_uri(path, options = {}) ⇒ Object



82
83
84
85
86
# File 'lib/fog/rackspace/cdn_v2.rb', line 82

def request_uri(path, options={})
  return path if options == {}
  require "addressable/uri"
  Addressable::URI.new({:path=>path, :query_values=>options}).request_uri
end

#service_nameObject



105
106
107
# File 'lib/fog/rackspace/cdn_v2.rb', line 105

def service_name
  :rackCDN
end

#update_service(service) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/fog/rackspace/requests/cdn_v2/update_service.rb', line 2

def update_service(service)
  request(
    :expects => [201, 202],
    :method  => 'PATCH',
    :body    => Fog::JSON.encode(service.operations),
    :path    => "services/#{service.id}"
  )
end