1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Start of SNS.

This commit is contained in:
phiggins 2011-01-14 00:55:33 -08:00 committed by geemus
parent 8ad32285c1
commit f48af55118
4 changed files with 167 additions and 1 deletions

View file

@ -0,0 +1,28 @@
module Fog
module Parsers
module AWS
module SNS
class ListTopics < Fog::Parsers::Base
def reset
@user = {}
@response = { 'Topics' => [] }
end
def end_element(name)
case name
when 'TopicARN'
@response['Topics'] << @user
@user = {}
when 'NextToken', 'RequestId'
response[name] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,50 @@
module Fog
module AWS
class SNS
class Real
require 'fog/aws/parsers/sns/list_topics'
# List users
#
# ==== Parameters
# * options<~Hash>:
# * 'Marker'<~String>: used to paginate subsequent requests
# * 'MaxItems'<~Integer>: limit results to this number per page
# * 'PathPrefix'<~String>: prefix for filtering results
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'Users'<~Array> - Matching groups
# * user<~Hash>:
# * Arn<~String> -
# * Path<~String> -
# * UserId<~String> -
# * UserName<~String> -
# * 'IsTruncated<~Boolean> - Whether or not results were truncated
# * 'Marker'<~String> - appears when IsTruncated is true as the next marker to use
# * 'RequestId'<~String> - Id of the request
#
# ==== See Also
# http://docs.amazonwebservices.com/IAM/latest/APIReference/API_ListUsers.html
#
def list_topics(options = {})
request({
'Action' => 'ListTopics',
:parser => Fog::Parsers::AWS::SNS::ListTopics.new
}.merge!(options))
end
end
class Mock
def list_topics(options = {})
Fog::Mock.not_implemented
end
end
end
end
end

87
lib/fog/aws/sns.rb Normal file
View file

@ -0,0 +1,87 @@
module Fog
module AWS
class SNS < Fog::Service
requires :aws_access_key_id, :aws_secret_access_key
recognizes :host, :path, :port, :scheme, :persistent
request_path 'fog/aws/requests/sns'
request :list_topics
class Mock
def initialize(options={})
end
end
class Real
# Initialize connection to SNS
#
# ==== Notes
# options parameter must include values for :aws_access_key_id and
# :aws_secret_access_key in order to create a connection
#
# ==== Examples
# sns = SNS.new(
# :aws_access_key_id => your_aws_access_key_id,
# :aws_secret_access_key => your_aws_secret_access_key
# )
#
# ==== Parameters
# * options<~Hash> - config arguments for connection. Defaults to {}.
#
# ==== Returns
# * SNS object with connection to AWS.
def initialize(options={})
require 'json'
@aws_access_key_id = options[:aws_access_key_id]
@aws_secret_access_key = options[:aws_secret_access_key]
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
@host = options[:host] || 'sns.amazonaws.com'
@path = options[:path] || '/'
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
end
def reload
@connection.reset
end
private
def request(params)
idempotent = params.delete(:idempotent)
parser = params.delete(:parser)
body = AWS.signed_params(
params,
{
:aws_access_key_id => @aws_access_key_id,
:hmac => @hmac,
:host => @host,
:path => @path,
:port => @port,
#:version => '2010-05-08'
}
)
response = @connection.request({
:body => body,
:expects => 200,
:idempotent => idempotent,
#:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:host => @host,
:method => 'POST',
:parser => parser
})
response
end
end
end
end
end

View file

@ -11,13 +11,14 @@ module Fog
service(:cdn, 'cdn/aws')
service(:compute, 'compute/aws')
service(:cloud_formation, 'aws/cloud_formation')
service(:cloud_watch, 'aws/cloud_watch')
service(:cloud_watch, 'aws/cloud_watch')
service(:dns, 'dns/aws')
service(:elb, 'aws/elb')
service(:iam, 'aws/iam')
service(:rds, 'aws/rds')
service(:ses, 'aws/ses')
service(:simpledb, 'aws/simpledb')
service(:sns, 'aws/sns')
service(:sqs, 'aws/sqs')
service(:storage, 'storage/aws')