endeca_xml 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +5 -125
- data/endeca_xml.gemspec +3 -4
- data/lib/endeca_xml.rb +168 -207
- data/lib/endeca_xml/record.rb +0 -2
- data/lib/endeca_xml/{search_report.rb → search.rb} +2 -4
- data/lib/endeca_xml/version.rb +1 -1
- metadata +5 -5
data/README.rdoc
CHANGED
|
@@ -1,135 +1,15 @@
|
|
|
1
1
|
= endeca_xml
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
== Features
|
|
6
|
-
|
|
7
|
-
* Builds an XML query, formatted to thanxmedia specifications, from a query string
|
|
8
|
-
* Parses the settings parameters and sends a completed XML query to thanxmedia API
|
|
9
|
-
* Handles the response XML and exposes methods to retrieve response data
|
|
10
|
-
|
|
11
|
-
== Install
|
|
12
|
-
|
|
13
|
-
=== Rails
|
|
14
|
-
|
|
15
|
-
Add this line to your Gemfile:
|
|
16
|
-
|
|
17
|
-
gem 'endeca_xml'
|
|
18
|
-
|
|
19
|
-
Then bundle install:
|
|
20
|
-
|
|
21
|
-
bundle install
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
=== Non Rails
|
|
26
|
-
|
|
27
|
-
gem install endeca_xml
|
|
28
|
-
|
|
29
|
-
== Usage
|
|
30
|
-
|
|
31
|
-
A restructure has been done since previous versions. endeca_xml now constructs an XML query to send to thanxmedia via a query string:
|
|
32
|
-
|
|
33
|
-
<a href='.../url?search-key=primary&search-term=name&DimensionValueIds=1,2,3,4&sort-key=name&sort-direction=descending&RecordOffset=0&RecordsPerPage=9&AggregationKey=name&UserProfiles=1,2,3,4&filter=between'>FULL ENDECA REQUEST</a>
|
|
34
|
-
|
|
35
|
-
The following is an example of an empty 'options' hash that would then need to be constructed from a query string, and sent to the module (any static values are added before, and not from a query string):
|
|
36
|
-
|
|
37
|
-
host = 'your/thanxmedia/api/url'
|
|
38
|
-
options = {
|
|
39
|
-
'add_base' => {'RecordsSet' => false, 'Dimensions' => true, 'BusinessRulesResult' => false, 'AppliedFilters' => true},
|
|
40
|
-
'add_keyword_search' => {},
|
|
41
|
-
'add_dimension_value_id_navigation' => {},
|
|
42
|
-
'add_category_navigation_query' => "current_category_id",
|
|
43
|
-
'add_sorting' => {},
|
|
44
|
-
'add_paging' => {},
|
|
45
|
-
'add_advanced_parameters' => {},
|
|
46
|
-
'add_profiles' => {},
|
|
47
|
-
'add_filters' => {}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
The following is what a prepared 'options' hash would look like, that is then passed into the module, using the above example query string:
|
|
51
|
-
|
|
52
|
-
options = {
|
|
53
|
-
'add_base' => {'RecordsSet' => true, 'Dimensions' => true, 'BusinessRulesResult' => true, 'AppliedFilters' => true},
|
|
54
|
-
'add_keyword_search' => {'searh-key => 'key', search-term => 'term'},
|
|
55
|
-
'add_dimension_value_id_navigation' => {[1, 2, 3, 4]},
|
|
56
|
-
'add_category_navigation_query' => 1,
|
|
57
|
-
'add_sorting' => {'sort-key' => 'key', 'sort-direction' => 'Descending'},
|
|
58
|
-
'add_paging' => {'RecordOffset' => 0, 'RecordsPerPage' => 9},
|
|
59
|
-
'add_advanced_parameters' => {'AggregationKey' => 'key'},
|
|
60
|
-
'add_profiles' => {[1, 2, 3, 4]},
|
|
61
|
-
'add_filters' => {}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
NOTE: add_dimension_value_id_navigation and add_category_navigation_query are mutually exclusive (the example doesn't reflect that)
|
|
65
|
-
|
|
66
|
-
This example is a complete example. It is not necessary to include anything that you don't intend to use (ie. blank or empty hash's/values). If you don't need an option, don't include the query string, and if you don't need a value within an option don't include it.
|
|
67
|
-
|
|
68
|
-
This is the command that would then send the above request:
|
|
69
|
-
EndecaXml.new(host, options)
|
|
70
|
-
|
|
71
|
-
Below are (ruby/rails) examples of how you could access the response data:
|
|
72
|
-
|
|
73
|
-
Records:
|
|
74
|
-
|
|
75
|
-
EndecaXml.records.each do |record|
|
|
76
|
-
puts "---------- BEGIN RECORD"
|
|
77
|
-
puts "RECORD: #{record.inspect}"
|
|
78
|
-
puts "---------- END"
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
Breadcrumbs:
|
|
82
|
-
|
|
83
|
-
EndecaXml.breadcrumbs.each do |crumb|
|
|
84
|
-
puts "---------- BEGIN CRUMB"
|
|
85
|
-
puts "CRUMB: #{crumb.inspect}"
|
|
86
|
-
puts "---------- END"
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
Dimensions:
|
|
90
|
-
|
|
91
|
-
EndecaXml.dimensions.each do |dimension|
|
|
92
|
-
puts "---------- BEGIN DIMENSION"
|
|
93
|
-
puts "DIMENSION: #{dimension.inspect}"
|
|
94
|
-
puts "DIMENSION VALUES: #{dimension.dimensionvalues}"
|
|
95
|
-
puts "DIMENSION VALUES ARRAY: #{dimension.dimension_values}"
|
|
96
|
-
puts "---------- END"
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
Rules:
|
|
100
|
-
|
|
101
|
-
EndecaXml.rules.each do |rule|
|
|
102
|
-
puts "---------- BEGIN RULE"
|
|
103
|
-
puts "RULE: #{rule.inspect}"
|
|
104
|
-
puts "RULE PROPERTIES: #{rule.properties}"
|
|
105
|
-
puts "RULE PROPERTIES_ARRAY: #{rule.properties_array}"
|
|
106
|
-
puts "RULE RECORDS: #{rule.records}"
|
|
107
|
-
puts "---------- END"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
Filters:
|
|
111
|
-
|
|
112
|
-
EndecaXml.filters.each do |filter|
|
|
113
|
-
puts "---------- BEGIN FILTER"
|
|
114
|
-
puts "FILTER: #{filter.inspect}"
|
|
115
|
-
puts "---------- END"
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
Each object will have associated instance variables that will allow you directly call any value on that object (the values below aren't actual response values):
|
|
119
|
-
|
|
120
|
-
EndecaXml.records.each do |record|
|
|
121
|
-
record.name
|
|
122
|
-
record.price
|
|
123
|
-
etc...
|
|
124
|
-
end
|
|
3
|
+
This has since been renamed to endeca_on-demand and moved to that repo. Feel free to continue using this functioning, nearly complete version, or the awesome new, and complete, release version.
|
|
125
4
|
|
|
126
5
|
== TODO
|
|
127
6
|
|
|
128
7
|
* (complete) Pass all parameters into the initializer and have EndecaXml deconstruct the url and reconstruct it as XML rather than having the developer use each method individually.
|
|
129
8
|
* (complete) Have EndecaXml make the request after its all done constructing the query rather than requiring that the developer use the request method.
|
|
130
|
-
* Review the code and clean things up, making it nice and sugary sweet.
|
|
131
|
-
* The add_filters method needs some documentation, an example, and to be tested in a query.
|
|
132
|
-
* It occurred to me that the name is a little too ambiguous as this gem deals more specifically with thanxmedia's XML API and not Endeca directly, so a change of name is in order
|
|
9
|
+
* (complete) Review the code and clean things up, making it nice and sugary sweet.
|
|
10
|
+
* (complete) The add_filters method needs some documentation, an example, and to be tested in a query.
|
|
11
|
+
* (complete) It occurred to me that the name is a little too ambiguous as this gem deals more specifically with thanxmedia's XML API and not Endeca directly, so a change of name is in order
|
|
12
|
+
* (complete) Build in the assumption that the first index in the breadcrumbs array is the category/grouping, and the following indexes are values associated with that title (for left nav filters)
|
|
133
13
|
|
|
134
14
|
== Copyright
|
|
135
15
|
|
data/endeca_xml.gemspec
CHANGED
|
@@ -9,13 +9,12 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.authors = ['sdomino']
|
|
10
10
|
s.email = ['sdomino@pagodabox.com']
|
|
11
11
|
s.homepage = 'http://github.com/sdomino/endeca_xml'
|
|
12
|
-
s.summary = '
|
|
13
|
-
s.description = '
|
|
12
|
+
s.summary = 'This has been officially released as endeca_on_demand. Feel free to continue using this functioning, nearly complete version, or the awesome new, and complete, release version.'
|
|
13
|
+
s.description = 'This has been officially released as endeca_on_demand. Feel free to continue using this functioning, nearly complete version, or the awesome new, and complete, release version.'
|
|
14
14
|
|
|
15
15
|
s.rubyforge_project = 'endeca_xml'
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
s.add_dependency 'crackoid' # So I just fixed it :). I'll use crack again if he accepts my pull request.
|
|
17
|
+
s.add_dependency 'crackoid'
|
|
19
18
|
|
|
20
19
|
s.add_development_dependency 'rspec'
|
|
21
20
|
|
data/lib/endeca_xml.rb
CHANGED
|
@@ -1,36 +1,18 @@
|
|
|
1
1
|
Dir["#{File.dirname(__FILE__)}/endeca_xml/*"].each { |file| require(file)}
|
|
2
2
|
|
|
3
3
|
require 'builder'
|
|
4
|
-
# require 'crack' # NOTE: see .gemspec
|
|
5
4
|
require 'crackoid'
|
|
6
5
|
require 'net/http'
|
|
7
6
|
require 'uri'
|
|
8
7
|
|
|
9
|
-
# <a href='.../url?search-key=primary&search-term=name&DimensionValueIds=1,2,3,4&sort-key=name&sort-direction=descending&RecordOffset=0&RecordsPerPage=9&AggregationKey=name&UserProfiles=1,2,3,4&filter=between'>FULL ENDECA REQUEST</a>
|
|
10
|
-
|
|
11
|
-
# host = 'http://eodhc.endecaondemand.net:30858/ws/main'
|
|
12
|
-
# options = {
|
|
13
|
-
# 'add_base' => {'RecordsSet' => true, 'Dimensions' => true, 'BusinessRulesResult' => true, 'AppliedFilters' => true},
|
|
14
|
-
# 'add_keyword_search' => {'searh-key => 'key', search-term => 'term'},
|
|
15
|
-
# 'add_dimension_value_id_navigation' => {[1, 2, 3, 4]},
|
|
16
|
-
# 'add_category_navigation_query' => 1,
|
|
17
|
-
# 'add_sorting' => {'sort-key' => 'key', 'sort-direction' => 'Descending'},
|
|
18
|
-
# 'add_paging' => {'RecordOffset' => 0, 'RecordsPerPage' => 9},
|
|
19
|
-
# 'add_advanced_parameters' => {'AggregationKey' => 'key'},
|
|
20
|
-
# 'add_profiles' => {[1, 2, 3, 4]},
|
|
21
|
-
# 'add_filters' => {}
|
|
22
|
-
# }
|
|
23
|
-
|
|
24
8
|
class EndecaXml
|
|
25
9
|
|
|
26
10
|
def initialize(host, options)
|
|
27
11
|
@body = Builder::XmlMarkup.new(:indent => 2)
|
|
28
|
-
|
|
12
|
+
|
|
29
13
|
#
|
|
30
14
|
set_host(host)
|
|
31
15
|
|
|
32
|
-
puts "OPTIONS: #{options}"
|
|
33
|
-
|
|
34
16
|
#
|
|
35
17
|
options.each do |key, value|
|
|
36
18
|
self.send(key.to_sym, value) unless value.empty?
|
|
@@ -42,77 +24,61 @@ class EndecaXml
|
|
|
42
24
|
|
|
43
25
|
### API
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
attr_reader :records, :record_offset, :records_per_page, :total_record_count
|
|
28
|
+
attr_reader :breadcrumbs, :filtercrumbs
|
|
29
|
+
attr_reader :dimensions
|
|
30
|
+
attr_reader :rules
|
|
31
|
+
attr_reader :searchs, :matchedrecordcount, :matchedmode, :applied_search_adjustments, :suggested_search_adjustments
|
|
32
|
+
attr_reader :selected_dimension_value_ids
|
|
48
33
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
## DEBUG
|
|
35
|
+
attr_reader :uri, :http
|
|
36
|
+
attr_reader :base, :query, :response
|
|
37
|
+
## /DEBUG
|
|
52
38
|
|
|
53
|
-
|
|
54
|
-
@dimensions
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def rules
|
|
58
|
-
@business_rules
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def search_reports
|
|
62
|
-
@search_reports
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def selected_dimension_value_ids
|
|
66
|
-
@selected_dimension_value_ids
|
|
67
|
-
end
|
|
39
|
+
### /API
|
|
68
40
|
|
|
69
41
|
private
|
|
70
42
|
|
|
71
43
|
### XML REQUEST ###
|
|
72
44
|
|
|
73
|
-
##
|
|
45
|
+
## SET REQUEST HOST
|
|
74
46
|
def set_host(host)
|
|
75
|
-
# puts "HOST: #{host}"
|
|
76
47
|
@uri = URI.parse(host)
|
|
77
48
|
@http = Net::HTTP.new(@uri.host, @uri.port)
|
|
78
|
-
# puts "URI: #{@uri}"
|
|
79
|
-
# puts "HTTP: #{@http}"
|
|
80
49
|
end
|
|
81
50
|
|
|
82
|
-
##
|
|
51
|
+
## ADD BASE OPTIONS TO REQUEST
|
|
83
52
|
def add_base(options)
|
|
84
|
-
# puts "BASE: #{options}"
|
|
85
53
|
options.each do |key, value|
|
|
86
54
|
@body.tag!(key, value)
|
|
87
55
|
end
|
|
88
|
-
|
|
56
|
+
|
|
57
|
+
@base = options
|
|
89
58
|
end
|
|
90
59
|
|
|
91
60
|
## BUILD REQUEST BODY
|
|
92
61
|
|
|
93
|
-
#
|
|
62
|
+
# Adds dimension_value_id_navigation to the request via one or more DimensionValueIds (DVID).
|
|
63
|
+
# NOTE: If the optional CategoryId (CID) is passed, all DVIDs must belong to the category.
|
|
94
64
|
def add_dimension_value_id_navigation(options)
|
|
95
|
-
# puts "DIMENSIONS: #{options}"
|
|
96
65
|
@body.SelectedDimensionValueIds do
|
|
97
66
|
options.each do |dimension|
|
|
98
67
|
@body.tag!('DimensionValueId', dimension)
|
|
99
68
|
end
|
|
100
69
|
end
|
|
101
|
-
# puts @body.target!
|
|
102
70
|
end
|
|
103
71
|
|
|
104
|
-
#
|
|
72
|
+
# (OPTIONAL) Adds category_navigation_query to the request via a CID.
|
|
73
|
+
# NOTE: If a CID is passed, all DVIDs must belong to the category. Passing a DVID that does not belong to this category will result in an endeca response error.
|
|
105
74
|
def add_category_navigation_query(options)
|
|
106
|
-
# puts "CATEGORY: #{options}"
|
|
107
75
|
@body.Category do
|
|
108
76
|
@body.tag!('CategoryId', options)
|
|
109
77
|
end
|
|
110
|
-
# puts @body.target!
|
|
111
78
|
end
|
|
112
79
|
|
|
113
|
-
#
|
|
80
|
+
# Adds search-key and search-term to the request.
|
|
114
81
|
def add_keyword_search(options)
|
|
115
|
-
# puts "SEARCH: #{options}"
|
|
116
82
|
@body.Searches do
|
|
117
83
|
@body.Search do
|
|
118
84
|
options.each do |key, value|
|
|
@@ -120,12 +86,10 @@ class EndecaXml
|
|
|
120
86
|
end
|
|
121
87
|
end
|
|
122
88
|
end
|
|
123
|
-
# puts @body.target!
|
|
124
89
|
end
|
|
125
90
|
|
|
126
|
-
#
|
|
91
|
+
# Adds sort-key and sort-direction to the request.
|
|
127
92
|
def add_sorting(options)
|
|
128
|
-
# puts "SORT: #{options}"
|
|
129
93
|
@body.Sorts do
|
|
130
94
|
@body.Sort do
|
|
131
95
|
options.each do |key, value|
|
|
@@ -133,36 +97,30 @@ class EndecaXml
|
|
|
133
97
|
end
|
|
134
98
|
end
|
|
135
99
|
end
|
|
136
|
-
# puts @body.target!
|
|
137
100
|
end
|
|
138
101
|
|
|
139
|
-
#
|
|
102
|
+
# Adds RecordOffset and RecordsPerPage to the request.
|
|
140
103
|
def add_paging(options)
|
|
141
|
-
# puts "PAGING: #{options}"
|
|
142
104
|
options.each do |key, value|
|
|
143
105
|
@body.tag!(key, value)
|
|
144
106
|
end
|
|
145
|
-
# puts @body.target!
|
|
146
107
|
end
|
|
147
108
|
|
|
148
|
-
#
|
|
109
|
+
# Adds advanced parameters to the request.
|
|
110
|
+
# NOTE: For this implementation I only had the default advanced parameter (AggregationKey) to test with. This has not been tested, and most likely will not work, with any other possible advanced parameters (if any)
|
|
149
111
|
def add_advanced_parameters(options)
|
|
150
|
-
# puts "PARAMETERS: #{options}"
|
|
151
112
|
options.each do |key, value|
|
|
152
113
|
@body.tag!(key, value)
|
|
153
114
|
end
|
|
154
|
-
# puts @body.target!
|
|
155
115
|
end
|
|
156
116
|
|
|
157
|
-
#
|
|
117
|
+
# Adds UserProfile(s) to the request.
|
|
158
118
|
def add_profiles(options)
|
|
159
|
-
# puts "PROFILES: #{options}"
|
|
160
119
|
@body.UserProfiles do
|
|
161
120
|
options.each do |profile|
|
|
162
121
|
@body.tag!('UserProfile', profile)
|
|
163
122
|
end
|
|
164
123
|
end
|
|
165
|
-
# puts @body.target!
|
|
166
124
|
end
|
|
167
125
|
|
|
168
126
|
#
|
|
@@ -181,108 +139,96 @@ class EndecaXml
|
|
|
181
139
|
# puts @body.target!
|
|
182
140
|
end
|
|
183
141
|
|
|
184
|
-
|
|
142
|
+
## SEND REQUEST
|
|
143
|
+
|
|
144
|
+
# Completes the endeca XML reqeust by inserting the XML body into the requred 'Query' tags, and sends the request to your hosted Endeca On-Demand Web API
|
|
185
145
|
def send_request
|
|
186
|
-
|
|
187
|
-
query
|
|
188
|
-
|
|
189
|
-
query << @body.target!
|
|
146
|
+
@query = Builder::XmlMarkup.new(:indent => 2)
|
|
147
|
+
@query.Query do
|
|
148
|
+
@query << @body.target!
|
|
190
149
|
end
|
|
191
|
-
|
|
192
|
-
puts "QUERY: #{query.target!}"
|
|
193
|
-
|
|
150
|
+
|
|
194
151
|
begin
|
|
195
|
-
request, response = @http.post(@uri.path, query.target!, 'Content-type' => 'application/xml')
|
|
152
|
+
request, response = @http.post(@uri.path, @query.target!, 'Content-type' => 'application/xml')
|
|
196
153
|
handle_response(Crackoid::XML.parse(response))
|
|
197
154
|
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => error
|
|
198
155
|
puts "ERROR: #{error.message}"
|
|
199
156
|
end
|
|
200
157
|
end
|
|
158
|
+
|
|
159
|
+
## HANDLE RESPONSE
|
|
201
160
|
|
|
202
|
-
# get the request response and parse it into an hash
|
|
203
161
|
def handle_response(response)
|
|
204
|
-
puts "RESPONSE: #{response}"
|
|
205
162
|
@response = response['Final']
|
|
206
|
-
|
|
207
163
|
build_data
|
|
208
164
|
end
|
|
209
165
|
|
|
210
166
|
def build_data
|
|
211
167
|
build_records
|
|
212
168
|
build_breadcrumbs
|
|
169
|
+
build_filtercrumbs
|
|
213
170
|
build_dimensions
|
|
214
171
|
build_business_rules
|
|
215
|
-
|
|
216
|
-
build_selected_dimension_value_ids
|
|
172
|
+
build_applied_filters
|
|
217
173
|
end
|
|
218
174
|
|
|
219
|
-
#
|
|
175
|
+
# Builds an array of RECORDS
|
|
220
176
|
def build_records
|
|
221
|
-
puts "RECORDS SET: #{@response['RecordsSet']}"
|
|
222
|
-
|
|
223
|
-
# NOTE: this may need to be reworked a little. look in recordset for nodes that our outside of records...
|
|
224
177
|
@records = []
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
178
|
+
|
|
179
|
+
record_set = @response['RecordsSet']
|
|
180
|
+
|
|
181
|
+
@record_offset = record_set.fetch('offset')
|
|
182
|
+
@records_per_page = record_set.fetch('recordsperpage')
|
|
183
|
+
@total_record_count = record_set.fetch('totalrecordcount')
|
|
184
|
+
|
|
185
|
+
unless record_set.nil?
|
|
186
|
+
record = @response['RecordsSet']['Record']
|
|
187
|
+
if record.instance_of?(Hash)
|
|
188
|
+
@records.push(EndecaXml::Record.new(record_set))
|
|
189
|
+
elsif record.instance_of?(Array)
|
|
190
|
+
record.each do |record|
|
|
230
191
|
@records.push(EndecaXml::Record.new(record))
|
|
231
192
|
end
|
|
232
|
-
else
|
|
233
|
-
puts "This record is a(n): #{@response['RecordsSet'].class}"
|
|
234
193
|
end
|
|
235
194
|
else
|
|
236
195
|
puts 'There are no records with this response!'
|
|
237
196
|
end
|
|
238
197
|
end
|
|
239
198
|
|
|
240
|
-
#
|
|
199
|
+
# Builds an array of BREADCRUMBS
|
|
241
200
|
def build_breadcrumbs
|
|
242
|
-
@breadcrumbs
|
|
201
|
+
@breadcrumbs = []
|
|
243
202
|
|
|
244
|
-
# puts "BREADCRUMBS: #{@response['Breadcrumbs'}"
|
|
245
203
|
breadcrumbs = @response['Breadcrumbs']
|
|
246
204
|
unless breadcrumbs.nil?
|
|
247
|
-
|
|
248
|
-
# puts "BREADS: #{@response['Breadcrumbs']['Breads']}"
|
|
249
205
|
breads = @response['Breadcrumbs']['Breads']
|
|
250
|
-
|
|
251
206
|
if breads.instance_of?(Hash)
|
|
252
|
-
|
|
253
|
-
if
|
|
254
|
-
|
|
255
|
-
|
|
207
|
+
bread = breads['Bread']
|
|
208
|
+
if bread.instance_of?(Hash)
|
|
209
|
+
bread.each do |key, value|
|
|
210
|
+
@breadcrumbs.push(EndecaXml::Crumb.new(bread))
|
|
211
|
+
end
|
|
256
212
|
elsif bread.instance_of?(Array)
|
|
257
|
-
|
|
258
|
-
breads.each do |crumb|
|
|
259
|
-
# puts "CRUMB: #{crumb}"
|
|
213
|
+
bread.each do |crumb|
|
|
260
214
|
@breadcrumbs.push(EndecaXml::Crumb.new(crumb))
|
|
261
215
|
end
|
|
262
216
|
end
|
|
263
217
|
elsif breads.instance_of?(Array)
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
# puts "HASH 2: #{bread}"
|
|
271
|
-
bread['Bread'].each do |key, value|
|
|
272
|
-
# puts "#{key} :: #{value}"
|
|
273
|
-
@breadcrumbs.push(EndecaXml::Crumb.new(bread['Bread']))
|
|
218
|
+
breads.each do |breadz|
|
|
219
|
+
bread = breadz['Bread']
|
|
220
|
+
if breadz.instance_of?(Hash)
|
|
221
|
+
if bread.instance_of?(Hash)
|
|
222
|
+
bread.each do |key, value|
|
|
223
|
+
@breadcrumbs.push(EndecaXml::Crumb.new(bread))
|
|
274
224
|
end
|
|
275
|
-
elsif bread
|
|
276
|
-
|
|
277
|
-
bread['Bread'].each do |crumb|
|
|
278
|
-
# puts "CRUMB 2: #{crumb}"
|
|
225
|
+
elsif bread.instance_of?(Array)
|
|
226
|
+
bread.each do |crumb|
|
|
279
227
|
@breadcrumbs.push(EndecaXml::Crumb.new(crumb))
|
|
280
228
|
end
|
|
281
229
|
end
|
|
282
|
-
elsif
|
|
283
|
-
|
|
284
|
-
bread['Bread'].each do |crumb|
|
|
285
|
-
# puts "CRUMB 3: #{crumb}"
|
|
230
|
+
elsif breadz.instance_of?(Array)
|
|
231
|
+
bread.each do |crumb|
|
|
286
232
|
@breadcrumbs.push(EndecaXml::Crumb.new(crumb))
|
|
287
233
|
end
|
|
288
234
|
end
|
|
@@ -293,134 +239,149 @@ class EndecaXml
|
|
|
293
239
|
end
|
|
294
240
|
end
|
|
295
241
|
|
|
296
|
-
#
|
|
297
|
-
|
|
242
|
+
# Builds an array of FILTERCRUMBS (BREADCRUMBS used as left nav filterables)
|
|
243
|
+
def build_filtercrumbs
|
|
244
|
+
@filtercrumbs = []
|
|
245
|
+
|
|
246
|
+
breads = @response['Breadcrumbs']['Breads']
|
|
247
|
+
if breads.instance_of?(Hash)
|
|
248
|
+
breads.each do |key, value|
|
|
249
|
+
@filtercrumbs.push(value)
|
|
250
|
+
end
|
|
251
|
+
elsif breads.instance_of?(Array)
|
|
252
|
+
breads.each do |bread|
|
|
253
|
+
if bread.instance_of?(Hash)
|
|
254
|
+
@filtercrumbs.push(bread['Bread'])
|
|
255
|
+
elsif bread.instance_of?(Array)
|
|
256
|
+
bread['Bread'].each do |crumb|
|
|
257
|
+
@filtercrumbs.push(crumb)
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# Builds an array of DIMENSIONS
|
|
298
265
|
def build_dimensions
|
|
299
266
|
@dimensions = []
|
|
300
267
|
|
|
301
|
-
puts "DIMENSIONS: #{@response['Dimensions']}"
|
|
302
268
|
dimensions = @response['Dimensions']
|
|
303
269
|
unless @response['Dimensions'].nil?
|
|
304
|
-
|
|
305
270
|
dimension = @response['Dimensions']['Dimension']
|
|
306
271
|
if dimension.instance_of?(Hash)
|
|
307
272
|
@dimension = EndecaXml::Dimension.new(dimensions)
|
|
308
|
-
|
|
309
|
-
if dimension['DimensionValues']['DimensionValue'].instance_of?(Hash)
|
|
310
|
-
@dimension.dimension_values.push(EndecaXml::Dimension.new(dimension['DimensionValues']))
|
|
311
|
-
elsif dimension['DimensionValues']['DimensionValue'].instance_of?(Array)
|
|
312
|
-
dimension['DimensionValues']['DimensionValue'].each do |dimension_value|
|
|
313
|
-
@dimension.dimension_values.push(EndecaXml::Dimension.new(dimension_value))
|
|
314
|
-
end
|
|
315
|
-
else
|
|
316
|
-
puts "This dimension value is a(n): #{dimension['DimensionValues']['DimensionValue'].class}"
|
|
317
|
-
end
|
|
318
|
-
@dimensions.push(@dimension)
|
|
319
|
-
else
|
|
320
|
-
puts "There are no dimension values on this dimension!"
|
|
321
|
-
end
|
|
273
|
+
add_dimension_values(dimension)
|
|
322
274
|
elsif dimension.instance_of?(Array)
|
|
323
275
|
dimension.each do |dimension|
|
|
324
276
|
@dimension = EndecaXml::Dimension.new(dimension)
|
|
325
|
-
|
|
326
|
-
if dimension['DimensionValues']['DimensionValue'].instance_of?(Hash)
|
|
327
|
-
@dimension.dimension_values.push(EndecaXml::Dimension.new(dimension['DimensionValues']))
|
|
328
|
-
elsif dimension['DimensionValues']['DimensionValue'].instance_of?(Array)
|
|
329
|
-
dimension['DimensionValues']['DimensionValue'].each do |dimension_value|
|
|
330
|
-
@dimension.dimension_values.push(EndecaXml::Dimension.new(dimension_value))
|
|
331
|
-
end
|
|
332
|
-
else
|
|
333
|
-
puts "This dimension value is a(n): #{dimension['DimensionValues']['DimensionValue'].class}"
|
|
334
|
-
end
|
|
335
|
-
@dimensions.push(@dimension)
|
|
336
|
-
else
|
|
337
|
-
puts 'There are no dimension values on this dimension!'
|
|
338
|
-
end
|
|
277
|
+
add_dimension_values(dimension)
|
|
339
278
|
end
|
|
340
|
-
else
|
|
341
|
-
puts "This dimension is a(n): #{dimensions.class}"
|
|
342
279
|
end
|
|
343
280
|
else
|
|
344
281
|
puts 'There are no dimensions with this response!'
|
|
345
282
|
end
|
|
346
283
|
end
|
|
347
284
|
|
|
348
|
-
#
|
|
285
|
+
# Adds an array of DIMENSION VALUES to each DIMENSION
|
|
286
|
+
def add_dimension_values(dimension)
|
|
287
|
+
unless dimension['DimensionValues'].nil?
|
|
288
|
+
if dimension['DimensionValues']['DimensionValue'].instance_of?(Hash)
|
|
289
|
+
@dimension.dimension_values.push(EndecaXml::Dimension.new(dimension['DimensionValues']))
|
|
290
|
+
elsif dimension['DimensionValues']['DimensionValue'].instance_of?(Array)
|
|
291
|
+
dimension['DimensionValues']['DimensionValue'].each do |dimension_value|
|
|
292
|
+
@dimension.dimension_values.push(EndecaXml::Dimension.new(dimension_value))
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
@dimensions.push(@dimension)
|
|
296
|
+
else
|
|
297
|
+
puts "There are no dimension values on this dimension!"
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# Builds an array of BUSINESS RULES
|
|
349
302
|
def build_business_rules
|
|
350
|
-
puts "BUSINESS RULES: #{@response['BusinessRulesResult']}"
|
|
351
|
-
|
|
352
|
-
# NOTE: needs to be looked at again. look at where the array is being pushed
|
|
353
303
|
@business_rules = []
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
304
|
+
|
|
305
|
+
business_rules_result = @response['BusinessRulesResult']
|
|
306
|
+
unless business_rules_result.nil?
|
|
307
|
+
business_rules = @response['BusinessRulesResult']['BusinessRules']
|
|
308
|
+
if business_rules.instance_of?(Hash)
|
|
309
|
+
business_rule = EndecaXml::Rule.new(business_rules)
|
|
310
|
+
business_rules.each do |key, value|
|
|
311
|
+
add_business_rule_properties(value) if key == 'properties'
|
|
312
|
+
add_business_rule_records(value) if key == 'RecordSet'
|
|
362
313
|
end
|
|
363
|
-
elsif
|
|
314
|
+
elsif business_rules.instance_of?(Array)
|
|
364
315
|
@response['BusinessRulesResult']['BusinessRules']['BusinessRule'].each do |rule|
|
|
365
|
-
|
|
316
|
+
business_rule = EndecaXml::Rule.new(rule)
|
|
366
317
|
rule.each do |key, value|
|
|
367
|
-
|
|
368
|
-
if key == 'RecordSet'
|
|
369
|
-
@business_rule.records.push(EndecaXml::Record.new(value['Record'])) unless value.nil?
|
|
370
|
-
end
|
|
318
|
+
add_business_rule_properties(key) if key == 'properties'
|
|
319
|
+
add_business_rule_records(key) if key == 'RecordSet'
|
|
371
320
|
end
|
|
372
321
|
end
|
|
373
|
-
else
|
|
374
|
-
puts "This busniess rule is a(n): #{@response['RecordsSet'].class}"
|
|
375
322
|
end
|
|
376
|
-
@business_rules.push(
|
|
323
|
+
@business_rules.push(business_rule)
|
|
377
324
|
else
|
|
378
325
|
puts 'There are no business rules with this response!'
|
|
379
326
|
end
|
|
380
327
|
end
|
|
381
328
|
|
|
382
|
-
#
|
|
383
|
-
def
|
|
384
|
-
@
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
329
|
+
# Adds an array of PROPERTIES to each BUSINESS RULE
|
|
330
|
+
def add_business_rule_properties(value)
|
|
331
|
+
@business_rule.properties_array.push(EndecaXml::Rule.new(value)) unless value.nil?
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Adds an array of RECORDS to each BUSINESS RULE
|
|
335
|
+
def add_business_rule_records(value)
|
|
336
|
+
@business_rule.records.push(EndecaXml::Record.new(value['Record'])) unless value.nil?
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# Builds the SEARCH REPORTS and SELECTED DIMENSION VALUE IDS if included in response
|
|
340
|
+
def build_applied_filters
|
|
341
|
+
unless @response['AppliedFilters'].nil?
|
|
342
|
+
unless @response['AppliedFilters']['SearchReports'].nil?
|
|
343
|
+
build_search_reports
|
|
394
344
|
else
|
|
395
345
|
puts 'There are no search reports with this response!'
|
|
396
346
|
end
|
|
397
|
-
|
|
347
|
+
unless @response['AppliedFilters']['SelectedDimensionValueIds'].nil?
|
|
348
|
+
build_selected_dimension_value_ids
|
|
349
|
+
else
|
|
350
|
+
puts "There are no selected dimension value ids with this response!"
|
|
351
|
+
end
|
|
398
352
|
else
|
|
399
353
|
puts 'There were not applied filters with this response!'
|
|
400
354
|
end
|
|
401
355
|
end
|
|
402
356
|
|
|
403
|
-
#
|
|
357
|
+
# Builds an array of SEARCH REPORTS
|
|
358
|
+
def build_search_reports
|
|
359
|
+
@searchs = []
|
|
360
|
+
|
|
361
|
+
search_report = @response['AppliedFilters']['SearchReports']['SearchReport']
|
|
362
|
+
|
|
363
|
+
@matchedrecordcount = search_report.fetch('matchedrecordcount')
|
|
364
|
+
@matchedmode = search_report.fetch('matchedmode')
|
|
365
|
+
@matchedtermscount = search_report.fetch('matchedtermscount')
|
|
366
|
+
@applied_search_adjustments = search_report.fetch('AppliedSearchAdjustments')
|
|
367
|
+
@suggested_search_adjustments = search_report.fetch('SuggestedSearchAdjustments')
|
|
368
|
+
|
|
369
|
+
@searchs.push(EndecaXml::Search.new(search_report.fetch('Search')))
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
# Builds an array of SELECTED DIMENSION VALUE IDS
|
|
404
373
|
def build_selected_dimension_value_ids
|
|
405
374
|
@selected_dimension_value_ids = []
|
|
406
375
|
|
|
407
|
-
# puts "SELECTED DIMENSION VALUE IDS: #{@response['AppliedFilters']['SelectedDimensionValueIds']}"
|
|
408
376
|
selected_dimension_value_ids = @response['AppliedFilters']['SelectedDimensionValueIds']
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
selected_dimension_value_ids.each do |key, value|
|
|
415
|
-
selected_dimension_value_id = EndecaXml::DimensionValueId.new(value)
|
|
416
|
-
end
|
|
377
|
+
if selected_dimension_value_ids.instance_of?(Hash)
|
|
378
|
+
selected_dimension_value_id = EndecaXml::DimensionValueId.new(selected_dimension_value_ids)
|
|
379
|
+
elsif selected_dimension_value_ids.instance_of?(Array)
|
|
380
|
+
selected_dimension_value_ids.each do |key, value|
|
|
381
|
+
selected_dimension_value_id = EndecaXml::DimensionValueId.new(value)
|
|
417
382
|
end
|
|
418
|
-
|
|
419
|
-
@selected_dimension_value_ids.push(selected_dimension_value_id)
|
|
420
|
-
|
|
421
|
-
else
|
|
422
|
-
puts "There are no selected dimension value ids with this response!"
|
|
423
383
|
end
|
|
384
|
+
@selected_dimension_value_ids.push(selected_dimension_value_id)
|
|
424
385
|
end
|
|
425
386
|
|
|
426
387
|
end
|
data/lib/endeca_xml/record.rb
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
class EndecaXml
|
|
2
|
-
class
|
|
2
|
+
class Search
|
|
3
3
|
|
|
4
4
|
def initialize(report)
|
|
5
|
-
# puts "REPORT: #{report}"
|
|
6
5
|
report.each do |key, value|
|
|
7
|
-
# puts "#{key} | #{value}"
|
|
8
6
|
self.instance_variable_set(:"@#{key.downcase}", value)
|
|
9
7
|
end
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
# is there anyway to do this dynamically?
|
|
13
|
-
attr_reader :
|
|
11
|
+
attr_reader :key, :mode, :relevancerankingsstrategy, :terms
|
|
14
12
|
|
|
15
13
|
end
|
|
16
14
|
end
|
data/lib/endeca_xml/version.rb
CHANGED
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: endeca_xml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.
|
|
5
|
+
version: 0.9.0
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- sdomino
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-07-
|
|
13
|
+
date: 2011-07-22 00:00:00 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: crackoid
|
|
@@ -34,7 +34,7 @@ dependencies:
|
|
|
34
34
|
version: "0"
|
|
35
35
|
type: :development
|
|
36
36
|
version_requirements: *id002
|
|
37
|
-
description:
|
|
37
|
+
description: This has been officially released as endeca_on_demand. Feel free to continue using this functioning, nearly complete version, or the awesome new, and complete, release version.
|
|
38
38
|
email:
|
|
39
39
|
- sdomino@pagodabox.com
|
|
40
40
|
executables: []
|
|
@@ -56,7 +56,7 @@ files:
|
|
|
56
56
|
- lib/endeca_xml/dimension_value_id.rb
|
|
57
57
|
- lib/endeca_xml/record.rb
|
|
58
58
|
- lib/endeca_xml/rule.rb
|
|
59
|
-
- lib/endeca_xml/
|
|
59
|
+
- lib/endeca_xml/search.rb
|
|
60
60
|
- lib/endeca_xml/version.rb
|
|
61
61
|
homepage: http://github.com/sdomino/endeca_xml
|
|
62
62
|
licenses: []
|
|
@@ -84,6 +84,6 @@ rubyforge_project: endeca_xml
|
|
|
84
84
|
rubygems_version: 1.7.2
|
|
85
85
|
signing_key:
|
|
86
86
|
specification_version: 3
|
|
87
|
-
summary:
|
|
87
|
+
summary: This has been officially released as endeca_on_demand. Feel free to continue using this functioning, nearly complete version, or the awesome new, and complete, release version.
|
|
88
88
|
test_files: []
|
|
89
89
|
|