basicgeo 0.0.1

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: 54a54014ad9405dbc54d742f9f8eb895d5dc6ef3
4
+ data.tar.gz: df1d5b1f9075b1cd461e2f1f9f5e2bf5f9fb58ff
5
+ SHA512:
6
+ metadata.gz: 92bdeaef62fda32ed23094d298d1472074667d04bd91c51021c1ddead0eb28efa1e94e2823534155a3045f09e1e7d3ad86ad814ebfcb90db4417cf1db50b2496
7
+ data.tar.gz: e6c7977b83d1399e00d3d0d07ab061f988679b4faf08187e47acd5f3c4a46716c342a99441b847f30dc72924f3c489e1d093e6f062f0c2d1ab4f5b4c889fbd64
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ ./basicgeo-0.0.0.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ httparty (0.13.3)
6
+ json (~> 1.8)
7
+ multi_xml (>= 0.5.2)
8
+ json (1.8.2)
9
+ multi_xml (0.5.5)
10
+ rspec (3.2.0)
11
+ rspec-core (~> 3.2.0)
12
+ rspec-expectations (~> 3.2.0)
13
+ rspec-mocks (~> 3.2.0)
14
+ rspec-core (3.2.0)
15
+ rspec-support (~> 3.2.0)
16
+ rspec-expectations (3.2.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.2.0)
19
+ rspec-mocks (3.2.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.2.0)
22
+ rspec-support (3.2.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ httparty
29
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Gabriel Malaquias
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,8 @@
1
+ =========
2
+ BasicGeo
3
+ =========
4
+
5
+ This repository has been created for develop an Location API.
6
+ Is simple, only for test my knowledge
7
+
8
+
data/json_parser.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+ module Basicgeo
3
+ module Parser
4
+ class Json
5
+
6
+ def parse_data
7
+ data = JSON.parse(data)
8
+ end
9
+
10
+ def navigate_to_node(data, index=[])
11
+ index.each do |method|
12
+ data = data[method]
13
+ end
14
+ data
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+
data/lib/basicgeo.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'basicgeo/consumer/google'
2
+ require 'basicgeo/parser/json'
3
+
4
+ module Basicgeo
5
+
6
+ def self.get_lat_long(address)
7
+ I18n.locale = :en
8
+ parser = Basicgeo::Parser::Json.new
9
+ parser.navigate_to_node(parse_data(get_google_data(address)), ['results', 0, 'geometry', 'location'])
10
+ end
11
+
12
+ def self.get_google_data(address)
13
+ Basicgeo::Consumer::Google.new.get_location(address)
14
+ end
15
+
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'httparty'
2
+ require 'i18n'
3
+
4
+ module Basicgeo
5
+ module Consumer
6
+
7
+ class Google
8
+ include HTTParty
9
+
10
+ def parse_address(string)
11
+ I18n.transliterate(string.gsub(" ", "+"))
12
+ end
13
+
14
+ def get_location(address)
15
+ self.class.get("http://maps.googleapis.com/maps/api/geocode/json?address=#{parse_address(address)}")
16
+ end
17
+
18
+ def get_address(latitude, longitude)
19
+ self.class.get("http://maps.googleapis.com/maps/api/geocode/json?latlng=#{latitude},#{longitude}")
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ require 'json'
3
+ module Basicgeo
4
+ module Parser
5
+ class Json
6
+
7
+ def parse_data(data)
8
+ data = JSON.parse(data)
9
+ end
10
+
11
+ def navigate_to_node(data, index=[])
12
+ index.each do |method|
13
+ data = data[method]
14
+ end
15
+ data
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,25 @@
1
+ require 'basicgeo'
2
+ require 'spec_helper'
3
+
4
+ describe Basicgeo::Consumer::Google do
5
+ it "change spaces of strings to + " do
6
+ expect(Basicgeo::Consumer::Google.new.parse_address("Av Imperador 341")).to eq("Av+Imperador+341")
7
+ end
8
+
9
+ it "get status of search from existent address" do
10
+ expect(JSON.parse(Basicgeo::Consumer::Google.new.get_location("Av Coronel Alves Rocha e Filho").body)["status"]).to eq("OK")
11
+ end
12
+
13
+ it "get status of search from inexistent address" do
14
+ expect(JSON.parse(Basicgeo::Consumer::Google.new.get_location("sdjafjdvfbgba bbabvbabffa").body)["status"]).to eq("ZERO_RESULTS")
15
+ end
16
+
17
+ it "get address of latitude and longitude" do
18
+ data = JSON.parse(Basicgeo::Consumer::Google.new.get_address(-23.5205452,-46.4665111).body)
19
+ expect(Basicgeo::Parser::Json.new.navigate_to_node(data, ['results',0,'formatted_address'])).to eq('Avenida Coronel Alves e Rocha Filho, 329-347 - Parque Guarani, São Paulo - SP, Brazil')
20
+ end
21
+
22
+ it 'get status of inexistent latitude and longitude' do
23
+ expect(JSON.parse(Basicgeo::Consumer::Google.new.get_address(5444644, 464464644).body)["status"]).to eq("ZERO_RESULTS")
24
+ end
25
+ end
@@ -0,0 +1,93 @@
1
+ require 'consumer/google_spec.rb'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is
56
+ # recommended. For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basicgeo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Malaquias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: An basic Geo
14
+ email: gabriel07malakias@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - ".rspec"
21
+ - Gemfile.lock
22
+ - LICENSE
23
+ - README.md
24
+ - json_parser.rb
25
+ - lib/basicgeo.rb
26
+ - lib/basicgeo/consumer/google.rb
27
+ - lib/basicgeo/parser/json.rb
28
+ - spec/consumer/google_spec.rb
29
+ - spec/spec_helper.rb
30
+ homepage: http://rubygems.org/gems/basicgeo
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.5
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: BasicGeo
54
+ test_files: []