-
Notifications
You must be signed in to change notification settings - Fork 2
/
product_catalog_search_service.rb
76 lines (68 loc) · 2.27 KB
/
product_catalog_search_service.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'services/wsdl/product_catalog_search_driver'
module Cj4r
class ProductCatalogSearch
class << self # Class methods
def find(*args)
options = args.extract_options!
options[:developer_key] ||= Cj4r.config[:developer_key]
options[:website_id] ||= Cj4r.config[:website_id]
options[:advertiser_ids] ||= ''
options[:keywords] ||= ''
options[:serviceable_area] ||= ''
options[:isbn] ||= ''
options[:upc] ||= ''
options[:manufacturer_name] ||= ''
options[:manufacturer_sku] ||= ''
options[:advertiser_sku] ||= ''
options[:low_price] ||= ''
options[:high_price] ||= ''
options[:low_sale_price] ||= ''
options[:high_sale_price] ||= ''
options[:currency] ||= ''
options[:sort_by] ||= ''
options[:sort_order] ||= 'asc'
options[:start_at] ||= '0'
options[:max_results] ||= '50'
case args.first
when :first then find_initial(options)
when :last then find_last(options)
when :all then find_every(options)
else find_every(options)
end
end
private
def find_initial(options)
find_every(options).first
end
def find_last(options)
find_every(options).last
end
def find_every(options)
params = Search.new(
options[:developer_key],
options[:website_id],
options[:advertiser_ids],
options[:keywords],
options[:serviceable_area],
options[:isbn],
options[:upc],
options[:manufacturer_name],
options[:manufacturer_sku],
options[:advertiser_sku],
options[:low_price],
options[:high_price],
options[:low_sale_price],
options[:high_sale_price],
options[:currency],
options[:sort_by],
options[:sort_order],
options[:start_at],
options[:max_results])
service.search(params).out.products
end
def service
@service ||= ProductSearchServiceV2PortType.new
end
end
end
end