baidu_map 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 617fd5031829ebfc730fdaa7e0a5cf7e478cd7e3
4
+ data.tar.gz: 6d190fe510efc50797e91391cc0d00f501dae1a5
5
+ SHA512:
6
+ metadata.gz: 106ef1b1a6b34242362362c2c0b9884529123a07133b2f1cd03e0dc62f48212607aee0306cd5f4c3d78acbb88fc61ea53c6509237517d62f949a03b9c75e2e7b
7
+ data.tar.gz: 652eca0405d09992d849ee170918faed429501ed6412cd0110b6f73999c396c7391f63896f2c7df2213b05c68ba6987ccb72595f3a7ce912942a522bfc330481
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ #source 'https://rubygems.org'
2
+ source 'http://ruby.taobao.org'
3
+
4
+ gem 'eat'
5
+
6
+ group :development do
7
+ gem 'pry'
8
+ end
9
+
10
+ # Specify your gem's dependencies in baidumap.gemspec
11
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Yanying Wang
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 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,
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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+
2
+ # Baidumap
3
+ [Baidu Map(百度地图) API](http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-placeapi) wrapper in Ruby
4
+
5
+
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'baidu_map'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install baidumap
23
+
24
+
25
+
26
+
27
+ ## Usage
28
+
29
+ ### Initialize
30
+
31
+ [ak申请](http://lbsyun.baidu.com/apiconsole/key?application=key)
32
+
33
+ ```ruby
34
+ Baidumap.ak = "aaaaaaaaaaaaaaaaaa"
35
+
36
+ # or
37
+
38
+ Baidumap.setup { @ak = "aaaaaaaaaaaaaaaaaa" }
39
+ ```
40
+
41
+
42
+
43
+
44
+ ### Example
45
+
46
+ [API wiki](http://developer.baidu.com/map/index.php?title=webapi)
47
+
48
+ Please note that params shouldn't including `output: 'json'` or `output: 'xml'`, because which will be added by gem automatically and the result is always a hash.
49
+
50
+
51
+ ```ruby
52
+ # Place API
53
+ Baidumap.place_search(query: "九亭", region: "上海", scope: '1')
54
+
55
+ Baidumap.place_detail(uid: "5508504d0319eecac6f0259a", scope: '2')
56
+
57
+ Baidumap.place_detail(uids: "5508504d0319eecac6f0259a, 104274a315f7134fc3f1cfde", output: 'json', scope: '2') # NOTE and TODO: there is a bug that "," in uids's value will be translated, so this method is not usable currently.
58
+
59
+
60
+ # Place Suggestion API
61
+ Baidumap.place_suggestion(query: "九亭", region: "全国")
62
+
63
+
64
+ # Geocoding API
65
+ Baidumap.geocoder(address: "九亭")
66
+
67
+ Baidumap.geocoder(location: '121.33428124857, 31.13491723367') # NOTE and TODO: there is a bug that "," in uids's value will be translated, so this method is not usable currently.
68
+
69
+
70
+ # IP定位API
71
+ Baidumap.location(ip: "115.172.82.212", coor: "bd09ll")
72
+ ```
73
+
74
+
75
+
76
+
77
+ ### Result Debug
78
+
79
+ If the result's return status from Baidu API is not "0", then there is an error. To debug it, you always can attatch a block `{ |debug| debug.inspect }` to show the original url requested from this gem to Baidu just like this:
80
+
81
+ `Baidumap.place_detail(uids: [ "5508504d0319eecac6f0259a, 104274a315f7134fc3f1cfde" ], output: 'json', scope: '2') { |deug| debug.inspect } `
82
+
83
+ You can show your ak value used by this gem through this code `Baidumap.ak`.
84
+
85
+
86
+
87
+
88
+
89
+
90
+ ## Development
91
+
92
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
93
+
94
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
95
+
96
+
97
+
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it ( https://github.com/yanyingwang/baidumap/fork )
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/baidumap.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'baidumap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "baidu_map"
8
+ spec.version = Baidumap::VERSION
9
+ spec.authors = ["YanyingWang"]
10
+ spec.email = ["wangyanying@gmail.com"]
11
+
12
+ spec.summary = %q{Baidu Map(百度地图) API in Ruby.}
13
+ spec.description = %q{Ruby wapper for Baidu Map API used for Place Suggestion and so on.}
14
+ spec.homepage = "https://github.com/yanyingwang/baidumap"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.9"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pry"
5
+ require "baidumap"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ Pry.start
12
+
13
+ # require "irb"
14
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module Baidumap
2
+ VERSION = "0.1.0"
3
+ end
data/lib/baidumap.rb ADDED
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "baidumap/version"
3
+ require 'eat'
4
+ require 'json'
5
+
6
+
7
+ module Baidumap
8
+ class << self
9
+ alias_method :setup, :instance_eval
10
+ attr_accessor :ak
11
+
12
+
13
+ private
14
+
15
+ def method_missing(method, **params)
16
+ endpoint = 'http://api.map.baidu.com/'
17
+ method_str = method.to_s
18
+
19
+ method_url = case method_str
20
+ when 'geoconv', 'direction' # 坐标转换API, # Direction API
21
+ method_str + "/v1/?"
22
+ when 'location' # IP定位API
23
+ method_str + "/ip?"
24
+ when /^direction_.*/ # Route Martrix API
25
+ method_str.sub('_', "/v1/") + '?'
26
+ when 'geocoder' # Geocoding API
27
+ method_str + '/v2/?'
28
+ else # /^place_.*/ --- Place API and Place Suggestion API
29
+ method_str.sub('_', "/v2/") + '?'
30
+ end
31
+
32
+ full_url = endpoint + method_url + URI.encode_www_form(params.merge(ak: @ak, output: 'json'))
33
+
34
+ block_given? ? yield(full_url) : JSON.parse(eat full_url)
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: baidu_map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - YanyingWang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Ruby wapper for Baidu Map API used for Place Suggestion and so on.
42
+ email:
43
+ - wangyanying@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - baidumap.gemspec
56
+ - bin/console
57
+ - bin/setup
58
+ - lib/baidumap.rb
59
+ - lib/baidumap/version.rb
60
+ homepage: https://github.com/yanyingwang/baidumap
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.7
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Baidu Map(百度地图) API in Ruby.
84
+ test_files: []