restcountry 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7d334d4e378ba7a4ffdf7f3dd3b35b329a5b1db
4
- data.tar.gz: cb6678bfa84b5192423e7cc0b377350387fd9794
3
+ metadata.gz: d4529a0a454e36b402e477bd82abfd26025be28d
4
+ data.tar.gz: 87527b89b7c60e2a7bbe34966210ab82e052d8a1
5
5
  SHA512:
6
- metadata.gz: 6bb19216eef2e41243af8a499cb7205d98ed200e9c8ab83c307b6dc23a7c01355fadcaf3d83b5c39efb4a11f9e6ec36db1b3ffdb18e0b7be6ee09859eb4f2b36
7
- data.tar.gz: 49c68cc58e80ba987e96281ea6324684e375b4c0dd89afbddc5ee9de4f51b5b483efe42fef5b62be1594e20c0ae7dd4f8ecb5337f93b50ebeedc2ff0f175b828
6
+ metadata.gz: 70ecb83e3b2b26a77987a46125587cd821dbde8667f61f0213af1f16cf263201011062131df36511e6347b071bd40b7ceaa846cf657d61bf55f2e73a9a51c35e
7
+ data.tar.gz: 1ba09405164a70b72b1b9c591cd286a22d0f3628adf0f9d98ce0782c1acb299418a97f2955c14bc1b27ef83b047e77f45b64a3ede49a5edb22c15ad4733dbe0b
@@ -52,8 +52,8 @@ module Restcountry
52
52
  end
53
53
 
54
54
  def self.find(name)
55
- response = get_response('name', name)
56
- response.success? ? new(JSON.parse(response.body).first) : []
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
- response = get_response('currency', currency)
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
- response = get_response('capital', capital)
71
- response.success? ? new(JSON.parse(response.body).first) : []
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
- response = get_response('region', region)
76
- countries = response.success? ? JSON.parse(response.body) : []
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
- response = get_response('lang', lang)
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
- response = get_response('callingcode', callingcode)
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
- response = get_response('all')
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
@@ -1,3 +1,3 @@
1
1
  module Restcountry
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restcountry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davide Santangelo