From e3b39b5363e1a3a0f0d9a51251e7505abaa42197 Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Mon, 1 Jul 2013 09:53:05 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=8E=BB=E6=8E=89iconv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/top4r.rb | 1 - lib/top4r/ext/stdlib.rb | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/top4r.rb b/lib/top4r.rb index 4cf292b..3d4b61c 100644 --- a/lib/top4r.rb +++ b/lib/top4r.rb @@ -14,7 +14,6 @@ def require_local(suffix) require 'cgi' require 'json' require 'yaml' -require 'iconv' require 'timeout' require 'base64' diff --git a/lib/top4r/ext/stdlib.rb b/lib/top4r/ext/stdlib.rb index 905e201..96c4ce7 100644 --- a/lib/top4r/ext/stdlib.rb +++ b/lib/top4r/ext/stdlib.rb @@ -19,10 +19,18 @@ def to_http_str class String def to_gbk - Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", self).to_s + if defined?(Iconv) + Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", self).to_s + else + encode 'GBK', 'UTF-8' + end end def to_utf8 - Iconv.iconv("UTF-8//IGNORE", "GBK//IGNORE", self).to_s + if defined?(Iconv) + Iconv.iconv("UTF-8//IGNORE", "GBK//IGNORE", self).to_s + else + encode 'UTF-8', 'GBK' + end end end From a06ec189796487de37fac60bf53c9a2f3b7fb78a Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Mon, 1 Jul 2013 10:50:04 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=A7=A3=E5=86=B3visitor=5Fnick=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去掉对iconv的依赖 --- lib/top4r.rb | 1 + lib/top4r/client/base.rb | 2 +- lib/top4r/ext/stdlib.rb | 18 ------------------ lib/top4r/model/user.rb | 2 +- top4r.gemspec | 1 + 5 files changed, 4 insertions(+), 20 deletions(-) diff --git a/lib/top4r.rb b/lib/top4r.rb index 3d4b61c..72bcc5f 100644 --- a/lib/top4r.rb +++ b/lib/top4r.rb @@ -16,6 +16,7 @@ def require_local(suffix) require 'yaml' require 'timeout' require 'base64' +require 'string/utf8' require_local('top4r/ext') require_local('top4r/version') diff --git a/lib/top4r/client/base.rb b/lib/top4r/client/base.rb index e8cedb8..7d91665 100644 --- a/lib/top4r/client/base.rb +++ b/lib/top4r/client/base.rb @@ -14,7 +14,7 @@ def init @@logger = Top4R::Logger.new(@@config.logger, @@config.trace) if @parameters and @session @parameters = Base64.decode64(@parameters).split('&').inject({}) do |hsh, i| kv = i.split('='); hsh[kv[0]] = kv[1]; hsh end - @login = user(@parameters['visitor_nick']) + @login = user( @parameters['visitor_nick'].utf8! ) end end diff --git a/lib/top4r/ext/stdlib.rb b/lib/top4r/ext/stdlib.rb index 96c4ce7..2c6816a 100644 --- a/lib/top4r/ext/stdlib.rb +++ b/lib/top4r/ext/stdlib.rb @@ -16,21 +16,3 @@ def to_http_str result.chop # remove the last '&' character, since it can be discarded end end - -class String - def to_gbk - if defined?(Iconv) - Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", self).to_s - else - encode 'GBK', 'UTF-8' - end - end - - def to_utf8 - if defined?(Iconv) - Iconv.iconv("UTF-8//IGNORE", "GBK//IGNORE", self).to_s - else - encode 'UTF-8', 'GBK' - end - end -end diff --git a/lib/top4r/model/user.rb b/lib/top4r/model/user.rb index e27b929..e3da0c8 100644 --- a/lib/top4r/model/user.rb +++ b/lib/top4r/model/user.rb @@ -98,7 +98,7 @@ def bless(client) end def is_me? - @nick == @client.instance_eval("@parameters['visitor_nick']") + @nick == @client.instance_eval("@parameters['visitor_nick']").try :utf8! end def unmarshal_other_attrs diff --git a/top4r.gemspec b/top4r.gemspec index cee821b..e53e881 100644 --- a/top4r.gemspec +++ b/top4r.gemspec @@ -10,6 +10,7 @@ Gem::Specification.new do |s| s.homepage = "https://github.com/nowa/top4r" s.rubyforge_project = "top4r" s.add_dependency("json", ">=1.1.1") + s.add_dependency("string_utf8", ">=0.0.1") # s.require_path = "lib" s.files = ["lib/top4r/client/base.rb","lib/top4r/client/item.rb","lib/top4r/client/shipping.rb","lib/top4r/client/shop.rb","lib/top4r/client/suite.rb","lib/top4r/client/taobaokeitem.rb","lib/top4r/client/itemcat.rb","lib/top4r/client/trade.rb","lib/top4r/client/user.rb","lib/top4r/client.rb","lib/top4r/config.rb","lib/top4r/console.rb","lib/top4r/core.rb","lib/top4r/ext/stdlib.rb","lib/top4r/ext.rb","lib/top4r/logger.rb","lib/top4r/meta.rb","lib/top4r/model/item.rb","lib/top4r/model/shipping.rb","lib/top4r/model/shop.rb","lib/top4r/model/suite.rb","lib/top4r/model/taobaokeitem.rb","lib/top4r/model/itemcat.rb","lib/top4r/model/trade.rb","lib/top4r/model/user.rb","lib/top4r/model.rb","lib/top4r/version.rb","lib/top4r.rb",] s.bindir = 'bin' From e5bdef8b63ef36c020476d24c0141e606d9b6610 Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Mon, 1 Jul 2013 10:52:23 +0800 Subject: [PATCH 3/7] ver 0.2.4 --- CHANGES | 3 +++ top4r.gemspec | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 749d4ec..a82d168 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +=== 0.2.4 / 2013-07-01 +Fix: 解决visitor_nick乱码问题 + === 0.2.3 / 2013-01-09 Add: taobao.items.inventory.get 获取当前用户的库存商品列表 diff --git a/top4r.gemspec b/top4r.gemspec index e53e881..7dfd00d 100644 --- a/top4r.gemspec +++ b/top4r.gemspec @@ -1,7 +1,7 @@ # Generated: 2011-12-28 02:43:59 UTC Gem::Specification.new do |s| s.name = "top4r" - s.version = "0.2.3" + s.version = "0.2.4" s.platform = Gem::Platform::RUBY s.extra_rdoc_files = ["README.textile","CHANGES","TODO","MIT-LICENSE",] s.summary = "TOP4R is a library that can help you build plugin for TaoBao.com quickly in pure Ruby." From 4a44225d4d0cbc022ef558f45dd7aad5ad3cf986 Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Mon, 1 Jul 2013 10:57:04 +0800 Subject: [PATCH 4/7] match the readme file name --- top4r.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/top4r.gemspec b/top4r.gemspec index 7dfd00d..4c04069 100644 --- a/top4r.gemspec +++ b/top4r.gemspec @@ -3,7 +3,7 @@ Gem::Specification.new do |s| s.name = "top4r" s.version = "0.2.4" s.platform = Gem::Platform::RUBY - s.extra_rdoc_files = ["README.textile","CHANGES","TODO","MIT-LICENSE",] + s.extra_rdoc_files = ["README.md","CHANGES","TODO","MIT-LICENSE",] s.summary = "TOP4R is a library that can help you build plugin for TaoBao.com quickly in pure Ruby." s.author = "Nowa Zhu" s.email = "nowazhu@gmail.com" From ada50ac0e445f6a0f00b5eb9f57df20966c0d79b Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Mon, 1 Jul 2013 11:07:20 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a82d168..9e5f84a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ === 0.2.4 / 2013-07-01 Fix: 解决visitor_nick乱码问题 +Del: 去掉iconv的依赖,以便在Ruby2.0中运行(兼容ruby1.8.7) === 0.2.3 / 2013-01-09 @@ -28,4 +29,4 @@ Add: 淘客商品、店铺转换支持 * 1 major enhancement - * Birthday! \ No newline at end of file + * Birthday! From 5342c37829b0094e14174df4718eca6f9e72a812 Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Mon, 1 Jul 2013 13:28:55 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=9B=9E=E9=80=80=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=EF=BC=8C=E5=8D=87=E7=BA=A7=E5=86=B3=E5=AE=9A?= =?UTF-8?q?=E6=9D=83=E5=9C=A8repo=20owner?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGES b/CHANGES index 9e5f84a..181b42b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,3 @@ -=== 0.2.4 / 2013-07-01 -Fix: 解决visitor_nick乱码问题 -Del: 去掉iconv的依赖,以便在Ruby2.0中运行(兼容ruby1.8.7) - === 0.2.3 / 2013-01-09 Add: taobao.items.inventory.get 获取当前用户的库存商品列表 From bcfea60914bcc14a553376da60fe8631b59c9b38 Mon Sep 17 00:00:00 2001 From: "hua.qiuh" Date: Wed, 3 Jul 2013 10:47:05 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=A6=82=E6=9E=9CTOP=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=A4=9A=E4=B8=AAvistor=5Fnick=EF=BC=8C=E5=88=99=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E7=AC=AC=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/top4r/client/base.rb | 28 ++++++++++++++++++++++++++-- lib/top4r/model/user.rb | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/top4r/client/base.rb b/lib/top4r/client/base.rb index 7d91665..da1c020 100644 --- a/lib/top4r/client/base.rb +++ b/lib/top4r/client/base.rb @@ -13,8 +13,32 @@ def init total_results = 0 @@logger = Top4R::Logger.new(@@config.logger, @@config.trace) if @parameters and @session - @parameters = Base64.decode64(@parameters).split('&').inject({}) do |hsh, i| kv = i.split('='); hsh[kv[0]] = kv[1]; hsh end - @login = user( @parameters['visitor_nick'].utf8! ) + @parameters = Base64.decode64(@parameters).split('&').inject({}) do |hsh, i| + k, v = i.split('=') + hsh[k] = v + hsh + end + @login = user( visitor_nick ) + end + end + + def visitor_nick + return @visitor_nick if @visitor_nick + + # TOP returns visitor nick in GBK encoding + raw_nick = @parameters['visitor_nick'].utf8! + + if raw_nick =~ /^\[.*\]$/ + # since TOP may return an array of nicknames + # e.g. + # [vistor1, visitor2] + # [vistor1] + # + # in this case, we keep the FIRST nickname: + # #=> "vistor1" + @visitor_nick == raw_nick[/^\[([^,]+).*\]/, 1] + else + @visitor_nick == raw_nick end end diff --git a/lib/top4r/model/user.rb b/lib/top4r/model/user.rb index e3da0c8..ecf26de 100644 --- a/lib/top4r/model/user.rb +++ b/lib/top4r/model/user.rb @@ -98,7 +98,7 @@ def bless(client) end def is_me? - @nick == @client.instance_eval("@parameters['visitor_nick']").try :utf8! + @nick == @client.vistor_nick end def unmarshal_other_attrs