restcountry 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/restcountry/country.rb +6 -0
- data/lib/restcountry/version.rb +1 -1
- data/restcountry.gemspec +32 -0
- data/spec/restcountry_spec.rb +32 -0
- data/spec/spec_helper.rb +2 -0
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d3d0c000b23698040620e022dc74aac3ef9e92e
|
4
|
+
data.tar.gz: b7665617042e687ce1c30025d202ce0b715517c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63a06b0884b54aa9939b347d6c81db2ff18cfe83954ad6c7c7d8fccf70229880711f2944bf1792a291349d54062430ee3a44e6171625010e8d0bde9ccc273797
|
7
|
+
data.tar.gz: 3e73fab420dd9b1c52e1beec11a0b122eca9c6d2d9b857e2bb15b961f7888607051ca0b2c2440471dcb463c38964688dc1f2127699729af3f3c66a029119dee2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Restcountry
|
2
|
+
|
3
|
+
This is a sample gem to wrap REST Countries API http://restcountries.eu
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'restcountry'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install restcountry
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'restcountry'
|
25
|
+
|
26
|
+
# Find all countries
|
27
|
+
countries = Restcountry::Country.all
|
28
|
+
|
29
|
+
# Find a country by name
|
30
|
+
country = Restcountry::Country.find('italy')
|
31
|
+
|
32
|
+
# Access the country's attributes
|
33
|
+
country.capital
|
34
|
+
#=> Rome
|
35
|
+
|
36
|
+
country.region
|
37
|
+
#=> Europe
|
38
|
+
|
39
|
+
country.callingCodes
|
40
|
+
#=> "39"
|
41
|
+
|
42
|
+
# Find a country by capital
|
43
|
+
country = Restcountry::Country.find_by_capital('Rome')
|
44
|
+
|
45
|
+
country.name
|
46
|
+
#=> Italy
|
47
|
+
|
48
|
+
```
|
49
|
+
## Attributes
|
50
|
+
|
51
|
+
name,
|
52
|
+
capital,
|
53
|
+
altSpellings,
|
54
|
+
relevance,
|
55
|
+
region,
|
56
|
+
subregion,
|
57
|
+
translations,
|
58
|
+
population,
|
59
|
+
latlng,
|
60
|
+
demonym,
|
61
|
+
area,
|
62
|
+
gini,
|
63
|
+
timezones,
|
64
|
+
borders,
|
65
|
+
nativeName,
|
66
|
+
callingCodes,
|
67
|
+
topLevelDomain,
|
68
|
+
alpha2Code,
|
69
|
+
alpha3Code,
|
70
|
+
currencies,
|
71
|
+
languages
|
72
|
+
|
73
|
+
## Credits
|
74
|
+
Many thanks to Fayder Florez(https://twitter.com/fayderflorez) for his implementation of the API.
|
75
|
+
|
76
|
+
## License
|
77
|
+
The restcountry GEM is released under the MIT License.
|
78
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "restcountry"
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/restcountry/country.rb
CHANGED
@@ -73,6 +73,12 @@ module Restcountry
|
|
73
73
|
countries.map { |attributes| new(attributes) }
|
74
74
|
end
|
75
75
|
|
76
|
+
def self.find_by_lang(lang)
|
77
|
+
response = Faraday.get("#{API_URL}/lang/#{lang}")
|
78
|
+
countries = response.success? ? JSON.parse(response.body) : []
|
79
|
+
countries.map { |attributes| new(attributes) }
|
80
|
+
end
|
81
|
+
|
76
82
|
def self.all
|
77
83
|
response = Faraday.get("#{API_URL}/all")
|
78
84
|
countries = response.success? ? JSON.parse(response.body) : []
|
data/lib/restcountry/version.rb
CHANGED
data/restcountry.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'restcountry/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "restcountry"
|
8
|
+
spec.version = Restcountry::VERSION
|
9
|
+
spec.authors = ["Davide Santangelo"]
|
10
|
+
spec.email = ["davide.santangelo@gmail.com"]
|
11
|
+
|
12
|
+
if spec.respond_to?(:metadata)
|
13
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
14
|
+
end
|
15
|
+
|
16
|
+
spec.summary = %q{Gem to wrap BensBenzes.com API}
|
17
|
+
spec.description = %q{Basic API implementation for REST Countries API http://restcountries.eu}
|
18
|
+
spec.homepage = "https://github.com/davidesantangelo/restcountry"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files`.split($/)
|
22
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
|
30
|
+
spec.add_dependency "faraday"
|
31
|
+
spec.add_dependency "json"
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Restcountry do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(Restcountry::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'get capital Rome from country Italy' do
|
9
|
+
country = Restcountry::Country.find('Italy')
|
10
|
+
expect(country.capital).to eq('Rome')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'get capital Madrid from country Spain' do
|
14
|
+
country = Restcountry::Country.find('Spain')
|
15
|
+
expect(country.capital).to eq('Madrid')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'get region Europe from country Ukraine' do
|
19
|
+
country = Restcountry::Country.find('Ukraine')
|
20
|
+
expect(country.region).to eq('Europe')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'get name Estonia from capital Tallinn' do
|
24
|
+
country = Restcountry::Country.find_by_capital('Tallinn')
|
25
|
+
expect(country.capital).to eq('Tallinn')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'get name from first country from language it' do
|
29
|
+
countries = Restcountry::Country.find_by_lang('it')
|
30
|
+
expect(countries.first.name).to eq('Italy')
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restcountry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Santangelo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,14 +83,27 @@ dependencies:
|
|
83
83
|
description: Basic API implementation for REST Countries API http://restcountries.eu
|
84
84
|
email:
|
85
85
|
- davide.santangelo@gmail.com
|
86
|
-
executables:
|
86
|
+
executables:
|
87
|
+
- console
|
88
|
+
- setup
|
87
89
|
extensions: []
|
88
90
|
extra_rdoc_files: []
|
89
91
|
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
90
100
|
- lib/restcountry.rb
|
91
101
|
- lib/restcountry/country.rb
|
92
102
|
- lib/restcountry/version.rb
|
93
|
-
|
103
|
+
- restcountry.gemspec
|
104
|
+
- spec/restcountry_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: https://github.com/davidesantangelo/restcountry
|
94
107
|
licenses:
|
95
108
|
- MIT
|
96
109
|
metadata:
|
@@ -115,4 +128,6 @@ rubygems_version: 2.4.6
|
|
115
128
|
signing_key:
|
116
129
|
specification_version: 4
|
117
130
|
summary: Gem to wrap BensBenzes.com API
|
118
|
-
test_files:
|
131
|
+
test_files:
|
132
|
+
- spec/restcountry_spec.rb
|
133
|
+
- spec/spec_helper.rb
|