Class: MWS::Connection
- Inherits:
-
Object
- Object
- MWS::Connection
- Defined in:
- lib/ruby-mws/connection.rb
Constant Summary collapse
- DEFAULT_HOST =
"mws.amazonservices.com"
Class Method Summary collapse
-
.server_time(host = DEFAULT_HOST) ⇒ Object
No connection needs to be initialized for this call.
Instance Method Summary collapse
- #attrs ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
-
#inspect ⇒ Object
an attempt to hide sensitive login credentials in logs, just being paranoid.
- #private_attrs ⇒ Object
- #public_attrs ⇒ Object
- #server_time ⇒ Object
- #to_hash ⇒ Object
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(={}) attrs.each do |a| self.class.send(:attr_reader, a) instance_variable_set("@#{a}", [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
#attrs ⇒ Object
26 27 28 |
# File 'lib/ruby-mws/connection.rb', line 26 def attrs public_attrs + private_attrs end |
#inspect ⇒ Object
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_attrs ⇒ Object
22 23 24 |
# File 'lib/ruby-mws/connection.rb', line 22 def private_attrs [:secret_access_key] end |
#public_attrs ⇒ Object
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_time ⇒ Object
35 36 37 |
# File 'lib/ruby-mws/connection.rb', line 35 def server_time self.class.server_time @host end |
#to_hash ⇒ Object
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 |