shopkit 0.1.3 → 0.1.4
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/README.md +50 -14
 - data/lib/shopkit.rb +5 -0
 - data/lib/shopkit/client.rb +2 -0
 - data/lib/shopkit/client/orders.rb +3 -1
 - data/lib/shopkit/client/products.rb +4 -0
 - data/lib/shopkit/configuration.rb +5 -1
 - data/lib/shopkit/connection.rb +6 -4
 - data/lib/shopkit/request.rb +1 -0
 - data/lib/shopkit/traversal.rb +17 -0
 - data/lib/shopkit/version.rb +1 -1
 - data/shopkit.gemspec +8 -2
 - data/spec/json/orders_empty.json +3 -0
 - data/spec/json/orders_page_2.json +29 -0
 - data/spec/json/orders_page_3.json +29 -0
 - data/spec/json/product.json +76 -0
 - data/spec/shopkit/client/products_spec.rb +6 -0
 - data/spec/shopkit/shopkit_spec.rb +21 -0
 - data/spec/spec_helper.rb +6 -4
 - metadata +9 -3
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,19 +1,55 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # Shopkit
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            ShopQi Ruby API 客户端
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
         
     | 
| 
       7 
     | 
    
         
            -
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
         
     | 
| 
       8 
     | 
    
         
            -
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
         
     | 
| 
       9 
     | 
    
         
            -
            * Fork the project.
         
     | 
| 
       10 
     | 
    
         
            -
            * Start a feature/bugfix branch.
         
     | 
| 
       11 
     | 
    
         
            -
            * Commit and push until you are happy with your contribution.
         
     | 
| 
       12 
     | 
    
         
            -
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
       13 
     | 
    
         
            -
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         
     | 
| 
      
 5 
     | 
    
         
            +
            ## 安装
         
     | 
| 
       14 
6 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
            $ gem install shopkit
         
     | 
| 
       16 
8 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            further details.
         
     | 
| 
      
 9 
     | 
    
         
            +
            ## 使用
         
     | 
| 
       19 
10 
     | 
    
         | 
| 
      
 11 
     | 
    
         
            +
            * 通过 api clients 访问
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                require 'shopkit'
         
     | 
| 
      
 14 
     | 
    
         
            +
                Shopkit.setup url: 'https://your-shop-name.shopqi.com', login: 'api key', password: 'password'
         
     | 
| 
      
 15 
     | 
    
         
            +
                Shopkit.orders # 获取订单
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            `api key`, `password` 在商店后台管理 [应用] - [私有应用],点击"生成新的应用"即可看到
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            * 通过 OAuth2 访问
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                require 'shopkit'
         
     | 
| 
      
 22 
     | 
    
         
            +
                Shopkit.setup url: 'https://rubyconfchina-shop.shopqi.com', access_token: 'access token'
         
     | 
| 
      
 23 
     | 
    
         
            +
                Shopkit.products # 获取商品
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            `access token`为商店授权给应用后获取
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ## API
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            ### 商店
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            [商店属性](https://github.com/saberma/shopqi/blob/master/app/views/api/v1/shops/show.rabl)
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ### 订单
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            [订单属性](https://github.com/saberma/shopqi/blob/master/app/views/api/v1/orders/show.rabl)
         
     | 
| 
      
 36 
     | 
    
         
            +
            [订单商品](https://github.com/saberma/shopqi/blob/master/app/views/api/v1/orders/line_items/show.rabl)
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            ### 商品
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            [商品属性](https://github.com/saberma/shopqi/blob/master/app/views/api/v1/products/show.rabl)
         
     | 
| 
      
 41 
     | 
    
         
            +
            [商品款式](https://github.com/saberma/shopqi/blob/master/app/views/api/v1/product_variants/show.rabl)
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            ## 开发
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            ### 发布
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            修改 `lib/shopkit/version.rb`
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                rake release -t -v
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            如果出现以下问题
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                ERROR:  Using beta/unreleased version of rubygems. Not pushing
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            请尝试使用 VPN 连接网络,推荐 vpncup(免费)
         
     | 
    
        data/lib/shopkit.rb
    CHANGED
    
    | 
         @@ -10,6 +10,8 @@ module Shopkit 
     | 
|
| 
       10 
10 
     | 
    
         
             
                def new(options={})
         
     | 
| 
       11 
11 
     | 
    
         
             
                  options['url'] = self.url
         
     | 
| 
       12 
12 
     | 
    
         
             
                  options['access_token'] = self.access_token
         
     | 
| 
      
 13 
     | 
    
         
            +
                  options['login'] = self.login
         
     | 
| 
      
 14 
     | 
    
         
            +
                  options['password'] = self.password
         
     | 
| 
       13 
15 
     | 
    
         
             
                  Shopkit::Client.new(options)
         
     | 
| 
       14 
16 
     | 
    
         
             
                end
         
     | 
| 
       15 
17 
     | 
    
         | 
| 
         @@ -22,7 +24,10 @@ module Shopkit 
     | 
|
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
                def setup(options)
         
     | 
| 
       24 
26 
     | 
    
         
             
                  self.url = options[:url]
         
     | 
| 
      
 27 
     | 
    
         
            +
                  self.url = "http://#{self.url}" unless self.url.start_with?('http://', 'https://')
         
     | 
| 
       25 
28 
     | 
    
         
             
                  self.access_token = options[:access_token]
         
     | 
| 
      
 29 
     | 
    
         
            +
                  self.login = options[:login] # or basic auth
         
     | 
| 
      
 30 
     | 
    
         
            +
                  self.password = options[:password]
         
     | 
| 
       26 
31 
     | 
    
         
             
                  options
         
     | 
| 
       27 
32 
     | 
    
         
             
                end
         
     | 
| 
       28 
33 
     | 
    
         | 
    
        data/lib/shopkit/client.rb
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'shopkit/connection'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'shopkit/request'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'shopkit/traversal'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            #Load all files in client/ directory
         
     | 
| 
       5 
6 
     | 
    
         
             
            Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/client/*.rb").sort.each do |f|
         
     | 
| 
         @@ -19,5 +20,6 @@ module Shopkit 
     | 
|
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
                include Shopkit::Connection
         
     | 
| 
       21 
22 
     | 
    
         
             
                include Shopkit::Request
         
     | 
| 
      
 23 
     | 
    
         
            +
                include Shopkit::Traversal
         
     | 
| 
       22 
24 
     | 
    
         
             
              end
         
     | 
| 
       23 
25 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,6 +8,8 @@ module Shopkit 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  :api_version,
         
     | 
| 
       9 
9 
     | 
    
         
             
                  :url,
         
     | 
| 
       10 
10 
     | 
    
         
             
                  :access_token,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  :login,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :password,
         
     | 
| 
       11 
13 
     | 
    
         
             
                  :user_agent,
         
     | 
| 
       12 
14 
     | 
    
         
             
                  :auto_traversal,
         
     | 
| 
       13 
15 
     | 
    
         
             
                  :per_page].freeze
         
     | 
| 
         @@ -34,7 +36,9 @@ module Shopkit 
     | 
|
| 
       34 
36 
     | 
    
         
             
                def reset
         
     | 
| 
       35 
37 
     | 
    
         
             
                  self.adapter        = DEFAULT_ADAPTER
         
     | 
| 
       36 
38 
     | 
    
         
             
                  self.api_version    = DEFAULT_API_VERSION
         
     | 
| 
       37 
     | 
    
         
            -
                  self.access_token 
     | 
| 
      
 39 
     | 
    
         
            +
                  self.access_token   = nil
         
     | 
| 
      
 40 
     | 
    
         
            +
                  self.login          = nil
         
     | 
| 
      
 41 
     | 
    
         
            +
                  self.password       = nil
         
     | 
| 
       38 
42 
     | 
    
         
             
                  self.user_agent     = DEFAULT_USER_AGENT
         
     | 
| 
       39 
43 
     | 
    
         
             
                  self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
         
     | 
| 
       40 
44 
     | 
    
         
             
                end
         
     | 
    
        data/lib/shopkit/connection.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: utf-8
         
     | 
| 
       1 
2 
     | 
    
         
             
            require 'faraday_middleware'
         
     | 
| 
       2 
3 
     | 
    
         
             
            require 'faraday_middleware/request/oauth2'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
         @@ -7,16 +8,17 @@ module Shopkit 
     | 
|
| 
       7 
8 
     | 
    
         
             
                private
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
10 
     | 
    
         
             
                def connection
         
     | 
| 
       10 
     | 
    
         
            -
                   
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                    builder.request : 
     | 
| 
      
 11 
     | 
    
         
            +
                  @conn ||= Faraday.new(:url => url) do |builder|
         
     | 
| 
      
 12 
     | 
    
         
            +
                    builder.request :oauth2, access_token if access_token
         
     | 
| 
      
 13 
     | 
    
         
            +
                    builder.request :basic_auth, login, password if login and password
         
     | 
| 
       13 
14 
     | 
    
         
             
                    builder.request :json # fixed: NoMethodError: undefined method `bytesize' for {...}:Hash
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                    #builder.response :logger
         
     | 
| 
      
 16 
     | 
    
         
            +
                    #builder.response :logger # 调试
         
     | 
| 
       16 
17 
     | 
    
         
             
                    builder.response :json, :content_type => /\bjson$/
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
                    builder.adapter :net_http
         
     | 
| 
       19 
20 
     | 
    
         
             
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @conn
         
     | 
| 
       20 
22 
     | 
    
         
             
                end
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
24 
     | 
    
         
             
              end
         
     | 
    
        data/lib/shopkit/request.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Shopkit
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Traversal
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                def traversal(options) # 遍历所有页面
         
     | 
| 
      
 5 
     | 
    
         
            +
                  list = yield(options)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  if auto_traversal and !list.empty?
         
     | 
| 
      
 7 
     | 
    
         
            +
                    options[:page] ||= 1
         
     | 
| 
      
 8 
     | 
    
         
            +
                    options[:page] += 1
         
     | 
| 
      
 9 
     | 
    
         
            +
                    list += traversal(options) do
         
     | 
| 
      
 10 
     | 
    
         
            +
                      yield(options)
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                  list
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/shopkit/version.rb
    CHANGED
    
    
    
        data/shopkit.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = "shopkit"
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.1.4"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["saberma"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = "2012- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = "2012-10-04"
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = "a gem for the ShopQi API"
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = "mahb45@gmail.com"
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
         @@ -35,10 +35,15 @@ Gem::Specification.new do |s| 
     | 
|
| 
       35 
35 
     | 
    
         
             
                "lib/shopkit/configuration.rb",
         
     | 
| 
       36 
36 
     | 
    
         
             
                "lib/shopkit/connection.rb",
         
     | 
| 
       37 
37 
     | 
    
         
             
                "lib/shopkit/request.rb",
         
     | 
| 
      
 38 
     | 
    
         
            +
                "lib/shopkit/traversal.rb",
         
     | 
| 
       38 
39 
     | 
    
         
             
                "lib/shopkit/version.rb",
         
     | 
| 
       39 
40 
     | 
    
         
             
                "shopkit.gemspec",
         
     | 
| 
       40 
41 
     | 
    
         
             
                "spec/json/order.json",
         
     | 
| 
       41 
42 
     | 
    
         
             
                "spec/json/orders.json",
         
     | 
| 
      
 43 
     | 
    
         
            +
                "spec/json/orders_empty.json",
         
     | 
| 
      
 44 
     | 
    
         
            +
                "spec/json/orders_page_2.json",
         
     | 
| 
      
 45 
     | 
    
         
            +
                "spec/json/orders_page_3.json",
         
     | 
| 
      
 46 
     | 
    
         
            +
                "spec/json/product.json",
         
     | 
| 
       42 
47 
     | 
    
         
             
                "spec/json/products.json",
         
     | 
| 
       43 
48 
     | 
    
         
             
                "spec/json/shop.json",
         
     | 
| 
       44 
49 
     | 
    
         
             
                "spec/json/variant.json",
         
     | 
| 
         @@ -48,6 +53,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       48 
53 
     | 
    
         
             
                "spec/shopkit/client/products_spec.rb",
         
     | 
| 
       49 
54 
     | 
    
         
             
                "spec/shopkit/client/shop_spec.rb",
         
     | 
| 
       50 
55 
     | 
    
         
             
                "spec/shopkit/client/webhooks_spec.rb",
         
     | 
| 
      
 56 
     | 
    
         
            +
                "spec/shopkit/shopkit_spec.rb",
         
     | 
| 
       51 
57 
     | 
    
         
             
                "spec/spec_helper.rb"
         
     | 
| 
       52 
58 
     | 
    
         
             
              ]
         
     | 
| 
       53 
59 
     | 
    
         
             
              s.homepage = "http://github.com/saberma/shopkit"
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            {
         
     | 
| 
      
 2 
     | 
    
         
            +
              "orders": [
         
     | 
| 
      
 3 
     | 
    
         
            +
                {
         
     | 
| 
      
 4 
     | 
    
         
            +
                  "cancel_reason": null,
         
     | 
| 
      
 5 
     | 
    
         
            +
                  "cancelled_at": null,
         
     | 
| 
      
 6 
     | 
    
         
            +
                  "closed_at": "2012-05-15T21:36:38+08:00",
         
     | 
| 
      
 7 
     | 
    
         
            +
                  "created_at": "2012-04-16T23:07:33+08:00",
         
     | 
| 
      
 8 
     | 
    
         
            +
                  "customer_id": 2,
         
     | 
| 
      
 9 
     | 
    
         
            +
                  "email": "mahb45@gmail.com",
         
     | 
| 
      
 10 
     | 
    
         
            +
                  "financial_status": "pending",
         
     | 
| 
      
 11 
     | 
    
         
            +
                  "fulfillment_status": "fulfilled",
         
     | 
| 
      
 12 
     | 
    
         
            +
                  "id": 100,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  "name": "#1096",
         
     | 
| 
      
 14 
     | 
    
         
            +
                  "note": "",
         
     | 
| 
      
 15 
     | 
    
         
            +
                  "number": 96,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  "order_number": 1096,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  "payment_id": 8,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  "shipping_rate": "普通快递-0",
         
     | 
| 
      
 19 
     | 
    
         
            +
                  "shop_id": 2,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  "status": "closed",
         
     | 
| 
      
 21 
     | 
    
         
            +
                  "subtotal_price": 45.0,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  "token": "96b1d0806s0d928f21f6480aa969d9a6",
         
     | 
| 
      
 23 
     | 
    
         
            +
                  "total_line_items_price": 45.0,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  "total_price": 45.0,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  "trade_no": null,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  "updated_at": "2012-05-15T21:36:38+08:00"
         
     | 
| 
      
 27 
     | 
    
         
            +
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
              ]
         
     | 
| 
      
 29 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            {
         
     | 
| 
      
 2 
     | 
    
         
            +
              "orders": [
         
     | 
| 
      
 3 
     | 
    
         
            +
                {
         
     | 
| 
      
 4 
     | 
    
         
            +
                  "cancel_reason": null,
         
     | 
| 
      
 5 
     | 
    
         
            +
                  "cancelled_at": null,
         
     | 
| 
      
 6 
     | 
    
         
            +
                  "closed_at": "2012-05-15T21:36:38+08:00",
         
     | 
| 
      
 7 
     | 
    
         
            +
                  "created_at": "2012-04-16T23:07:33+08:00",
         
     | 
| 
      
 8 
     | 
    
         
            +
                  "customer_id": 2,
         
     | 
| 
      
 9 
     | 
    
         
            +
                  "email": "mahb45@gmail.com",
         
     | 
| 
      
 10 
     | 
    
         
            +
                  "financial_status": "pending",
         
     | 
| 
      
 11 
     | 
    
         
            +
                  "fulfillment_status": "fulfilled",
         
     | 
| 
      
 12 
     | 
    
         
            +
                  "id": 101,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  "name": "#1097",
         
     | 
| 
      
 14 
     | 
    
         
            +
                  "note": "",
         
     | 
| 
      
 15 
     | 
    
         
            +
                  "number": 97,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  "order_number": 1097,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  "payment_id": 8,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  "shipping_rate": "普通快递-0",
         
     | 
| 
      
 19 
     | 
    
         
            +
                  "shop_id": 2,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  "status": "closed",
         
     | 
| 
      
 21 
     | 
    
         
            +
                  "subtotal_price": 45.0,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  "token": "96b1d0806s0d928f21f6480aa969d9a6",
         
     | 
| 
      
 23 
     | 
    
         
            +
                  "total_line_items_price": 45.0,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  "total_price": 45.0,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  "trade_no": null,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  "updated_at": "2012-05-15T21:36:38+08:00"
         
     | 
| 
      
 27 
     | 
    
         
            +
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
              ]
         
     | 
| 
      
 29 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,76 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            {
         
     | 
| 
      
 2 
     | 
    
         
            +
              "product": {
         
     | 
| 
      
 3 
     | 
    
         
            +
                "body_html": "",
         
     | 
| 
      
 4 
     | 
    
         
            +
                "created_at": "2012-01-14T11:02:58+08:00",
         
     | 
| 
      
 5 
     | 
    
         
            +
                "handle": "tee-01",
         
     | 
| 
      
 6 
     | 
    
         
            +
                "id": 138,
         
     | 
| 
      
 7 
     | 
    
         
            +
                "price": 45.0,
         
     | 
| 
      
 8 
     | 
    
         
            +
                "product_type": "T恤",
         
     | 
| 
      
 9 
     | 
    
         
            +
                "published": true,
         
     | 
| 
      
 10 
     | 
    
         
            +
                "shop_id": 2,
         
     | 
| 
      
 11 
     | 
    
         
            +
                "title": "Tee 01",
         
     | 
| 
      
 12 
     | 
    
         
            +
                "updated_at": "2012-05-21T18:49:13+08:00",
         
     | 
| 
      
 13 
     | 
    
         
            +
                "vendor": "吉尔丹",
         
     | 
| 
      
 14 
     | 
    
         
            +
                "variants": [
         
     | 
| 
      
 15 
     | 
    
         
            +
                  {
         
     | 
| 
      
 16 
     | 
    
         
            +
                    "compare_at_price": null,
         
     | 
| 
      
 17 
     | 
    
         
            +
                    "created_at": "2012-03-26T21:45:47+08:00",
         
     | 
| 
      
 18 
     | 
    
         
            +
                    "id": 169,
         
     | 
| 
      
 19 
     | 
    
         
            +
                    "inventory_management": "",
         
     | 
| 
      
 20 
     | 
    
         
            +
                    "inventory_policy": "deny",
         
     | 
| 
      
 21 
     | 
    
         
            +
                    "inventory_quantity": null,
         
     | 
| 
      
 22 
     | 
    
         
            +
                    "option1": "默认大小",
         
     | 
| 
      
 23 
     | 
    
         
            +
                    "option2": "1",
         
     | 
| 
      
 24 
     | 
    
         
            +
                    "option3": "M",
         
     | 
| 
      
 25 
     | 
    
         
            +
                    "position": 1,
         
     | 
| 
      
 26 
     | 
    
         
            +
                    "price": 1900.0,
         
     | 
| 
      
 27 
     | 
    
         
            +
                    "product_id": 138,
         
     | 
| 
      
 28 
     | 
    
         
            +
                    "requires_shipping": true,
         
     | 
| 
      
 29 
     | 
    
         
            +
                    "shop_id": 2,
         
     | 
| 
      
 30 
     | 
    
         
            +
                    "sku": "",
         
     | 
| 
      
 31 
     | 
    
         
            +
                    "updated_at": "2012-05-21T21:24:58+08:00",
         
     | 
| 
      
 32 
     | 
    
         
            +
                    "weight": 0.0
         
     | 
| 
      
 33 
     | 
    
         
            +
                  },
         
     | 
| 
      
 34 
     | 
    
         
            +
                  {
         
     | 
| 
      
 35 
     | 
    
         
            +
                    "compare_at_price": null,
         
     | 
| 
      
 36 
     | 
    
         
            +
                    "created_at": "2012-05-21T18:49:53+08:00",
         
     | 
| 
      
 37 
     | 
    
         
            +
                    "id": 177,
         
     | 
| 
      
 38 
     | 
    
         
            +
                    "inventory_management": "",
         
     | 
| 
      
 39 
     | 
    
         
            +
                    "inventory_policy": "deny",
         
     | 
| 
      
 40 
     | 
    
         
            +
                    "inventory_quantity": null,
         
     | 
| 
      
 41 
     | 
    
         
            +
                    "option1": "默认",
         
     | 
| 
      
 42 
     | 
    
         
            +
                    "option2": "3",
         
     | 
| 
      
 43 
     | 
    
         
            +
                    "option3": "XL",
         
     | 
| 
      
 44 
     | 
    
         
            +
                    "position": 2,
         
     | 
| 
      
 45 
     | 
    
         
            +
                    "price": 1900.0,
         
     | 
| 
      
 46 
     | 
    
         
            +
                    "product_id": 138,
         
     | 
| 
      
 47 
     | 
    
         
            +
                    "requires_shipping": true,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    "shop_id": 2,
         
     | 
| 
      
 49 
     | 
    
         
            +
                    "sku": "",
         
     | 
| 
      
 50 
     | 
    
         
            +
                    "updated_at": "2012-05-21T21:24:58+08:00",
         
     | 
| 
      
 51 
     | 
    
         
            +
                    "weight": 0.0
         
     | 
| 
      
 52 
     | 
    
         
            +
                  }
         
     | 
| 
      
 53 
     | 
    
         
            +
                ],
         
     | 
| 
      
 54 
     | 
    
         
            +
                "photos": [
         
     | 
| 
      
 55 
     | 
    
         
            +
                  {
         
     | 
| 
      
 56 
     | 
    
         
            +
                    "created_at": "2012-03-23T11:24:42+08:00",
         
     | 
| 
      
 57 
     | 
    
         
            +
                    "id": 154,
         
     | 
| 
      
 58 
     | 
    
         
            +
                    "position": 0,
         
     | 
| 
      
 59 
     | 
    
         
            +
                    "product_id": 138,
         
     | 
| 
      
 60 
     | 
    
         
            +
                    "product_image_format": "jpg",
         
     | 
| 
      
 61 
     | 
    
         
            +
                    "product_image_uid": "2/products/138/pink-preview_810.jpg",
         
     | 
| 
      
 62 
     | 
    
         
            +
                    "updated_at": "2012-03-23T11:24:54+08:00"
         
     | 
| 
      
 63 
     | 
    
         
            +
                  }
         
     | 
| 
      
 64 
     | 
    
         
            +
                ],
         
     | 
| 
      
 65 
     | 
    
         
            +
                "options": [
         
     | 
| 
      
 66 
     | 
    
         
            +
                  {
         
     | 
| 
      
 67 
     | 
    
         
            +
                    "name": "标题",
         
     | 
| 
      
 68 
     | 
    
         
            +
                    "position": 1
         
     | 
| 
      
 69 
     | 
    
         
            +
                  },
         
     | 
| 
      
 70 
     | 
    
         
            +
                  {
         
     | 
| 
      
 71 
     | 
    
         
            +
                    "name": "大小",
         
     | 
| 
      
 72 
     | 
    
         
            +
                    "position": 2
         
     | 
| 
      
 73 
     | 
    
         
            +
                  }
         
     | 
| 
      
 74 
     | 
    
         
            +
                ]
         
     | 
| 
      
 75 
     | 
    
         
            +
              }
         
     | 
| 
      
 76 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -9,5 +9,11 @@ describe Shopkit::Client::Products do 
     | 
|
| 
       9 
9 
     | 
    
         
             
              it 'should get products' do
         
     | 
| 
       10 
10 
     | 
    
         
             
                Shopkit.products.size.should_not eql 0
         
     | 
| 
       11 
11 
     | 
    
         
             
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              it 'should get product' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                id = 138
         
     | 
| 
      
 15 
     | 
    
         
            +
                fake_web "products/#{id}", json_file: :product
         
     | 
| 
      
 16 
     | 
    
         
            +
                Shopkit.product(id)['id'].should eql id
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
       12 
18 
     | 
    
         | 
| 
       13 
19 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Shopkit do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                fake_web "orders", query: {per_page: 1, page: 1}
         
     | 
| 
      
 7 
     | 
    
         
            +
                fake_web "orders", query: {per_page: 1, page: 2}, json_file: "orders_page_2"
         
     | 
| 
      
 8 
     | 
    
         
            +
                fake_web "orders", query: {per_page: 1, page: 3}, json_file: "orders_page_3"
         
     | 
| 
      
 9 
     | 
    
         
            +
                fake_web "orders", query: {per_page: 1, page: 4}, json_file: "orders_empty"
         
     | 
| 
      
 10 
     | 
    
         
            +
                Shopkit.auto_traversal = true
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              after do
         
     | 
| 
      
 14 
     | 
    
         
            +
                Shopkit.auto_traversal = false
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              it 'should be auto_traversal' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                Shopkit.orders(per_page: 1, page: 1).size.should eql 3
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -5,7 +5,8 @@ require 'webmock/rspec' 
     | 
|
| 
       5 
5 
     | 
    
         
             
            RSpec.configure do |config|
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
              config.before(:each) do
         
     | 
| 
       8 
     | 
    
         
            -
                shop_url = 'ruby-china-shop.shopqi.com'
         
     | 
| 
      
 8 
     | 
    
         
            +
                #shop_url = 'https://ruby-china-shop.shopqi.com'
         
     | 
| 
      
 9 
     | 
    
         
            +
                shop_url = 'http://ruby-china-shop.shopqi.com'
         
     | 
| 
       9 
10 
     | 
    
         
             
                access_token = 'b68da7c5eb6c07ff3f5a1ce731555fdc'
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
                Shopkit.setup(url: shop_url, access_token: access_token)
         
     | 
| 
         @@ -21,9 +22,10 @@ RSpec.configure do |config| 
     | 
|
| 
       21 
22 
     | 
    
         
             
                body = options.has_key?(:body) ? options.delete(:body) : load_json(file)
         
     | 
| 
       22 
23 
     | 
    
         
             
                method = options.delete(:method) || :get
         
     | 
| 
       23 
24 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
      
 25 
     | 
    
         
            +
                url = "#{Shopkit.url}/api/#{endpoint}.json"
         
     | 
| 
      
 26 
     | 
    
         
            +
                params = {body: request_body}
         
     | 
| 
      
 27 
     | 
    
         
            +
                params.merge! query: options[:query] if options[:query]
         
     | 
| 
      
 28 
     | 
    
         
            +
                stub_request(method, url).with(params).to_return(body: body, headers: { content_type: 'text/json' })
         
     | 
| 
       27 
29 
     | 
    
         
             
              end
         
     | 
| 
       28 
30 
     | 
    
         | 
| 
       29 
31 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: shopkit
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2012- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-10-04 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: faraday
         
     | 
| 
         @@ -165,10 +165,15 @@ files: 
     | 
|
| 
       165 
165 
     | 
    
         
             
            - lib/shopkit/configuration.rb
         
     | 
| 
       166 
166 
     | 
    
         
             
            - lib/shopkit/connection.rb
         
     | 
| 
       167 
167 
     | 
    
         
             
            - lib/shopkit/request.rb
         
     | 
| 
      
 168 
     | 
    
         
            +
            - lib/shopkit/traversal.rb
         
     | 
| 
       168 
169 
     | 
    
         
             
            - lib/shopkit/version.rb
         
     | 
| 
       169 
170 
     | 
    
         
             
            - shopkit.gemspec
         
     | 
| 
       170 
171 
     | 
    
         
             
            - spec/json/order.json
         
     | 
| 
       171 
172 
     | 
    
         
             
            - spec/json/orders.json
         
     | 
| 
      
 173 
     | 
    
         
            +
            - spec/json/orders_empty.json
         
     | 
| 
      
 174 
     | 
    
         
            +
            - spec/json/orders_page_2.json
         
     | 
| 
      
 175 
     | 
    
         
            +
            - spec/json/orders_page_3.json
         
     | 
| 
      
 176 
     | 
    
         
            +
            - spec/json/product.json
         
     | 
| 
       172 
177 
     | 
    
         
             
            - spec/json/products.json
         
     | 
| 
       173 
178 
     | 
    
         
             
            - spec/json/shop.json
         
     | 
| 
       174 
179 
     | 
    
         
             
            - spec/json/variant.json
         
     | 
| 
         @@ -178,6 +183,7 @@ files: 
     | 
|
| 
       178 
183 
     | 
    
         
             
            - spec/shopkit/client/products_spec.rb
         
     | 
| 
       179 
184 
     | 
    
         
             
            - spec/shopkit/client/shop_spec.rb
         
     | 
| 
       180 
185 
     | 
    
         
             
            - spec/shopkit/client/webhooks_spec.rb
         
     | 
| 
      
 186 
     | 
    
         
            +
            - spec/shopkit/shopkit_spec.rb
         
     | 
| 
       181 
187 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       182 
188 
     | 
    
         
             
            homepage: http://github.com/saberma/shopkit
         
     | 
| 
       183 
189 
     | 
    
         
             
            licenses:
         
     | 
| 
         @@ -194,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       194 
200 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       195 
201 
     | 
    
         
             
                  segments:
         
     | 
| 
       196 
202 
     | 
    
         
             
                  - 0
         
     | 
| 
       197 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 203 
     | 
    
         
            +
                  hash: 474065761
         
     | 
| 
       198 
204 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       199 
205 
     | 
    
         
             
              none: false
         
     | 
| 
       200 
206 
     | 
    
         
             
              requirements:
         
     |