endeca_xml 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +0 -0
- data/Rakefile +2 -0
- data/endeca_xml.gemspec +26 -0
- data/lib/endeca_xml/version.rb +3 -0
- data/lib/endeca_xml.rb +138 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
data/endeca_xml.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'endeca_xml/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'endeca_xml'
|
7
|
+
s.version = EndecaXml::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['sdomino']
|
10
|
+
s.email = ['sdomino@pagodabox.com']
|
11
|
+
s.homepage = 'http://www.pagodabox.com'
|
12
|
+
s.summary = ''
|
13
|
+
s.description = ''
|
14
|
+
|
15
|
+
s.rubyforge_project = 'endeca_xml'
|
16
|
+
|
17
|
+
s.add_dependency 'crack'
|
18
|
+
s.add_dependency 'builder'
|
19
|
+
|
20
|
+
s.add_development_dependency 'rspec'
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
end
|
data/lib/endeca_xml.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'crack'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
class EndecaXml
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@body = Builder::XmlMarkup.new(:indent => 2)
|
10
|
+
end
|
11
|
+
|
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])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
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
|
23
|
+
when 'category'
|
24
|
+
@body.SelectedDimensionalValueIds do
|
25
|
+
ids.each do |id|
|
26
|
+
@body.tag!('DimensionValueId', id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
when 'dimension'
|
30
|
+
@body.Category do
|
31
|
+
ids.each do |id|
|
32
|
+
@body.tag!('Category', id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
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)
|
41
|
+
@body.Searches do
|
42
|
+
@body.Search do
|
43
|
+
options.each do |option|
|
44
|
+
@body.tag!(option[0], option[1])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# add sorting to the endeca query (ex. endeca.add_sorting(['sort-key', 'p_price_sort'], ['sort-direction', 'Descending']))
|
51
|
+
def add_sorting(*options)
|
52
|
+
@body.Sorts do
|
53
|
+
@body.Sort do
|
54
|
+
options.each do |option|
|
55
|
+
@body.tag!(option[0], option[1])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
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])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
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])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# adds user profiles to the endeca query (ex. endeca.add_user_profiles([1, 2, 3, 4, 5]))
|
76
|
+
def add_user_profiles(profiles)
|
77
|
+
@body.UserProfiles do
|
78
|
+
profiles.each do |profile|
|
79
|
+
@body.tag!('UserProfile', profile)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# FILTERS VALUE DEFAULT
|
85
|
+
# ---------------------------------------------------------
|
86
|
+
# Between
|
87
|
+
# LessThan
|
88
|
+
# LessThanOrEqual
|
89
|
+
# GreaterThan
|
90
|
+
# GreaterThanOrEqual
|
91
|
+
# GeocodeLessThan
|
92
|
+
# GeocodeGreaterThan
|
93
|
+
# GeocodeBetween
|
94
|
+
|
95
|
+
# OPTIONS VALUE DEFAULT
|
96
|
+
# ---------------------------------------------------------
|
97
|
+
# attribute-name
|
98
|
+
# lower-bound
|
99
|
+
# upper-bound
|
100
|
+
# lat-long
|
101
|
+
# 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])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# complete the endeca XML reqeust and send the request to the endeca API
|
115
|
+
def request
|
116
|
+
# insert all of the XML blocks that have been included in the request into the endeca Query XML tag
|
117
|
+
query = Builder::XmlMarkup.new(:indent => 2)
|
118
|
+
query.Query do
|
119
|
+
query << @body.target!
|
120
|
+
end
|
121
|
+
|
122
|
+
uri = URI.parse('http://workbench.deliverframework.net:4000/ws/main')
|
123
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
124
|
+
|
125
|
+
begin
|
126
|
+
request, @response = http.post(uri.path, query.target!, 'Content-type' => 'application/xml')
|
127
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => error
|
128
|
+
puts "ERROR: #{error.message}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# return the request response
|
133
|
+
def response
|
134
|
+
# parse XML response into an hash and return
|
135
|
+
return Crack::XML.parse(@response)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: endeca_xml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.5
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- sdomino
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-22 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: crack
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: builder
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
description: ""
|
49
|
+
email:
|
50
|
+
- sdomino@pagodabox.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- README
|
61
|
+
- Rakefile
|
62
|
+
- endeca_xml.gemspec
|
63
|
+
- lib/endeca_xml.rb
|
64
|
+
- lib/endeca_xml/version.rb
|
65
|
+
homepage: http://www.pagodabox.com
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: endeca_xml
|
88
|
+
rubygems_version: 1.7.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: ""
|
92
|
+
test_files: []
|
93
|
+
|