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

Direct Known Subclasses

AutoScaling, CloudFormation, CloudFront, CloudWatch, DynamoDB, EC2, ELB, ElastiCache, ElasticBeanstalk, IAM, ImportExport, MapReduce, MechanicalTurk, RDS, S3, SES, SNS, SQS, STS, SimpleDB

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (API) initialize(access_key, secret_key, region = nil)

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

- (Object) access_key (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

- (Object) region (readonly)

Returns the value of attribute region



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

def region
  @region
end

- (Object) secret_key (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

- (Object) version (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

+ (Object) default_region(region)

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

+ (Object) endpoint(endpoint)

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

+ (Object) use_https(value)

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

+ (Object) version(version)

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

- (String) uri

Get the full host name for the current API

Returns:

  • (String)

    Full URI for this API



83
84
85
86
87
88
89
90
91
# File 'lib/simple_aws/api.rb', line 83

def uri
  return @uri if @uri

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