Module: Jeff

Defined in:
lib/jeff.rb,
lib/jeff/secret.rb,
lib/jeff/version.rb

Overview

Jeff is a light-weight module that mixes in client behaviour for Amazon Web Services (AWS).

Defined Under Namespace

Modules: ClassMethods Classes: Secret

Constant Summary collapse

USER_AGENT =
"Jeff/#{VERSION} (Language=Ruby; #{`hostname`.chomp})"
MissingEndpoint =
Class.new ArgumentError
MissingKey =
Class.new ArgumentError
MissingSecret =
Class.new ArgumentError
UNRESERVED =
/([^\w.~-]+)/
VERSION =
'0.4.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointObject

Internal: Gets the String AWS endpoint.

Raises a MissingEndpoint error if endpoint is missing.



51
52
53
# File 'lib/jeff.rb', line 51

def endpoint
  @endpoint or raise MissingEndpoint
end

#keyObject

Internal: Gets the String AWS access key id.

Raises a MissingKey error if key is missing.



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

def key
  @key or raise MissingKey
end

Class Method Details

.included(base) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/jeff.rb', line 18

def self.included(base)
  base.extend ClassMethods

  base.headers 'User-Agent'       => USER_AGENT

  base.params  'AWSAccessKeyId'   => -> { key },
               'SignatureVersion' => '2',
               'SignatureMethod'  => 'HmacSHA256',
               'Timestamp'        => -> { Time.now.utc.iso8601 }
end

Instance Method Details

#build_query(hsh) ⇒ Object

 Internal: Builds a sorted query.

hsh - A hash of query parameters specific to the request.

Returns a query String.



34
35
36
37
38
39
40
# File 'lib/jeff.rb', line 34

def build_query(hsh)
  params
    .merge(hsh)
    .sort
    .map { |k, v| "#{k}=#{ escape v }" }
    .join '&'
end

#connectionObject

Internal: Returns an Excon::Connection.



43
44
45
46
# File 'lib/jeff.rb', line 43

def connection
  @connection ||= Excon.new endpoint, headers:    headers,
                                      idempotent: true
end

#headersObject

Internal: Returns the Hash default headers.



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

def headers
  self.class.headers
end

#paramsObject

Internal: Returns the Hash default request parameters.



74
75
76
77
78
# File 'lib/jeff.rb', line 74

def params
  self.class.params.reduce({}) do |a, (k, v)|
    a.update k => (v.is_a?(Proc) ? instance_exec(&v) : v)
  end
end

#secretObject

Internal: Gets the Jeff::Secret.

Raises a MissingSecret error if secret is missing.



83
84
85
# File 'lib/jeff.rb', line 83

def secret
  @secret or raise MissingSecret
end

#secret=(key) ⇒ Object

Sets the AWS secret key.

key - A String secret.

Returns a Jeff::Secret.



92
93
94
# File 'lib/jeff.rb', line 92

def secret=(key)
  @secret = Secret.new key
end