Class: SimpleAWS::CloudFront
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
-
#call(method, path, options = {}) ⇒ SimpleAWS::Response
Execute an HTTP request against CloudFront.
-
#delete(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP DELETE.
-
#get(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP GET.
-
#initialize(key, secret) ⇒ CloudFront
constructor
A new instance of CloudFront.
-
#post(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP POST.
-
#put(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP PUT.
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.
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, = {}) request = SimpleAWS::Request.new method, self.uri, "/#{self.version}#{path}" ([:params] || {}).each do |k, v| request.params[k] = v end ([:headers] || {}).each do |k, v| request.headers[k] = v end if xml = [: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 = [: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
118 119 120 |
# File 'lib/simple_aws/cloud_front.rb', line 118 def delete(path, = {}) call :delete, path, end |
#get(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP GET
76 77 78 |
# File 'lib/simple_aws/cloud_front.rb', line 76 def get(path, = {}) call :get, path, end |
#post(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP POST
90 91 92 |
# File 'lib/simple_aws/cloud_front.rb', line 90 def post(path, = {}) call :post, path, end |
#put(path, options = {}) ⇒ SimpleAWS::Response
Send a request using HTTP PUT
104 105 106 |
# File 'lib/simple_aws/cloud_front.rb', line 104 def put(path, = {}) call :put, path, end |