Class: RTop::RTop

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/RTop/rtop.rb

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

Constructor Details

#initialize(config_file = nil) ⇒ RTop

Returns a new instance of RTop.



17
18
19
20
21
# File 'lib/RTop/rtop.rb', line 17

def initialize(config_file = nil)
  config_file ||= "#{Rails.root}/config/taobao.yml"
  @settings = YAML.load_file(config_file)
  @settings = (defined? Rails) ? @settings[Rails.env] : @settings["defaults"]
end

Instance Method Details

#delete(url, options) ⇒ Object



47
48
49
50
# File 'lib/RTop/rtop.rb', line 47

def delete(url, options)
  options = prepare_options(method, options)
  self.class.delete(api_url, :query => options)
end

#get(method, options) ⇒ Object



32
33
34
35
# File 'lib/RTop/rtop.rb', line 32

def get(method, options)
  options = prepare_options(method, options)
  self.class.get(api_url, :query => options)
end

#get_item(item_id) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/RTop/rtop.rb', line 23

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



37
38
39
40
# File 'lib/RTop/rtop.rb', line 37

def post(url, options)
  options = prepare_options(method, options)
  self.class.post(api_url, :query => options)
end

#put(url, options) ⇒ Object



42
43
44
45
# File 'lib/RTop/rtop.rb', line 42

def put(url, options)
  options = prepare_options(method, options)
  self.class.put(api_url, :query => options)
end