From 2a77066d4dae79c8e9e1f005fd54b002a75d6d16 Mon Sep 17 00:00:00 2001 From: geemus Date: Mon, 1 Nov 2010 15:01:55 -0700 Subject: [PATCH] [aws|cdn] first pass at post_invalidation --- lib/fog/aws/cdn.rb | 1 + lib/fog/aws/parsers/cdn/post_invalidation.rb | 28 +++++++++ lib/fog/aws/requests/cdn/post_invalidation.rb | 58 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 lib/fog/aws/parsers/cdn/post_invalidation.rb create mode 100644 lib/fog/aws/requests/cdn/post_invalidation.rb diff --git a/lib/fog/aws/cdn.rb b/lib/fog/aws/cdn.rb index b4657577e..e8ef5ddcc 100644 --- a/lib/fog/aws/cdn.rb +++ b/lib/fog/aws/cdn.rb @@ -8,6 +8,7 @@ module Fog request_path 'fog/aws/requests/cdn' request 'get_distribution_list' + request 'post_invalidation' class Mock diff --git a/lib/fog/aws/parsers/cdn/post_invalidation.rb b/lib/fog/aws/parsers/cdn/post_invalidation.rb new file mode 100644 index 000000000..a1fdf44b1 --- /dev/null +++ b/lib/fog/aws/parsers/cdn/post_invalidation.rb @@ -0,0 +1,28 @@ +module Fog + module Parsers + module AWS + module CDN + + class PostInvalidation < Fog::Parsers::Base + + def reset + @response = { 'InvalidationBatch' => { 'Path' => [] } } + end + + def end_element(name) + case name + when 'CallerReference' + @response['InvalidationBatch'][name] = @value + when 'CreateTime', 'ID', 'Status' + @response[name] = @value + when 'Path' + @response['InvalidationBatch'][name] << @value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/cdn/post_invalidation.rb b/lib/fog/aws/requests/cdn/post_invalidation.rb new file mode 100644 index 000000000..ee093a3be --- /dev/null +++ b/lib/fog/aws/requests/cdn/post_invalidation.rb @@ -0,0 +1,58 @@ +module Fog + module AWS + class CDN + class Real + + require 'fog/aws/parsers/cdn/post_invalidation' + + # List information about distributions in CloudFront + # + # ==== Parameters + # * distribution_id<~String> - Id of distribution for invalidations + # * paths<~Array> - Array of string paths to objects to invalidate + # * caller_reference<~String> - Used to prevent replay, defaults to Time.now.to_i.to_s + # + # + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'Id'<~String> - Id of invalidation + # * 'Status'<~String> - Status of invalidation + # * 'CreateTime'<~Integer> - Time of invalidation creation + # * 'InvalidationBatch'<~Array>: + # * 'Path'<~Array>: Array of strings of objects to invalidate + # * 'CallerReference'<~String>: Used to prevent replay, defaults to Time.now.to_i.to_s + # + # ==== See Also + # http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateInvalidation.html + + def post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s) + body = '' + body << "" + for path in paths + body << "" << path << "" + end + body << "" << caller_reference << "" + body << "" + request({ + :expects => 201, + :headers => {'Content-Type' => 'text/xml'}, + :idempotent => true, + :method => 'POST', + :parser => Fog::Parsers::AWS::CDN::PostInvalidation.new, + :path => "/distribution/#{distribution_id}/invalidation" + }) + end + + end + + class Mock # :nodoc:all + + def post_invalidation(distribution_id, paths, caller_reference = Time.now.to_i.to_s) + Fog::Mock.not_implemented + end + + end + end + end +end