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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c317775582752570fffe91c6c1970f65a6add149
4
- data.tar.gz: 06f4381f223c8c420f21f1144a2d254a6e4fe292
3
+ metadata.gz: 8cec0b5d2b430e1dfdebaf823c82bb2ebc5e2388
4
+ data.tar.gz: c756debe95e16ef4913ad7db57a2d7451319fba1
5
5
  SHA512:
6
- metadata.gz: 47095ba9d207d4cc5be2055f51a54609767819179e4ae86391374ee74d0c818fdce16ee89cd88749c1a6a00f90ef7a784333d892aa9dbab4414d7507b0ea590c
7
- data.tar.gz: fff84b620b19be92aff7c8bf2cb524d6201a9f8990eefaf6d1d4198a06ce22894031b54230183e8130379e9d0e3e88fb1d576120c4b19f934a66d34f72cd5965
6
+ metadata.gz: d3d3ec46c5a042eec9f07bd8030e0132c8908151e8ee23674f10ed6373b35174913ce212b72804a0a4f41692bc8d9d03fba5ddac104e25367e6588b564dff8e9
7
+ data.tar.gz: 6bbf3411fa073750e6a25dc28c73bbc7b6aee7f7825643143f6e19b85f61af84207bd39bb1b21c59d03a4287c3bdcdf976f091dc7300e272c290a31eac33c678
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .DS_Store
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BaiduApi::LbsCloud
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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/[my-github-username]/baidu_api-lbs_cloud/fork )
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`)
@@ -19,4 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.7"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_runtime_dependency "httparty"
22
24
  end
@@ -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
@@ -0,0 +1,11 @@
1
+
2
+ module BaiduApi
3
+ module LbsCloud
4
+ module V3
5
+ end
6
+ end
7
+ end
8
+
9
+ require File.expand_path("../v3/request_base", __FILE__)
10
+ require File.expand_path("../v3/geodata", __FILE__)
11
+ require File.expand_path("../v3/geosearch", __FILE__)
@@ -1,5 +1,5 @@
1
1
  module BaiduApi
2
2
  module LbsCloud
3
- VERSION = "0.0.0"
3
+ VERSION = "0.0.1"
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
- require "baidu_api/lbs_cloud/version"
2
-
3
1
  module BaiduApi
4
2
  module LbsCloud
5
- # Your code goes here...
6
3
  end
7
4
  end
5
+
6
+ require "baidu_api/lbs_cloud/version"
7
+ require "baidu_api/lbs_cloud/v3"
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.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: 2014-12-29 00:00:00.000000000 Z
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: