endeca_on_demand 1.1.0 → 1.2.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.
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_dependency 'builder'
27
27
  s.add_dependency 'activesupport', '~> 3.1'
28
28
  s.add_dependency 'i18n'
29
+ s.add_dependency 'facets'
29
30
  end
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/hash'
2
+ require 'facets/hash/recurse'
2
3
 
3
4
  require 'endeca_on_demand/pp'
4
5
  require 'endeca_on_demand/proxy'
@@ -9,7 +9,7 @@ class EndecaOnDemand::Client
9
9
  attr_reader :api, :default_options, :query
10
10
 
11
11
  def initialize(api, default_options = {})
12
- @api, @default_options = api, default_options.dup.with_indifferent_access
12
+ @api, @default_options = api, default_options.dup.recurse(&:symbolize_keys)
13
13
  end
14
14
 
15
15
  ## associations ##
@@ -9,7 +9,7 @@ class EndecaOnDemand::Query
9
9
  attr_reader :body, :client, :errors, :http, :options, :response, :uri, :xml
10
10
 
11
11
  def initialize(client, options = {})
12
- @client, @options = client, options.dup.with_indifferent_access
12
+ @client, @options = client, options.dup.recurse(&:symbolize_keys)
13
13
 
14
14
  process_options!
15
15
  end
@@ -77,11 +77,11 @@ class EndecaOnDemand::Query
77
77
  ### data ###
78
78
 
79
79
  def flags
80
- @flags ||= options[:flags] = (options[:flags] || {}).inject({}.with_indifferent_access) do |hash,(key,value)|
80
+ @flags ||= options[:flags] = (options[:flags] || {}).inject({}) do |hash,(key,value)|
81
81
  hash.tap do
82
82
  hash[key.to_s.underscore] = value
83
83
  end
84
- end
84
+ end.symbolize_keys
85
85
  end
86
86
 
87
87
  def searches
@@ -109,11 +109,11 @@ class EndecaOnDemand::Query
109
109
  end
110
110
 
111
111
  def advanced_parameters
112
- @advanced_parameters ||= options[:advanced] = (options[:advanced] || {}).inject({}.with_indifferent_access) do |hash,(key,value)|
112
+ @advanced_parameters ||= options[:advanced] = (options[:advanced] || {}).inject({}) do |hash,(key,value)|
113
113
  hash.tap do
114
114
  hash[key.to_s.underscore] = value
115
115
  end
116
- end
116
+ end.symbolize_keys
117
117
  end
118
118
 
119
119
  ###
@@ -132,8 +132,8 @@ class EndecaOnDemand::Query
132
132
  xml.tag!(:Searches) do
133
133
  searches.each do |key,term|
134
134
  xml.tag!(:Search) do
135
- xml.tag!('search-key', key)
136
- xml.tag!('search-term', term)
135
+ xml.tag!('search-key', key.to_s)
136
+ xml.tag!('search-term', term.to_s)
137
137
  end
138
138
  end
139
139
  end
@@ -160,7 +160,7 @@ class EndecaOnDemand::Query
160
160
  xml.tag!(:Sorts) do
161
161
  sorts.each do |key,direction|
162
162
  xml.tag!(:Sort) do
163
- xml.tag!('sort-key', key)
163
+ xml.tag!('sort-key', key.to_s)
164
164
  xml.tag!('sort-direction', direction.to_s.capitalize)
165
165
  end
166
166
  end
@@ -178,8 +178,16 @@ class EndecaOnDemand::Query
178
178
  end
179
179
 
180
180
  def process_options!
181
- default_options = client.default_options[:query] || {}
182
- @options = default_options.dup.merge(options)
181
+ new_options = (client.default_options[:query] || {}).dup
182
+
183
+ (new_options[:flags] ||= {}).merge!(options[:flags] || {}).recurse(&:symbolize_keys) if options[:flags].present?
184
+ (new_options[:paging] ||= {}).merge!(options[:paging] || {}).recurse(&:symbolize_keys) if options[:paging].present?
185
+ (new_options[:searches] ||= {}).merge!(options[:searches] || {}).recurse(&:symbolize_keys) if options[:searches].present?
186
+ (new_options[:sorts] ||= {}).merge!(options[:sorts] || {}).recurse(&:symbolize_keys) if options[:sorts].present?
187
+ (new_options[:dimensions] = [*new_options[:dimensions]]).concat [*options[:dimensions]] if options[:dimensions].present?
188
+ new_options[:category] = options[:category] if options[:category].present?
189
+
190
+ @options = new_options
183
191
  end
184
192
 
185
193
  ##
@@ -23,11 +23,11 @@ class EndecaOnDemand::Response::AppliedFilters::KeywordRedirect < EndecaOnDemand
23
23
  ## data ##
24
24
 
25
25
  def options
26
- @options ||= xml.children.inject({}.with_indifferent_access) do |hash,child|
27
- hash.tap do
28
- hash[child.name] = child.content
29
- end
30
- end
26
+ @options ||= xml.children.inject({}) do |hash,child|
27
+ hash.tap do
28
+ hash[child.name] = child.content
29
+ end
30
+ end.symbolize_keys
31
31
  end
32
32
 
33
33
  ##
@@ -31,11 +31,11 @@ class EndecaOnDemand::Response::AppliedFilters::SearchReport < EndecaOnDemand::P
31
31
  ## data ##
32
32
 
33
33
  def options
34
- @options ||= xml.xpath('child::node()[not(local-name() = "Search")]').inject({}.with_indifferent_access) do |hash,child|
35
- hash.tap do
36
- hash[child.name] = child.content
37
- end
38
- end
34
+ @options ||= xml.xpath('child::node()[not(local-name() = "Search")]').inject({}) do |hash,child|
35
+ hash.tap do
36
+ hash[child.name] = child.content
37
+ end
38
+ end.symbolize_keys
39
39
  end
40
40
 
41
41
  ##
@@ -23,11 +23,11 @@ class EndecaOnDemand::Response::AppliedFilters::SearchReport::Search < EndecaOnD
23
23
  ## data ##
24
24
 
25
25
  def options
26
- @options ||= xml.children.inject({}.with_indifferent_access) do |hash,child|
27
- hash.tap do
28
- hash[child.name] = child.content
29
- end
30
- end
26
+ @options ||= xml.children.inject({}) do |hash,child|
27
+ hash.tap do
28
+ hash[child.name] = child.content
29
+ end
30
+ end.symbolize_keys
31
31
  end
32
32
 
33
33
  ##
@@ -7,6 +7,7 @@ class EndecaOnDemand::Response::Breadcrumb < EndecaOnDemand::Proxy
7
7
  ## fields ##
8
8
 
9
9
  attr_reader :response
10
+ attr_accessor :breads
10
11
 
11
12
  def initialize(response, xml)
12
13
  @response, @xml = response, xml
@@ -18,10 +19,6 @@ class EndecaOnDemand::Response::Breadcrumb < EndecaOnDemand::Proxy
18
19
  EndecaOnDemand::Response::Breadcrumb
19
20
  end
20
21
 
21
- # def inspection
22
- # [ "breads: #{breads.inspect}" ]
23
- # end
24
-
25
22
  ##
26
23
 
27
24
  ## associations ##
@@ -23,11 +23,11 @@ class EndecaOnDemand::Response::Breadcrumb::Bread < EndecaOnDemand::Proxy
23
23
  ## data ##
24
24
 
25
25
  def options
26
- xml.children.inject({}.with_indifferent_access) do |hash,child|
26
+ xml.children.inject({}) do |hash,child|
27
27
  hash.tap do
28
28
  hash[child.name] = child.content
29
29
  end
30
- end
30
+ end.symbolize_keys
31
31
  end
32
32
 
33
33
  ##
@@ -35,11 +35,11 @@ class EndecaOnDemand::Response::BusinessRulesResult::BusinessRule < EndecaOnDema
35
35
  ## data ##
36
36
 
37
37
  def options
38
- xml.xpath('child::node()[not(local-name() = "properties" or local-name() = "RecordsSet")]').inject({}.with_indifferent_access) do |hash,child|
38
+ xml.xpath('child::node()[not(local-name() = "properties" or local-name() = "RecordsSet")]').inject({}) do |hash,child|
39
39
  hash.tap do
40
40
  hash[child.name] = child.content
41
41
  end
42
- end
42
+ end.symbolize_keys
43
43
  end
44
44
 
45
45
  ##
@@ -31,11 +31,11 @@ class EndecaOnDemand::Response::Dimension < EndecaOnDemand::Proxy
31
31
  ## data ##
32
32
 
33
33
  def options
34
- xml.xpath('child::node()[not(local-name() = "DimensionValues")]').inject({}.with_indifferent_access) do |hash,child|
34
+ xml.xpath('child::node()[not(local-name() = "DimensionValues")]').inject({}) do |hash,child|
35
35
  hash.tap do
36
36
  hash[child.name] = child.content
37
37
  end
38
- end
38
+ end.symbolize_keys
39
39
  end
40
40
 
41
41
  ##
@@ -31,11 +31,11 @@ class EndecaOnDemand::Response::Dimension::DimensionValue < EndecaOnDemand::Prox
31
31
  ## data ##
32
32
 
33
33
  def options
34
- xml.children.inject({}.with_indifferent_access) do |hash,child|
34
+ xml.children.inject({}) do |hash,child|
35
35
  hash.tap do
36
36
  hash[child.name] = child.content
37
37
  end
38
- end
38
+ end.symbolize_keys
39
39
  end
40
40
 
41
41
  ##
@@ -31,11 +31,11 @@ class EndecaOnDemand::Response::RecordsSet < EndecaOnDemand::Proxy
31
31
  ## data ##
32
32
 
33
33
  def options
34
- xml.xpath('child::node()[not(local-name() = "Record")]').inject({}.with_indifferent_access) do |hash,child|
34
+ xml.xpath('child::node()[not(local-name() = "Record")]').inject({}) do |hash,child|
35
35
  hash.tap do
36
36
  hash[child.name] = child.content
37
37
  end
38
- end
38
+ end.symbolize_keys
39
39
  end
40
40
 
41
41
  ##
@@ -10,6 +10,8 @@ class EndecaOnDemand::Response::RecordsSet::Record < EndecaOnDemand::Proxy
10
10
 
11
11
  def initialize(records_set, xml)
12
12
  @records_set, @xml = records_set, xml
13
+
14
+ properties
13
15
  end
14
16
 
15
17
  ## override proxy ##
@@ -35,7 +37,7 @@ class EndecaOnDemand::Response::RecordsSet::Record < EndecaOnDemand::Proxy
35
37
  end
36
38
 
37
39
  def serializable_hash
38
- properties.inject({}.with_indifferent_access) { |hash,property| hash.tap { hash[property.name] = property } }
40
+ properties.inject({}) { |hash,property| hash.tap { hash[property.name] = property } }.symbolize_keys
39
41
  end
40
42
  alias :to_hash :serializable_hash
41
43
 
@@ -45,9 +47,11 @@ class EndecaOnDemand::Response::RecordsSet::Record < EndecaOnDemand::Proxy
45
47
 
46
48
  def method_missing(method, *args, &block)
47
49
  if @properties.present? and (property = properties.where(label: method.to_s).first || properties.where(name: method.to_s).first).present?
48
- return property
50
+ return property.value
49
51
  end
50
52
  super(method, *args, &block)
53
+ rescue NoMethodError
54
+ ''
51
55
  end
52
56
 
53
57
  end
@@ -1,3 +1,3 @@
1
- class EndecaOnDemand
2
- VERSION = "1.1.0"
1
+ module EndecaOnDemand
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: endeca_on_demand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70127698146980 !ruby/object:Gem::Requirement
16
+ requirement: &70144082452440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70127698146980
24
+ version_requirements: *70144082452440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: pry
27
- requirement: &70127698146080 !ruby/object:Gem::Requirement
27
+ requirement: &70144082452020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70127698146080
35
+ version_requirements: *70144082452020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70127698145060 !ruby/object:Gem::Requirement
38
+ requirement: &70144082451580 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70127698145060
46
+ version_requirements: *70144082451580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: builder
49
- requirement: &70127698143600 !ruby/object:Gem::Requirement
49
+ requirement: &70144082451040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70127698143600
57
+ version_requirements: *70144082451040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70127698141200 !ruby/object:Gem::Requirement
60
+ requirement: &70144082443940 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.1'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70127698141200
68
+ version_requirements: *70144082443940
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: i18n
71
- requirement: &70127698134580 !ruby/object:Gem::Requirement
71
+ requirement: &70144082443100 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,18 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70127698134580
79
+ version_requirements: *70144082443100
80
+ - !ruby/object:Gem::Dependency
81
+ name: facets
82
+ requirement: &70144082442160 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *70144082442160
80
91
  description: EndecaOnDemand will take a query-string and construct an XML query and
81
92
  send it to an hosted Endeca On-Demand Cluster. It will then parse the response and
82
93
  expose an API for using the response data.