dianping-api 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3221f07cd5c4e9b610a2ad6e5752816a542387b8db12f0f3c86f2d631ed39089
4
- data.tar.gz: 15032efba732a33d797ab1d3a8f96695ef6f55ce92c09cc6048b777684e315ec
3
+ metadata.gz: 8739ca18c627d07503c20dc80087fb335e4c67165490c301db372ec9a506168d
4
+ data.tar.gz: 97e6298fe7d94c9f78cd6ed25d9f8cfa39b88cf5054e9325bca77b40cdebb273
5
5
  SHA512:
6
- metadata.gz: 5d94c5c7381bb2e560689cbd858f98748d5aa743f7da4fd39db94d142a679a2c5df70c77c42417d051c045eae6b37e96a88840c99bd2eb6f138e61446ece3e73
7
- data.tar.gz: c4c76fab3731eccc2b31244c852451403cb7310d33f4a25d3824f3419fdabe68b143117dbf0a1e3902abd7fd81f9d5363cd9e280388cbf871f8896d474a259c0
6
+ metadata.gz: 1ed02e94b7c8ff8e7d6a039ffe7466aeb15fb53dd459fc0dd045795cacddd32e6f77ff376c7e6cad39383e0a37ab7ca40fa24eff3f6f6ed342bbf1d8af7d3af6
7
+ data.tar.gz: 158b17cc9141e222e2c3e1d820747ddf678075035227eba2cae13e56f22605d717f7f6ebcdd12fdb5aa83e49cfee05a0f829f9f1f6f711a1ffed7f37418d5b44
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dianping-api (0.1.0)
4
+ dianping-api (0.1.1)
5
5
  faraday (~> 1.0)
6
6
  multi_json (~> 1.0)
7
7
 
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Dianping::Api
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dianping/api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ 美团点评北极星平台Open API SDK for Ruby
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,19 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ 注册 https://open.dianping.com 按开发测试说明使用
24
+
25
+ ```ruby
26
+
27
+ # redirect_url 专门给获取access_token (session)使用
28
+ client = Dianping::Api::Client.new 'app_key', 'app_secrent', redirect_url: 'https://example.org/callback'
29
+
30
+ # 公共请求参数会自动提供并签名
31
+ # 正常结果 `code 200` 以外的返回报文会抛出异常
32
+ body_json = client.post '/routers/xxxx', biz_key1: 1, biz_key2: 2
33
+ body_json = client.get '/routers/xxxx', url_key1: 1, url_key2: 2
34
+
35
+ ```
26
36
 
27
37
  ## Development
28
38
 
@@ -1,12 +1,27 @@
1
1
  require 'dianping/api/version'
2
2
  require 'faraday'
3
+ require 'logger'
3
4
 
4
5
  module Dianping
5
6
  module Api
6
7
  class TokenExpireError < Faraday::RetriableResponse; end
7
- class TokenMissingError < StandardError; end
8
- class UsageError < StandardError; end
9
8
  class Error < StandardError; end
9
+ class TokenMissingError < Error; end
10
+ class UsageError < Error; end
11
+
12
+ def self.logger
13
+ @@logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT)
14
+ end
15
+
16
+ def self.logger=(logger)
17
+ @@logger = logger
18
+ end
19
+
20
+ def self.client
21
+ return @client = yield(Client) if block_given?
22
+
23
+ @client || raise(::Dianping::Api::Error, 'initialize client with block first')
24
+ end
10
25
 
11
26
  module Modules; end
12
27
  end
@@ -94,7 +94,8 @@ module Dianping
94
94
  merged = share_params.merge(params || {}).dup
95
95
  content = merged.to_a.sort.flatten.join.encode!('UTF-8')
96
96
  # puts @secret + content
97
- sign = Digest::MD5.hexdigest(@secret + content + @secret)
97
+ Api.logger.debug { format('content: %s', content) }
98
+ sign = Digest::MD5.hexdigest([@secret, content, @secret].compact.join)
98
99
  merged.merge(sign: sign)
99
100
  end
100
101
  end
@@ -9,9 +9,11 @@ module Dianping
9
9
  end
10
10
 
11
11
  def call(env)
12
+ Api.logger.debug { { request: env } }
12
13
  check_session(env)
13
14
  @app.call(env).on_complete do |response_env|
14
- hash = MultiJson.load response_env.body, symbolized_keys: true
15
+ Api.logger.debug { { response: response_env } }
16
+ hash = MultiJson.load response_env.body, symbolize_keys: true
15
17
  check_response(hash)
16
18
  end
17
19
  end
@@ -28,6 +30,8 @@ module Dianping
28
30
  code = body[:code].to_i
29
31
  msg = format('[%<code>d]%<msg>s', code: code, msg: body[:msg])
30
32
 
33
+ Api.logger.debug { { response: body, msg: msg } }
34
+
31
35
  raise TokenExpireError, msg if code == 608
32
36
  raise UsageError, msg if code >= 800
33
37
  raise Error, msg unless code == 200
@@ -54,7 +54,7 @@ module Dianping
54
54
  end
55
55
 
56
56
  def expires_at
57
- updated_at + expires_in
57
+ updated_at + expires_in rescue nil
58
58
  end
59
59
 
60
60
  def expired?
@@ -1,5 +1,5 @@
1
1
  module Dianping
2
2
  module Api
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-27 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday