baidu_api-lbs_cloud 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +67 -3
- data/baidu_api-lbs_cloud.gemspec +2 -0
- data/lib/baidu_api/lbs_cloud/v3/geodata/column.rb +30 -0
- data/lib/baidu_api/lbs_cloud/v3/geodata/geotable.rb +30 -0
- data/lib/baidu_api/lbs_cloud/v3/geodata/job.rb +21 -0
- data/lib/baidu_api/lbs_cloud/v3/geodata/poi.rb +33 -0
- data/lib/baidu_api/lbs_cloud/v3/geodata.rb +47 -0
- data/lib/baidu_api/lbs_cloud/v3/geosearch.rb +33 -0
- data/lib/baidu_api/lbs_cloud/v3/request_base.rb +64 -0
- data/lib/baidu_api/lbs_cloud/v3.rb +11 -0
- data/lib/baidu_api/lbs_cloud/version.rb +1 -1
- data/lib/baidu_api/lbs_cloud.rb +3 -3
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cec0b5d2b430e1dfdebaf823c82bb2ebc5e2388
|
4
|
+
data.tar.gz: c756debe95e16ef4913ad7db57a2d7451319fba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d3ec46c5a042eec9f07bd8030e0132c8908151e8ee23674f10ed6373b35174913ce212b72804a0a4f41692bc8d9d03fba5ddac104e25367e6588b564dff8e9
|
7
|
+
data.tar.gz: 6bbf3411fa073750e6a25dc28c73bbc7b6aee7f7825643143f6e19b85f61af84207bd39bb1b21c59d03a4287c3bdcdf976f091dc7300e272c290a31eac33c678
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# BaiduApi::LbsCloud
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby client to call [Baidu LBS Cloud API](http://developer.baidu.com/map/index.php?title=lbscloud)
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,11 +20,75 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
```ruby
|
24
|
+
require 'baidu_api/lbs_cloud'
|
25
|
+
|
26
|
+
# Call Geodata APIs
|
27
|
+
|
28
|
+
# :sk is unnecessary if you are not authenticating with SN
|
29
|
+
BaiduApi::LbsCloud::V3::Geodata.setup ak: 'xxxx', sk: 'xxxxx'
|
30
|
+
|
31
|
+
# get geodata singleton instance
|
32
|
+
geodata = BaiduApi::LbsCloud::V3::Geodata.instance
|
33
|
+
|
34
|
+
# list existing geotables
|
35
|
+
geodata.geotable.list()
|
36
|
+
=> {"status"=>0,
|
37
|
+
"geotables"=>
|
38
|
+
[{"name"=>"5656", "geotype"=>1, "is_published"=>1, "create_time"=>1420180426, "modify_time"=>1420180426, "id"=>90286},
|
39
|
+
{"create_time"=>1419816767, "geotype"=>1, "is_published"=>1, "modify_time"=>1420180449, "name"=>"gogo", "id"=>89998}],
|
40
|
+
"size"=>2,
|
41
|
+
"message"=>"成功"}
|
42
|
+
|
43
|
+
# create geotable
|
44
|
+
geodata.geotable.create(name: 'mytest', geotype: 3, is_published: 0)
|
45
|
+
=> {"status"=>0, "id"=>90288, "message"=>"成功"}
|
46
|
+
|
47
|
+
# Call Geosearch APIs
|
48
|
+
|
49
|
+
BaiduApi::LbsCloud::V3::Geosearch.setup ak: 'xxx', sk: 'xxx'
|
50
|
+
|
51
|
+
geosearch = BaiduApi::LbsCloud::V3::Geosearch.instance
|
52
|
+
|
53
|
+
geosearch.local(geotable_id: 89998)
|
54
|
+
=> {"status"=>0,
|
55
|
+
"total"=>2,
|
56
|
+
"size"=>2,
|
57
|
+
"contents"=>
|
58
|
+
[{"title"=>"qqq",
|
59
|
+
"location"=>[116.401147, 39.899501],
|
60
|
+
"city"=>"北京市",
|
61
|
+
"create_time"=>1419816873,
|
62
|
+
"geotable_id"=>89998,
|
63
|
+
"address"=>"北京市西城区煤市街146号",
|
64
|
+
"province"=>"北京市",
|
65
|
+
"district"=>"西城区",
|
66
|
+
"uid"=>585565808,
|
67
|
+
"coord_type"=>3,
|
68
|
+
"type"=>0,
|
69
|
+
"distance"=>0,
|
70
|
+
"weight"=>0},
|
71
|
+
{"title"=>"oo",
|
72
|
+
"location"=>[116.407682, 39.902137],
|
73
|
+
"city"=>"北京市",
|
74
|
+
"create_time"=>1419817076,
|
75
|
+
"geotable_id"=>89998,
|
76
|
+
"address"=>"北京市东城区得丰西巷25号",
|
77
|
+
"province"=>"北京市",
|
78
|
+
"district"=>"东城区",
|
79
|
+
"icon_style_id"=>"sid1",
|
80
|
+
"uid"=>585567281,
|
81
|
+
"coord_type"=>3,
|
82
|
+
"type"=>0,
|
83
|
+
"distance"=>0,
|
84
|
+
"weight"=>0}]}
|
85
|
+
|
86
|
+
```
|
87
|
+
|
24
88
|
|
25
89
|
## Contributing
|
26
90
|
|
27
|
-
1. Fork it ( https://github.com/
|
91
|
+
1. Fork it ( https://github.com/xiaohui-zhangxh/baidu_api-lbs_cloud/fork )
|
28
92
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
93
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
94
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/baidu_api-lbs_cloud.gemspec
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module BaiduApi::LbsCloud::V3::Geodata
|
2
|
+
class Column
|
3
|
+
|
4
|
+
include BaiduApi::LbsCloud::V3::RequestBase
|
5
|
+
self.module_name = 'geodata'
|
6
|
+
self.controller = 'column'
|
7
|
+
|
8
|
+
def create(data)
|
9
|
+
request('create', data, :post)
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(data = {})
|
13
|
+
request('list', data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def detail(data)
|
17
|
+
request('detail', data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(data)
|
21
|
+
request('update', data, :post)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(data)
|
25
|
+
request('delete', data, :post)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module BaiduApi::LbsCloud::V3::Geodata
|
2
|
+
class Geotable
|
3
|
+
|
4
|
+
include BaiduApi::LbsCloud::V3::RequestBase
|
5
|
+
self.module_name = 'geodata'
|
6
|
+
self.controller = 'geotable'
|
7
|
+
|
8
|
+
def create(data)
|
9
|
+
request('create', data, :post)
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(data = {})
|
13
|
+
request('list', data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def detail(data)
|
17
|
+
request('detail', data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(data)
|
21
|
+
request('update', data, :post)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(data)
|
25
|
+
request('delete', data, :post)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BaiduApi::LbsCloud::V3::Geodata
|
2
|
+
class Job
|
3
|
+
|
4
|
+
include BaiduApi::LbsCloud::V3::RequestBase
|
5
|
+
self.module_name = 'geodata'
|
6
|
+
self.controller = 'job'
|
7
|
+
|
8
|
+
def listimportdata(data)
|
9
|
+
request('listimportdata', data, :post)
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(data = {})
|
13
|
+
request('list', data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def detail(data)
|
17
|
+
request('detail', data, :post)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module BaiduApi::LbsCloud::V3::Geodata
|
2
|
+
class Poi
|
3
|
+
|
4
|
+
include BaiduApi::LbsCloud::V3::RequestBase
|
5
|
+
self.module_name = 'geodata'
|
6
|
+
self.controller = 'poi'
|
7
|
+
|
8
|
+
def create(data)
|
9
|
+
request('create', data, :post)
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(data = {})
|
13
|
+
request('list', data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def detail(data)
|
17
|
+
request('detail', data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(data)
|
21
|
+
request('update', data, :post)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(data)
|
25
|
+
request('delete', data, :post)
|
26
|
+
end
|
27
|
+
|
28
|
+
def upload(data)
|
29
|
+
fail 'This function is not implemented!'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module BaiduApi::LbsCloud::V3::Geodata
|
2
|
+
|
3
|
+
class Basement
|
4
|
+
attr_reader :ak, :sk, :geotable, :column, :poi, :job
|
5
|
+
|
6
|
+
def initialize(ak, sk = nil)
|
7
|
+
@ak, @sk = ak, sk
|
8
|
+
@geotable = Geotable.new(ak, sk)
|
9
|
+
@column = Column.new(ak, sk)
|
10
|
+
@poi = Poi.new(ak, sk)
|
11
|
+
@job = Job.new(ak, sk)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.setup(params)
|
17
|
+
ak = params.fetch(:ak) { fail ':ak is required.' }
|
18
|
+
sk = params.fetch(:sk, nil)
|
19
|
+
@basement = Basement.new(ak, sk)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.instance
|
23
|
+
@basement || fail('Has to setup Geodata before using')
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.geotable
|
27
|
+
instance && @basement.geotable
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.column
|
31
|
+
instance && @basement.column
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.poi
|
35
|
+
instance && @basement.poi
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.job
|
39
|
+
instance && @basement.job
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
require File.expand_path('../geodata/geotable', __FILE__)
|
45
|
+
require File.expand_path('../geodata/column', __FILE__)
|
46
|
+
require File.expand_path('../geodata/poi', __FILE__)
|
47
|
+
require File.expand_path('../geodata/job', __FILE__)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class BaiduApi::LbsCloud::V3::Geosearch
|
2
|
+
|
3
|
+
def self.setup(params)
|
4
|
+
ak = params.fetch(:ak) { fail ':ak is required.' }
|
5
|
+
sk = params.fetch(:sk, nil)
|
6
|
+
@instance = new(ak, sk)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.instance
|
10
|
+
@instance || fail('Has to setup Geosearch before using')
|
11
|
+
end
|
12
|
+
|
13
|
+
include BaiduApi::LbsCloud::V3::RequestBase
|
14
|
+
|
15
|
+
self.module_name = 'geosearch'
|
16
|
+
|
17
|
+
def nearby(data)
|
18
|
+
request('nearby', data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def local(data)
|
22
|
+
request('local', data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def bound(data)
|
26
|
+
request('bound', data)
|
27
|
+
end
|
28
|
+
|
29
|
+
def detail(uid, data)
|
30
|
+
request("detail/#{uid}", data)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'uri'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'httparty'
|
5
|
+
|
6
|
+
module BaiduApi::LbsCloud::V3::RequestBase
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.send(:include, HTTParty)
|
10
|
+
base.send(:extend, ClassMethods)
|
11
|
+
|
12
|
+
base.instance_eval do
|
13
|
+
base_uri "http://api.map.baidu.com/"
|
14
|
+
format :json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
|
20
|
+
attr_writer :module_name, :controller
|
21
|
+
|
22
|
+
def module_name
|
23
|
+
fail 'module_name has to be defined' if @module_name.nil?
|
24
|
+
@module_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def controller
|
28
|
+
@controller
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :ak, :sk
|
34
|
+
|
35
|
+
def initialize(ak, sk = nil)
|
36
|
+
@ak, @sk = ak, sk
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def request(action, data, method = :get)
|
42
|
+
uri = build_uri(action)
|
43
|
+
query_str = build_query(uri, data)
|
44
|
+
if method == :post
|
45
|
+
self.class.post(uri, body: query_str)
|
46
|
+
else
|
47
|
+
self.class.get(uri, query: query_str)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_uri(action)
|
52
|
+
"/#{self.class.module_name}/v3/#{self.class.controller + '/' if self.class.controller}#{action}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_query(uri, data)
|
56
|
+
data = data.merge(ak: ak)
|
57
|
+
query_str = data.sort.map do |key, value|
|
58
|
+
"#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
|
59
|
+
end.join('&')
|
60
|
+
return query_str if sk.nil?
|
61
|
+
sn = Digest::MD5.hexdigest(ERB::Util.url_encode("#{uri}?#{query_str}#{sk}"))
|
62
|
+
"#{query_str}&sn=#{sn}"
|
63
|
+
end
|
64
|
+
end
|
data/lib/baidu_api/lbs_cloud.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baidu_api-lbs_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiaohui
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email:
|
43
57
|
- xiaohui@zhangxh.net
|
@@ -52,6 +66,14 @@ files:
|
|
52
66
|
- Rakefile
|
53
67
|
- baidu_api-lbs_cloud.gemspec
|
54
68
|
- lib/baidu_api/lbs_cloud.rb
|
69
|
+
- lib/baidu_api/lbs_cloud/v3.rb
|
70
|
+
- lib/baidu_api/lbs_cloud/v3/geodata.rb
|
71
|
+
- lib/baidu_api/lbs_cloud/v3/geodata/column.rb
|
72
|
+
- lib/baidu_api/lbs_cloud/v3/geodata/geotable.rb
|
73
|
+
- lib/baidu_api/lbs_cloud/v3/geodata/job.rb
|
74
|
+
- lib/baidu_api/lbs_cloud/v3/geodata/poi.rb
|
75
|
+
- lib/baidu_api/lbs_cloud/v3/geosearch.rb
|
76
|
+
- lib/baidu_api/lbs_cloud/v3/request_base.rb
|
55
77
|
- lib/baidu_api/lbs_cloud/version.rb
|
56
78
|
homepage: ''
|
57
79
|
licenses:
|