Module: Amazon

Defined in:
lib/amazon.rb,
lib/amazon/aws.rb,
lib/amazon/aws/cache.rb,
lib/amazon/aws/search.rb,
lib/amazon/aws/shoppingcart.rb

Overview

$Id: search.rb,v 1.30 2009/02/19 16:19:47 ianmacd Exp $

Defined Under Namespace

Modules: AWS Classes: AmazonError, Config

Constant Summary collapse

NAME =
'Ruby/Amazon'
@@config =
{}

Class Method Summary collapse

Class Method Details

.dprintf(format = '', *args) ⇒ Object

Prints debugging messages and works like printf, except that it prints only when Ruby is run with the -d switch.



16
17
18
# File 'lib/amazon.rb', line 16

def Amazon.dprintf(format='', *args)
  $stderr.printf( format + "\n", *args ) if $DEBUG
end

.uncamelise(str) ⇒ Object

Convert a string from CamelCase to ruby_case.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/amazon.rb', line 35

def Amazon.uncamelise(str)
  # Avoid modifying by reference.
  #
  str = str.dup

  # Don't mess with string if all caps.
  #
  str.gsub!( /(.+?)(([A-Z][a-z]|[A-Z]+$))/, "\\1_\\2" ) if str =~ /[a-z]/

  # Convert to lower case.
  #
  str.downcase
end

.url_encode(string) ⇒ Object

Encode a string, such that it is suitable for HTTP transmission.



23
24
25
26
27
28
29
30
# File 'lib/amazon.rb', line 23

def Amazon.url_encode(string)

  # Shamelessly plagiarised from Wakou Aoyama's cgi.rb.
  #
  string.gsub( /([^ a-zA-Z0-9_.-]+)/n ) do
    '%' + $1.unpack( 'H2' * $1.size ).join( '%' ).upcase
  end.tr( ' ', '+' )
end