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.



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

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

  authenticate

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

Instance Method Details

#authenticate(options = {}) ⇒ Object



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

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



119
120
121
# File 'lib/fog/rackspace/cdn_v2.rb', line 119

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



94
95
96
# File 'lib/fog/rackspace/cdn_v2.rb', line 94

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



90
91
92
# File 'lib/fog/rackspace/cdn_v2.rb', line 90

def ping
  self.get_ping.status == 204
end

#regionObject



115
116
117
# File 'lib/fog/rackspace/cdn_v2.rb', line 115

def region
  @rackspace_region
end

#request(params, parse_json = true) ⇒ Object



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

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



111
112
113
# File 'lib/fog/rackspace/cdn_v2.rb', line 111

def request_id_header
  "x-raxcdn-id"
end

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



84
85
86
87
88
# File 'lib/fog/rackspace/cdn_v2.rb', line 84

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



107
108
109
# File 'lib/fog/rackspace/cdn_v2.rb', line 107

def service_name
  :rackCDN
end

#update_service(service) ⇒ Object



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

def update_service(service)
  request(
    :expects => [201, 202],
    :method  => 'PATCH',
    :headers => {"Content-Type" => "application/json-patch+json"},
    :body    => Fog::JSON.encode(service.operations),
    :path    => "services/#{service.id}"
  )

  service.operations = []
end