endeca_xml 0.5.6 → 0.7.5

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 CHANGED
@@ -45,6 +45,64 @@ A lot more work has been done since the previous version. endeca_xml now constru
45
45
 
46
46
  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 input field, and if you don't need a value within an option don't include it.
47
47
 
48
+ This is the command that would send the above request:
49
+ EndecaXml.request(params[:endeca])
50
+
51
+ Below are examples of how you could access the response data:
52
+
53
+ Records:
54
+
55
+ EndecaXml.records.each do |record|
56
+ puts "---------- BEGIN RECORD"
57
+ puts "RECORD: #{record.inspect}"
58
+ puts "---------- END"
59
+ end
60
+
61
+ Breadcrumbs:
62
+
63
+ EndecaXml.breadcrumbs.each do |crumb|
64
+ puts "---------- BEGIN CRUMB"
65
+ puts "CRUMB: #{crumb.inspect}"
66
+ puts "---------- END"
67
+ end
68
+
69
+ Dimensions:
70
+
71
+ EndecaXml.dimensions.each do |dimension|
72
+ puts "---------- BEGIN DIMENSION"
73
+ puts "DIMENSION: #{dimension.inspect}"
74
+ puts "DIMENSION VALUES: #{dimension.dimensionvalues}"
75
+ puts "DIMENSION VALUES ARRAY: #{dimension.dimension_values}"
76
+ puts "---------- END"
77
+ end
78
+
79
+ Rules:
80
+
81
+ EndecaXml.rules.each do |rule|
82
+ puts "---------- BEGIN RULE"
83
+ puts "RULE: #{rule.inspect}"
84
+ puts "RULE PROPERTIES: #{rule.properties}"
85
+ puts "RULE PROPERTIES_ARRAY: #{rule.properties_array}"
86
+ puts "RULE RECORDS: #{rule.records}"
87
+ puts "---------- END"
88
+ end
89
+
90
+ Filters:
91
+
92
+ EndecaXml.filters.each do |filter|
93
+ puts "---------- BEGIN FILTER"
94
+ puts "FILTER: #{filter.inspect}"
95
+ puts "---------- END"
96
+ end
97
+
98
+ 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):
99
+
100
+ EndecaXml.records.each do |record|
101
+ record.name
102
+ record.price
103
+ etc...
104
+ end
105
+
48
106
  == TODO
49
107
 
50
108
  * (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.
data/endeca_xml.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ['sdomino']
10
10
  s.email = ['sdomino@pagodabox.com']
11
- s.homepage = 'http://www.pagodabox.com'
11
+ s.homepage = 'http://github.com/sdomino/endeca_xml'
12
12
  s.summary = 'endeca_xml provides an interface between your web application and the thanxmedia Endeca XML API'
13
13
  s.description = 'endeca_xml provides an interface between your web application and the thanxmedia Endeca XML API'
14
14
 
@@ -0,0 +1,14 @@
1
+ module EndecaXml
2
+ class Crumb
3
+
4
+ def initialize(crumb)
5
+ crumb.each do |key, value|
6
+ self.instance_variable_set(:"@#{key.downcase}", value)
7
+ end
8
+ end
9
+
10
+ # is there anyway to do this dynamically?
11
+ attr_reader :name, :original_id, :id
12
+
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module EndecaXml
2
+ class Dimension
3
+
4
+ def initialize(dimension)
5
+ dimension.each do |key, value|
6
+ self.instance_variable_set(:"@#{key.downcase}", value)
7
+ end
8
+
9
+ @dimension_values = []
10
+ end
11
+
12
+ # is there anyway to do this dynamically?
13
+ attr_reader :name, :id, :group_name, :hasmore, :dimensionvalues, :dimension_values
14
+
15
+ end
16
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ module EndecaXml
2
+ class Record
3
+
4
+ def initialize(record)
5
+ record.each do |key, value|
6
+ self.instance_variable_set(:"@#{key.downcase}", value)
7
+ end
8
+ end
9
+
10
+ # is there anyway to do this dynamically?
11
+ attr_reader :p_name, :p_category_id, :p_dax_item_number, :p_image, :p_price_retail, :p_price_sale, :p_price_sort, :p_url_detail
12
+
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module EndecaXml
2
+ class Rule
3
+
4
+ def initialize(rule)
5
+ rule.each do |key, value|
6
+ self.instance_variable_set(:"@#{key.downcase}", value)
7
+ end
8
+
9
+ @properties_array = []
10
+ @records = []
11
+ end
12
+
13
+ # is there anyway to do this dynamically?
14
+ attr_reader :title, :id, :style, :zone, :recordcount, :recordset, :properties, :properties_array, :records
15
+
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
- class EndecaXml
2
- VERSION = "0.5.6"
1
+ module EndecaXml
2
+ VERSION = "0.7.5"
3
3
  end
data/lib/endeca_xml.rb CHANGED
@@ -1,3 +1,5 @@
1
+ Dir["#{File.dirname(__FILE__)}/endeca_xml/*"].each { |file| require(file)}
2
+
1
3
  require 'builder'
2
4
  # require 'crack' # NOTE: see .gemspec
3
5
  require 'crackoid'
@@ -20,9 +22,9 @@ require 'uri'
20
22
  # <input type="submit" />
21
23
  # </form>
22
24
 
23
- class EndecaXml
25
+ module EndecaXml
24
26
 
25
- def initialize(params)
27
+ def self.request(params)
26
28
  @body = Builder::XmlMarkup.new(:indent => 2)
27
29
 
28
30
  # puts "PARAMS: #{params}"
@@ -44,22 +46,49 @@ class EndecaXml
44
46
  send_request
45
47
  end
46
48
 
47
- def host(options)
49
+ def self.records
50
+ @records
51
+ end
52
+
53
+ def self.breadcrumbs
54
+ @breadcrumbs
55
+ end
56
+
57
+ def self.dimensions
58
+ @dimensions
59
+ end
60
+
61
+ def self.rules
62
+ @business_rules
63
+ end
64
+
65
+ def self.filters
66
+ @applied_filters
67
+ end
68
+
69
+ private
70
+
71
+ ### XML REQUEST ###
72
+
73
+ # constructs the http request
74
+ def self.host(options)
48
75
  options.each do |key, value|
49
76
  @uri = URI.parse(value)
50
77
  end
51
78
  @http = Net::HTTP.new(@uri.host, @uri.port)
52
79
  end
53
-
54
- def base(options)
80
+
81
+ # adds BASE OPTIONS to the XML request
82
+ def self.base(options)
55
83
  # puts "BASE: #{options}"
56
84
  options.each do |key, value|
57
85
  @body.tag!(key, value)
58
86
  end
59
87
  # print @body.target!
60
88
  end
61
-
62
- def nav(options)
89
+
90
+ # adds NAV to the XML request
91
+ def self.nav(options)
63
92
  # puts "NAV: #{options}"
64
93
  case options['type']
65
94
  when 'category'
@@ -79,8 +108,9 @@ class EndecaXml
79
108
  end
80
109
  # puts @body.target!
81
110
  end
82
-
83
- def search(options)
111
+
112
+ # adds SEARCHES to the XML request
113
+ def self.search(options)
84
114
  # puts "SEARCH: #{options}"
85
115
  @body.Searches do
86
116
  @body.Search do
@@ -91,8 +121,9 @@ class EndecaXml
91
121
  end
92
122
  # puts @body.target!
93
123
  end
94
-
95
- def sort(options)
124
+
125
+ # adds SORTS to the XML request
126
+ def self.sort(options)
96
127
  # puts "SORT: #{options}"
97
128
  @body.Sorts do
98
129
  @body.Sort do
@@ -103,24 +134,27 @@ class EndecaXml
103
134
  end
104
135
  # puts @body.target!
105
136
  end
106
-
107
- def paging(options)
137
+
138
+ # adds PAGING to the XML request
139
+ def self.paging(options)
108
140
  # puts "PAGING: #{options}"
109
141
  options.each do |key, value|
110
142
  @body.tag!(key, value)
111
143
  end
112
144
  # puts @body.target!
113
145
  end
114
-
115
- def parameters(options)
146
+
147
+ # adds ADVANCED PARAMETERS to the XML request
148
+ def self.parameters(options)
116
149
  # puts "PARAMETERS: #{options}"
117
150
  options.each do |key, value|
118
151
  @body.tag!(key, value)
119
152
  end
120
153
  # puts @body.target!
121
154
  end
122
-
123
- def profiles(options)
155
+
156
+ # adds PROFILES to the XML request
157
+ def self.profiles(options)
124
158
  # puts "PROFILES: #{options}"
125
159
  @body.UserProfiles do
126
160
  options.each do |key, value|
@@ -132,8 +166,9 @@ class EndecaXml
132
166
  end
133
167
  # puts @body.target!
134
168
  end
135
-
136
- def filters(options)
169
+
170
+ # adds FILTERS to the XML request
171
+ def self.filters(options)
137
172
  # puts "FILTERS: #{options}"
138
173
  @body.RangeFilters do
139
174
  options.each do |key, value|
@@ -148,98 +183,91 @@ class EndecaXml
148
183
  # puts @body.target!
149
184
  end
150
185
 
151
- def get_records
186
+ # complete the endeca XML reqeust and send the request to the endeca API
187
+ def self.send_request
188
+ # insert all of the XML blocks that have been included in the request into the endeca Query XML tag
189
+ query = Builder::XmlMarkup.new(:indent => 2)
190
+ query.Query do
191
+ query << @body.target!
192
+ end
193
+
194
+ # puts "QUERY: #{query.target!}"
195
+
196
+ begin
197
+ request, response = @http.post(@uri.path, query.target!, 'Content-type' => 'application/xml')
198
+ handle_response(Crackoid::XML.parse(response))
199
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => error
200
+ puts "ERROR: #{error.message}"
201
+ end
202
+ end
203
+
204
+ # get the request response and parse it into an hash
205
+ def self.handle_response(response)
206
+ # puts "RESPONSE: #{response}"
207
+ @response = response['Final']
208
+
209
+ self.build_data
210
+ end
211
+
212
+ def self.build_data
213
+ self.build_records
214
+ self.build_breadcrumbs
215
+ self.build_dimensions
216
+ self.build_business_rules
217
+ # self.build_applied_filters
218
+ end
219
+
220
+ # builds the RECORDS hash
221
+ @records = []
222
+ def self.build_records
152
223
  @response['RecordsSet']['Record'].each do |record|
153
- record.each do |key, value|
154
- puts "#{key}: #{value}"
155
- end
224
+ @records.push(EndecaXml::Record.new(record))
156
225
  end unless @response['RecordsSet'].nil?
157
226
  end
158
-
159
- def get_breadcrumbs
227
+
228
+ # builds the BREADCRUMBS hash
229
+ @breadcrumbs = []
230
+ def self.build_breadcrumbs
160
231
  @response['Breadcrumbs']['Breads'].each do |crumb|
161
- crumb.each do |key, value|
162
- puts "#{key}: #{value}"
163
- end
232
+ @breadcrumbs.pusn(EndecaXml::Crumb.new(crumb))
164
233
  end unless @response['Breadcrumbs'].nil?
165
234
  end
166
-
167
- def get_dimensions
235
+
236
+ # builds the DIMENSIONS hash
237
+ @dimensions = []
238
+ def self.build_dimensions
168
239
  @response['Dimensions']['Dimension'].each do |dimension|
240
+ @dimension = EndecaXml::Dimension.new(dimension)
169
241
  dimension.each do |key, value|
170
- puts "#{key}: #{value}"
171
- if key == 'DimensionValues'
172
- if value['DimensionValue'].instance_of?(Array)
173
- value['DimensionValue'].each do |value|
174
- value.each do |key, value|
175
- puts " #{key}: #{value}"
176
- end
177
- end
178
- elsif value['DimensionValue'].instance_of?(Hash)
179
- value['DimensionValue'].each do |key, value|
180
- puts " #{key}: #{value}"
181
- end
182
- end
183
- end
242
+ value['DimensionValue'].each do |value|
243
+ @dimension.dimension_values.push(EndecaXml::Dimension.new(value))
244
+ end if key == 'DimensionValues'
184
245
  end
246
+ @dimensions.push(@dimension)
185
247
  end unless @response['Dimensions'].nil?
186
248
  end
187
-
188
- def get_business_rules
249
+
250
+ # builds the BUSINESS RULES hash
251
+ @business_rules = []
252
+ def self.build_business_rules
189
253
  @response['BusinessRulesResult']['BusinessRules']['BusinessRule'].each do |rule|
254
+ @business_rule = EndecaXml::Rule.new(rule)
190
255
  rule.each do |key, value|
191
- puts "#{key}: #{value}"
192
- value.each do |key, value|
193
- puts " #{key}: #{value}"
194
- end if key == 'properties'
195
-
256
+ @business_rule.properties_array.push(EndecaXml::Rule.new(value)) if key == 'properties'
196
257
  if key == 'RecordSet'
197
- if value.instance_of?(Array)
198
- value['Record'].each do |record|
199
- record.each do |key, value|
200
- puts " #{key}: #{value}"
201
- end
202
- end
203
- elsif value.instance_of?(Hash)
204
- value['Record'].each do |key, value|
205
- puts " #{key}: #{value}"
206
- end
207
- end
258
+ @business_rule.records.push(EndecaXml::Record.new(value['Record'])) unless value.nil?
208
259
  end
209
260
  end
261
+ @business_rules.push(@business_rule)
210
262
  end unless @response['BusinessRulesResult'].nil?
211
263
  end
212
-
213
- def get_applied_filters
264
+
265
+ # builds the APPLIED FILTERS hash
266
+ @applied_filters = []
267
+ def self.build_applied_filters
214
268
  @response['AppliedFilters'].each do |filter|
215
- puts "FILTER: #{filter}"
269
+ # puts "FILTER: #{filter}"
216
270
  end unless @response['AppliedFilters'].nil?
217
271
  end
218
272
 
219
- private
220
-
221
- # complete the endeca XML reqeust and send the request to the endeca API
222
- def send_request
223
- # insert all of the XML blocks that have been included in the request into the endeca Query XML tag
224
- query = Builder::XmlMarkup.new(:indent => 2)
225
- query.Query do
226
- query << @body.target!
227
- end
228
-
229
- # puts "QUERY: #{query.target!}"
230
-
231
- begin
232
- request, response = @http.post(@uri.path, query.target!, 'Content-type' => 'application/xml')
233
- handle_response(Crackoid::XML.parse(response))
234
- rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => error
235
- puts "ERROR: #{error.message}"
236
- end
237
- end
238
-
239
- # get the request response and parse it into an hash
240
- def handle_response(response)
241
- puts "RESPONSE: #{response}"
242
- # @response = response['Final']
243
- end
244
-
245
273
  end
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.6
5
+ version: 0.7.5
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-05 00:00:00 Z
13
+ date: 2011-07-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: crackoid
@@ -51,8 +51,13 @@ files:
51
51
  - Rakefile
52
52
  - endeca_xml.gemspec
53
53
  - lib/endeca_xml.rb
54
+ - lib/endeca_xml/crumb.rb
55
+ - lib/endeca_xml/dimension.rb
56
+ - lib/endeca_xml/filter.rb
57
+ - lib/endeca_xml/record.rb
58
+ - lib/endeca_xml/rule.rb
54
59
  - lib/endeca_xml/version.rb
55
- homepage: http://www.pagodabox.com
60
+ homepage: http://github.com/sdomino/endeca_xml
56
61
  licenses: []
57
62
 
58
63
  post_install_message: