Skip to content

Instantly share code, notes, and snippets.

@kuzmik
Created August 8, 2017 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuzmik/fd92bd473991fc2688ead63cb1cf2b38 to your computer and use it in GitHub Desktop.
Save kuzmik/fd92bd473991fc2688ead63cb1cf2b38 to your computer and use it in GitHub Desktop.
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