restcountry 0.4.2 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 465f64d7d8a2e84d0945b7f9e82c9df1913d3a97
4
- data.tar.gz: 0fdd40748dac35069919c0f1d64b55d66292f540
3
+ metadata.gz: faef79b2dfbf36a87e60855199d7a733f48b3c4e
4
+ data.tar.gz: 0d1a076b4a65cbff619c6fafd7ec1921f8e8ebb5
5
5
  SHA512:
6
- metadata.gz: 8082395ad93696bc70036f65ef22e08f97c3419ebd9b827d75cd08e14d596919b7b6c4ff9916678aaf870067061c0d2afbcf259f247155fb752cdbb3597ef451
7
- data.tar.gz: a0c87e0e049c536b7e76f6afd940c83689abc10fa519e72d8e897978271896172a453c71fd8a18330ee02e35f4a780089d0162235df4340fad7b389e2e79a0d6
6
+ metadata.gz: 693cc175e539626f4ce0793ec8075ddd0bb0bd010de9c6ec6b87ccfabf840f674abdd7cd38c551ae929c59da79554375e54cb90d1f5ca93d1afb0b06d3c26e80
7
+ data.tar.gz: 7347b620db1e32690c08ea6c11e7c087c9b8ddf24206d7817e3679b8722b74d82b1b309c7593a85ed052b53361a521516f66d98f57fb0b3efe145c1e6c2702f9
data/README.md CHANGED
@@ -46,6 +46,7 @@ country.name
46
46
  #=> Italy
47
47
 
48
48
  countries = Restcountry::Country.find_by_lang('it')
49
+
49
50
  countries.first
50
51
  #=> Italy
51
52
 
@@ -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
- response = Faraday.get(URI.parse(URI.encode("#{API_URL}/#{api.to_s}/#{action}")))
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
@@ -1,3 +1,3 @@
1
1
  module Restcountry
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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.2
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-17 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler