dianping-api 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +93 -0
- data/Guardfile +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dianping-api.gemspec +50 -0
- data/lib/dianping/api.rb +18 -0
- data/lib/dianping/api/client.rb +100 -0
- data/lib/dianping/api/middle_ware.rb +30 -0
- data/lib/dianping/api/token.rb +78 -0
- data/lib/dianping/api/version.rb +5 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0d90607c0ebb98542b7b46e660a0e0d58e752e9e9b039605c3b775526d28f4b2
|
4
|
+
data.tar.gz: ea4989f921379d2c2ed163421473edba4702f9178df563fa8af7c814704d6a0e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c39d73c68ff6362a4956829e343d8868d095faa06cd70c3325e2c0d540fe94ec130e0d963cc5c91b9ca0e0b4ef4744141694aaa85c94ec0c6974b7d9150f6ebf
|
7
|
+
data.tar.gz: f4e95c77e75256976d43cb4622b7acb544421a4f92812f8c2e261e8ee3d94c14fc7483afa519e57d38f2de03da0d67d3f6923975bb1535c490512d46fdab1853
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dianping-api (0.1.0)
|
5
|
+
faraday (~> 1.0)
|
6
|
+
multi_json (>= 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
coderay (1.1.3)
|
14
|
+
crack (0.4.4)
|
15
|
+
diff-lcs (1.4.4)
|
16
|
+
faraday (1.1.0)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
ruby2_keywords
|
19
|
+
ffi (1.13.1)
|
20
|
+
formatador (0.2.5)
|
21
|
+
guard (2.16.2)
|
22
|
+
formatador (>= 0.2.4)
|
23
|
+
listen (>= 2.7, < 4.0)
|
24
|
+
lumberjack (>= 1.0.12, < 2.0)
|
25
|
+
nenv (~> 0.1)
|
26
|
+
notiffany (~> 0.0)
|
27
|
+
pry (>= 0.9.12)
|
28
|
+
shellany (~> 0.0)
|
29
|
+
thor (>= 0.18.1)
|
30
|
+
guard-compat (1.2.1)
|
31
|
+
guard-rspec (4.7.3)
|
32
|
+
guard (~> 2.1)
|
33
|
+
guard-compat (~> 1.1)
|
34
|
+
rspec (>= 2.99.0, < 4.0)
|
35
|
+
hashdiff (1.0.1)
|
36
|
+
listen (3.3.1)
|
37
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
38
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
39
|
+
lumberjack (1.2.8)
|
40
|
+
method_source (1.0.0)
|
41
|
+
multi_json (1.15.0)
|
42
|
+
multipart-post (2.1.1)
|
43
|
+
nenv (0.3.0)
|
44
|
+
notiffany (0.1.3)
|
45
|
+
nenv (~> 0.1)
|
46
|
+
shellany (~> 0.0)
|
47
|
+
pry (0.13.1)
|
48
|
+
coderay (~> 1.1)
|
49
|
+
method_source (~> 1.0)
|
50
|
+
public_suffix (4.0.6)
|
51
|
+
rake (10.5.0)
|
52
|
+
rb-fsevent (0.10.4)
|
53
|
+
rb-inotify (0.10.1)
|
54
|
+
ffi (~> 1.0)
|
55
|
+
rspec (3.10.0)
|
56
|
+
rspec-core (~> 3.10.0)
|
57
|
+
rspec-expectations (~> 3.10.0)
|
58
|
+
rspec-mocks (~> 3.10.0)
|
59
|
+
rspec-core (3.10.0)
|
60
|
+
rspec-support (~> 3.10.0)
|
61
|
+
rspec-expectations (3.10.0)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.10.0)
|
64
|
+
rspec-its (1.3.0)
|
65
|
+
rspec-core (>= 3.0.0)
|
66
|
+
rspec-expectations (>= 3.0.0)
|
67
|
+
rspec-mocks (3.10.0)
|
68
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
69
|
+
rspec-support (~> 3.10.0)
|
70
|
+
rspec-support (3.10.0)
|
71
|
+
ruby2_keywords (0.0.2)
|
72
|
+
shellany (0.0.1)
|
73
|
+
thor (1.0.1)
|
74
|
+
webmock (3.10.0)
|
75
|
+
addressable (>= 2.3.6)
|
76
|
+
crack (>= 0.3.2)
|
77
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
bundler (~> 1.17)
|
84
|
+
dianping-api!
|
85
|
+
guard (>= 2.0)
|
86
|
+
guard-rspec (>= 4.0)
|
87
|
+
rake (~> 10.0)
|
88
|
+
rspec (>= 3.0)
|
89
|
+
rspec-its (>= 1.0)
|
90
|
+
webmock (>= 3.0)
|
91
|
+
|
92
|
+
BUNDLED WITH
|
93
|
+
1.17.3
|
data/Guardfile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
28
|
+
require "guard/rspec/dsl"
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ryan Wong
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Dianping::Api
|
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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dianping-api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dianping-api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dianping-api.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dianping/api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "dianping/api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dianping-api"
|
8
|
+
spec.version = Dianping::Api::VERSION
|
9
|
+
spec.authors = ["Ryan Wong"]
|
10
|
+
spec.email = ["lazing@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{dianping api client}
|
13
|
+
spec.description = %q{dianping api client for simple request signature}
|
14
|
+
spec.homepage = "https://github.com/lazing/dianping-api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
+
# else
|
26
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
# "public gem pushes."
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "bin"
|
36
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_dependency 'faraday', '~> 1.0'
|
40
|
+
spec.add_dependency 'multi_json', '~> 1.0'
|
41
|
+
|
42
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
43
|
+
spec.add_development_dependency "guard", "~> 2.0"
|
44
|
+
spec.add_development_dependency "guard-rspec", "~> 4.0"
|
45
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
46
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
47
|
+
spec.add_development_dependency "rspec-its", "~> 1.0"
|
48
|
+
spec.add_development_dependency 'webmock', "~> 3.0"
|
49
|
+
|
50
|
+
end
|
data/lib/dianping/api.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "dianping/api/version"
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Dianping
|
5
|
+
module Api
|
6
|
+
class TokenExpireError < Faraday::RetriableResponse; end
|
7
|
+
class TokenMissingError < StandardError; end
|
8
|
+
class UsageError < StandardError; end
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'dianping/api/middle_ware'
|
15
|
+
require 'dianping/api/token'
|
16
|
+
require 'dianping/api/client'
|
17
|
+
|
18
|
+
Faraday::Request.register_middleware dianping: ::Dianping::Api::MiddleWare
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Dianping
|
4
|
+
module Api
|
5
|
+
class Client
|
6
|
+
|
7
|
+
attr_reader :app_key, :site, :token, :redirect_url
|
8
|
+
|
9
|
+
def initialize(app_key, secret, **options)
|
10
|
+
@app_key = app_key
|
11
|
+
@secret = secret
|
12
|
+
@site = 'https://openapi.dianping.com'
|
13
|
+
@redirect_url = options[:redirect_url]
|
14
|
+
@token = Token.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection
|
18
|
+
Faraday.new(url: @site) do |conn|
|
19
|
+
conn.request :retry
|
20
|
+
conn.request :dianping, self
|
21
|
+
conn.request :url_encoded
|
22
|
+
conn.response :logger
|
23
|
+
conn.response :raise_error
|
24
|
+
conn.adapter :net_http
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(url = nil, params = nil, headers = nil)
|
29
|
+
res = connection.get(url, sign_with_share(params), headers)
|
30
|
+
json(res.body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def post(url = nil, body = nil, headers = nil)
|
34
|
+
res = connection.post(url, sign_with_share(body), headers)
|
35
|
+
json(res.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def auth(auth_code)
|
39
|
+
token.auth(auth_code)
|
40
|
+
end
|
41
|
+
|
42
|
+
def auth_conn
|
43
|
+
Faraday.new(url: @site) do |conn|
|
44
|
+
conn.request :url_encoded
|
45
|
+
conn.response :logger
|
46
|
+
conn.response :raise_error
|
47
|
+
conn.adapter :net_http
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def auth_token(auth_code)
|
52
|
+
res = auth_conn.post('/router/oauth/token') do |req|
|
53
|
+
req.body = {
|
54
|
+
app_key: @app_key,
|
55
|
+
app_secret: @secret,
|
56
|
+
auth_code: auth_code,
|
57
|
+
grant_type: 'authorization_code',
|
58
|
+
redirect_url: redirect_url
|
59
|
+
}
|
60
|
+
end
|
61
|
+
json(res.body)
|
62
|
+
end
|
63
|
+
|
64
|
+
def refresh_token(refresh_code)
|
65
|
+
res = auth_conn.post('/router/oauth/token') do |req|
|
66
|
+
req.body = {
|
67
|
+
app_key: @app_key,
|
68
|
+
app_secret: @secret,
|
69
|
+
refresh_token: refresh_code,
|
70
|
+
grant_type: 'refresh_token'
|
71
|
+
}
|
72
|
+
end
|
73
|
+
json(res.body)
|
74
|
+
end
|
75
|
+
|
76
|
+
def json(text)
|
77
|
+
MultiJson.load(text || '{}', symbolize_keys: true)
|
78
|
+
end
|
79
|
+
|
80
|
+
def share_params
|
81
|
+
{
|
82
|
+
app_key: app_key,
|
83
|
+
timestamp: Time.now.strftime('%F %T'),
|
84
|
+
session: token.access_token,
|
85
|
+
format: 'json',
|
86
|
+
v: 1,
|
87
|
+
sign_method: 'MD5'
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def sign_with_share(params = {})
|
92
|
+
merged = share_params.merge(params || {}).dup
|
93
|
+
content = merged.to_a.sort.flatten.join.encode!('UTF-8')
|
94
|
+
# puts @secret + content
|
95
|
+
sign = Digest::MD5.hexdigest(@secret + content + @secret)
|
96
|
+
merged.merge(sign: sign)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Dianping
|
4
|
+
module Api
|
5
|
+
class MiddleWare
|
6
|
+
def initialize(app, client)
|
7
|
+
@app = app
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
check_session(env)
|
13
|
+
@app.call(env).on_complete do |response_env|
|
14
|
+
check_response(response_env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_session(_env)
|
19
|
+
raise TokenMissingError unless @client.token.authorized?
|
20
|
+
return unless @client.token.expired?
|
21
|
+
|
22
|
+
@client.token.refresh
|
23
|
+
raise TokenExpireError
|
24
|
+
end
|
25
|
+
|
26
|
+
def check_response(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module Dianping
|
4
|
+
module Api
|
5
|
+
class Token
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
@token_file = File.join('/tmp', "dianping-api-#{client.app_key}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def access_hash
|
14
|
+
@access_hash ||=
|
15
|
+
begin
|
16
|
+
token = MultiJson.load(File.read(@token_file), symbolize_keys: true)
|
17
|
+
token[:access_hash] || (raise 'empty token')
|
18
|
+
rescue Errno::ENOENT
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def refresh
|
24
|
+
raise Error, 'no refresh_token' unless refresh_token && remain_refresh_count > 1
|
25
|
+
|
26
|
+
save_token(client.refresh_token(@access_hash[:refresh_token]))
|
27
|
+
end
|
28
|
+
|
29
|
+
def auth(authcode)
|
30
|
+
save_token(client.auth_token(authcode))
|
31
|
+
end
|
32
|
+
|
33
|
+
def save_token(token)
|
34
|
+
token = { updated_at: Time.now.to_s }.merge(token)
|
35
|
+
json = MultiJson.dump(access_hash: token )
|
36
|
+
File.open(@token_file, 'w') { |f| f.write(json) }
|
37
|
+
@access_hash = token
|
38
|
+
end
|
39
|
+
|
40
|
+
def access_token
|
41
|
+
access_hash[:access_token]
|
42
|
+
end
|
43
|
+
|
44
|
+
def refresh_token
|
45
|
+
access_hash[:refresh_token]
|
46
|
+
end
|
47
|
+
|
48
|
+
def expires_in
|
49
|
+
access_hash[:expires_in]
|
50
|
+
end
|
51
|
+
|
52
|
+
def updated_at
|
53
|
+
Time.parse(access_hash[:updated_at])
|
54
|
+
end
|
55
|
+
|
56
|
+
def expires_at
|
57
|
+
updated_at + expires_in
|
58
|
+
end
|
59
|
+
|
60
|
+
def expired?
|
61
|
+
# puts access_hash, authorized?, expires_at, Time.now
|
62
|
+
!authorized? || Time.now > expires_at
|
63
|
+
end
|
64
|
+
|
65
|
+
def remain_refresh_count
|
66
|
+
(access_hash[:remain_refresh_count] || 12).to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
def authorized?
|
70
|
+
!access_token.nil?
|
71
|
+
end
|
72
|
+
|
73
|
+
def destory
|
74
|
+
save_token({})
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dianping-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Wong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-its
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
description: dianping api client for simple request signature
|
140
|
+
email:
|
141
|
+
- lazing@gmail.com
|
142
|
+
executables:
|
143
|
+
- console
|
144
|
+
- setup
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files: []
|
147
|
+
files:
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- Guardfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- dianping-api.gemspec
|
159
|
+
- lib/dianping/api.rb
|
160
|
+
- lib/dianping/api/client.rb
|
161
|
+
- lib/dianping/api/middle_ware.rb
|
162
|
+
- lib/dianping/api/token.rb
|
163
|
+
- lib/dianping/api/version.rb
|
164
|
+
homepage: https://github.com/lazing/dianping-api
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
requirements: []
|
183
|
+
rubygems_version: 3.0.6
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: dianping api client
|
187
|
+
test_files: []
|