endeca_xml 0.2.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 sdomino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ = endeca_xml
2
+
3
+ endeca_xml provides a way for you to make http requests via the endeca XML API.
4
+
5
+ == Features
6
+
7
+ not much right now, but it will get there... hopefully
8
+
9
+ == Install
10
+
11
+ === Rails
12
+
13
+ Add this line to your Gemfile:
14
+
15
+ gem 'endeca_xml'
16
+
17
+ Then bundle install:
18
+
19
+ bundle install
20
+
21
+ ---
22
+
23
+ === Non Rails
24
+
25
+ gem install compressit
26
+
27
+ == Usage
28
+
29
+ The gem provides examples of each of the methods available. Right now its kind of clunky and you have to call each method individually to construct the XML request, then submit it. The response is returned as a 'cracked' ruby hash.
30
+
31
+ == TODO
32
+
33
+ * 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.
34
+ * Have EndecaXml make the request after its all done constructing the query rather than requiring that the developer use the request method.
35
+ * Review the code and clean things up, making it nice and sugary sweet.
36
+ * The add_filters method needs some documentation, an example, and to be tested in a query.
37
+
38
+ ---
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2011 Steve Domino. See LICENSE.txt for further details
data/endeca_xml.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ['sdomino']
10
10
  s.email = ['sdomino@pagodabox.com']
11
11
  s.homepage = 'http://www.pagodabox.com'
12
- s.summary = ''
13
- s.description = ''
12
+ s.summary = 'endeca_xml provides a way for you to make http requests via the endeca XML API. '
13
+ s.description = 'endeca_xml provides a way for you to make http requests via the endeca XML API. '
14
14
 
15
15
  s.rubyforge_project = 'endeca_xml'
16
16
 
@@ -1,3 +1,3 @@
1
1
  class EndecaXml
2
- VERSION = "0.2.5"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/endeca_xml.rb CHANGED
@@ -3,82 +3,125 @@ require 'crack'
3
3
  require 'net/http'
4
4
  require 'uri'
5
5
 
6
+ # This is an example of the form used to post all the desired options that will be used to construct the endeca XML query,
7
+ # each input name corresponds to a function that is called when building the XML. It is important that the names stay the same (for now)!
8
+ #
9
+ # <form action="/endeca" method="post">
10
+ # <input type="hidden" name="endeca[base]" value="{'RecordsSet' => true, 'Dimensions' => true, 'BusinessRulesResult' => true, 'AppliedFilters' => true}" />
11
+ # <input type="hidden" name="endeca[nav]" value="{'type' => '', 'ids' => [1, 2, 3, 4]}" />
12
+ # <input type="hidden" name="endeca[search]" value="{'search-key' => 'key', 'search-term' => 'term'}" />
13
+ # <input type="hidden" name="endeca[sort]" value="{'sort-key' => 'key', 'direction' => 'direction'}" />
14
+ # <input type="hidden" name="endeca[paging]" value="{'RecordsOffset' => 0, 'RecordsPerPage' => 10}" />
15
+ # <input type="hidden" name="endeca[parameters]" value="{'AggregationKey' => 'key'}" />
16
+ # <input type="hidden" name="endeca[profiles]" value="{'profiles' => [1, 2, 3, 4]}" />
17
+ # <input type="hidden" name="endeca[filters]" value="{'filter' => {'option' => 'option', 'option' => 'option'}}" />
18
+ # <input type="submit" />
19
+ # </form>
20
+
6
21
  class EndecaXml
7
22
 
8
- def initialize
23
+ def initialize(params)
9
24
  @body = Builder::XmlMarkup.new(:indent => 2)
25
+
26
+ # puts "PARAMS: #{params}"
27
+
28
+ # take the parameters past in a form post and creates the options hash out of each key|value pair, using the key as root key in a new hash, and the value as that hash's value
29
+ options = {}
30
+ params.each do |key, value|
31
+ options.update(Hash[key, eval(value)])
32
+ end
33
+
34
+ # puts "OPTIONS: #{options}"
35
+
36
+ # call a corresponding function based off the root key created for each hash in the options hash to build the endeca query
37
+ options.each do |key, value|
38
+ self.send(key.to_sym, value)
39
+ end
40
+
41
+ # once the XML request is built send it off
42
+ send_request
10
43
  end
11
44
 
12
- # adds endeca base options to the endeca query (ex. endeca.add_base_options(['Dimensions', true], ['RecordsSet', true], ['BusinessRulesResult', true], ['AppliedFilters', true]))
13
- def add_base_options(*options)
14
- options.each do |option|
15
- @body.tag!(option[0], option[1])
45
+ def base(options)
46
+ # puts "BASE: #{options}"
47
+ options.each do |key, value|
48
+ @body.tag!(key, value)
16
49
  end
50
+ # print @body.target!
17
51
  end
18
52
 
19
- # IMPORTANT: this option is mutually exclusive with the add_search option
20
- # makes the endeca query a type nav (ex. endeca.add_nav('category', [1, 2, 3, 4, 5]))
21
- def add_nav(type, ids)
22
- case type
53
+ def nav(options)
54
+ # puts "NAV: #{options}"
55
+ case options['type']
23
56
  when 'category'
24
- @body.SelectedDimensionalValueIds do
25
- ids.each do |id|
26
- @body.tag!('DimensionValueId', id)
57
+ @body.Category do
58
+ options['ids'].each do |id|
59
+ @body.tag!('Category', id)
27
60
  end
28
61
  end
29
62
  when 'dimension'
30
- @body.Category do
31
- ids.each do |id|
32
- @body.tag!('Category', id)
63
+ @body.SelectedDimensionalValueIds do
64
+ options['ids'].each do |id|
65
+ @body.tag!('DimensionValueId', id)
33
66
  end
34
67
  end
68
+ else
69
+ #
35
70
  end
71
+ # puts @body.target!
36
72
  end
37
73
 
38
- # IMPORTANT: this option is mutually exclusive with the add_nav option
39
- # makes the endeca query a type search (ex. endeca.add_searches(['searck-key', 'primary'], ['serach-term', 'gold']))
40
- def add_searches(*options)
74
+ def search(options)
75
+ # puts "SEARCH: #{options}"
41
76
  @body.Searches do
42
77
  @body.Search do
43
- options.each do |option|
44
- @body.tag!(option[0], option[1])
78
+ options.each do |key, value|
79
+ @body.tag!(key, value)
45
80
  end
46
81
  end
47
82
  end
83
+ # puts @body.target!
48
84
  end
49
85
 
50
- # add sorting to the endeca query (ex. endeca.add_sorting(['sort-key', 'p_price_sort'], ['sort-direction', 'Descending']))
51
- def add_sorting(*options)
86
+ def sort(options)
87
+ # puts "SORT: #{options}"
52
88
  @body.Sorts do
53
89
  @body.Sort do
54
- options.each do |option|
55
- @body.tag!(option[0], option[1])
90
+ options.each do |key, value|
91
+ @body.tag!(key, value)
56
92
  end
57
93
  end
58
94
  end
95
+ # puts @body.target!
59
96
  end
60
97
 
61
- # adds paging to the endeca query (ex. endeca.add_paging(['RecrodOffset', 0], ['RecordsPerPage', 10]))
62
- def add_paging(*options)
63
- options.each do |option|
64
- @body.tag!(option[0], option[1])
98
+ def paging(options)
99
+ # puts "PAGING: #{options}"
100
+ options.each do |key, value|
101
+ @body.tag!(key, value)
65
102
  end
103
+ # puts @body.target!
66
104
  end
67
105
 
68
- # adds advanced parameters to the endeca query (ex. endeca.add_advanced_parameters(['AggregationKey', 'p_group_id']))
69
- def add_advanced_parameters(*parameters)
70
- parameters.each do |parameter|
71
- @body.tag!(parameter[0], parameter[1])
106
+ def parameters(options)
107
+ # puts "PARAMETERS: #{parameters}"
108
+ options.each do |key, value|
109
+ @body.tag!(key, value)
72
110
  end
111
+ # puts @body.target!
73
112
  end
74
113
 
75
- # adds user profiles to the endeca query (ex. endeca.add_user_profiles([1, 2, 3, 4, 5]))
76
- def add_user_profiles(profiles)
114
+ def profiles(options)
115
+ # puts "PROFILES: #{profiles}"
77
116
  @body.UserProfiles do
78
- profiles.each do |profile|
79
- @body.tag!('UserProfile', profile)
117
+ options.each do |key, value|
118
+ # puts "#{key}: #{value}"
119
+ value.each do |profile|
120
+ @body.tag!('UserProfile', profile)
121
+ end
80
122
  end
81
123
  end
124
+ # puts @body.target!
82
125
  end
83
126
 
84
127
  # FILTERS VALUE DEFAULT
@@ -99,26 +142,99 @@ class EndecaXml
99
142
  # upper-bound
100
143
  # lat-long
101
144
  # distance
102
- def add_filters(*filters)
103
- filters.each do |filter|
104
- @body.RangeFilters do
105
- @body.tag!(filter[0], filter[1]) do
106
- filters[2].each do |option|
107
- @body.tag!(option[0], option[1])
145
+ def filters(filters)
146
+ puts "FILTERS: #{filters}"
147
+ # filters.each do |filter|
148
+ # @body.RangeFilters do
149
+ # @body.tag!(filter[0], filter[1]) do
150
+ # filters[2].each do |option|
151
+ # @body.tag!(option[0], option[1])
152
+ # end
153
+ # end
154
+ # end
155
+ # end
156
+ end
157
+
158
+ def get_records
159
+ @blarg['RecordsSet']['Record'].each do |record|
160
+ record.each do |key, value|
161
+ puts "#{key}: #{value}"
162
+ end
163
+ end unless response['RecordsSet'].nil?
164
+ end
165
+
166
+ def get_breadcrumbs
167
+ @blarg['Breadcrumbs']['Breads'].each do |crumb|
168
+ crumb.each do |key, value|
169
+ puts "#{key}: #{value}"
170
+ end
171
+ end unless response['Breadcrumbs'].nil?
172
+ end
173
+
174
+ def get_dimensions
175
+ @blarg['Dimensions']['Dimension'].each do |dimension|
176
+ dimension.each do |key, value|
177
+ puts "#{key}: #{value}"
178
+ if key == 'DimensionValues'
179
+ if value['DimensionValue'].instance_of?(Array)
180
+ value['DimensionValue'].each do |value|
181
+ value.each do |key, value|
182
+ puts " #{key}: #{value}"
183
+ end
184
+ end
185
+ elsif value['DimensionValue'].instance_of?(Hash)
186
+ value['DimensionValue'].each do |key, value|
187
+ puts " #{key}: #{value}"
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end unless response['Dimensions'].nil?
193
+ end
194
+
195
+ def get_business_rules
196
+ @blarg['BusinessRulesResult']['BusinessRules']['BusinessRule'].each do |rule|
197
+ rule.each do |key, value|
198
+ puts "#{key}: #{value}"
199
+ value.each do |key, value|
200
+ puts " #{key}: #{value}"
201
+ end if key == 'properties'
202
+
203
+ if key == 'RecordSet'
204
+ if value.instance_of?(Array)
205
+ value['Record'].each do |record|
206
+ record.each do |key, value|
207
+ puts " #{key}: #{value}"
208
+ end
209
+ end
210
+ elsif value.instance_of?(Hash)
211
+ value['Record'].each do |key, value|
212
+ puts " #{key}: #{value}"
213
+ end
108
214
  end
109
215
  end
110
216
  end
111
- end
217
+ end unless response['BusinessRulesResult'].nil?
218
+ end
219
+
220
+ def get_applied_filters
221
+ @blarg['AppliedFilters'].each do |filter|
222
+ puts "FILTER: #{filter}"
223
+ end unless response['AppliedFilters'].nil?
112
224
  end
113
225
 
226
+ private
227
+
114
228
  # complete the endeca XML reqeust and send the request to the endeca API
115
- def request
229
+ def send_request
116
230
  # insert all of the XML blocks that have been included in the request into the endeca Query XML tag
117
231
  query = Builder::XmlMarkup.new(:indent => 2)
118
232
  query.Query do
119
233
  query << @body.target!
120
234
  end
121
235
 
236
+ # puts "QUERY: #{query.target!}"
237
+
122
238
  uri = URI.parse('http://workbench.deliverframework.net:4000/ws/main')
123
239
  http = Net::HTTP.new(uri.host, uri.port)
124
240
 
@@ -129,10 +245,13 @@ class EndecaXml
129
245
  end
130
246
  end
131
247
 
132
- # return the request response
248
+ # get the request response
133
249
  def response
134
- # parse XML response into an hash and return
135
- return Crack::XML.parse(@response)
250
+ # parse XML response into an hash
251
+ response = Crack::XML.parse(@response)
252
+ # puts "RESPONSE: #{response}"
253
+
254
+ @blarg = response['Final']
136
255
  end
137
256
 
138
257
  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.2.5
5
+ version: 0.5.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-06-22 00:00:00 Z
13
+ date: 2011-06-23 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: crack
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: "0"
46
46
  type: :development
47
47
  version_requirements: *id003
48
- description: ""
48
+ description: "endeca_xml provides a way for you to make http requests via the endeca XML API. "
49
49
  email:
50
50
  - sdomino@pagodabox.com
51
51
  executables: []
@@ -57,7 +57,8 @@ extra_rdoc_files: []
57
57
  files:
58
58
  - .gitignore
59
59
  - Gemfile
60
- - README
60
+ - LICENSE.txt
61
+ - README.rdoc
61
62
  - Rakefile
62
63
  - endeca_xml.gemspec
63
64
  - lib/endeca_xml.rb
@@ -88,6 +89,6 @@ rubyforge_project: endeca_xml
88
89
  rubygems_version: 1.7.2
89
90
  signing_key:
90
91
  specification_version: 3
91
- summary: ""
92
+ summary: endeca_xml provides a way for you to make http requests via the endeca XML API.
92
93
  test_files: []
93
94
 
data/README DELETED
File without changes