Class: AWS::SES::Base
- Inherits:
-
Object
- Object
- AWS::SES::Base
- Defined in:
- lib/aws/ses/base.rb,
lib/aws/ses/addresses.rb
Overview
AWS::SES::Base is the abstract super class of all classes who make requests against SES
Direct Known Subclasses
Instance Attribute Summary collapse
-
#message_id_domain ⇒ Object
readonly
Returns the value of attribute message_id_domain.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#proxy_server ⇒ Object
readonly
Returns the value of attribute proxy_server.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#signature_version ⇒ Object
readonly
Returns the value of attribute signature_version.
-
#use_ssl ⇒ Object
readonly
Returns the value of attribute use_ssl.
Instance Method Summary collapse
- #addresses ⇒ Object
- #connection ⇒ Object
-
#get_aws_auth_param(timestamp, secret_access_key, action = '', signature_version = 2) ⇒ Object
Set the Authorization header using AWS signed header authentication.
-
#initialize(options = {}) ⇒ Object
constructor
The object.
-
#request(action, params = {}) ⇒ Object
Make the connection to AWS passing in our request.
Methods included from Info
Methods included from SendEmail
Constructor Details
#initialize(options = {}) ⇒ Object
Returns the object.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/aws/ses/base.rb', line 100 def initialize( = {} ) = { :access_key_id => "", :secret_access_key => "", :use_ssl => true, :server => DEFAULT_HOST, :message_id_domain => DEFAULT_MESSAGE_ID_DOMAIN, :path => "/", :user_agent => USER_AGENT, :proxy_server => nil, :region => DEFAULT_REGION }.merge() @signature_version = [:signature_version] || 2 @server = [:server] @message_id_domain = [:message_id_domain] @proxy_server = [:proxy_server] @use_ssl = [:use_ssl] @path = [:path] @user_agent = [:user_agent] @region = [:region] @settings = {} raise ArgumentError, "No :access_key_id provided" if [:access_key_id].nil? || [:access_key_id].empty? raise ArgumentError, "No :secret_access_key provided" if [:secret_access_key].nil? || [:secret_access_key].empty? raise ArgumentError, "No :use_ssl value provided" if [:use_ssl].nil? raise ArgumentError, "Invalid :use_ssl value provided, only 'true' or 'false' allowed" unless [:use_ssl] == true || [:use_ssl] == false raise ArgumentError, "No :server provided" if [:server].nil? || [:server].empty? if [:port] # user-specified port @port = [:port] elsif @use_ssl # https @port = 443 else # http @port = 80 end @access_key_id = [:access_key_id] @secret_access_key = [:secret_access_key] # Use proxy server if defined # Based on patch by Mathias Dalheimer. 20070217 proxy = @proxy_server ? URI.parse(@proxy_server) : OpenStruct.new @http = Net::HTTP::Proxy( proxy.host, proxy.port, proxy.user, proxy.password).new([:server], @port) @http.use_ssl = @use_ssl end |
Instance Attribute Details
#message_id_domain ⇒ Object (readonly)
Returns the value of attribute message_id_domain.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def @message_id_domain end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def port @port end |
#proxy_server ⇒ Object (readonly)
Returns the value of attribute proxy_server.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def proxy_server @proxy_server end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def region @region end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def server @server end |
#settings ⇒ Object
Returns the value of attribute settings.
89 90 91 |
# File 'lib/aws/ses/base.rb', line 89 def settings @settings end |
#signature_version ⇒ Object (readonly)
Returns the value of attribute signature_version.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def signature_version @signature_version end |
#use_ssl ⇒ Object (readonly)
Returns the value of attribute use_ssl.
88 89 90 |
# File 'lib/aws/ses/base.rb', line 88 def use_ssl @use_ssl end |
Instance Method Details
#addresses ⇒ Object
69 70 71 |
# File 'lib/aws/ses/addresses.rb', line 69 def addresses @addresses ||= Addresses.new(self) end |
#connection ⇒ Object
154 155 156 |
# File 'lib/aws/ses/base.rb', line 154 def connection @http end |
#get_aws_auth_param(timestamp, secret_access_key, action = '', signature_version = 2) ⇒ Object
Set the Authorization header using AWS signed header authentication
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/aws/ses/base.rb', line 197 def get_aws_auth_param(, secret_access_key, action = '', signature_version = 2) raise(ArgumentError, "signature_version must be `2` or `4`") unless signature_version == 2 || signature_version == 4 encoded_canonical = SES.encode(secret_access_key, , false) if signature_version == 4 SES.(sig_v4_auth_credential, sig_v4_auth_signed_headers, sig_v4_auth_signature(action)) else SES.(@access_key_id, 'HmacSHA256', encoded_canonical) end end |
#request(action, params = {}) ⇒ Object
Make the connection to AWS passing in our request.
allow us to have a one line call in each method which will do all of the work in making the actual request to AWS.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/aws/ses/base.rb', line 161 def request(action, params = {}) # Use a copy so that we don't modify the caller's Hash, remove any keys that have nil or empty values params = params.reject { |key, value| value.nil? or value.empty?} = Time.now.getutc params.merge!( {"Action" => action, "SignatureVersion" => signature_version.to_s, "SignatureMethod" => 'HmacSHA256', "AWSAccessKeyId" => @access_key_id, "Version" => API_VERSION, "Timestamp" => .iso8601 } ) query = params.sort.collect do |param| CGI::escape(param[0]) + "=" + CGI::escape(param[1]) end.join("&") req = {} req['X-Amzn-Authorization'] = get_aws_auth_param(.httpdate, @secret_access_key, action, signature_version) req['Date'] = .httpdate req['User-Agent'] = @user_agent response = connection.post(@path, query, req) response_class = AWS::SES.const_get( "#{action}Response" ) result = response_class.new(action, response) if result.error? raise ResponseError.new(result) end result end |