Created
August 8, 2017 03:28
-
-
Save kuzmik/fd92bd473991fc2688ead63cb1cf2b38 to your computer and use it in GitHub Desktop.
client for CJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.product_search(str) | |
key = 'YOUR_KEY' | |
pid = 'YOUR_PID' | |
cj = CommissionJunction.new(key, pid) | |
items = cj.product_search( | |
'keywords' => str.split(' ').reduce('') { |keywords, s| keywords += " +#{s}" }, | |
'serviceable-area' => 'us', | |
'advertiser-ids' => '2045991, 3379721, 1461363, 3449087, 3055640', | |
'currency' => 'usd', | |
'sort-by' => 'Price', | |
'sort-order' => 'desc', | |
) | |
logger.info "Returned #{items.count} items from CJ" | |
items.reduce([]) do |list, res| | |
list << { | |
id: res.ad_id, | |
title: res.name, | |
seller: res.advertiser_name, | |
seller_id: res.advertiser_id, | |
buy_url: res.buy_url, | |
description: res.description, | |
image: res.image_url, | |
price: res.price, | |
upc: res.upc, | |
} | |
end | |
end | |
def self.get_product_for_seller(upc, seller) | |
key = 'YOUR_KEY' | |
pid = 'YOUR_PID' | |
cj = CommissionJunction.new(key, pid) | |
res = cj.product_search( | |
'keywords' => '', | |
'serviceable-area' => 'us', | |
'advertiser-ids' => seller, | |
'currency' => 'usd', | |
'sort-by' => 'Price', | |
'sort-order' => 'desc', | |
'upc' => upc | |
) | |
res.first | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment