restcountry 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/restcountry/country.rb +16 -15
- data/lib/restcountry/version.rb +1 -1
- data/spec/restcountry_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4529a0a454e36b402e477bd82abfd26025be28d
|
4
|
+
data.tar.gz: 87527b89b7c60e2a7bbe34966210ab82e052d8a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70ecb83e3b2b26a77987a46125587cd821dbde8667f61f0213af1f16cf263201011062131df36511e6347b071bd40b7ceaa846cf657d61bf55f2e73a9a51c35e
|
7
|
+
data.tar.gz: 1ba09405164a70b72b1b9c591cd286a22d0f3628adf0f9d98ce0782c1acb299418a97f2955c14bc1b27ef83b047e77f45b64a3ede49a5edb22c15ad4733dbe0b
|
data/lib/restcountry/country.rb
CHANGED
@@ -52,8 +52,8 @@ module Restcountry
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.find(name)
|
55
|
-
|
56
|
-
|
55
|
+
countries = get_response('name', name)
|
56
|
+
new(countries.first) unless countries.empty?
|
57
57
|
end
|
58
58
|
|
59
59
|
def self.find_by_name(name)
|
@@ -61,42 +61,43 @@ module Restcountry
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.find_by_currency(currency)
|
64
|
-
|
65
|
-
countries = response.success? ? JSON.parse(response.body) : []
|
64
|
+
countries = get_response('currency', currency)
|
66
65
|
countries.map { |attributes| new(attributes) }
|
67
66
|
end
|
68
67
|
|
69
68
|
def self.find_by_capital(capital)
|
70
|
-
|
71
|
-
|
69
|
+
countries = get_response('capital', capital)
|
70
|
+
new(countries.first) unless countries.empty?
|
72
71
|
end
|
73
72
|
|
74
73
|
def self.find_by_region(region)
|
75
|
-
|
76
|
-
countries
|
74
|
+
countries = get_response('region', region)
|
75
|
+
countries.map { |attributes| new(attributes) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.find_by_subregion(subregion)
|
79
|
+
countries = get_response('subregion', subregion)
|
77
80
|
countries.map { |attributes| new(attributes) }
|
78
81
|
end
|
79
82
|
|
80
83
|
def self.find_by_lang(lang)
|
81
|
-
|
82
|
-
countries = response.success? ? JSON.parse(response.body) : []
|
84
|
+
countries = get_response('lang', lang)
|
83
85
|
countries.map { |attributes| new(attributes) }
|
84
86
|
end
|
85
87
|
|
86
88
|
def self.find_by_callingcode(callingcode)
|
87
|
-
|
88
|
-
countries = response.success? ? JSON.parse(response.body) : []
|
89
|
+
countries = get_response('callingcode', callingcode)
|
89
90
|
countries.map { |attributes| new(attributes) }
|
90
91
|
end
|
91
92
|
|
92
93
|
def self.all
|
93
|
-
|
94
|
-
countries = response.success? ? JSON.parse(response.body) : []
|
94
|
+
countries = get_response('all')
|
95
95
|
countries.map { |attributes| new(attributes) }
|
96
96
|
end
|
97
97
|
private
|
98
98
|
def self.get_response(api, action=nil)
|
99
|
-
Faraday.get("#{API_URL}/#{api.to_s}/#{action}")
|
99
|
+
response = Faraday.get(URI.parse(URI.encode("#{API_URL}/#{api.to_s}/#{action}")))
|
100
|
+
return response.success? ? JSON.parse(response.body) : []
|
100
101
|
end
|
101
102
|
end
|
102
103
|
end
|
data/lib/restcountry/version.rb
CHANGED
data/spec/restcountry_spec.rb
CHANGED
@@ -55,4 +55,11 @@ describe Restcountry do
|
|
55
55
|
expect(countries.first.name).to eq('Italy')
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
it 'get name Armenia from first country of subregion "western asia"' do
|
60
|
+
VCR.use_cassette 'find_by_subregion' do
|
61
|
+
countries = Restcountry::Country.find_by_subregion('western asia')
|
62
|
+
expect(countries.first.name).to eq('Armenia')
|
63
|
+
end
|
64
|
+
end
|
58
65
|
end
|