Class: SimpleAWS::API

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_aws/api.rb

Overview

Base class for all AWS API wrappers.

See the list of AWS Endpoints for the values to use when implementing various APIs:

http://docs.amazonwebservices.com/general/latest/gr/index.html?rande.html

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key, secret_key, region = nil) ⇒ API

Construct a new access object for the API in question.

Parameters:

  • access_key (String)

    Amazon access key

  • secret_key (String)

    Amazon secret key

  • region (String) (defaults to: nil)

    Give a specific region to talk to



68
69
70
71
72
73
74
75
76
# File 'lib/simple_aws/api.rb', line 68

def initialize(access_key, secret_key, region = nil)
  @access_key = access_key
  @secret_key = secret_key

  @region = region || self.class.instance_variable_get("@default_region")
  @endpoint = self.class.instance_variable_get("@endpoint")
  @use_https = self.class.instance_variable_get("@use_https")
  @version = self.class.instance_variable_get("@version")
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



59
60
61
# File 'lib/simple_aws/api.rb', line 59

def access_key
  @access_key
end

#debug_toObject (readonly)

Returns the value of attribute debug_to.



59
60
61
# File 'lib/simple_aws/api.rb', line 59

def debug_to
  @debug_to
end

#regionObject (readonly)

Returns the value of attribute region.



59
60
61
# File 'lib/simple_aws/api.rb', line 59

def region
  @region
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



59
60
61
# File 'lib/simple_aws/api.rb', line 59

def secret_key
  @secret_key
end

#versionObject (readonly)

Returns the value of attribute version.



59
60
61
# File 'lib/simple_aws/api.rb', line 59

def version
  @version
end

Class Method Details

.default_region(region) ⇒ Object

Specify a default region for all requests for this API.

Parameters:

  • region (String)

    Specify the region this API defaults to



33
34
35
# File 'lib/simple_aws/api.rb', line 33

def default_region(region)
  @default_region = region
end

.endpoint(endpoint) ⇒ Object

Define the AWS endpoint for the API being wrapped.

Parameters:

  • endpoint (String)

    Subdomain endpoint for this API. E.g. "s3" for Amazon's S3



24
25
26
# File 'lib/simple_aws/api.rb', line 24

def endpoint(endpoint)
  @endpoint = endpoint
end

.use_https(value) ⇒ Object

Specify whether this API uses HTTPS for requests. If not set, the system will use HTTP. Some API endpoints are not available under HTTP and some are only HTTP.

Parameters:

  • value (Boolean)

    Set whether this API uses HTTPS by default or not



44
45
46
# File 'lib/simple_aws/api.rb', line 44

def use_https(value)
  @use_https = value
end

.version(version) ⇒ Object

Specify the AWS version of the API in question.

Parameters:

  • version (String)

    The version this API currently uses.



53
54
55
# File 'lib/simple_aws/api.rb', line 53

def version(version)
  @version = version
end

Instance Method Details

#debug!(location = $stdout) ⇒ Object

Flag this API to render debugging information to an IO location. Default is $stdout



82
83
84
# File 'lib/simple_aws/api.rb', line 82

def debug!(location = $stdout)
  @debug_to = location
end

#uriString

Get the full host name for the current API

Returns:

  • (String)

    Full URI for this API



91
92
93
94
95
96
97
98
99
# File 'lib/simple_aws/api.rb', line 91

def uri
  return @uri if @uri

  @uri = @use_https ? "https" : "http"
  @uri += "://#{@endpoint}"
  @uri += ".#{@region}" if @region
  @uri += ".amazonaws.com"
  @uri
end