Class: Stree::Service

Inherits:
Object
  • Object
show all
Extended by:
Roxy::Moxie
Includes:
Parser
Defined in:
lib/stree/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Roxy::Moxie

proxy

Methods included from Parser

#parse_copy_object_result, #parse_error, #parse_list_all_my_buckets_result, #parse_list_bucket_result, #parse_location_constraint, #rexml_document

Constructor Details

#initialize(options) ⇒ Service

Parameters:

options

a hash of options described below

Options:

access_key_id

Amazon access key id, required

secret_access_key

Amazon secret access key, required

use_ssl

true if use ssl in connection, otherwise false

timeout

parameter for Net::HTTP module

debug

prints the raw requests to STDOUT



22
23
24
25
26
27
28
# File 'lib/stree/service.rb', line 22

def initialize(options)
  @access_key_id = options[:access_key_id] or raise ArgumentError, "No access key id given"
  @secret_access_key = options[:secret_access_key] or raise ArgumentError, "No secret access key given"
  @use_ssl = options[:use_ssl]
  @timeout = options[:timeout]
  @debug = options[:debug]
end

Instance Attribute Details

#access_key_idObject (readonly)

Returns the value of attribute access_key_id.



6
7
8
# File 'lib/stree/service.rb', line 6

def access_key_id
  @access_key_id
end

#secret_access_keyObject (readonly)

Returns the value of attribute secret_access_key.



6
7
8
# File 'lib/stree/service.rb', line 6

def secret_access_key
  @secret_access_key
end

#use_sslObject (readonly)

Returns the value of attribute use_ssl.



6
7
8
# File 'lib/stree/service.rb', line 6

def use_ssl
  @use_ssl
end

Instance Method Details

#==(other) ⇒ Object

Compares service to other, by access_key_id and secret_access_key



9
10
11
# File 'lib/stree/service.rb', line 9

def ==(other)
  self.access_key_id == other.access_key_id and self.secret_access_key == other.secret_access_key
end

#buckets(reload = false) ⇒ Object

Returns all buckets in the service and caches the result (see reload)



31
32
33
34
35
36
37
# File 'lib/stree/service.rb', line 31

def buckets(reload = false)
  if reload or @buckets.nil?
    @buckets = list_all_my_buckets
  else
    @buckets
  end
end

#inspectObject

:nodoc:



82
83
84
# File 'lib/stree/service.rb', line 82

def inspect #:nodoc:
  "#<#{self.class}:#@access_key_id>"
end

#portObject

Return 443 or 80, depends on use_ssl value from initializer



45
46
47
# File 'lib/stree/service.rb', line 45

def port
  use_ssl ? 443 : 80
end

#protocolObject

Returns “http://” or “https://”, depends on use_ssl value from initializer



40
41
42
# File 'lib/stree/service.rb', line 40

def protocol
  use_ssl ? "https://" : "http://"
end