dian_ping 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +19 -0
- data/lib/dian_ping.rb +46 -0
- data/lib/dianping/business.rb +20 -0
- data/lib/dianping/common.rb +75 -0
- data/lib/dianping/parameter.rb +27 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dbb29e776796798619371bebbabb1260202081bc
|
4
|
+
data.tar.gz: 88d14fce31fc65a5fff91942644caeddc737c63d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd84f5b900f29ae86a84d95708c16cdfe5e4e3257988bd5be7e5114e038c51f47ea42bfab76d193054b1228cc9692c06c95802a9bd8a6de99bc8db222cbfc061
|
7
|
+
data.tar.gz: a3366ff7ec4e39478e38c0d55b40c280da8e295d229e606ace59c5f9add676931af24e351810e6490aa2519b9cb8be934f240fe956b53de8c8e6df99abdcdd3d
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Thierry Zires
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
dian-ping
|
2
|
+
=========
|
3
|
+
|
4
|
+
[ruby]大众点评api
|
5
|
+
|
6
|
+
Install
|
7
|
+
=========
|
8
|
+
|
9
|
+
gem install 'dian_ping'
|
10
|
+
|
11
|
+
Usage
|
12
|
+
=========
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'dian_ping'
|
16
|
+
|
17
|
+
dp = DianPing.new(key: 'Your key', secret: 'Your secret')
|
18
|
+
dp.coordinate([31.18268013000488,121.42769622802734]).page(1).has_coupon.get('/v1/business/find_businesses')
|
19
|
+
|
20
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'yard'
|
9
|
+
YARD::Rake::YardocTask.new
|
10
|
+
|
11
|
+
require 'rake/testtask'
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.libs << 'test'
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
t.verbose = true
|
17
|
+
end
|
18
|
+
|
19
|
+
task :default => :test
|
data/lib/dian_ping.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "digest/md5"
|
3
|
+
require 'httparty'
|
4
|
+
require 'dianping/parameter'
|
5
|
+
|
6
|
+
class DianPing
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
VERSION = '0.0.1'
|
10
|
+
|
11
|
+
attr_accessor :key, :secret
|
12
|
+
|
13
|
+
base_uri 'http://api.dianping.com'
|
14
|
+
|
15
|
+
def initialize(opts = {})
|
16
|
+
@key, @secret = opts.values_at(:key, :secret)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(route, param)
|
20
|
+
param[:sign] = signature(param)
|
21
|
+
param[:appkey] = @key
|
22
|
+
self.class.get route, query: param
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# 签名
|
28
|
+
def signature(param)
|
29
|
+
plaintext = param.keys.sort.map{|k| "#{k}#{param[k]}"}.join
|
30
|
+
Digest::SHA1.hexdigest("#{@key}#{plaintext}#{@secret}").upcase
|
31
|
+
end
|
32
|
+
|
33
|
+
def parameter
|
34
|
+
DP::Parameter.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(method_name, *args, &block)
|
38
|
+
super unless parameter.respond_to?(method_name)
|
39
|
+
if args.empty?
|
40
|
+
parameter.send(method_name)
|
41
|
+
else
|
42
|
+
parameter.send(method_name, args.first)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module DP
|
3
|
+
module Business
|
4
|
+
|
5
|
+
# coordinate[31.2204200000392, 121.41163000018]
|
6
|
+
def coordinate(location)
|
7
|
+
add :latitude, location.first
|
8
|
+
add :longitude, location.last
|
9
|
+
end
|
10
|
+
|
11
|
+
def latitude(lat)
|
12
|
+
add :latitude, lat
|
13
|
+
end
|
14
|
+
|
15
|
+
def longitude(long)
|
16
|
+
add :longitude, long
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module DP
|
3
|
+
module Common
|
4
|
+
|
5
|
+
# 根据是否有优惠券来筛选返回的商户
|
6
|
+
# 1:有,0:没有
|
7
|
+
def has_coupon
|
8
|
+
add :has_coupon, 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_not_coupon
|
12
|
+
add :has_coupon, 0
|
13
|
+
end
|
14
|
+
|
15
|
+
# 根据是否有团购来筛选返回的商户,1:有,0:没有
|
16
|
+
def has_deal
|
17
|
+
add :has_deal, 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_not_deal
|
21
|
+
add :has_deal, 0
|
22
|
+
end
|
23
|
+
|
24
|
+
# 每页返回的商户结果条目数上限,最小值1,最大值40,如不传入默认为20
|
25
|
+
def limit(number)
|
26
|
+
warn 'limit 最大值40' if number > 40
|
27
|
+
add :limit, number
|
28
|
+
end
|
29
|
+
|
30
|
+
# 搜索半径,单位为米,最小值1,最大值5000,如不传入默认为1000
|
31
|
+
def radius
|
32
|
+
warn 'radius 最大值5000' if number > 5000
|
33
|
+
add :radius, number
|
34
|
+
end
|
35
|
+
|
36
|
+
# category
|
37
|
+
# 分类名,可选范围见相关API返回结果;支持同时输入多个分类,以逗号分隔,最大不超过5个
|
38
|
+
|
39
|
+
# offset_type
|
40
|
+
# 偏移类型,0:未偏移,1:高德坐标系偏移,2:图吧坐标系偏移,如不传入,默认值为0
|
41
|
+
|
42
|
+
# keyword
|
43
|
+
# 关键词,搜索范围包括商户名、地址、标签等
|
44
|
+
|
45
|
+
# out_offset_type
|
46
|
+
# 传出经纬度偏移类型,1:高德坐标系偏移,2:图吧坐标系偏移,如不传入,默认值为1
|
47
|
+
|
48
|
+
# platform
|
49
|
+
# 传出链接类型,1:web站链接(适用于网页应用),2:HTML5站链接(适用于移动应用和联网车载应用),如不传入,默认值为1
|
50
|
+
|
51
|
+
# sort
|
52
|
+
# 结果排序
|
53
|
+
# 1:默认,
|
54
|
+
# 2:星级高优先,
|
55
|
+
# 3:产品评价高优先,
|
56
|
+
# 4:环境评价高优先,
|
57
|
+
# 5:服务评价高优先,
|
58
|
+
# 6:点评数量多优先,
|
59
|
+
# 7:离传入经纬度坐标距离近优先,
|
60
|
+
# 8:人均价格低优先,
|
61
|
+
# 9:人均价格高优先
|
62
|
+
|
63
|
+
# page
|
64
|
+
# 页码,如不传入默认为1,即第一页
|
65
|
+
|
66
|
+
# format
|
67
|
+
# 返回数据格式,可选值为json或xml,如不传入,默认值为json
|
68
|
+
[:category, :offset_type, :keyword, :out_offset_type, :platform, :sort, :page, :format].each do |key|
|
69
|
+
define_method(key) {|value|
|
70
|
+
add key, value
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'dianping/common'
|
3
|
+
require 'dianping/business'
|
4
|
+
|
5
|
+
module DP
|
6
|
+
class Parameter < Hash
|
7
|
+
include DP::Common
|
8
|
+
include DP::Business
|
9
|
+
|
10
|
+
attr_reader :client
|
11
|
+
|
12
|
+
def initialize(client)
|
13
|
+
@client = client
|
14
|
+
end
|
15
|
+
|
16
|
+
def add(key, value)
|
17
|
+
self[key] = value
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(route)
|
22
|
+
client.get(route, self)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dian_ping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zires
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: turn
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: 大众点评开放平台ruby版SDK-http://developer.dianping.com/app/api
|
98
|
+
email:
|
99
|
+
- zshuaibin@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/dian_ping.rb
|
105
|
+
- lib/dianping/business.rb
|
106
|
+
- lib/dianping/common.rb
|
107
|
+
- lib/dianping/parameter.rb
|
108
|
+
- LICENSE
|
109
|
+
- Rakefile
|
110
|
+
- README.md
|
111
|
+
homepage: https://github.com/zires/dian-ping
|
112
|
+
licenses: []
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.0.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: 大众点评开放平台ruby版SDK
|
134
|
+
test_files: []
|
135
|
+
has_rdoc:
|