letsshop_mapper 1.0.0 → 1.1.1

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.
@@ -10,6 +10,7 @@ module LetsShopMapper
10
10
  attr_reader :response
11
11
  attr_reader :feed
12
12
  attr_reader :tree
13
+ attr_reader :suggest
13
14
 
14
15
  def initialize(server = nil, key = nil)
15
16
  @server = server
@@ -62,6 +63,16 @@ module LetsShopMapper
62
63
  raise LetsShopMapper::Error::RequestBaseSearchException::new
63
64
  end
64
65
  end
66
+
67
+ def do_suggest(word = nil)
68
+ uri = "http://#{@server}/suggest/#{@key}"
69
+ begin
70
+ @response = Net::HTTP.get_response(URI.parse("#{uri}/?q=#{word}"))
71
+ @suggest = LetsShopMapper::Model::Suggest::Suggest::new(@response.body)
72
+ rescue Exception
73
+ raise LetsShopMapper::Error::RequestBaseSearchException::new
74
+ end
75
+ end
65
76
  end
66
77
  end
67
78
  end
@@ -13,10 +13,8 @@ module LetsShopMapper
13
13
  attr_reader :thumb
14
14
  attr_reader :supplier
15
15
  attr_reader :facets
16
- attr_reader :xml
17
16
 
18
17
  def initialize(entry = nil)
19
- @xml = entry
20
18
  @id, @link, @title, @description, @price, @thumb, @supplier = nil
21
19
  @facets = []
22
20
  parse(entry) if entry
@@ -0,0 +1,32 @@
1
+ module LetsShopMapper
2
+ module Model
3
+ module Suggest
4
+ class Item
5
+ attr_reader :text
6
+ attr_reader :type
7
+ attr_reader :nhits
8
+ attr_reader :filter
9
+
10
+ def initialize(item = nil)
11
+ @text, @type, @nhits, @filter = nil
12
+ parse(item) if item
13
+ end
14
+
15
+ def parse(item)
16
+ @text = item.at('text').text
17
+ @type = item.at('text')['type']
18
+ @nhits = item.at('nhits').text
19
+ @filter = Base::Filter::new(item.at('filter')['value'])
20
+ end
21
+
22
+ def to_s(localtime = true)
23
+ s = ''
24
+ s += "Text: #{@text}\n"
25
+ s += "Type: #{@type}\n"
26
+ s += "NHits: #{@nhits}\n"
27
+ s += "Filter: \n#{@filter}\n"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module LetsShopMapper
2
+ module Model
3
+ module Suggest
4
+ class Suggest
5
+ attr_reader :items
6
+ attr_reader :xml
7
+
8
+ def initialize(suggest = nil)
9
+ @items = []
10
+ parse(suggest) if suggest
11
+ end
12
+
13
+ def parse(suggest)
14
+ @xml = Nokogiri::XML(suggest)
15
+ if @xml.at('suggest')
16
+ @xml.xpath('suggest/item').each do |c|
17
+ @items << Item::new(c)
18
+ end
19
+ else
20
+ raise LetsShopMapper::Error::UnknownFeedTypeException::new
21
+ end
22
+ end
23
+
24
+ def to_s(localtime = true)
25
+ s = ''
26
+ @items.each { |i| s += i.to_s(localtime) }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -5,12 +5,13 @@ module LetsShopMapper
5
5
  attr_reader :categories
6
6
  attr_reader :xml
7
7
 
8
- def initialize(str = nil)
9
- parse(str) if str
8
+ def initialize(tree = nil)
9
+ @categories = []
10
+ parse(tree) if tree
10
11
  end
11
12
 
12
- def parse(str)
13
- @xml = Nokogiri::XML(str)
13
+ def parse(tree)
14
+ @xml = Nokogiri::XML(tree)
14
15
  if @xml.at('/categories')
15
16
  @xml.xpath('/categories/category').each do |c|
16
17
  @categories = Base::Category::new
@@ -1,8 +1,8 @@
1
1
  module LetsShopMapper
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 0
5
- TINY = 0
4
+ MINOR = 1
5
+ TINY = 1
6
6
  BUILD = ""
7
7
  STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
8
8
  end
@@ -19,6 +19,10 @@ module LetsShopMapper
19
19
  module Tree
20
20
  autoload :Tree, "letsshop_mapper/model/tree/tree"
21
21
  end
22
+ module Suggest
23
+ autoload :Suggest, "letsshop_mapper/model/suggest/suggest"
24
+ autoload :Item, "letsshop_mapper/model/suggest/item"
25
+ end
22
26
  end
23
27
  def self.Boolean(string)
24
28
  return true if string == true || string =~ /^true$/i
@@ -78,7 +78,7 @@ module LetsShopMapper
78
78
  assert_equal "Search: ", lshop.feed.title
79
79
  assert_equal "http://letsshop.dev.happun.com/search/82842d494583280b940b208664f34014", lshop.feed.link
80
80
  f = lshop.feed.entries[0].get_facets_by("category")
81
- assert_equal "chaussure", f[0].title
81
+ assert_equal "botte", f[0].title
82
82
  assert_equal "subset", f[0].role
83
83
  f = lshop.feed.entries[0].get_facets_by("universe")
84
84
  assert_equal "mode", f[0].title
@@ -90,7 +90,7 @@ module LetsShopMapper
90
90
  assert_equal "Search: escarpin AND noir", lshop.feed.title
91
91
  assert_equal "http://letsshop.dev.happun.com/search/82842d494583280b940b208664f34014", lshop.feed.link
92
92
  f = lshop.feed.entries[0].get_facets_by("category")
93
- assert_equal "chaussure", f[0].title
93
+ assert_equal "escarpin", f[0].title
94
94
  assert_equal "subset", f[0].role
95
95
  f = lshop.feed.entries[0].get_facets_by("universe")
96
96
  assert_equal "mode", f[0].title
@@ -175,6 +175,31 @@ module LetsShopMapper
175
175
  assert_equal "femme", lshopTree.categories.children[0].children[0].filters[0].value
176
176
  end
177
177
  end
178
+ def test_suggest
179
+ Dir.foreach(FIXTURESDIR) do |f|
180
+ next if f !~ /suggest*.xml$/
181
+ puts "Checking #{f}"
182
+ str = File::read(FIXTURESDIR + '/' + f)
183
+ lshopSuggest = LetsShopMapper::Model::Suggest::Suggest::new(str)
184
+ assert_equal "asos", lshopSuggest.items[0].text
185
+ assert_equal "supplier", lshopSuggest.items[0].type
186
+ assert_equal "supplier:asos", lshopSuggest.items[0].filter.str_value
187
+ assert_equal "achatdesign", lshopSuggest.items[8].text
188
+ assert_equal "brand", lshopSuggest.items[8].type
189
+ assert_equal "brand:achatdesign", lshopSuggest.items[8].filter.str_value
190
+ end
191
+ end
192
+ def test_suggest_request
193
+ config = YAML.load_file('test/letsshop.yml')['development']
194
+ lshop = LetsShopMapper::Connection::Base::new(config["server"], config["key"])
195
+ lshop.do_suggest("ju")
196
+ assert_equal "jupe", lshop.suggest.items[0].text
197
+ assert_equal "category", lshop.suggest.items[0].type
198
+ assert_equal "category:jupe", lshop.suggest.items[0].filter.str_value
199
+ assert_equal "junk de luxe", lshop.suggest.items[9].text
200
+ assert_equal "brand", lshop.suggest.items[9].type
201
+ assert_equal "brand:junk de luxe", lshop.suggest.items[9].filter.str_value
202
+ end
178
203
  end
179
204
  end
180
205
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: letsshop_mapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
8
+ - 1
9
+ - 1
10
+ version: 1.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - happun
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-23 00:00:00 +02:00
18
+ date: 2010-08-25 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -37,6 +37,8 @@ files:
37
37
  - lib/letsshop_mapper/version.rb
38
38
  - lib/letsshop_mapper/patch/rexml.rb
39
39
  - lib/letsshop_mapper/model/tree/tree.rb
40
+ - lib/letsshop_mapper/model/suggest/suggest.rb
41
+ - lib/letsshop_mapper/model/suggest/item.rb
40
42
  - lib/letsshop_mapper/model/opensearch/feed.rb
41
43
  - lib/letsshop_mapper/model/opensearch/entry.rb
42
44
  - lib/letsshop_mapper/model/base/filter.rb