Class: Elasticity::AwsSession
- Inherits:
-
Object
- Object
- Elasticity::AwsSession
- Defined in:
- lib/elasticity/aws_session.rb
Instance Attribute Summary collapse
-
#access_key ⇒ Object
readonly
Returns the value of attribute access_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
Class Method Summary collapse
-
.parse_error_response(error_xml) ⇒ Object
AWS error responses all follow the same form.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(access = nil, secret = nil, options = {}) ⇒ AwsSession
constructor
Supported values for options: :region - AWS region (e.g. us-west-1) :secure - true or false, default true.
- #submit(ruby_service_hash) ⇒ Object
Constructor Details
#initialize(access = nil, secret = nil, options = {}) ⇒ AwsSession
Supported values for options:
:region - AWS region (e.g. us-west-1)
:secure - true or false, default true.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/elasticity/aws_session.rb', line 18 def initialize(access=nil, secret=nil, ={}) # There is a cryptic error if this isn't set if .has_key?(:region) && [:region] == nil raise MissingRegionError, 'A valid :region is required to connect to EMR' end [:region] = 'us-east-1' unless [:region] @region = [:region] @access_key = get_access_key(access) @secret_key = get_secret_key(secret) @host = "elasticmapreduce.#@region.amazonaws.com" end |
Instance Attribute Details
#access_key ⇒ Object (readonly)
Returns the value of attribute access_key.
10 11 12 |
# File 'lib/elasticity/aws_session.rb', line 10 def access_key @access_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
12 13 14 |
# File 'lib/elasticity/aws_session.rb', line 12 def host @host end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
13 14 15 |
# File 'lib/elasticity/aws_session.rb', line 13 def region @region end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
11 12 13 |
# File 'lib/elasticity/aws_session.rb', line 11 def secret_key @secret_key end |
Class Method Details
.parse_error_response(error_xml) ⇒ Object
AWS error responses all follow the same form. Extract the message from the error document.
64 65 66 67 68 |
# File 'lib/elasticity/aws_session.rb', line 64 def self.parse_error_response(error_xml) xml_doc = Nokogiri::XML(error_xml) xml_doc.remove_namespaces! xml_doc.xpath('/ErrorResponse/Error/Message').text end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/elasticity/aws_session.rb', line 40 def ==(other) return false unless other.is_a? AwsSession return false unless @access_key == other.access_key return false unless @secret_key == other.secret_key return false unless @host == other.host true end |
#submit(ruby_service_hash) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/elasticity/aws_session.rb', line 31 def submit(ruby_service_hash) aws_request = AwsRequestV4.new(self, ruby_service_hash) begin RestClient.post(aws_request.url, aws_request.payload, aws_request.headers) rescue RestClient::BadRequest => e raise ArgumentError, AwsSession.parse_error_response(e.http_body) end end |