Skip to content

Commit

Permalink
minor fixing and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
davidesantangelo committed Jun 18, 2015
1 parent 6253eb1 commit 09fc1ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/restcountry/country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def initialize(attributes)
end

def self.find(name, fulltext = false)
countries = get_response('name', name + "?fullText=#{fulltext.to_s}")
countries = get_response('name', name + "?fullText=#{fulltext}")
new(countries.first) unless countries.empty?
end

Expand Down Expand Up @@ -100,14 +100,14 @@ def self.all
countries = get_response('all')
countries.map { |attributes| new(attributes) }
end

private

private_class_method
def self.get_response(api, action = nil)
url = URI.parse(URI.encode("#{API_URL}#{api ? '/' + api : ''}/#{action}"))
response = Faraday.get(url)
return response.success? ? JSON.parse(response.body) : []
response.success? ? JSON.parse(response.body) : []
end
end
end
2 changes: 1 addition & 1 deletion lib/restcountry/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Restcountry
VERSION = "0.5.1"
VERSION = "0.5.2"
end
7 changes: 7 additions & 0 deletions spec/restcountry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
end
end

it 'get capital London from country United Kingdom' do
VCR.use_cassette 'find' do
country = Restcountry::Country.find('United Kingdom')
expect(country.capital).to eq('London')
end
end

it 'get region Europe from country Ukraine' do
VCR.use_cassette 'find' do
country = Restcountry::Country.find('Ukraine')
Expand Down

0 comments on commit 09fc1ef

Please sign in to comment.