Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Add: 淘客商品、店铺转换支持

* 1 major enhancement

* Birthday!
* Birthday!
2 changes: 1 addition & 1 deletion lib/top4r.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def require_local(suffix)
require 'cgi'
require 'json'
require 'yaml'
require 'iconv'
require 'timeout'
require 'base64'
require 'string/utf8'

require_local('top4r/ext')
require_local('top4r/version')
Expand Down
28 changes: 26 additions & 2 deletions lib/top4r/client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
@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

Expand Down
10 changes: 0 additions & 10 deletions lib/top4r/ext/stdlib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,3 @@ def to_http_str
result.chop # remove the last '&' character, since it can be discarded
end
end

class String
def to_gbk
Iconv.iconv("GBK//IGNORE", "UTF-8//IGNORE", self).to_s
end

def to_utf8
Iconv.iconv("UTF-8//IGNORE", "GBK//IGNORE", self).to_s
end
end
2 changes: 1 addition & 1 deletion lib/top4r/model/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def bless(client)
end

def is_me?
@nick == @client.instance_eval("@parameters['visitor_nick']")
@nick == @client.vistor_nick
end

def unmarshal_other_attrs
Expand Down
5 changes: 3 additions & 2 deletions top4r.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# 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.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"
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'
Expand Down