Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/total_results'
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Oct 27, 2012
2 parents f66a915 + 37a0027 commit 1a37872
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/extension/array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# encoding: utf-8


class Array
attr_accessor :total_results
end
1 change: 1 addition & 0 deletions lib/toby.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8

require "extension/array"
require "toby/client"
require "toby/request"
require "toby/request/base"
Expand Down
7 changes: 7 additions & 0 deletions lib/toby/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def parse

if parsed_response.kind_of?(Array)
parsed_response.map! { |item| Hashie::Mash.new(item) }
begin
total_results_key_path = response_key_path.split(".").first + ".total_results"
parsed_response.total_results = total_results_key_path.split(".").inject(@response) { |hash, key| hash[key.to_sym] }
rescue
# do nothing
end
parsed_response
else
Hashie::Mash.new(parsed_response)
end
Expand Down
1 change: 1 addition & 0 deletions spec/toby/request/taobao/taobaoke_items_get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

items = @client.execute(request)
items.first.num_iid.should eq 18083496676
items.total_results.should eq 3703416
end
end
1 change: 1 addition & 0 deletions spec/toby/request/taobao/taobaoke_shops_get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
shops = @client.execute(request)

shops.first.shop_title.should eq "一米阳光官方旗舰店"
shops.total_results.should eq 1
end
end

0 comments on commit 1a37872

Please sign in to comment.