Class: EndecaOnDemand::Query

Inherits:
Object
  • Object
show all
Includes:
PP
Defined in:
lib/endeca_on_demand/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PP

#inspect, #pretty_print

Constructor Details

#initialize(client, options = {}) ⇒ Query

Returns a new instance of Query.



12
13
14
15
16
# File 'lib/endeca_on_demand/query.rb', line 12

def initialize(client, options = {})
  @client, @options = client, options.dup.recurse(&:symbolize_keys)

  process_options!
end

Instance Attribute Details

#bodyObject (readonly)

associations ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def body
  @body
end

#clientObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def client
  @client
end

#errorsObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def errors
  @errors
end

#httpObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def http
  @http
end

#optionsObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def options
  @options
end

#responseObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def response
  @response
end

#uriObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def uri
  @uri
end

#xmlObject (readonly)

fields ##



10
11
12
# File 'lib/endeca_on_demand/query.rb', line 10

def xml
  @xml
end

Instance Method Details

#advanced_parametersObject



92
93
94
95
96
97
98
# File 'lib/endeca_on_demand/query.rb', line 92

def advanced_parameters
  @advanced_parameters ||= options[:advanced] = (options[:advanced] || {}).inject({}) do |hash,(key,value)|
      hash.tap do
        hash[key.to_s.underscore] = value
      end
    end.symbolize_keys
end

#categoryObject



76
77
78
# File 'lib/endeca_on_demand/query.rb', line 76

def category
  @category ||= options[:category]
end

#dimensionsObject



72
73
74
# File 'lib/endeca_on_demand/query.rb', line 72

def dimensions
  @dimensions ||= [*options[:dimensions]]
end

#flagsObject

data ###



60
61
62
63
64
65
66
# File 'lib/endeca_on_demand/query.rb', line 60

def flags
  @flags ||= options[:flags] = (options[:flags] || {}).inject({}) do |hash,(key,value)|
      hash.tap do
        hash[key.to_s.underscore] = value
      end
    end.symbolize_keys
end

#inspect_attributesObject



6
# File 'lib/endeca_on_demand/query.rb', line 6

def inspect_attributes; [ :uri, :xml, :errors, :options ]; end

#pagingObject



84
85
86
87
88
89
90
# File 'lib/endeca_on_demand/query.rb', line 84

def paging
  @paging ||= options[:paging] = (options[:paging] || {}).tap do |paging|
      if paging.has_key?(:page) and paging.has_key?(:per_page)
        paging[:offset] = (paging[:page].to_i * paging[:per_page].to_i rescue 0)
      end
    end
end

#searchesObject



68
69
70
# File 'lib/endeca_on_demand/query.rb', line 68

def searches
  @searches ||= options[:searches]
end

#sortsObject



80
81
82
# File 'lib/endeca_on_demand/query.rb', line 80

def sorts
  @sorts ||= options[:sorts]
end

#to_xmlObject

xml builder ##



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/endeca_on_demand/query.rb', line 44

def to_xml
  Builder::XmlMarkup.new(indent: 2).tag!(:Query) do |xml|

    Flags(xml)
    KeywordSearch(xml)
    NavigationQuery(xml)
    CategoryNavigationQuery(xml)
    Sorting(xml)
    Paging(xml)
    AdvancedParameters(xml)

  end
end