Class: MWS::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-mws/connection.rb

Constant Summary collapse

DEFAULT_HOST =
"mws.amazonservices.com"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
11
12
13
14
15
16
# File 'lib/ruby-mws/connection.rb', line 7

def initialize(options={})
  attrs.each do |a|
    self.class.send(:attr_reader, a)
    instance_variable_set("@#{a}", options[a])
  end

  @host ||= DEFAULT_HOST

  attrs.each { |a| raise MissingConnectionOptions, ":#{a} is required" if instance_variable_get("@#{a}").nil?}
end

Class Method Details

.server_time(host = DEFAULT_HOST) ⇒ Object

No connection needs to be initialized for this call



46
47
48
49
# File 'lib/ruby-mws/connection.rb', line 46

def self.server_time(host=DEFAULT_HOST)
  response = HTTParty.get("https://#{host}")
  Time.parse(response['PingResponse']['Timestamp']['timestamp'])
end

Instance Method Details

#attrsObject



26
27
28
# File 'lib/ruby-mws/connection.rb', line 26

def attrs
  public_attrs + private_attrs
end

#inspectObject

an attempt to hide sensitive login credentials in logs, just being paranoid



31
32
33
# File 'lib/ruby-mws/connection.rb', line 31

def inspect
  "#<MWS::Connection:#{object_id}>"
end

#private_attrsObject



22
23
24
# File 'lib/ruby-mws/connection.rb', line 22

def private_attrs
  [:secret_access_key]
end

#public_attrsObject



18
19
20
# File 'lib/ruby-mws/connection.rb', line 18

def public_attrs
  [:aws_access_key_id, :seller_id, :marketplace_id, :host]
end

#server_timeObject



35
36
37
# File 'lib/ruby-mws/connection.rb', line 35

def server_time
  self.class.server_time @host
end

#to_hashObject



39
40
41
42
43
# File 'lib/ruby-mws/connection.rb', line 39

def to_hash
  hsh = {}
  attrs.each { |a| hsh[a] = instance_variable_get("@#{a}")}
  hsh
end