restcountry 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/restcountry/country.rb +7 -1
- data/lib/restcountry/version.rb +1 -1
- data/spec/restcountry_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faef79b2dfbf36a87e60855199d7a733f48b3c4e
|
4
|
+
data.tar.gz: 0d1a076b4a65cbff619c6fafd7ec1921f8e8ebb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 693cc175e539626f4ce0793ec8075ddd0bb0bd010de9c6ec6b87ccfabf840f674abdd7cd38c551ae929c59da79554375e54cb90d1f5ca93d1afb0b06d3c26e80
|
7
|
+
data.tar.gz: 7347b620db1e32690c08ea6c11e7c087c9b8ddf24206d7817e3679b8722b74d82b1b309c7593a85ed052b53361a521516f66d98f57fb0b3efe145c1e6c2702f9
|
data/README.md
CHANGED
data/lib/restcountry/country.rb
CHANGED
@@ -91,6 +91,11 @@ module Restcountry
|
|
91
91
|
countries.map { |attributes| new(attributes) }
|
92
92
|
end
|
93
93
|
|
94
|
+
def self.find_by_countrycode(countrycode)
|
95
|
+
countries = get_response(nil, "alpha?codes=#{countrycode}")
|
96
|
+
countries.map { |attributes| new(attributes) }
|
97
|
+
end
|
98
|
+
|
94
99
|
def self.all
|
95
100
|
countries = get_response('all')
|
96
101
|
countries.map { |attributes| new(attributes) }
|
@@ -100,7 +105,8 @@ module Restcountry
|
|
100
105
|
|
101
106
|
private_class_method
|
102
107
|
def self.get_response(api, action = nil)
|
103
|
-
|
108
|
+
url = URI.parse(URI.encode("#{API_URL}#{api ? '/' + api : ''}/#{action}"))
|
109
|
+
response = Faraday.get(url)
|
104
110
|
return response.success? ? JSON.parse(response.body) : []
|
105
111
|
end
|
106
112
|
end
|
data/lib/restcountry/version.rb
CHANGED
data/spec/restcountry_spec.rb
CHANGED
@@ -62,4 +62,11 @@ describe Restcountry do
|
|
62
62
|
expect(countries.first.name).to eq('Armenia')
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
it 'get name from first country from countrycode it' do
|
67
|
+
VCR.use_cassette 'find_by_callingcode' do
|
68
|
+
countries = Restcountry::Country.find_by_countrycode('it')
|
69
|
+
expect(countries.first.name).to eq('Italy')
|
70
|
+
end
|
71
|
+
end
|
65
72
|
end
|
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.
|
4
|
+
version: 0.5.0
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|