Skip to content

Commit bc94ee1

Browse files
authored
Merge pull request #1 from cloudsight/mchutra/fixes
Modify to be compatible with NuGenie app
2 parents 5a91599 + d760ca8 commit bc94ee1

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lib/ebay_ruby/connect.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,48 @@
33

44
class EbayConnect
55

6-
def initialize(app_id)
6+
def initialize(app_id:, campaign_id:)
77
@app_id = app_id
8+
@campaign_id = campaign_id
89
end
910

10-
attr_reader :app_id, :build_uri
11+
attr_reader :app_id, :build_uri, :campaign_id
1112

1213
def get_connect(url)
1314
response = Net::HTTP.get_response url
1415
response.body
1516
end
1617

17-
def find_items_by_keywords(search_keyword, per_page)
18+
def find_items_by_keywords(search_keyword, per_page, page_number = 1)
1819
str = __method__.to_s.camelize
1920
operation_name = str.gsub(str.first, str.first.downcase)
2021
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)))
2223
ebay_items.all_items
2324
end
2425

25-
def find_items_by_category(category_id, per_page)
26+
def find_items_by_category(category_id, per_page, page_number = 1)
2627
str = __method__.to_s.camelize
2728
operation_name = str.gsub(str.first, str.first.downcase)
2829
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)))
3031
ebay_items.all_items
3132
end
3233
#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)
3435
str = __method__.to_s.camelize
3536
operation_name = str.gsub(str.first, str.first.downcase)
3637
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)))
3839
ebay_items.all_items
3940
end
4041

41-
4242
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"
4548
URI(uri_string)
4649
end
47-
end
50+
end

0 commit comments

Comments
 (0)