endeca 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.1.0 / 2009-01-20
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
@@ -0,0 +1,37 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ endeca.gemspec
6
+ example/benchmark.rb
7
+ example/listing.rb
8
+ lib/class_to_proc.rb
9
+ lib/core_ext.rb
10
+ lib/endeca.rb
11
+ lib/endeca/benchmarking.rb
12
+ lib/endeca/breadcrumb.rb
13
+ lib/endeca/breadcrumbs.rb
14
+ lib/endeca/dimension.rb
15
+ lib/endeca/document.rb
16
+ lib/endeca/document_collection.rb
17
+ lib/endeca/logging.rb
18
+ lib/endeca/map.rb
19
+ lib/endeca/readers.rb
20
+ lib/endeca/refinement.rb
21
+ lib/endeca/request.rb
22
+ lib/endeca/transformer.rb
23
+ spec/core_ext_spec.rb
24
+ spec/endeca/benchmarking_spec.rb
25
+ spec/endeca/breadcrumb_spec.rb
26
+ spec/endeca/dimension_spec.rb
27
+ spec/endeca/document_collection_spec.rb
28
+ spec/endeca/document_spec.rb
29
+ spec/endeca/map_spec.rb
30
+ spec/endeca/readers_spec.rb
31
+ spec/endeca/refinement_spec.rb
32
+ spec/endeca/request_spec.rb
33
+ spec/endeca/transformer_spec.rb
34
+ spec/endeca_spec.rb
35
+ spec/rcov.opts
36
+ spec/spec.opts
37
+ spec/spec_helper.rb
@@ -0,0 +1,60 @@
1
+ endeca
2
+ by Rein Henrichs and Andy Stone
3
+
4
+ == DESCRIPTION:
5
+
6
+ An Endeca client library for Ruby.
7
+
8
+ == FEATURES/PROBLEMS:
9
+
10
+ == SYNOPSIS:
11
+ class Listing < Endeca::Document
12
+ path 'http://endeca.example.com/api'
13
+
14
+ map :id => 'R'
15
+ map(:expand_refinements => :expand_all_dims).into(:M)
16
+
17
+ float_reader \
18
+ :latitude,
19
+ :longitude,
20
+
21
+ integer_reader :endeca_id
22
+
23
+ boolean_reader :isawesome => :awesome?
24
+ end
25
+
26
+ Listing.find(1234).awesome? # => true
27
+ Listing.find(:all, :per_page => 10).size # => 10
28
+
29
+ == REQUIREMENTS:
30
+
31
+ * FakeWeb (for running tests)
32
+
33
+ == INSTALL:
34
+
35
+ sudo gem install primedia-endeca --source=http://gems.github.com
36
+
37
+ == LICENSE:
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2008 PRIMEDIA Inc.
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ begin
6
+ require 'bones'
7
+ Bones.setup
8
+ rescue LoadError
9
+ begin
10
+ load 'tasks/setup.rb'
11
+ rescue LoadError
12
+ raise RuntimeError, '### please install the "bones" gem ###'
13
+ end
14
+ end
15
+
16
+ begin; require 'metric_fu'; rescue LoadError; end
17
+
18
+ ensure_in_path 'lib'
19
+ require 'endeca'
20
+
21
+ task :default => 'rcov'
22
+
23
+ desc "Simple benchmarking"
24
+ task :benchmark do
25
+ sh('ruby example/benchmark.rb')
26
+ end
27
+ task :bm => :benchmark
28
+
29
+ desc "Flog your code for Justice!"
30
+ task :flog do
31
+ sh('flog lib/**/*.rb')
32
+ end
33
+
34
+ desc "Run all specs and rcov in a non-sucky way"
35
+ Spec::Rake::SpecTask.new(:rcov) do |t|
36
+ t.spec_opts = IO.readlines("spec/spec.opts").map {|l| l.chomp.split " "}.flatten
37
+ t.spec_files = FileList['spec/**/*_spec.rb']
38
+ t.rcov = true
39
+ t.rcov_opts = IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
40
+ end
41
+
42
+ PROJ.name = 'endeca'
43
+ PROJ.authors = ['Rein Henrichs', 'Andy Stone']
44
+ PROJ.email = ''
45
+ PROJ.url = 'http://github.com/primedia/endeca-ruby'
46
+ PROJ.version = Endeca::VERSION
47
+ PROJ.rubyforge.name = 'endeca'
48
+ PROJ.readme_file = "README.rdoc"
49
+ PROJ.exclude << '.swp'
50
+ PROJ.exclude << '.gitignore'
51
+
52
+ # EOF
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{endeca}
5
+ s.version = "1.3.7"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Rein Henrichs", "Andy Stone"]
9
+ s.date = %q{2009-09-15}
10
+ s.description = %q{An Endeca client library for Ruby.}
11
+ s.email = %q{}
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "endeca.gemspec", "example/benchmark.rb", "example/listing.rb", "lib/class_to_proc.rb", "lib/core_ext.rb", "lib/endeca.rb", "lib/endeca/benchmarking.rb", "lib/endeca/breadcrumb.rb", "lib/endeca/breadcrumbs.rb", "lib/endeca/dimension.rb", "lib/endeca/document.rb", "lib/endeca/document_collection.rb", "lib/endeca/logging.rb", "lib/endeca/map.rb", "lib/endeca/readers.rb", "lib/endeca/refinement.rb", "lib/endeca/refinement_dimension.rb", "lib/endeca/request.rb", "lib/endeca/transformer.rb", "spec/core_ext_spec.rb", "spec/endeca/benchmarking_spec.rb", "spec/endeca/breadcrumb_spec.rb", "spec/endeca/dimension_spec.rb", "spec/endeca/document_collection_spec.rb", "spec/endeca/document_spec.rb", "spec/endeca/map_spec.rb", "spec/endeca/readers_spec.rb", "spec/endeca/refinement_dimension_spec.rb", "spec/endeca/refinement_spec.rb", "spec/endeca/request_spec.rb", "spec/endeca/transformer_spec.rb", "spec/endeca_spec.rb", "spec/rcov.opts", "spec/spec.opts", "spec/spec_helper.rb"]
14
+ s.homepage = %q{http://github.com/primedia/endeca}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{endeca}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{An Endeca client library for Ruby}
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'benchmark'
2
+
3
+ $:.unshift(File.expand_path(File.dirname(__FILE__)))
4
+ require 'lib/endeca'
5
+ require 'listing'
6
+
7
+ RUNS = 10
8
+ Benchmark.bmbm do |results|
9
+ results.report('Full Request') {RUNS.times{Listing.all}}
10
+ results.report('Parse JSON') {RUNS.times{Endeca::Request.perform(Listing.get_path,'')}}
11
+ results.report('Get Net Response') {RUNS.times{Endeca::Request.new(Listing.get_path,'').send(:get_response)}}
12
+ end
13
+
@@ -0,0 +1,33 @@
1
+ require 'lib/endeca'
2
+ class Listing < Endeca::Document
3
+ path "http://10.130.83.75:9888/bridge/JSONControllerServlet.do"
4
+
5
+ reader \
6
+ :address,
7
+ :contact,
8
+ :description,
9
+ :header,
10
+ :phone
11
+
12
+ integer_reader \
13
+ 'RecordSpec' => :listing_id
14
+
15
+ float_reader \
16
+ :longitude,
17
+ :latitude
18
+
19
+ decimal_reader :rent => :price
20
+
21
+ boolean_reader :showemail => :show_email?
22
+
23
+ reader(:rh_url => :details_url) {|url| "/{url}"}
24
+
25
+ add_reader(:caret_delimited_reader) {|string| string.split('^+^')}
26
+
27
+ caret_delimited_reader \
28
+ :thumbnails,
29
+ :graphicurl => :graphic_urls
30
+
31
+ def coordinates; [latitude, longitude] end
32
+ def image_url; (graphic_urls || thumbnails).first rescue nil end
33
+ end
@@ -0,0 +1,5 @@
1
+ module ClassToProc
2
+ def to_proc
3
+ proc(&method(:new))
4
+ end
5
+ end
@@ -0,0 +1,106 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? empty? : !self
4
+ end
5
+ end
6
+
7
+ class Array
8
+ def to_endeca_params
9
+ join('&').to_endeca_params
10
+ end
11
+ end
12
+
13
+ require 'benchmark'
14
+ class << Benchmark
15
+ # Earlier Ruby had a slower implementation.
16
+ if RUBY_VERSION < '1.8.7'
17
+ remove_method :realtime
18
+
19
+ def realtime
20
+ r0 = Time.now
21
+ yield
22
+ r1 = Time.now
23
+ r1.to_f - r0.to_f
24
+ end
25
+ end
26
+
27
+ def ms
28
+ 1000 * realtime { yield }
29
+ end
30
+ end
31
+
32
+
33
+ class Class
34
+ def inherited_property(accessor, default = nil)
35
+ instance_eval <<-RUBY, __FILE__, __LINE__ + 1
36
+ @#{accessor} = default
37
+
38
+ def set_#{accessor}(value)
39
+ @#{accessor} = value
40
+ end
41
+ alias #{accessor} set_#{accessor}
42
+
43
+ def get_#{accessor}
44
+ return @#{accessor} if instance_variable_defined?(:@#{accessor})
45
+ superclass.send(:get_#{accessor})
46
+ end
47
+ RUBY
48
+
49
+ # @path = default
50
+ #
51
+ # def set_path(value)
52
+ # @path = value
53
+ # end
54
+ # alias_method path, set_path
55
+
56
+ # def get_path
57
+ # return @path if instance_variable_defined?(:path)
58
+ # superclass.send(:path)
59
+ # end
60
+ end
61
+
62
+ def inherited_accessor(accessor, default = nil)
63
+ instance_eval <<-RUBY, __FILE__, __LINE__ + 1
64
+ class << self; attr_writer :#{accessor}; end
65
+ @#{accessor} = default
66
+
67
+ def #{accessor}
68
+ @#{accessor} ||= superclass.send(:#{accessor}).dup
69
+ end
70
+ RUBY
71
+ end
72
+ end
73
+
74
+ class Hash
75
+ def to_endeca_params
76
+ map { |k, v|
77
+ if v.instance_of?(Hash)
78
+ v.map { |sk, sv|
79
+ "#{k}[#{sk}]=#{sv}"
80
+ }.join('&')
81
+ else
82
+ "#{k}=#{v}"
83
+ end
84
+ }.join('&').to_endeca_params
85
+ end
86
+
87
+ def symbolize_keys
88
+ inject({}) do |options, (key, value)|
89
+ options[(key.to_sym rescue key) || key] = value
90
+ options
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ class NilClass
97
+ def to_endeca_params
98
+ ''
99
+ end
100
+ end
101
+
102
+ class String
103
+ def to_endeca_params
104
+ Endeca.escape(self)
105
+ end
106
+ end
@@ -0,0 +1,76 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'logger'
5
+
6
+ $:.unshift(File.dirname(__FILE__))
7
+ require 'core_ext'
8
+ require 'class_to_proc'
9
+ require 'endeca/logging'
10
+ require 'endeca/benchmarking'
11
+ require 'endeca/readers'
12
+ require 'endeca/map'
13
+ require 'endeca/transformer'
14
+ require 'endeca/dimension'
15
+ require 'endeca/refinement_dimension'
16
+ require 'endeca/refinement'
17
+ require 'endeca/breadcrumbs'
18
+ require 'endeca/breadcrumb'
19
+ require 'endeca/request'
20
+ require 'endeca/document_collection'
21
+ require 'endeca/document'
22
+
23
+
24
+ module Endeca
25
+ extend Benchmarking
26
+ extend Logging
27
+
28
+ # :stopdoc:
29
+ VERSION = '1.3.7'
30
+ # :startdoc:
31
+
32
+ # Returns the version string for the library.
33
+ def self.version
34
+ VERSION
35
+ end
36
+
37
+ # Set Endeca.debug = true to turn on query logging
38
+ # Set Endeca.benchmark = true to turn on query benchmarking
39
+ class << self
40
+ attr_accessor :logger
41
+ attr_accessor :debug
42
+ attr_accessor :benchmark
43
+ attr_accessor :timeout
44
+
45
+ def analyze?
46
+ debug && logger && benchmark
47
+ end
48
+
49
+ def timer
50
+ @timer ||= get_timer
51
+ end
52
+
53
+ private
54
+
55
+ def get_timer
56
+ require 'system_timer'
57
+ SystemTimer
58
+ rescue LoadError
59
+ require 'timeout'
60
+ Timeout
61
+ end
62
+ end
63
+
64
+ self.logger = Logger.new(STDOUT)
65
+ self.debug = false
66
+ self.benchmark = false
67
+ self.timeout = 8
68
+
69
+
70
+ # Endeca URIs require colons to be escaped
71
+ def self.escape(str)
72
+ URI.escape(str, /[^-_.!~*'()a-zA-Z\d;\/?@&=+$,\[\]]/n)
73
+ end
74
+ end
75
+
76
+ puts ">> Using Endeca gem version: #{Endeca::VERSION}"
@@ -0,0 +1,38 @@
1
+ require 'benchmark'
2
+
3
+ module Endeca
4
+ module Benchmarking
5
+ # Log and benchmark the workings of a single block. Will only be called if
6
+ # Endeca.debug and Endeca.benchmark are true.
7
+ def bm(metric_symbol, detail = nil)
8
+ if Endeca.analyze?
9
+ result = nil
10
+ ms = ::Benchmark.ms { result = yield }
11
+ add_bm_detail(metric_symbol,ms,detail) if detail.to_s.strip.length > 0
12
+ increase_metric(metric_symbol, ms)
13
+ Endeca.logger.debug("#{metric_symbol.to_s}: #{'%.1f' % ms}ms")
14
+ result
15
+ else
16
+ yield
17
+ end
18
+ end
19
+
20
+ def increase_metric(metric_symbol, up_value)
21
+ if Endeca.analyze?
22
+ Thread.current[:endeca] ||= {}
23
+ Thread.current[:endeca][metric_symbol] ||= 0
24
+ Thread.current[:endeca][metric_symbol] += up_value
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def add_bm_detail(label,time,detail)
31
+ if Endeca.analyze?
32
+ Thread.current[:endeca] ||= {}
33
+ Thread.current[:endeca]["#{label}_detail"] ||= []
34
+ Thread.current[:endeca]["#{label}_detail"] << {:detail => detail, :time => time}
35
+ end
36
+ end
37
+ end
38
+ end