|
3 | 3 |
|
4 | 4 | class EbayConnect |
5 | 5 |
|
6 | | - def initialize(app_id) |
| 6 | + def initialize(app_id:, campaign_id:) |
7 | 7 | @app_id = app_id |
| 8 | + @campaign_id = campaign_id |
8 | 9 | end |
9 | 10 |
|
10 | | - attr_reader :app_id, :build_uri |
| 11 | + attr_reader :app_id, :build_uri, :campaign_id |
11 | 12 |
|
12 | 13 | def get_connect(url) |
13 | 14 | response = Net::HTTP.get_response url |
14 | 15 | response.body |
15 | 16 | end |
16 | 17 |
|
17 | | - def find_items_by_keywords(search_keyword, per_page) |
| 18 | + def find_items_by_keywords(search_keyword, per_page, page_number = 1) |
18 | 19 | str = __method__.to_s.camelize |
19 | 20 | operation_name = str.gsub(str.first, str.first.downcase) |
20 | 21 | search_param = "keywords=#{URI::encode(search_keyword)}" |
21 | | - ebay_items = EbayFindItem.new(get_connect(build_uri(operation_name, search_param, per_page))) |
| 22 | + ebay_items = EbayFindItem.new(get_connect(build_uri(operation_name, search_param, per_page, page_number))) |
22 | 23 | ebay_items.all_items |
23 | 24 | end |
24 | 25 |
|
25 | | - def find_items_by_category(category_id, per_page) |
| 26 | + def find_items_by_category(category_id, per_page, page_number = 1) |
26 | 27 | str = __method__.to_s.camelize |
27 | 28 | operation_name = str.gsub(str.first, str.first.downcase) |
28 | 29 | search_param = "categoryId=#{category_id}" |
29 | | - ebay_items = EbayFindItem.new(get_connect(build_uri(operation_name, search_param, per_page))) |
| 30 | + ebay_items = EbayFindItem.new(get_connect(build_uri(operation_name, search_param, per_page, page_number))) |
30 | 31 | ebay_items.all_items |
31 | 32 | end |
32 | 33 | #productId can be ISBN,UPC,EAN |
33 | | - def find_items_by_product(product_id, per_page) |
| 34 | + def find_items_by_product(product_id, per_page, page_number = 1) |
34 | 35 | str = __method__.to_s.camelize |
35 | 36 | operation_name = str.gsub(str.first, str.first.downcase) |
36 | 37 | search_param = "productId=#{product_id}" |
37 | | - ebay_items = EbayFindItem.new(get_connect(build_uri(operation_name, search_param, per_page))) |
| 38 | + ebay_items = EbayFindItem.new(get_connect(build_uri(operation_name, search_param, per_page, page_number))) |
38 | 39 | ebay_items.all_items |
39 | 40 | end |
40 | 41 |
|
41 | | - |
42 | 42 | private |
43 | | - def build_uri(operation_name, search_keyword, per_page) |
44 | | - uri_string = "http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=#{operation_name}&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=#{app_id}&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=JSON&#{search_keyword}&paginationInput.entriesPerPage=#{per_page.to_i}" |
| 43 | + def build_uri(operation_name, search_keyword, per_page, page_number = 1) |
| 44 | + uri_string = "http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=#{operation_name}" \ |
| 45 | + "&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=#{app_id}&GLOBAL-ID=EBAY-US&RESPONSE-DATA-FORMAT=JSON" \ |
| 46 | + "&#{search_keyword}&paginationInput.entriesPerPage=#{per_page.to_i}&paginationInput.pageNumber=#{page_number.to_i}" \ |
| 47 | + "&affiliate.trackingId=#{campaign_id}&affiliate.networkId=9" |
45 | 48 | URI(uri_string) |
46 | 49 | end |
47 | | - end |
| 50 | +end |
0 commit comments