Class: SimpleAWS::CloudFront

Inherits:
API
  • Object
show all
Defined in:
lib/simple_aws/cloud_front.rb

Overview

Amazon's CloudFront

http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/Welcome.html

As CloudFront is much closer to a RESTful service than the other AWS APIs, all calls through this API are done through these four HTTP methods: GET, PUT, DELETE, and POST.

The paths for all request get the version prepended on to them, you do not have to worry about that part of the path. Outside of this, in keeping with the goals of SimpleAWS, everything else should be exactly as you read it in the AWS API docs in the link above.

So "GET Distribution List" is

cloud_front.get "/distribution"

For requests that need extra parameters, use the :params option

cloud_front.get "/distribution", :params => {
  "MaxItems" => 10
}

Like :params, use :headers to add headers to the request

cloud_front.get "/distribution", :headers => {
  "x-amz-security-token" => "security string"
}

The details of CloudFront requests are all passed through XML bodies. To make this as simple and painless as possible, this API supports the :xml option to turn a Hash into an XML string

cloud_front.post "/distribution", :xml => {
  :DistributionConfig => {
    ...
  }
}

Do note that this XML building is very simple, does not support attributes, and will only work on Hashes, Arrays, and objects that can be easily to_s-ed. Anything else will error out or might result in invalid request bodies.

If you already have the XML string and just need to give it to the request, you can use :body to set the raw value of the request body:

cloud_front.post "/distribution", :body => raw_body_xml

All responses are wrapped in a SimpleAWS::Response object.

Instance Attribute Summary

Attributes inherited from API

#access_key, #debug_to, #region, #secret_key, #version

Instance Method Summary collapse

Methods inherited from API

#debug!, default_region, endpoint, #uri, use_https, version

Constructor Details

#initialize(key, secret) ⇒ CloudFront

Returns a new instance of CloudFront


62
63
64
# File 'lib/simple_aws/cloud_front.rb', line 62

def initialize(key, secret)
  super(key, secret)
end

Instance Method Details

#call(method, path, options = {}) ⇒ SimpleAWS::Response

Execute an HTTP request against CloudFront.

Parameters:

  • method (Symbol, String)

    The HTTP method to use

  • path (String)

    The path of the resource at hand

  • options (Hash) (defaults to: {})

    Options as defined above

Returns:

Raises:


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/simple_aws/cloud_front.rb', line 133

def call(method, path, options = {})
  request = SimpleAWS::Request.new method, self.uri, "/#{self.version}#{path}"

  (options[:params] || {}).each do |k, v|
    request.params[k] = v
  end

  (options[:headers] || {}).each do |k, v|
    request.headers[k] = v
  end

  if xml = options[:xml]
    raise ":xml must be a Hash" unless xml.is_a?(Hash)

    namespace = "http://cloudfront.amazonaws.com/doc/#{self.version}"
    request.body = SimpleAWS::Util.build_xml_from xml, namespace
    request.headers["Content-Type"] = "text/xml"
  else
    request.body = options[:body]
  end

  connection = SimpleAWS::Connection.new self
  connection.call finish_and_sign_request(request)
end

#delete(path, options = {}) ⇒ SimpleAWS::Response

Send a request using HTTP DELETE

Parameters:

  • path (String)

    The path of the resource at hand

  • options (Hash) (defaults to: {})

    Options as defined above

Returns:

Raises:


118
119
120
# File 'lib/simple_aws/cloud_front.rb', line 118

def delete(path, options = {})
  call :delete, path, options
end

#get(path, options = {}) ⇒ SimpleAWS::Response

Send a request using HTTP GET

Parameters:

  • path (String)

    The path of the resource at hand

  • options (Hash) (defaults to: {})

    Options as defined above

Returns:

Raises:


76
77
78
# File 'lib/simple_aws/cloud_front.rb', line 76

def get(path, options = {})
  call :get, path, options
end

#post(path, options = {}) ⇒ SimpleAWS::Response

Send a request using HTTP POST

Parameters:

  • path (String)

    The path of the resource at hand

  • options (Hash) (defaults to: {})

    Options as defined above

Returns:

Raises:


90
91
92
# File 'lib/simple_aws/cloud_front.rb', line 90

def post(path, options = {})
  call :post, path, options
end

#put(path, options = {}) ⇒ SimpleAWS::Response

Send a request using HTTP PUT

Parameters:

  • path (String)

    The path of the resource at hand

  • options (Hash) (defaults to: {})

    Options as defined above

Returns:

Raises:


104
105
106
# File 'lib/simple_aws/cloud_front.rb', line 104

def put(path, options = {})
  call :put, path, options
end