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


75
76
77
78
79
80
81
82
83
# File 'lib/simple_aws/api.rb', line 75

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

Read or change the AWS Version this API is using. If the default version defined in the code is not the current version, please open an Issue and set the version manually in the mean time.


66
67
68
# File 'lib/simple_aws/api.rb', line 66

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


89
90
91
# File 'lib/simple_aws/api.rb', line 89

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


98
99
100
101
102
103
104
105
106
# File 'lib/simple_aws/api.rb', line 98

def uri
  return @uri if @uri

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