Skip to content

Instantly share code, notes, and snippets.

@coolaj86
Created March 20, 2010 00:52
Show Gist options
  • Save coolaj86/338372 to your computer and use it in GitHub Desktop.
Save coolaj86/338372 to your computer and use it in GitHub Desktop.
# lib/ez_amz.rb
module EZAmz
require 'rubygems'
require 'amazon/aws'
require 'amazon/aws/search'
require 'active_support'
include Amazon::AWS
include Amazon::AWS::Search
def EZAmz.find_customer(email)
ccs = CustomerContentSearch.new(email)
ccs.response_group = ResponseGroup.new( :CustomerInfo )
#ccs.response_group = :CustomerInfo
req = Request.new
resp = req.search( ccs )
ccls = []
cclh = {}
ccss = resp.customer_content_search_response.customers.customer
ccss.each do |c|
ccl = CustomerContentLookup.new(c.customer_id)
ccl.response_group = ResponseGroup.new( :CustomerFull )
req = Request.new
ccl = req.search(ccl)
#ccls << ccl.customer_content_lookup_response.customers.customer.to_h #.to_hash
cclh = ccl.customer_content_lookup_response.customers.customer.to_h #.to_hash
end
cclh
end
end
irb
require 'ez_amz'
require 'active_support'
c = EZAmz.find_customer('[email protected]')
c.to_h
#NoMethodError: undefined method `to_h' for #<Hash:0xb7347328>
c.to_json
#ActiveSupport::JSON::CircularReferenceError: object references itself
c['location']
#=> #<Amazon::AWS::AWSObject::Location:0xb739c42c @user_defined_location=[#<Amazon::AWS::AWSObject::UserDefinedLocation:0xb739c2b0 value="Shelburne, VT USA">]>
c['location'].to_h
#=> {"user_defined_location"=>#<Amazon::AWS::AWSObject::UserDefinedLocation:0xb739c2b0 value="Shelburne, VT USA">}
c['location'][:user_defined_location].to_h
#=> {}
c['location']['user_defined_location']
#=> [#<Amazon::AWS::AWSObject::UserDefinedLocation:0xb739c2b0 value="Shelburne, VT USA">]
c['location'].to_h['user_defined_location']
#=> #<Amazon::AWS::AWSObject::UserDefinedLocation:0xb739c2b0 value="Shelburne, VT USA">
c['location'].to_h['user_defined_location'].to_h
#=> {}
# What!?!?
c['location'].to_h['user_defined_location'].to_s
#=> "Shelburne, VT USA"
print c['location'].to_yaml
#--- !ruby/object:Amazon::AWS::AWSObject::Location
#user_defined_location: !seq:Amazon::AWS::AWSArray
# - !ruby/object:Amazon::AWS::AWSObject::UserDefinedLocation
# __val__: Shelburne, VT USA
#=> nil
# Who can read that? It's not so hard with one little attribute, but try this:
print c.to_yaml
# It doesn't help that much for debugging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment