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
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#proxy_server ⇒ Object
readonly
Returns the value of attribute proxy_server.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#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) ⇒ 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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/aws/ses/base.rb', line 73 def initialize( = {} ) = { :access_key_id => "", :secret_access_key => "", :use_ssl => true, :server => DEFAULT_HOST, :path => "/", :user_agent => USER_AGENT, :proxy_server => nil }.merge() @server = [:server] @proxy_server = [:proxy_server] @use_ssl = [:use_ssl] @path = [:path] @user_agent = [:user_agent] 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 # Don't verify the SSL certificates. Avoids SSL Cert warning in log on every GET. @http.verify_mode = OpenSSL::SSL::VERIFY_NONE end |
Instance Attribute Details
#port ⇒ Object (readonly)
Returns the value of attribute port.
64 65 66 |
# File 'lib/aws/ses/base.rb', line 64 def port @port end |
#proxy_server ⇒ Object (readonly)
Returns the value of attribute proxy_server.
64 65 66 |
# File 'lib/aws/ses/base.rb', line 64 def proxy_server @proxy_server end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
64 65 66 |
# File 'lib/aws/ses/base.rb', line 64 def server @server end |
#settings ⇒ Object
Returns the value of attribute settings.
125 126 127 |
# File 'lib/aws/ses/base.rb', line 125 def settings @settings end |
#use_ssl ⇒ Object (readonly)
Returns the value of attribute use_ssl.
64 65 66 |
# File 'lib/aws/ses/base.rb', line 64 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
127 128 129 |
# File 'lib/aws/ses/base.rb', line 127 def connection @http end |
#get_aws_auth_param(timestamp, secret_access_key) ⇒ Object
Set the Authorization header using AWS signed header authentication
170 171 172 173 |
# File 'lib/aws/ses/base.rb', line 170 def get_aws_auth_param(, secret_access_key) encoded_canonical = SES.encode(secret_access_key, , false) SES.(@access_key_id, 'HmacSHA256', encoded_canonical) 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.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/aws/ses/base.rb', line 134 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" => "2", "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) 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 |