yahoo_countries_and_provinces 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +10 -0
- data/lib/yahoo_countries_and_provinces.rb +16 -0
- data/lib/yahoo_countries_and_provinces/version.rb +3 -0
- data/lib/yahoo_countries_and_provinces/yahoo_country_list.rb +34 -0
- data/lib/yahoo_countries_and_provinces/yahoo_province_list.rb +34 -0
- data/test/test_helper.rb +2 -0
- data/test/yahoo_countries_and_provinces_test.rb +19 -0
- data/yahoo_countries_and_provinces.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e2f239a96839073bf7ab77aa7d9bf2610fc03cc1
|
4
|
+
data.tar.gz: 377c52e44a672428a7ee29add7e1b460ec82cf66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03e55675f500db7a68604df51a2a5f826adb531b101a5579ba2ecbc969ae22cf66ffbfa112d45ed33e41a43ee72f1c7d11f7fbe2e59d033705be20a776b2e17f
|
7
|
+
data.tar.gz: b36ea14357cfd431a20873091093bd216d636eb09012260cb7cf3df251902eb4b1dc7c0497dbbb28fe11daa1f962e046382de84155ed35b4aa1e4896c33fcc98
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 jonesamra
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# YahooCountriesAndProvinces
|
2
|
+
|
3
|
+
A Ruby gem for generating a list of all the countries and provinces using Yahoo's YQL.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'yahoo_countries_and_provinces'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install yahoo_countries_and_provinces
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
|
22
|
+
#To get a list of the countries in english
|
23
|
+
country_array = YahooCountriesAndStates::countries("en")
|
24
|
+
|
25
|
+
#To get a list of the countries in swedish
|
26
|
+
country_array = YahooCountriesAndStates::countries("sv")
|
27
|
+
|
28
|
+
#To get Germany's provinces in english
|
29
|
+
provinces_array = YahooCountriesAndStates::provinces("Germany", "en")
|
30
|
+
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "yahoo_countries_and_provinces/version"
|
2
|
+
require "yahoo_countries_and_provinces/yahoo_country_list"
|
3
|
+
require "yahoo_countries_and_provinces/yahoo_province_list"
|
4
|
+
|
5
|
+
|
6
|
+
module YahooCountriesAndProvinces
|
7
|
+
def self.countries(language="en")
|
8
|
+
c = YahooCountriesAndProvinces::YahooCountryList.new
|
9
|
+
c.countries(language)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.provinces(country, language="en")
|
13
|
+
p = YahooCountriesAndProvinces::YahooProvinceList.new
|
14
|
+
p.provinces(country, language)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module YahooCountriesAndProvinces
|
5
|
+
class YahooCountryList
|
6
|
+
def initialize()
|
7
|
+
@country_array = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def countries(language = "en")
|
11
|
+
set_url(language)
|
12
|
+
|
13
|
+
@country_array.clear if @country_array.any?
|
14
|
+
begin
|
15
|
+
resp = Net::HTTP.get_response(URI.parse(@url))
|
16
|
+
data = resp.body
|
17
|
+
result = JSON.parse(data)["query"]["results"]["place"]
|
18
|
+
rescue
|
19
|
+
raise "Could not get the data from yahoo's servers"
|
20
|
+
end
|
21
|
+
|
22
|
+
result.each { |country|
|
23
|
+
@country_array << country['name']
|
24
|
+
}
|
25
|
+
|
26
|
+
@country_array
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def set_url(language)
|
31
|
+
@url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.countries%20where%20lang%3D%22" + language + "%22&format=json&callback="
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module YahooCountriesAndProvinces
|
5
|
+
class YahooProvinceList
|
6
|
+
def initialize()
|
7
|
+
@states_array = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def provinces(country, language = "en")
|
11
|
+
set_url(country, language)
|
12
|
+
|
13
|
+
@states_array.clear if @states_array.any?
|
14
|
+
begin
|
15
|
+
resp = Net::HTTP.get_response(URI.parse(@url))
|
16
|
+
data = resp.body
|
17
|
+
result = JSON.parse(data)["query"]["results"]["place"]
|
18
|
+
rescue
|
19
|
+
raise "Could not get the data from yahoo's servers"
|
20
|
+
end
|
21
|
+
|
22
|
+
result.each { |state|
|
23
|
+
@states_array << state['name']
|
24
|
+
}
|
25
|
+
|
26
|
+
@states_array
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def set_url(country, language)
|
31
|
+
@url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.states%20where%20place%3D%22" + country + "%22%20and%20lang%3D%22" + language + "%22&format=json&callback="
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class YahooCountriesAndProvincesTest < Test::Unit::TestCase
|
4
|
+
def test_get_country_iraq_in_swedish
|
5
|
+
assert YahooCountriesAndProvinces::countries("sv").include?("Irak")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_get_minor_outlying_islands_united_states_in_german
|
9
|
+
assert YahooCountriesAndProvinces::countries("de").include?("Kleinere Inselbesitzungen der Vereinigten Staaten")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_state_baghdad_in_english
|
13
|
+
assert YahooCountriesAndProvinces::provinces("Iraq", "en").include?("Baghdad")
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_get_state_stockholm_in_arabic
|
17
|
+
assert YahooCountriesAndProvinces::provinces("Sweden", "ar").include?("ستوكهولم")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yahoo_countries_and_provinces/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yahoo_countries_and_provinces"
|
8
|
+
spec.version = YahooCountriesAndProvinces::VERSION
|
9
|
+
spec.authors = ["Jone Samra"]
|
10
|
+
spec.email = ["jonemob@gmail.com"]
|
11
|
+
spec.summary = %q{Generates a list of all the countries and provinces using Yahoo's YQL.}
|
12
|
+
spec.description = %q{Generates a list of all the countries and provinces using Yahoo's YQL.}
|
13
|
+
spec.homepage = "https://github.com/phenomen2277/yahoo_countries_and_provinces"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "json", ">= 1.8.1"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yahoo_countries_and_provinces
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jone Samra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.1
|
55
|
+
description: Generates a list of all the countries and provinces using Yahoo's YQL.
|
56
|
+
email:
|
57
|
+
- jonemob@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/yahoo_countries_and_provinces.rb
|
68
|
+
- lib/yahoo_countries_and_provinces/version.rb
|
69
|
+
- lib/yahoo_countries_and_provinces/yahoo_country_list.rb
|
70
|
+
- lib/yahoo_countries_and_provinces/yahoo_province_list.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
- test/yahoo_countries_and_provinces_test.rb
|
73
|
+
- yahoo_countries_and_provinces.gemspec
|
74
|
+
homepage: https://github.com/phenomen2277/yahoo_countries_and_provinces
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.4.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Generates a list of all the countries and provinces using Yahoo's YQL.
|
98
|
+
test_files:
|
99
|
+
- test/test_helper.rb
|
100
|
+
- test/yahoo_countries_and_provinces_test.rb
|