top4r 0.0.25 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/top4rsh ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+
@@ -122,9 +122,9 @@ class Top4R::Client
122
122
  :session => @session,
123
123
  :timestamp => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
124
124
  :format => "#{@@config.format}",
125
- :app_key => @app_key,
126
- :v => "1.0"
125
+ :app_key => @app_key
127
126
  })
127
+ params[:v] = "1.0" unless params[:v]
128
128
  params = params.merge({
129
129
  :sign => Digest::MD5.hexdigest(params.sort {|a,b| "#{a[0]}"<=>"#{b[0]}"}.flatten.unshift(@app_secret).join).upcase
130
130
  })
@@ -0,0 +1,16 @@
1
+ class Top4R::Client
2
+ @@ITEM_METHODS = {
3
+ :onsale_list => 'taobao.items.onsale.get'
4
+ }
5
+
6
+ def items_onsale(q = nil, method = :onsale_list, options = {}, &block)
7
+ valid_method(method, @@ITEM_METHODS, :item)
8
+ options = {:q => q}.merge(options) if q
9
+ params = {:fields => Top4R::Item.fields}.merge(options)
10
+ response = http_connect {|conn| create_http_get_request(@@ITEM_METHODS[method], params)}
11
+ items = Top4R::Item.unmarshal(JSON.parse(response.body)["rsp"]["items"])
12
+ items.each {|item| bless_model(item); yield item if block_given?}
13
+ @total_results = JSON.parse(response.body)["rsp"]["totalResults"].to_i
14
+ items
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ class Top4R::Client
2
+ @@SHOP_METHODS = {
3
+ :cats_list => 'taobao.sellercats.list.get',
4
+ :shop_info => 'taobao.shop.get'
5
+ }
6
+
7
+ def seller_cats(u, method = :cats_list, options = {}, &block)
8
+ valid_method(method, @@SHOP_METHODS, :shop)
9
+ u = u.nick if u.is_a?(Top4R::User)
10
+ params = options.merge(:nick => u)
11
+ response = http_connect {|conn| create_http_get_request(@@SHOP_METHODS[method], params)}
12
+ seller_cats = Top4R::SellerCat.unmarshal(JSON.parse(response.body)["rsp"]["seller_cats"])
13
+ seller_cats.each {|cat| bless_model(cat); yield cat if block_given?}
14
+ # puts "\nsuites: #{suites.inspect}"
15
+ seller_cats
16
+ end
17
+
18
+ def shop(u, method = :shop_info, options = {}, &block)
19
+ valid_method(method, @@SHOP_METHODS, :shop)
20
+ u = u.nick if u.is_a?(Top4R::User)
21
+ params = {:fields => Top4R::Shop.fields}.merge(options).merge(:nick => u)
22
+ response = http_connect {|conn| create_http_get_request(@@SHOP_METHODS[method], params)}
23
+ shops = Top4R::Shop.unmarshal(JSON.parse(response.body)["rsp"]["shops"])
24
+ method == :shop_info ? bless_model(shops.first) : bless_models(shops)
25
+ end
26
+ end
@@ -8,6 +8,12 @@ class Top4R::Client
8
8
  u = u.nick if u.is_a?(Top4R::User)
9
9
  params = {:service_code => service_code}.merge(options).merge(:nick => u)
10
10
  response = http_connect {|conn| create_http_get_request(@@SUITE_METHODS[method], params)}
11
+ if response.body == "{\"rsp\":{}}"
12
+ raise Top4R::SuiteNotOrderedError.new(:code => 630,
13
+ :message => "没有#{service_code}的订购记录",
14
+ :error => "{}",
15
+ :uri => @@SUITE_METHODS[method])
16
+ end
11
17
  suites = Top4R::Suite.unmarshal(JSON.parse(response.body)["rsp"]["suites"])
12
18
  suites.each {|suite| bless_model(suite); yield suite if block_given?}
13
19
  # puts "\nsuites: #{suites.inspect}"
@@ -0,0 +1,17 @@
1
+ class Top4R::Client
2
+ @@TAOBAOKEITEM_METHODS = {
3
+ :taobaoke_items_get => 'taobao.taobaoke.items.get'
4
+ }
5
+
6
+ def taobaoke_items(q = nil, method = :taobaoke_items_get, options = {}, &block)
7
+ valid_method(method, @@TAOBAOKEITEM_METHODS, :taobaoke_item)
8
+ options = {:keyword => q}.merge(options) if q
9
+ params = {:fields => Top4R::TaobaokeItem.fields, :v => "2.0"}.merge(options)
10
+ response = http_connect {|conn| create_http_get_request(@@TAOBAOKEITEM_METHODS[method], params)}
11
+
12
+ items = Top4R::TaobaokeItem.unmarshal(JSON.parse(response.body)["taobaoke_items_get_response"]["taobaoke_items"]["taobaoke_item"])
13
+ items.each {|item| bless_model(item); yield item if block_given?}
14
+ @total_results = JSON.parse(response.body)["taobaoke_items_get_response"]["total_results"].to_i
15
+ items
16
+ end
17
+ end
data/lib/top4r/client.rb CHANGED
@@ -12,6 +12,14 @@ class Top4R::Client
12
12
  },
13
13
  :logistic_company => {
14
14
  :list => 'taobao.logisticcompanies.get'
15
+ },
16
+ :shop => {
17
+ :cats_list => 'taobao.sellercats.list.get',
18
+ :shop_info => 'taobao.shop.get'
19
+ },
20
+ :item => {},
21
+ :taobaoke_item => {
22
+ :taobaoke_items_get => 'taobao.taobaoke.items.get'
15
23
  }
16
24
  }
17
25
  end
@@ -20,4 +28,7 @@ require 'top4r/client/base'
20
28
  require 'top4r/client/user'
21
29
  require 'top4r/client/shipping'
22
30
  require 'top4r/client/trade'
23
- require 'top4r/client/suite'
31
+ require 'top4r/client/suite'
32
+ require 'top4r/client/item'
33
+ require 'top4r/client/shop'
34
+ require 'top4r/client/taobaokeitem'
data/lib/top4r/config.rb CHANGED
@@ -51,7 +51,7 @@ module Top4R
51
51
  :rest_uri => '/router/rest',
52
52
  :port => 80,
53
53
  :protocol => :http,
54
- :test_host => 'gw.sandbox.taobao.com',
54
+ :test_host => 'gw.api.tbsandbox.com',
55
55
  :test_rest_uri => '/router/rest',
56
56
  :test_port => 80,
57
57
  :test_protocol => :http,
@@ -0,0 +1,97 @@
1
+ module Top4R
2
+ # ItemImg Model
3
+ class ItemImg
4
+ include ModelMixin
5
+ @@ATTRIBUTES = [:id, :url, :position]
6
+ attr_accessor *@@ATTRIBUTES
7
+
8
+ class << self
9
+ def attributes; @@ATTRIBUTES; end
10
+ end
11
+ end
12
+
13
+ # PropImg Model
14
+ class PropImg
15
+ include ModelMixin
16
+ @@ATTRIBUTES = [:id, :url, :properties, :position]
17
+ attr_accessor *@@ATTRIBUTES
18
+
19
+ class << self
20
+ def attributes; @@ATTRIBUTES; end
21
+ end
22
+ end
23
+
24
+ # Sku Model
25
+ class Sku
26
+ include ModelMixin
27
+ @@ATTRIBUTES = [:id, :sku_id, :iid, :properties, :quantity, :price, :outer_id, :created, :modified, :status]
28
+ attr_accessor *@@ATTRIBUTES
29
+
30
+ class << self
31
+ def attributes; @@ATTRIBUTES; end
32
+ end
33
+
34
+ def unmarshal_other_attrs
35
+ @id = @sku_id
36
+ end
37
+ end
38
+
39
+ # Video Model
40
+ class Video
41
+ include ModelMixin
42
+ @@ATTRIBUTES = [:id, :video_id, :url, :created, :modified]
43
+ attr_accessor *@@ATTRIBUTES
44
+
45
+ class << self
46
+ def attributes; @@ATTRIBUTES; end
47
+ end
48
+ end
49
+
50
+ # Item Model
51
+ class Item
52
+ include ModelMixin
53
+ @@ATTRIBUTES = [:id, :iid, :detail_url, :num_iid, :title, :nick, :type, :cid,
54
+ :seller_cids, :props, :input_pids, :input_str, :desc, :pic_path, :num, :valid_thru,
55
+ :list_time, :delist_time, :stuff_status, :location, :price, :post_fee, :express_fee,
56
+ :ems_fee, :has_discount, :freight_payer, :has_invoice, :has_warranty, :has_showcase,
57
+ :modified, :increment, :auto_repost, :approve_status, :postage_id, :product_id, :auction_point,
58
+ :property_alias, :item_imgs, :prop_imgs, :skus, :outer_id, :is_virtual, :is_taobao,
59
+ :is_ex, :videos, :is_3D, :score, :volume, :one_station]
60
+ attr_accessor *@@ATTRIBUTES
61
+
62
+ class << self
63
+ def attributes; @@ATTRIBUTES; end
64
+
65
+ def default_public_fields
66
+ ["approve_status", "iid", "num_iid", "title", "nick", "type", "cid", "pic_path", "num", "props",
67
+ "valid_thru", "list_time", "price", "has_discount", "has_invoice", "has_warranty",
68
+ "has_showcase", "modified", "delist_time", "postage_id", "seller_cids", "outer_id"]
69
+ end
70
+ end
71
+
72
+ def search(q)
73
+ @client.items_onsale(q)
74
+ end
75
+
76
+ def unmarshal_other_attrs
77
+ @id = @iid
78
+ if @location && @location.size > 0
79
+ @location = Location.new(@location)
80
+ else
81
+ @location = nil
82
+ end
83
+ if @item_imgs.is_a?(Array) && @item_imgs.size > 0
84
+ @item_imgs.map {|img| ItemImg.new(img)}
85
+ else
86
+ @item_imgs = []
87
+ end
88
+ if @prop_imgs.is_a?(Array) && @prop_imgs.size > 0
89
+ @prop_imgs.map {|img| PropImg.new(img)}
90
+ else
91
+ @prop_imgs = []
92
+ end
93
+
94
+ self
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,37 @@
1
+ module Top4R
2
+ # SellerCat Model
3
+ class SellerCat
4
+ include ModelMixin
5
+ @@ATTRIBUTES = [:id, :cid, :parent_cid, :name, :pict_url, :sort_order]
6
+ attr_accessor *@@ATTRIBUTES
7
+
8
+ class << self
9
+ def attributes; @@ATTRIBUTES; end
10
+ end
11
+
12
+ def unmarshal_other_attrs
13
+ @id = @cid
14
+ self
15
+ end
16
+ end
17
+
18
+ # Shop Model
19
+ class Shop
20
+ include ModelMixin
21
+ @@ATTRIBUTES = [:id, :sid, :cid, :nick, :title, :desc, :bulletin, :pic_path, :created, :modified]
22
+ attr_accessor *@@ATTRIBUTES
23
+
24
+ class << self
25
+ def attributes; @@ATTRIBUTES; end
26
+
27
+ def default_public_fields
28
+ ["sid", "cid", "title", "nick", "desc", "bulletin", "pic_path", "created", "modified"]
29
+ end
30
+ end
31
+
32
+ def unmarshal_other_attrs
33
+ @id = @sid
34
+ self
35
+ end
36
+ end
37
+ end
@@ -10,7 +10,6 @@ module Top4R
10
10
  end
11
11
 
12
12
  def unmarshal_other_attrs
13
- @id = 0
14
13
  self
15
14
  end
16
15
  end
@@ -0,0 +1,25 @@
1
+ module Top4R
2
+
3
+ # TaobaokeItem Model
4
+ class TaobaokeItem
5
+ include ModelMixin
6
+ @@ATTRIBUTES = [:id, :iid, :num_iid, :title, :nick, :pic_url, :price, :click_url, :commission, :commission_rate,
7
+ :commission_num, :commission_volume, :shop_click_url, :seller_credit_score, :item_location, :volume]
8
+ attr_accessor *@@ATTRIBUTES
9
+
10
+ class << self
11
+ def attributes; @@ATTRIBUTES; end
12
+
13
+ def default_public_fields
14
+ ["iid", "num_iid", "title", "pic_url", "price", "nick", "click_url"]
15
+ end
16
+ end
17
+
18
+ def unmarshal_other_attrs
19
+ @id = @iid
20
+
21
+ self
22
+ end
23
+ end
24
+
25
+ end
@@ -8,6 +8,14 @@ module Top4R
8
8
  def suites(service_code, options = {})
9
9
  @client.suites(self.nick, service_code, :list, options)
10
10
  end
11
+
12
+ def search_items(q = nil, options = {})
13
+ @client.items_onsale(q, :onsale_list, options)
14
+ end
15
+
16
+ def cats
17
+ @client.seller_cats(self.nick)
18
+ end
11
19
  end
12
20
 
13
21
  def self.included(receiver)
data/lib/top4r/model.rb CHANGED
@@ -108,4 +108,7 @@ end
108
108
  require 'top4r/model/user'
109
109
  require 'top4r/model/shipping'
110
110
  require 'top4r/model/trade'
111
- require 'top4r/model/suite'
111
+ require 'top4r/model/suite'
112
+ require 'top4r/model/item'
113
+ require 'top4r/model/shop'
114
+ require 'top4r/model/taobaokeitem'
data/lib/top4r/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Top4R::Version
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- REVISION = 25
4
+ REVISION = 39
5
5
 
6
6
  class << self
7
7
  # Returns X.Y.Z formatted version string
metadata CHANGED
@@ -1,31 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ hash: 81
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 39
10
+ version: 0.0.39
5
11
  platform: ruby
6
12
  authors:
7
13
  - Nowa Zhu
8
- autorequire: top4r
14
+ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-15 00:00:00 +08:00
18
+ date: 2010-07-02 00:00:00 +08:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: json
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 1
23
34
  version: 1.1.1
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  description:
26
38
  email: nowazhu@gmail.com
27
- executables: []
28
-
39
+ executables:
40
+ - top4rsh
29
41
  extensions: []
30
42
 
31
43
  extra_rdoc_files:
@@ -35,8 +47,11 @@ extra_rdoc_files:
35
47
  - MIT-LICENSE
36
48
  files:
37
49
  - lib/top4r/client/base.rb
50
+ - lib/top4r/client/item.rb
38
51
  - lib/top4r/client/shipping.rb
52
+ - lib/top4r/client/shop.rb
39
53
  - lib/top4r/client/suite.rb
54
+ - lib/top4r/client/taobaokeitem.rb
40
55
  - lib/top4r/client/trade.rb
41
56
  - lib/top4r/client/user.rb
42
57
  - lib/top4r/client.rb
@@ -47,8 +62,11 @@ files:
47
62
  - lib/top4r/ext.rb
48
63
  - lib/top4r/logger.rb
49
64
  - lib/top4r/meta.rb
65
+ - lib/top4r/model/item.rb
50
66
  - lib/top4r/model/shipping.rb
67
+ - lib/top4r/model/shop.rb
51
68
  - lib/top4r/model/suite.rb
69
+ - lib/top4r/model/taobaokeitem.rb
52
70
  - lib/top4r/model/trade.rb
53
71
  - lib/top4r/model/user.rb
54
72
  - lib/top4r/model.rb
@@ -58,6 +76,7 @@ files:
58
76
  - CHANGES
59
77
  - TODO
60
78
  - MIT-LICENSE
79
+ - bin/top4rsh
61
80
  has_rdoc: true
62
81
  homepage: http://top4r.labs.nowa.me
63
82
  licenses: []
@@ -68,21 +87,27 @@ rdoc_options: []
68
87
  require_paths:
69
88
  - lib
70
89
  required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
71
91
  requirements:
72
92
  - - ">="
73
93
  - !ruby/object:Gem::Version
74
- version: 1.8.2
75
- version:
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
76
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
77
100
  requirements:
78
101
  - - ">="
79
102
  - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
80
106
  version: "0"
81
- version:
82
- requirements:
83
- - Ruby 1.8.4+
107
+ requirements: []
108
+
84
109
  rubyforge_project: top4r
85
- rubygems_version: 1.3.3
110
+ rubygems_version: 1.3.7
86
111
  signing_key:
87
112
  specification_version: 3
88
113
  summary: TOP4R is a library that can help you build plugin for TaoBao.com quickly in pure Ruby.