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 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_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 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 end end