module Tbkapi class Taobaoke include Tbkapi def build_query(hash) hash.map{|key, value| "#{key}=#{value}"}.join('&') end def taobao_tbk_uatm_favorites_get(api_key, secret, page_no = 1, page_size = 20) action_params = { fields: "favorites_title,favorites_id,type", page_no: page_no, page_size: page_size } params = system_params("taobao.tbk.uatm.favorites.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + build_query(params.merge({sign: my_sign})))) end def taobao_tbk_uatm_favorites_item_get(favorites_id, adzone_id, unid, api_key, secret, platform = 2,page_no = 1, page_size = 20) action_params = { adzone_id: adzone_id, unid: unid, favorites_id: favorites_id, fields: "num_iid,title,pict_url,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type,click_url,status,category,coupon_click_url,coupon_end_time,coupon_info,coupon_start_time,coupon_total_count,coupon_remain_count", platform: platform, page_no: page_no, page_size: page_size } params = system_params("taobao.tbk.uatm.favorites.item.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + build_query(params.merge({sign: my_sign})))) end # 只有 start_price 与 end_price 同时不为nil的时候价格筛选才生效 def taobao_tbk_item_get_new(keyword, cat, sort, is_tmall, start_price, end_price, api_key, secret, page_no = 1, page_size = 20) action_params = { fields: "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick", page_no: page_no, page_size: page_size } action_params[:q] = keyword unless keyword.nil? action_params[:cat] = cat unless cat.nil? action_params[:sort] = sort unless sort.nil? action_params[:is_tmall] = is_tmall unless is_tmall.nil? action_params[:start_price] = start_price unless start_price.nil? action_params[:end_price] = end_price unless end_price.nil? params = system_params("taobao.tbk.item.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(URI.encode((TBURI + '?' + build_query(params.merge({sign: my_sign})))))) end def taobao_tbk_item_get(keyword, api_key, secret, page_no = 1, page_size = 20) action_params = { fields: "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick", q: keyword, page_no: page_no, page_size: page_size } params = system_params("taobao.tbk.item.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(URI.encode((TBURI + '?' + build_query(params.merge({sign: my_sign})))))) end def taobao_tbk_item_recommend_get(num_iid, api_key, secret, page_size = 20) action_params = { fields: "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url", num_iid: num_iid, count: page_size } params = system_params("taobao.tbk.item.recommend.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(URI.encode((TBURI + '?' + build_query(params.merge({sign: my_sign})))))) end def taobao_tbk_items_detail_get(ids, api_key, secret) action_params = { fields: "num_iid,seller_id,nick,title,volume,pic_url,item_url,shop_url,click_url,price,discount_price", num_iids: ids.join(",") } params = system_params("taobao.tbk.items.detail.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + build_query(params.merge({sign: my_sign})))) end def taobao_tbk_item_info_get(ids, api_key, secret) action_params = { fields: "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,nick,seller_id,volume,cat_leaf_name,cat_name", num_iids: ids.join(",") } params = system_params("taobao.tbk.item.info.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + build_query(params.merge({sign: my_sign})))) end def taobao_tbk_item_coupon_get(q, pid, api_key, secret) action_params = { q: q, pid: pid } params = system_params("taobao.tbk.item.coupon.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase if q.include?('//') url = URI(TBURI + '?' + URI.escape(build_query(params.merge({sign: my_sign})),'/:?')) else url = URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign})))) end Net::HTTP.get(url) end def taobao_tbk_shop_get(q, api_key, secret) action_params ={ fields: "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url", q: q } params = system_params("taobao.tbk.shop.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_shop_get_new(q, api_key, secret, is_tmall = false, start_credit = 1, end_credit = 20, page_no = 1, page_size= 20) action_params ={ fields: "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url", q: q, is_tmall: is_tmall, start_credit: start_credit, end_credit: end_credit, page_no: page_no, page_size: page_size, sort: "total_auction_des" } params = system_params("taobao.tbk.shop.get",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_ju_items_search(q, pid, api_key, secret) action_params ={ param_top_item_query: { pid: pid, word: q }.to_json } params = system_params("taobao.ju.items.search", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_dg_item_coupon_get(q, adzone_id, api_key, secret, page_no = 1, page_size = 20) action_params = { adzone_id: adzone_id, page_size: page_size, page_no: page_no, q: q } params = system_params("taobao.tbk.dg.item.coupon.get", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_tpwd_create(url, text, api_key, secret, logo = nil, user_id = nil) action_params = { text: text, url: url } action_params[:logo] = logo if logo action_params[:user_id] = user_id if user_id params = system_params("taobao.tbk.tpwd.create", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase params.delete(:url) Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))) + "&url=" + URI.encode_www_form_component(url))) end def taobao_wireless_share_tpwd_create(url, text, api_key, secret, logo = nil, user_id = nil) data = { text: text, url: url } data[:logo] = logo if logo data[:user_id] = user_id if user_id action_params = { tpwd_param: data.to_json } params = system_params("taobao.wireless.share.tpwd.create", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_wireless_share_tpwd_query(password_content, api_key, secret) action_params = { password_content: password_content } params = system_params("taobao.wireless.share.tpwd.query", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end # 只有 start_price 与 end_price 有一个不为nil的时候价格筛选就生效 # npx_level include_pay_rate_30 include_good_rate include_rfd_rate 测试没什么效果 # start_dsr 0 - 50000 def taobao_tbk_dg_material_optional(keyword, cat, sort, is_tmall, is_overseas, has_coupon, start_dsr, start_tk_rate, end_tk_rate, start_price, end_price, material_id, api_key, secret, adzone_id, page_no = 1, page_size = 20) action_params = { adzone_id: adzone_id, material_id: material_id, page_no: page_no, page_size: page_size } action_params[:q] = keyword unless keyword.nil? action_params[:cat] = cat unless cat.nil? action_params[:sort] = sort unless sort.nil? action_params[:is_tmall] = is_tmall unless is_tmall.nil? action_params[:is_overseas] = is_overseas unless is_overseas.nil? action_params[:has_coupon] = has_coupon unless has_coupon.nil? action_params[:start_dsr] = start_dsr unless start_dsr.nil? action_params[:start_tk_rate] = start_tk_rate unless start_tk_rate.nil? action_params[:end_tk_rate] = end_tk_rate unless end_tk_rate.nil? action_params[:start_price] = start_price unless start_price.nil? action_params[:end_price] = end_price unless end_price.nil? params = system_params("taobao.tbk.dg.material.optional.upgrade",api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(URI.encode((TBURI + '?' + build_query(params.merge({sign: my_sign})))))) end def taobao_tbk_dg_optimus_material(adzone_id, api_key, secret, material_id = 4071, page_no = 1, page_size = 20) action_params = { adzone_id: adzone_id, material_id: material_id, page_no: page_no, page_size: page_size } params = system_params("taobao.tbk.dg.optimus.material", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_content_get(adzone_id, api_key, secret, type, before_time, count, cid, content_set) action_params = { adzone_id: adzone_id } action_params[:type] = type if type && type > 0 action_params[:before_timestamp] = before_time if before_time && before_time > 0 action_params[:count] = count if count && count > 0 action_params[:cid] = cid if cid && cid > 0 action_params[:content_set] = content_set if content_set && content_set > 0 params = system_params("taobao.tbk.content.get", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_shop_convert(adzone_id, api_key, secret, shop_id) action_params = { adzone_id: adzone_id, fields: "user_id,click_url", user_ids: shop_id } params = system_params("taobao.tbk.shop.convert", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_item_convert(adzone_id, api_key, secret, item_id) action_params = { adzone_id: adzone_id, fields: "num_iid,click_url", num_iids: item_id } params = system_params("taobao.tbk.item.convert", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_itemcats_get(parent_cid, cids, api_key, secret) action_params = { parent_cid: parent_cid, fields: "cid,parent_cid,name,is_parent", cids: cids } params = system_params("taobao.itemcats.get", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_item_word_get(item_id, count, adzone_id, api_key, secret) action_params = { item_id: item_id, adzone_id: adzone_id, count: count } params = system_params("taobao.tbk.item.word.get", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end def taobao_tbk_spread_get(url, api_key, secret) action_params = { requests: [{url: url}].to_json } params = system_params("taobao.tbk.spread.get", api_key).merge(action_params) my_sign = get_sign(params, secret).upcase Net::HTTP.get(URI(TBURI + '?' + URI.encode(build_query(params.merge({sign: my_sign}))))) end end end