Class: LetsShopMapper::Connection::Base
- Inherits:
-
Object
- Object
- LetsShopMapper::Connection::Base
- Defined in:
- lib/letsshop_mapper/connection.rb
Instance Attribute Summary collapse
-
#feed ⇒ Object
readonly
Returns the value of attribute feed.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#suggest ⇒ Object
readonly
Returns the value of attribute suggest.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #connect_and_get ⇒ Object
- #do_suggest(word = nil) ⇒ Object
- #find(conditions = {}) ⇒ Object
- #get_tree(category = nil) ⇒ Object
-
#initialize(server = nil, key = nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(server = nil, key = nil) ⇒ Base
Returns a new instance of Base.
15 16 17 18 |
# File 'lib/letsshop_mapper/connection.rb', line 15 def initialize(server = nil, key = nil) @server = server @key = key end |
Instance Attribute Details
#feed ⇒ Object (readonly)
Returns the value of attribute feed.
11 12 13 |
# File 'lib/letsshop_mapper/connection.rb', line 11 def feed @feed end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/letsshop_mapper/connection.rb', line 9 def key @key end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/letsshop_mapper/connection.rb', line 10 def response @response end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/letsshop_mapper/connection.rb', line 8 def server @server end |
#suggest ⇒ Object (readonly)
Returns the value of attribute suggest.
13 14 15 |
# File 'lib/letsshop_mapper/connection.rb', line 13 def suggest @suggest end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
12 13 14 |
# File 'lib/letsshop_mapper/connection.rb', line 12 def tree @tree end |
Instance Method Details
#connect_and_get ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/letsshop_mapper/connection.rb', line 20 def connect_and_get() uri = "http://#{@server}/search/#{@key}" begin @response = Net::HTTP.get_response(URI.parse(uri)) @feed = @response.body rescue Exception raise LetsShopMapper::RequestBaseSearchException::new end end |
#do_suggest(word = nil) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/letsshop_mapper/connection.rb', line 67 def do_suggest(word = nil) uri = "http://#{@server}/suggest/#{@key}" begin @response = Net::HTTP.get_response(URI.parse("#{uri}/?q=#{word}")) @suggest = LetsShopMapper::Model::Suggest::Suggest::new(@response.body) rescue Exception raise LetsShopMapper::Error::RequestBaseSearchException::new end end |
#find(conditions = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/letsshop_mapper/connection.rb', line 30 def find(conditions = {}) uri = "http://#{@server}/search/#{@key}" query = "?" query << "q=#{CGI.escape(conditions[:q])}" if conditions[:q] != nil query << "&products=#{conditions[:products]}" if conditions[:products] != nil query << "&start=#{conditions[:start]}" if conditions[:start] != nil query << "&nhits=#{conditions[:nhits]}" if conditions[:nhits] != nil if conditions[:f] != nil refine = "" refine_splited = conditions[:f].split(',') refine_splited.each do |f| refine << f.gsub(/(refine:||refine:\()+(\047)(.+)(\047)/, '\1"\3"').gsub(/(\047) (OR||AND) (\047)/, '" \2 "') refine << "," unless f == refine_splited.last end query << "&f=#{CGI.escape(refine)}" end query << "&c=#{CGI.escape(conditions[:c])}" if conditions[:c] != nil query << "&sort=#{CGI.escape(conditions[:sort])}" if conditions[:sort] != nil begin @response = Net::HTTP.get_response(URI.parse("#{uri}/#{query}")) @feed = LetsShopMapper::Model::OpenSearch::Feed::new(@response.body) rescue Exception raise LetsShopMapper::Error::RequestBaseSearchException::new end end |
#get_tree(category = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/letsshop_mapper/connection.rb', line 56 def get_tree(category = nil) uri = "http://#{@server}/tree/#{@key}" id = "#{category}" if category != nil begin @response = Net::HTTP.get_response(URI.parse("#{uri}/#{id}")) @tree = LetsShopMapper::Model::Tree::Tree::new(@response.body) rescue Exception raise LetsShopMapper::Error::RequestBaseSearchException::new end end |