dianping-api 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d90607c0ebb98542b7b46e660a0e0d58e752e9e9b039605c3b775526d28f4b2
4
- data.tar.gz: ea4989f921379d2c2ed163421473edba4702f9178df563fa8af7c814704d6a0e
3
+ metadata.gz: 3221f07cd5c4e9b610a2ad6e5752816a542387b8db12f0f3c86f2d631ed39089
4
+ data.tar.gz: 15032efba732a33d797ab1d3a8f96695ef6f55ce92c09cc6048b777684e315ec
5
5
  SHA512:
6
- metadata.gz: c39d73c68ff6362a4956829e343d8868d095faa06cd70c3325e2c0d540fe94ec130e0d963cc5c91b9ca0e0b4ef4744141694aaa85c94ec0c6974b7d9150f6ebf
7
- data.tar.gz: f4e95c77e75256976d43cb4622b7acb544421a4f92812f8c2e261e8ee3d94c14fc7483afa519e57d38f2de03da0d67d3f6923975bb1535c490512d46fdab1853
6
+ metadata.gz: 5d94c5c7381bb2e560689cbd858f98748d5aa743f7da4fd39db94d142a679a2c5df70c77c42417d051c045eae6b37e96a88840c99bd2eb6f138e61446ece3e73
7
+ data.tar.gz: c4c76fab3731eccc2b31244c852451403cb7310d33f4a25d3824f3419fdabe68b143117dbf0a1e3902abd7fd81f9d5363cd9e280388cbf871f8896d474a259c0
@@ -3,7 +3,7 @@ PATH
3
3
  specs:
4
4
  dianping-api (0.1.0)
5
5
  faraday (~> 1.0)
6
- multi_json (>= 1.0)
6
+ multi_json (~> 1.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -82,12 +82,12 @@ PLATFORMS
82
82
  DEPENDENCIES
83
83
  bundler (~> 1.17)
84
84
  dianping-api!
85
- guard (>= 2.0)
86
- guard-rspec (>= 4.0)
85
+ guard (~> 2.0)
86
+ guard-rspec (~> 4.0)
87
87
  rake (~> 10.0)
88
- rspec (>= 3.0)
89
- rspec-its (>= 1.0)
90
- webmock (>= 3.0)
88
+ rspec (~> 3.0)
89
+ rspec-its (~> 1.0)
90
+ webmock (~> 3.0)
91
91
 
92
92
  BUNDLED WITH
93
93
  1.17.3
@@ -1,4 +1,4 @@
1
- require "dianping/api/version"
1
+ require 'dianping/api/version'
2
2
  require 'faraday'
3
3
 
4
4
  module Dianping
@@ -8,11 +8,14 @@ module Dianping
8
8
  class UsageError < StandardError; end
9
9
  class Error < StandardError; end
10
10
 
11
+ module Modules; end
11
12
  end
12
13
  end
13
14
 
15
+ require 'dianping/api/modules/tuangou'
16
+
14
17
  require 'dianping/api/middle_ware'
15
18
  require 'dianping/api/token'
16
19
  require 'dianping/api/client'
17
20
 
18
- Faraday::Request.register_middleware dianping: ::Dianping::Api::MiddleWare
21
+ Faraday::Request.register_middleware dianping: ::Dianping::Api::MiddleWare
@@ -4,6 +4,8 @@ module Dianping
4
4
  module Api
5
5
  class Client
6
6
 
7
+ include Modules::Tuangou
8
+
7
9
  attr_reader :app_key, :site, :token, :redirect_url
8
10
 
9
11
  def initialize(app_key, secret, **options)
@@ -11,7 +11,8 @@ module Dianping
11
11
  def call(env)
12
12
  check_session(env)
13
13
  @app.call(env).on_complete do |response_env|
14
- check_response(response_env)
14
+ hash = MultiJson.load response_env.body, symbolized_keys: true
15
+ check_response(hash)
15
16
  end
16
17
  end
17
18
 
@@ -23,7 +24,13 @@ module Dianping
23
24
  raise TokenExpireError
24
25
  end
25
26
 
26
- def check_response(env)
27
+ def check_response(body)
28
+ code = body[:code].to_i
29
+ msg = format('[%<code>d]%<msg>s', code: code, msg: body[:msg])
30
+
31
+ raise TokenExpireError, msg if code == 608
32
+ raise UsageError, msg if code >= 800
33
+ raise Error, msg unless code == 200
27
34
  end
28
35
  end
29
36
  end
@@ -0,0 +1,20 @@
1
+ module Dianping
2
+ module Api
3
+ module Modules
4
+ module Tuangou
5
+ def receipt_pre_code(shop_uuid, code)
6
+ post('/router/tuangou/receipt/prepare', open_shop_uuid: shop_uuid, receipt_code: code)
7
+ end
8
+
9
+ def receipt_consume(shop_uuid, code, request_id, count = 1, **params)
10
+ params.merge! open_shop_uuid: shop_uuid,
11
+ receipt_code: code,
12
+ request_id: request_id,
13
+ count: count
14
+
15
+ post '/router/tuangou/receipt/consume', params
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Dianping
2
2
  module Api
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dianping-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Wong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2020-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -159,6 +159,7 @@ files:
159
159
  - lib/dianping/api.rb
160
160
  - lib/dianping/api/client.rb
161
161
  - lib/dianping/api/middle_ware.rb
162
+ - lib/dianping/api/modules/tuangou.rb
162
163
  - lib/dianping/api/token.rb
163
164
  - lib/dianping/api/version.rb
164
165
  homepage: https://github.com/lazing/dianping-api