├── .rspec ├── lib ├── geo_names │ ├── version.rb │ ├── get.rb │ ├── address.rb │ ├── cities.rb │ ├── gtopo30.rb │ ├── ocean.rb │ ├── search.rb │ ├── srtm1.rb │ ├── srtm3.rb │ ├── weather.rb │ ├── astergdem.rb │ ├── contains.rb │ ├── hierarchy.rb │ ├── siblings.rb │ ├── timezone.rb │ ├── country_code.rb │ ├── country_info.rb │ ├── earthquakes.rb │ ├── find_nearby.rb │ ├── neighbours.rb │ ├── weather_icao.rb │ ├── neighbourhood.rb │ ├── geo_code_address.rb │ ├── postal_code_lookup.rb │ ├── postal_code_search.rb │ ├── wikipedia_search.rb │ ├── country_subdivision.rb │ ├── extended_find_nearby.rb │ ├── find_near_by_weather.rb │ ├── find_nearby_po_is_osm.rb │ ├── find_nearby_streets.rb │ ├── find_nearest_address.rb │ ├── find_nearby_place_name.rb │ ├── find_nearby_streets_osm.rb │ ├── find_nearby_wikipedia.rb │ ├── wikipedia_bounding_box.rb │ ├── find_nearby_postal_codes.rb │ ├── find_nearest_intersection.rb │ ├── postal_code_country_info.rb │ ├── find_nearest_intersection_osm.rb │ ├── children.rb │ └── base.rb └── geo_names.rb ├── renovate.json ├── bin ├── setup └── console ├── Rakefile ├── spec ├── geo_names_spec.rb ├── spec_helper.rb └── geo_names │ ├── search_spec.rb │ ├── geo_code_address_spec.rb │ ├── get_spec.rb │ ├── ocean_spec.rb │ ├── srtm1_spec.rb │ ├── srtm3_spec.rb │ ├── cities_spec.rb │ ├── address_spec.rb │ ├── gtopo30_spec.rb │ ├── weather_spec.rb │ ├── children_spec.rb │ ├── contains_spec.rb │ ├── country_info_spec.rb │ ├── siblings_spec.rb │ ├── timezone_spec.rb │ ├── wikipedia_search_spec.rb │ ├── astergdem_spec.rb │ ├── hierarchy_spec.rb │ ├── postal_code_lookup_spec.rb │ ├── find_nearby_spec.rb │ ├── neighbours_spec.rb │ ├── country_code_spec.rb │ ├── earthquakes_spec.rb │ ├── weather_icao_spec.rb │ ├── neighbourhood_spec.rb │ ├── postal_code_country_info_spec.rb │ ├── postal_code_search_spec.rb │ ├── country_subdivision_spec.rb │ ├── find_near_by_weather_spec.rb │ ├── find_nearby_po_is_osm_spec.rb │ ├── find_nearby_streets_spec.rb │ ├── extended_find_nearby_spec.rb │ ├── find_nearby_place_name_spec.rb │ ├── find_nearby_wikipedia_spec.rb │ ├── find_nearby_streets_osm_spec.rb │ ├── wikipedia_bounding_box_spec.rb │ ├── find_nearby_postal_codes_spec.rb │ ├── find_nearest_intersection_spec.rb │ └── find_nearest_intersection_osm_spec.rb ├── .gitignore ├── Gemfile ├── CHANGELOG.md ├── LICENSE.txt ├── geo_names.gemspec ├── .github └── workflows │ └── ci.yml ├── CODE_OF_CONDUCT.md └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /lib/geo_names/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | VERSION = '1.0.2' 5 | end 6 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "commitMessagePrefix": ":arrow_up:" 6 | } 7 | -------------------------------------------------------------------------------- /lib/geo_names/get.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Get < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/address.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Address < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/cities.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Cities < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/gtopo30.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Gtopo30 < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/ocean.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Ocean < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/search.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Search < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/srtm1.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Srtm1 < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/srtm3.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Srtm3 < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/weather.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Weather < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/astergdem.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Astergdem < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/contains.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Contains < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/hierarchy.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Hierarchy < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/siblings.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Siblings < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/timezone.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Timezone < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/country_code.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class CountryCode < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/country_info.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class CountryInfo < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/earthquakes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Earthquakes < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearby < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/neighbours.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Neighbours < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/weather_icao.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class WeatherIcao < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/neighbourhood.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Neighbourhood < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/geo_code_address.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class GeoCodeAddress < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/postal_code_lookup.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class PostalCodeLookup < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/postal_code_search.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class PostalCodeSearch < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/wikipedia_search.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class WikipediaSearch < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/country_subdivision.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class CountrySubdivision < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/extended_find_nearby.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class ExtendedFindNearby < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_near_by_weather.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearByWeather < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby_po_is_osm.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearbyPOIsOSM < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby_streets.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearbyStreets < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearest_address.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearestAddress < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby_place_name.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearbyPlaceName < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby_streets_osm.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearbyStreetsOSM < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby_wikipedia.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearbyWikipedia < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/wikipedia_bounding_box.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class WikipediaBoundingBox < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearby_postal_codes.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearbyPostalCodes < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearest_intersection.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearestIntersection < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/geo_names/postal_code_country_info.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class PostalCodeCountryInfo < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /lib/geo_names/find_nearest_intersection_osm.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class FindNearestIntersectionOSM < Base 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | require 'rspec/core/rake_task' 5 | 6 | RSpec::Core::RakeTask.new(:spec) 7 | 8 | task :default => :spec 9 | -------------------------------------------------------------------------------- /spec/geo_names_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames do 4 | it 'has a version number' do 5 | expect(GeoNames::VERSION).not_to be nil 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | 10 | # rspec failure tracking 11 | .rspec_status 12 | 13 | Gemfile.lock 14 | -------------------------------------------------------------------------------- /lib/geo_names/children.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module GeoNames 4 | class Children < Base 5 | def required_param_names 6 | %i[geonameId] 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } 6 | 7 | # Specify your gem's dependencies in geo_names.gemspec 8 | gemspec 9 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bundler/setup' 4 | require 'geo_names' 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | require 'pry' 10 | Pry.start 11 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/setup' 4 | require 'pry' 5 | require 'geo_names' 6 | 7 | RSpec.configure do |config| 8 | # Enable flags like --only-failures and --next-failure 9 | config.example_status_persistence_file_path = '.rspec_status' 10 | 11 | # Disable RSpec exposing methods globally on `Module` and `main` 12 | config.disable_monkey_patching! 13 | 14 | config.expect_with :rspec do |c| 15 | c.syntax = :expect 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## Unreleased 4 | 5 | - ... 6 | 7 | ## 1.0.2 8 | 9 | - GeoNames API changed the behavior and now we need to rescue RestClient::Unauthorized exception. [Pr #4](https://github.com/WaKeMaTTa/geo_names/pull/4) 10 | - Fixed missing `GeoNames::DatabaseTimeoutError` class and fixed a typo in the class `GeoNames::NoResultFoundError`. [Pr #3](https://github.com/WaKeMaTTa/geo_names/pull/3) (thanks to @dgilperez) 11 | 12 | ## 1.0.1 13 | 14 | - A typo in `GeoNames.configuration` -> `username`. [commit 8d8d7e3](https://github.com/WaKeMaTTa/geo_names/commit/8d8d7e3329cc4ca08209d3d99f1263c665d51135) 15 | 16 | ## 1.0.0 17 | 18 | - First release 19 | -------------------------------------------------------------------------------- /spec/geo_names/search_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Search do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Search.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Search.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Search.search 29 | end.not_to raise_error 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/geo_code_address_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::GeoCodeAddress do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::GeoCodeAddress.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::GeoCodeAddress.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect(GeoNames::GeoCodeAddress.search).to eq({}) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /spec/geo_names/get_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Get do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Get.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Get.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Get.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/ocean_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Ocean do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Ocean.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Ocean.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Ocean.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/srtm1_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Srtm1 do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Srtm1.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Srtm1.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Srtm1.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/srtm3_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Srtm3 do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Srtm3.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Srtm3.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Srtm3.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/cities_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Cities do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Cities.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Cities.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Cities.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/address_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Address do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Address.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Address.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Address.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/gtopo30_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Gtopo30 do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Gtopo30.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Gtopo30.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Gtopo30.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/weather_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Weather do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Weather.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Weather.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Weather.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/children_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Children do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Children.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Children.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Children.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/contains_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Contains do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Contains.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Contains.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Contains.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/country_info_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Address do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Address.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Address.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Address.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/siblings_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Siblings do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Siblings.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Siblings.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Siblings.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/timezone_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Timezone do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Timezone.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Timezone.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Timezone.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/wikipedia_search_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::WikipediaSearch do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::WikipediaSearch.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::WikipediaSearch.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::WikipediaSearch.search 29 | end.not_to raise_error 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/astergdem_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Astergdem do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Astergdem.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Astergdem.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Astergdem.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/hierarchy_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Hierarchy do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Hierarchy.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Hierarchy.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Hierarchy.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/postal_code_lookup_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::PostalCodeLookup do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::PostalCodeLookup.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::PostalCodeLookup.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::PostalCodeLookup.search 29 | end.not_to raise_error 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearby do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearby.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearby.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearby.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/neighbours_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Neighbours do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Neighbours.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Neighbours.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Neighbours.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/country_code_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::CountryCode do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::CountryCode.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::CountryCode.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::CountryCode.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/earthquakes_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Earthquakes do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Earthquakes.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Earthquakes.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Earthquakes.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/weather_icao_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::WeatherIcao do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::WeatherIcao.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::WeatherIcao.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::WeatherIcao.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/neighbourhood_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::Neighbourhood do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::Neighbourhood.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::Neighbourhood.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::Neighbourhood.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/postal_code_country_info_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::PostalCodeCountryInfo do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::PostalCodeCountryInfo.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::PostalCodeCountryInfo.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::PostalCodeCountryInfo.search 29 | end.not_to raise_error 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/postal_code_search_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::PostalCodeSearch do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::PostalCodeSearch.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::PostalCodeSearch.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::PostalCodeSearch.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/country_subdivision_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::CountrySubdivision do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::CountrySubdivision.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::CountrySubdivision.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::CountrySubdivision.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_near_by_weather_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearByWeather do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearByWeather.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearByWeather.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearByWeather.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_po_is_osm_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearbyPOIsOSM do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearbyPOIsOSM.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearbyPOIsOSM.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearbyPOIsOSM.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_streets_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearbyStreets do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearbyStreets.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearbyStreets.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearbyStreets.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/extended_find_nearby_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::ExtendedFindNearby do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::ExtendedFindNearby.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::ExtendedFindNearby.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::ExtendedFindNearby.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_place_name_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearbyPlaceName do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearbyPlaceName.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearbyPlaceName.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearbyPlaceName.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_wikipedia_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearbyWikipedia do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearbyWikipedia.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearbyWikipedia.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearbyWikipedia.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_streets_osm_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearbyStreetsOSM do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearbyStreetsOSM.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearbyStreetsOSM.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearbyStreetsOSM.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/wikipedia_bounding_box_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::WikipediaBoundingBox do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::WikipediaBoundingBox.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::WikipediaBoundingBox.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::WikipediaBoundingBox.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearby_postal_codes_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearbyPostalCodes do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearbyPostalCodes.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearbyPostalCodes.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearbyPostalCodes.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearest_intersection_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearestIntersection do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearestIntersection.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearestIntersection.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearestIntersection.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /spec/geo_names/find_nearest_intersection_osm_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | RSpec.describe GeoNames::FindNearestIntersectionOSM do 4 | before :each do 5 | GeoNames.configuration.username = nil 6 | end 7 | 8 | let(:username) { 'gem_geo_names' } 9 | 10 | it 'raises an error on empty username' do 11 | RSpec::Expectations.configuration.on_potential_false_positives = :nothing 12 | GeoNames.configuration.username = nil 13 | expect do 14 | GeoNames::FindNearestIntersectionOSM.search 15 | end.to raise_error(GeoNames::AuthorizationExceptionError) 16 | end 17 | 18 | it 'do not raises an error if username is in the options' do 19 | GeoNames.configuration.username = nil 20 | expect do 21 | GeoNames::FindNearestIntersectionOSM.search(username: username) 22 | end.not_to raise_error(GeoNames::AuthorizationExceptionError) 23 | end 24 | 25 | it 'works' do 26 | GeoNames.configuration.username = username 27 | expect do 28 | GeoNames::FindNearestIntersectionOSM.search 29 | end.to raise_error(GeoNames::MissingOrInvalidParameterError) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 Mohamed Ziata 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /geo_names.gemspec: -------------------------------------------------------------------------------- 1 | 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'geo_names/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'geo_names' 8 | spec.version = GeoNames::VERSION 9 | spec.authors = ['Mohamed Ziata'] 10 | spec.email = ['wakematta@gmail.com'] 11 | 12 | spec.summary = %q{An API wrapper for GeoNames API's} 13 | spec.description = %q{A Gem to expose a wrapping API for the GeoNames API's} 14 | spec.homepage = 'https://github.com/WaKeMaTTa/geo_names' 15 | spec.license = 'MIT' 16 | 17 | # Specify which files should be added to the gem when it is released. 18 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 19 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 20 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 21 | end 22 | spec.bindir = 'exe' 23 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 24 | spec.require_paths = ['lib'] 25 | 26 | spec.add_runtime_dependency 'rest-client', '~> 2' 27 | 28 | spec.add_development_dependency 'bundler' 29 | spec.add_development_dependency 'gem-release', '~> 2.0' 30 | spec.add_development_dependency 'pry-byebug' 31 | spec.add_development_dependency 'rake', '~> 10.0' 32 | spec.add_development_dependency 'rspec', '~> 3.0' 33 | end 34 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake 6 | # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby 7 | 8 | name: CI 9 | 10 | # Controls when the action will run. 11 | on: 12 | # Triggers the workflow on push or pull request events but only for the master branch 13 | push: 14 | branches: [ master ] 15 | pull_request: 16 | branches: [ master ] 17 | 18 | # Allows you to run this workflow manually from the Actions tab 19 | workflow_dispatch: 20 | 21 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 22 | jobs: 23 | # This workflow contains a single job called "test" 24 | test: 25 | # The type of runner that the job will run on 26 | runs-on: ubuntu-latest 27 | 28 | # All the ruby versions that we want to test on 29 | strategy: 30 | matrix: 31 | ruby-version: 32 | - "2.3" 33 | - "2.4" 34 | - "2.5" 35 | - "2.6" 36 | - "2.7" 37 | - "3.0" 38 | - "3.1" 39 | - "3.2" 40 | - "3.3" 41 | 42 | # Steps represent a sequence of tasks that will be executed as part of the job 43 | steps: 44 | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 45 | 46 | - name: Set up Ruby 47 | # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, 48 | # change this to (see https://github.com/ruby/setup-ruby#versioning): 49 | uses: ruby/setup-ruby@v1 50 | with: 51 | ruby-version: ${{ matrix.ruby-version }} 52 | bundler-cache: true # runs 'bundle install' and caches installed gems automatically 53 | 54 | - name: Run tests 55 | run: bundle exec rake 56 | -------------------------------------------------------------------------------- /lib/geo_names.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'geo_names/version' 4 | require 'geo_names/base' 5 | require 'geo_names/address' 6 | require 'geo_names/astergdem' 7 | require 'geo_names/children' 8 | require 'geo_names/cities' 9 | require 'geo_names/contains' 10 | require 'geo_names/country_code' 11 | require 'geo_names/country_info' 12 | require 'geo_names/country_subdivision' 13 | require 'geo_names/earthquakes' 14 | require 'geo_names/extended_find_nearby' 15 | require 'geo_names/find_nearby_place_name' 16 | require 'geo_names/find_nearby_po_is_osm' 17 | require 'geo_names/find_nearby_postal_codes' 18 | require 'geo_names/find_nearby' 19 | require 'geo_names/find_nearby_streets_osm' 20 | require 'geo_names/find_nearby_streets' 21 | require 'geo_names/find_near_by_weather' 22 | require 'geo_names/find_nearby_wikipedia' 23 | require 'geo_names/find_nearest_address' 24 | require 'geo_names/find_nearest_intersection_osm' 25 | require 'geo_names/find_nearest_intersection' 26 | require 'geo_names/geo_code_address' 27 | require 'geo_names/get' 28 | require 'geo_names/gtopo30' 29 | require 'geo_names/hierarchy' 30 | require 'geo_names/neighbourhood' 31 | require 'geo_names/neighbours' 32 | require 'geo_names/ocean' 33 | require 'geo_names/postal_code_country_info' 34 | require 'geo_names/postal_code_lookup' 35 | require 'geo_names/postal_code_search' 36 | require 'geo_names/search' 37 | require 'geo_names/siblings' 38 | require 'geo_names/srtm1' 39 | require 'geo_names/srtm3' 40 | require 'geo_names/timezone' 41 | require 'geo_names/version' 42 | require 'geo_names/weather_icao' 43 | require 'geo_names/weather' 44 | require 'geo_names/wikipedia_bounding_box' 45 | require 'geo_names/wikipedia_search' 46 | 47 | 48 | module GeoNames 49 | def self.configuration 50 | @configuration ||= Configuration.new 51 | end 52 | 53 | def self.configure 54 | self.configuration ||= Configuration.new 55 | yield(configuration) if block_given? 56 | end 57 | 58 | # Main configuration class. 59 | class Configuration 60 | attr_accessor :api_base, :username 61 | 62 | def initialize 63 | @api_base = 'http://api.geonames.org/' 64 | @username = nil 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at wakematta@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /lib/geo_names/base.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'json' 4 | require 'rest_client' 5 | 6 | module GeoNames 7 | class Base 8 | attr_reader :url, :params 9 | 10 | def self.search(params = {}) 11 | new(params).call 12 | end 13 | 14 | def initialize(params = {}) 15 | @url = "#{configuration.api_base}#{controller_name_for(self.class)}" 16 | @params = { 17 | username: configuration.username 18 | }.merge(params) 19 | end 20 | 21 | def call 22 | result = make_request 23 | parse(result) 24 | end 25 | 26 | private 27 | 28 | def configuration 29 | @configuration ||= GeoNames.configuration 30 | end 31 | 32 | def make_request 33 | RestClient.get(url, params: params) 34 | rescue RestClient::Unauthorized => e 35 | e.response.to_s 36 | end 37 | 38 | def parse(json_string) 39 | hash = JSON.parse(json_string) 40 | return hash unless hash['status'] 41 | 42 | status_code = hash.dig('status', 'value') 43 | message = hash.dig('status', 'message') 44 | raise_error_according_to!(status_code, message) 45 | end 46 | 47 | def controller_name_for(klass) 48 | name = klass.to_s.sub('GeoNames::', '') 49 | name_camelized = name.chars.map.with_index do |char, index| 50 | index.zero? ? char.downcase : char 51 | end.join 52 | "#{name_camelized}JSON" 53 | end 54 | 55 | def raise_error_according_to!(status_code, message) 56 | case status_code 57 | when 10 58 | raise(AuthorizationExceptionError, message) 59 | when 11 60 | raise(RecordDoesNotExistError, message) 61 | when 12 62 | raise(OtherError, message) 63 | when 13 64 | raise(DatabaseTimeoutError, message) 65 | when 14 66 | raise(MissingOrInvalidParameterError, message) 67 | when 15 68 | raise(NoResultFoundError, message) 69 | when 16 70 | raise(DuplicateExceptionError, message) 71 | when 17 72 | raise(PostalCodeNotFoundError, message) 73 | when 18 74 | raise(DailyLimitOfCreditsExceededError, message) 75 | when 19 76 | raise(HourlyLimitOfCreditsExceededError, message) 77 | when 20 78 | raise(WeeklyLimitOfCreditsExceededError, message) 79 | when 21 80 | raise(InvalidInputError, message) 81 | when 22 82 | raise(ServerOverloadedExceptionError, message) 83 | when 23 84 | raise(ServiceNotImplementedError, message) 85 | when 24 86 | raise(RadiusTooLargeError, message) 87 | when 25 88 | raise(MaxRowsTooLargeError, message) 89 | else 90 | raise(StatusCodeNotImplementedError, 'please report it in github.com/wakematta/geo_names') 91 | end 92 | end 93 | end 94 | 95 | class AuthorizationExceptionError < StandardError; end 96 | class DatabaseTimeoutError < StandardError; end 97 | class MissingOrInvalidParameterError < StandardError; end 98 | class RecordDoesNotExistError < StandardError; end 99 | class OtherError < StandardError; end 100 | class NoResultFoundError < StandardError; end 101 | class PostalCodeNotFoundError < StandardError; end 102 | class DailyLimitOfCreditsExceededError < StandardError; end 103 | class HourlyLimitOfCreditsExceededError < StandardError; end 104 | class WeeklyLimitOfCreditsExceededError < StandardError; end 105 | class InvalidInputError < StandardError; end 106 | class ServerOverloadedExceptionError < StandardError; end 107 | class ServiceNotImplementedError < StandardError; end 108 | class RadiusTooLargeError < StandardError; end 109 | class MaxRowsTooLargeError < StandardError; end 110 | class StatusCodeNotImplementedError < StandardError; end 111 | end 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GeoNames 2 | 3 | GeoNames Ruby API Wrapper 4 | 5 | [![Build Status](https://travis-ci.org/WaKeMaTTa/geo_names.svg?branch=master)](https://travis-ci.org/WaKeMaTTa/geo_names) 6 | [![Maintainability](https://api.codeclimate.com/v1/badges/a69ae1a450119061f8e2/maintainability)](https://codeclimate.com/github/WaKeMaTTa/geo_names/maintainability) 7 | ![GitHub](https://img.shields.io/github/license/wakematta/geo_names.svg) 8 | 9 | This gem is a ruby API wrapper for [GeoNames](https://www.geonames.org/) [API's](https://www.geonames.org/export/web-services.html). 10 | 11 | ## Security 12 | 13 | Multifactor authentication: 14 | 15 | ![Security github.com account](https://img.shields.io/badge/github.com-enabled-brightgreen.svg) 16 | ![Security rubygems.org account](https://img.shields.io/badge/rubygems.org-enabled-brightgreen.svg) 17 | 18 | ## Installation 19 | 20 | Add this line to your application's Gemfile: 21 | 22 | ```ruby 23 | gem 'geo_names' 24 | ``` 25 | 26 | And then execute: 27 | 28 | ```bash 29 | $ bundle 30 | ``` 31 | 32 | Or install it yourself as: 33 | 34 | ```bash 35 | $ gem install geo_names 36 | ``` 37 | 38 | ## Usage 39 | 40 | ### Pre-requirement 41 | 42 | You need a valid `username` to use the gem. You can get it by signing up [here](http://www.geonames.org/login). 43 | 44 | If you don't set the `username` it will *raises an exception*. 45 | 46 | ### Configuration 47 | 48 | You can use add initializer for example if you're on Rails. 49 | 50 | ```ruby 51 | # config/initializers/geo_names.rb 52 | 53 | GeoNames.configure do |config| 54 | config.username = ENV['GEONAMES_USERNAME'] 55 | end 56 | ``` 57 | 58 | ### Searching 59 | 60 | #### How to search? 61 | 62 | First you need a `Hash` with the criteria that you want to search. 63 | 64 | ```ruby 65 | # example of criteria 66 | criteria = { 67 | country: 'US', 68 | name: 'New York', 69 | featureClass: %w[P S], 70 | maxRows: 1, 71 | style: 'short' 72 | } 73 | ``` 74 | 75 | Then you can search 76 | ```ruby 77 | result = GeoNames::Search.search(criteria) 78 | ``` 79 | 80 | The `result` it will be a `Hash` if was successful, like this one: 81 | ```ruby 82 | { "totalResultsCount" => 1360, 83 | "geonames" => [ 84 | { "lng" => "-74.00597", 85 | "geonameId" => 5128581, 86 | "countryCode" => "US", 87 | "name" => "New York", 88 | "toponymName" => "New York City", 89 | "lat" => "40.71427", 90 | "fcl" => "P", 91 | "fcode" => "PPL" 92 | } 93 | ] 94 | } 95 | ``` 96 | 97 | Or if something was wrong it will raise an error of this list: 98 | ```ruby 99 | GeoNames::AuthorizationExceptionError 100 | GeoNames::DatabaseTimeoutError 101 | GeoNames::MissingOrInvalidParameterError 102 | GeoNames::RecordDoesNotExistError 103 | GeoNames::OtherError 104 | GeoNames::NoResultFoundError 105 | GeoNames::PostalCodeNotFoundError 106 | GeoNames::DailyLimitOfCreditsExceededError 107 | GeoNames::HourlyLimitOfCreditsExceededError 108 | GeoNames::WeeklyLimitOfCreditsExceededError 109 | GeoNames::InvalidInputError 110 | GeoNames::ServerOverloadedExceptionError 111 | GeoNames::ServiceNotImplementedError 112 | GeoNames::RadiusTooLargeError 113 | GeoNames::MaxRowsTooLargeError 114 | GeoNames::StatusCodeNotImplementedError 115 | ``` 116 | 117 | #### Search engines available 118 | 119 | ```ruby 120 | GeoNames::Address 121 | GeoNames::Astergdem 122 | GeoNames::Children 123 | GeoNames::Cities 124 | GeoNames::Configuration 125 | GeoNames::Contains 126 | GeoNames::CountryCode 127 | GeoNames::CountryInfo 128 | GeoNames::CountrySubdivision 129 | GeoNames::Earthquakes 130 | GeoNames::ExtendedFindNearby 131 | GeoNames::FindNearByWeather 132 | GeoNames::FindNearby 133 | GeoNames::FindNearbyPOIsOSM 134 | GeoNames::FindNearbyPlaceName 135 | GeoNames::FindNearbyPostalCodes 136 | GeoNames::FindNearbyStreets 137 | GeoNames::FindNearbyStreetsOSM 138 | GeoNames::FindNearbyWikipedia 139 | GeoNames::FindNearestAddress 140 | GeoNames::FindNearestIntersection 141 | GeoNames::FindNearestIntersectionOSM 142 | GeoNames::GeoCodeAddress 143 | GeoNames::Get 144 | GeoNames::Gtopo30 145 | GeoNames::Hierarchy 146 | GeoNames::Neighbourhood 147 | GeoNames::Neighbours 148 | GeoNames::Ocean 149 | GeoNames::PostalCodeCountryInfo 150 | GeoNames::PostalCodeLookup 151 | GeoNames::PostalCodeSearch 152 | GeoNames::Search 153 | GeoNames::Siblings 154 | GeoNames::Srtm1 155 | GeoNames::Srtm3 156 | GeoNames::Timezone 157 | GeoNames::Weather 158 | GeoNames::WeatherIcao 159 | GeoNames::WikipediaBoundingBox 160 | GeoNames::WikipediaSearch 161 | ``` 162 | 163 | ## Development 164 | 165 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 166 | 167 | 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 168 | 169 | ## Contributing 170 | 171 | Bug reports and pull requests are welcome on GitHub at [geo_names repository](https://github.com/wakematta/geo_names). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 172 | 173 | ## License 174 | 175 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 176 | 177 | ## Code of Conduct 178 | 179 | Everyone interacting in the GeoNames project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/geo_names/blob/master/CODE_OF_CONDUCT.md). 180 | --------------------------------------------------------------------------------