Class: Rapa::Queries::BaseQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/rapa/queries/base_query.rb

Constant Summary collapse

SERVICE =
"AWSECommerceService"
VERSION =
"2013-08-01"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BaseQuery

Returns a new instance of BaseQuery.

Parameters:

  • options (Hash) (defaults to: {})


40
41
42
# File 'lib/rapa/queries/base_query.rb', line 40

def initialize(options = {})
  @options = options
end

Class Attribute Details

.property_namesArray<Symbol>

Returns:

  • (Array<Symbol>)


19
20
21
# File 'lib/rapa/queries/base_query.rb', line 19

def property_names
  @property_names ||= []
end

Class Method Details

.inherited(child_class) ⇒ Object

Note:

Override



14
15
16
# File 'lib/rapa/queries/base_query.rb', line 14

def inherited(child_class)
  child_class.property_names = property_names.clone
end

.property(property_name) ⇒ Object

Parameters:

  • property_name (Symbol)


24
25
26
# File 'lib/rapa/queries/base_query.rb', line 24

def property(property_name)
  property_names << property_name
end

Instance Method Details

#AssociateTagString

Returns:

  • (String)


50
51
52
# File 'lib/rapa/queries/base_query.rb', line 50

def AssociateTag
  options[:associate_tag]
end

#AWSAccessKeyIdString

Returns:

  • (String)


55
56
57
# File 'lib/rapa/queries/base_query.rb', line 55

def AWSAccessKeyId
  options[:access_key_id]
end

#inspectObject

Note:

Override



45
46
47
# File 'lib/rapa/queries/base_query.rb', line 45

def inspect
  "#<#{self.class}>"
end

#OperationString

Returns:

  • (String)

Raises:

  • (::NotImplementedError)


60
61
62
# File 'lib/rapa/queries/base_query.rb', line 60

def Operation
  raise ::NotImplementedError
end

#RelatedItemPageInteger?

Returns:

  • (Integer, nil)


65
66
67
# File 'lib/rapa/queries/base_query.rb', line 65

def RelatedItemPage
  options[:related_item_page]
end

#RelationshipTypeString?

Returns:

  • (String, nil)


70
71
72
# File 'lib/rapa/queries/base_query.rb', line 70

def RelationshipType
  options[:relationship_type]
end

#ResponseGroupString?

Returns:

  • (String, nil)


75
76
77
78
79
# File 'lib/rapa/queries/base_query.rb', line 75

def ResponseGroup
  if options[:response_groups]
    options[:response_groups].join(",")
  end
end

#ServiceString

Returns:

  • (String)


82
83
84
# File 'lib/rapa/queries/base_query.rb', line 82

def Service
  SERVICE
end

#TimestampString

Returns:

  • (String)


87
88
89
# File 'lib/rapa/queries/base_query.rb', line 87

def Timestamp
  ::Time.now.utc.iso8601
end

#to_hashHash

Returns:

  • (Hash)


92
93
94
95
96
97
98
99
# File 'lib/rapa/queries/base_query.rb', line 92

def to_hash
  self.class.property_names.each_with_object({}) do |property_name, result|
    value = send(property_name)
    unless value.nil?
      result[property_name.to_s] = ::ERB::Util.url_encode(value)
    end
  end.sort.to_h
end

#to_sString

Returns:

  • (String)


102
103
104
105
106
107
108
109
# File 'lib/rapa/queries/base_query.rb', line 102

def to_s
  to_hash.map do |key, value|
    [
      key,
      value,
    ].join("=")
  end.join("&")
end

#VersionString

Returns:

  • (String)


112
113
114
# File 'lib/rapa/queries/base_query.rb', line 112

def Version
  VERSION
end