restcountry 0.2.1 → 0.3.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: 5d3d0c000b23698040620e022dc74aac3ef9e92e
4
- data.tar.gz: b7665617042e687ce1c30025d202ce0b715517c9
3
+ metadata.gz: 721868f79209e1a64f3ebf97e3e55107f14b3f22
4
+ data.tar.gz: f03f3ff568894e3d15b8da23d6f173cd0c85f6e5
5
5
  SHA512:
6
- metadata.gz: 63a06b0884b54aa9939b347d6c81db2ff18cfe83954ad6c7c7d8fccf70229880711f2944bf1792a291349d54062430ee3a44e6171625010e8d0bde9ccc273797
7
- data.tar.gz: 3e73fab420dd9b1c52e1beec11a0b122eca9c6d2d9b857e2bb15b961f7888607051ca0b2c2440471dcb463c38964688dc1f2127699729af3f3c66a029119dee2
6
+ metadata.gz: 1eef3bb6ce960793f03fde50e83e1d88d0944fe427344891e7867a35c1e5ca53924519db6254d6e292b467e4d6b63b9fb94a5410b2a14b8eaeb120dddabacbd3
7
+ data.tar.gz: 4fe4766e0d039b3c22dcba3a5d89f24d1410a53deb4d98ebc0e75e7359c2142a5a6f93954d32b1c276f59f643d96c5dc9e3f142cca7af6a8ff3c7313bba77283
@@ -5,26 +5,26 @@ API_URL = "https://restcountries.eu/rest/v1"
5
5
 
6
6
  module Restcountry
7
7
  class Country
8
- attr_reader :name,
9
- :capital,
10
- :altSpellings,
11
- :relevance,
12
- :region,
13
- :subregion,
14
- :translations,
15
- :population,
16
- :latlng,
17
- :demonym,
18
- :area,
19
- :gini,
20
- :timezones,
21
- :borders,
22
- :nativeName,
23
- :callingCodes,
24
- :topLevelDomain,
25
- :alpha2Code,
26
- :alpha3Code,
27
- :currencies,
8
+ attr_reader :name,
9
+ :capital,
10
+ :altSpellings,
11
+ :relevance,
12
+ :region,
13
+ :subregion,
14
+ :translations,
15
+ :population,
16
+ :latlng,
17
+ :demonym,
18
+ :area,
19
+ :gini,
20
+ :timezones,
21
+ :borders,
22
+ :nativeName,
23
+ :callingCodes,
24
+ :topLevelDomain,
25
+ :alpha2Code,
26
+ :alpha3Code,
27
+ :currencies,
28
28
  :languages
29
29
 
30
30
  def initialize(attributes)
@@ -56,6 +56,10 @@ module Restcountry
56
56
  response.success? ? new(JSON.parse(response.body).first) : []
57
57
  end
58
58
 
59
+ def self.find_by_name(name)
60
+ find(name)
61
+ end
62
+
59
63
  def self.find_by_currency(currency)
60
64
  response = Faraday.get("#{API_URL}/currency/#{currency}")
61
65
  countries = response.success? ? JSON.parse(response.body) : []
@@ -79,10 +83,16 @@ module Restcountry
79
83
  countries.map { |attributes| new(attributes) }
80
84
  end
81
85
 
86
+ def self.find_by_callingcode(callingcode)
87
+ response = Faraday.get("#{API_URL}/callingcode/#{callingcode}")
88
+ countries = response.success? ? JSON.parse(response.body) : []
89
+ countries.map { |attributes| new(attributes) }
90
+ end
91
+
82
92
  def self.all
83
93
  response = Faraday.get("#{API_URL}/all")
84
94
  countries = response.success? ? JSON.parse(response.body) : []
85
95
  countries.map { |attributes| new(attributes) }
86
96
  end
87
97
  end
88
- end
98
+ end
@@ -1,3 +1,3 @@
1
1
  module Restcountry
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -26,6 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "bundler", "~> 1.8"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency "vcr"
30
+ spec.add_development_dependency "typhoeus"
31
+
32
+ spec.required_ruby_version = ">= 1.9.3"
29
33
 
30
34
  spec.add_dependency "faraday"
31
35
  spec.add_dependency "json"
@@ -1,32 +1,59 @@
1
1
  require 'spec_helper'
2
+ require 'vcr'
2
3
 
3
4
  describe Restcountry do
5
+
6
+ it 'get a response from api' do
7
+ VCR.use_cassette 'find_by_name' do
8
+ result = Restcountry::Country.all
9
+ expect(result).to be_kind_of(Array)
10
+ expect(result.first).to be_kind_of(Restcountry::Country)
11
+ end
12
+ end
13
+
4
14
  it 'has a version number' do
5
15
  expect(Restcountry::VERSION).not_to be nil
6
16
  end
7
17
 
8
18
  it 'get capital Rome from country Italy' do
9
- country = Restcountry::Country.find('Italy')
10
- expect(country.capital).to eq('Rome')
19
+ VCR.use_cassette 'find' do
20
+ country = Restcountry::Country.find('Italy')
21
+ expect(country.capital).to eq('Rome')
22
+ end
11
23
  end
12
24
 
13
25
  it 'get capital Madrid from country Spain' do
14
- country = Restcountry::Country.find('Spain')
15
- expect(country.capital).to eq('Madrid')
26
+ VCR.use_cassette 'find' do
27
+ country = Restcountry::Country.find('Spain')
28
+ expect(country.capital).to eq('Madrid')
29
+ end
16
30
  end
17
31
 
18
32
  it 'get region Europe from country Ukraine' do
19
- country = Restcountry::Country.find('Ukraine')
20
- expect(country.region).to eq('Europe')
33
+ VCR.use_cassette 'find' do
34
+ country = Restcountry::Country.find('Ukraine')
35
+ expect(country.region).to eq('Europe')
36
+ end
21
37
  end
22
38
 
23
39
  it 'get name Estonia from capital Tallinn' do
24
- country = Restcountry::Country.find_by_capital('Tallinn')
25
- expect(country.capital).to eq('Tallinn')
40
+ VCR.use_cassette 'find_by_capital' do
41
+ country = Restcountry::Country.find_by_capital('Tallinn')
42
+ expect(country.capital).to eq('Tallinn')
43
+ end
26
44
  end
27
45
 
28
46
  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')
47
+ VCR.use_cassette 'find_by_lang' do
48
+ countries = Restcountry::Country.find_by_lang('it')
49
+ expect(countries.first.name).to eq('Italy')
50
+ end
51
+ end
52
+
53
+ it 'get name from first country from callingcode 39' do
54
+ VCR.use_cassette 'find_by_callingcode' do
55
+ countries = Restcountry::Country.find_by_callingcode('39')
56
+ expect(countries.first.name).to eq('Italy')
57
+ end
31
58
  end
32
59
  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.2.1
4
+ version: 0.3.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-10 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: typhoeus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: faraday
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
144
  requirements:
117
145
  - - ">="
118
146
  - !ruby/object:Gem::Version
119
- version: '0'
147
+ version: 1.9.3
120
148
  required_rubygems_version: !ruby/object:Gem::Requirement
121
149
  requirements:
122
150
  - - ">="