Class: RTop::RTop
Constant Summary collapse
- API_URL =
'http://gw.api.taobao.com/router/rest'
- API_URL_SANDBOX =
'http://gw.api.tbsandbox.com/router/rest'
- API_OPTION =
{ "format" => "json", "v" => "2.0", "sign_method" => "md5" }
Instance Method Summary collapse
- #delete(url, options) ⇒ Object
- #get(method, options) ⇒ Object
- #get_item(item_id) ⇒ Object
-
#initialize(config_file = nil) ⇒ RTop
constructor
A new instance of RTop.
- #post(url, options) ⇒ Object
- #put(url, options) ⇒ Object
Constructor Details
#initialize(config_file = nil) ⇒ RTop
Returns a new instance of RTop.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/RTop/rtop.rb', line 18 def initialize(config_file = nil) unless config_file if defined? Rails config_file = "#{Rails.root}/config/taobao.yml" else config_file = File.join(Dir.pwd, 'config/taobao.yml') unless File.file?(config_file) config_file = File.join(Dir.pwd, 'taobao.yml') end end raise "taobao.yml not found, generate one with 'rtop generate [path]'." unless File.file?(config_file) end @settings = YAML.load_file(config_file) @settings = (defined? Rails) ? @settings[Rails.env] : @settings["defaults"] end |
Instance Method Details
#delete(url, options) ⇒ Object
59 60 61 62 |
# File 'lib/RTop/rtop.rb', line 59 def delete(url, ) = (method, ) self.class.delete(api_url, :query => ) end |
#get(method, options) ⇒ Object
44 45 46 47 |
# File 'lib/RTop/rtop.rb', line 44 def get(method, ) = (method, ) self.class.get(api_url, :query => ) end |
#get_item(item_id) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/RTop/rtop.rb', line 35 def get_item(item_id) response = self.get("taobao.item.get", { "num_iid" => item_id, "fields" => "title,price,ems_fee,express_fee,detail_url,item_imgs,pic_url,location" }) if response and response.parsed_response and response.parsed_response["item_get_response"] and response.parsed_response["item_get_response"]["item"] return response.parsed_response["item_get_response"]["item"] end end |
#post(url, options) ⇒ Object
49 50 51 52 |
# File 'lib/RTop/rtop.rb', line 49 def post(url, ) = (method, ) self.class.post(api_url, :query => ) end |
#put(url, options) ⇒ Object
54 55 56 57 |
# File 'lib/RTop/rtop.rb', line 54 def put(url, ) = (method, ) self.class.put(api_url, :query => ) end |