client for CJ
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