Skip to content

Commit 1438973

Browse files
committed
MergeFix
2 parents 15564ee + 827c682 commit 1438973

File tree

10 files changed

+113
-95
lines changed

10 files changed

+113
-95
lines changed

CONTRIBUTORS.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### CONTRIBUTORS
2+
3+
[Harisankar P S](https://github.com/coderhs)
4+
5+
[Deepak Kumar](https://github.com/42races)
6+
7+
[Daniel Nitsikopoulos](https://github.com/dNitza)
8+
9+
[Yone Lacort Collado](https://github.com/yonelacort)
10+
11+
[iamdeuterium](https://github.com/iamdeuterium)
12+
13+
[ssendev](https://github.com/ssendev)
14+
15+
[Nithin Bekal](https://github.com/nithinbekal)

lib/open_weather.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module OpenWeather
2-
$LOAD_PATH<< "../lib"
2+
$LOAD_PATH<< '../lib'
33

4-
autoload :Base, "open_weather/base"
5-
autoload :Current, "open_weather/current"
6-
autoload :Forecast, "open_weather/forecast"
7-
autoload :ForecastDaily, "open_weather/forecast_daily"
8-
autoload :VERSION, "open_weather/version"
4+
autoload :Base, 'open_weather/base'
5+
autoload :Current, 'open_weather/current'
6+
autoload :Forecast, 'open_weather/forecast'
7+
autoload :ForecastDaily, 'open_weather/forecast_daily'
8+
autoload :VERSION, 'open_weather/version'
99

10-
require "open_weather/api.rb"
10+
require 'open_weather/api.rb'
1111
end

lib/open_weather/api.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11

22
module OpenWeather
33
module ClassMethods
4-
#City format : Eg, Cochin,IN
5-
#Useage: OpenWeather::Current.city('Cochin,In')
4+
# City format : Eg, Cochin,IN
5+
# Useage: OpenWeather::Current.city('Cochin,In')
66
def city(city, options = {})
77
new(options.merge(city: city)).retrive
88
end
99

10-
#City Id, an integer value. Eg, 2172797
11-
#Useage: OpenWeather::Current.city_id(2172797)
10+
# City Id, an integer value. Eg, 2172797
11+
# Useage: OpenWeather::Current.city_id(2172797)
1212
def city_id(id, options = {})
1313
new(options.merge(id: id)).retrive
1414
end
1515

16-
#City Geographics Cordingates : Eg, lat 35 lon 139
16+
# City Geographics Cordingates : Eg, lat 35 lon 139
1717
def geocode(lat, lon, options = {})
1818
new(options.merge(lat: lat, lon: lon)).retrive
1919
end

lib/open_weather/base.rb

+16-13
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ class Base
66

77
attr_reader :url, :options, :weather_info, :status, :message
88

9-
def initialize url, options
10-
@status = false
11-
@url = url
9+
def initialize(url, options)
10+
@status = false
11+
@url = url
1212
@options = extract_options!(options)
1313
end
1414

1515
def retrive
16-
@response = send_request(self) unless @options.empty?
17-
parse_response if @response
16+
response = send_request unless @options.empty?
17+
parse_response(response)
1818
end
1919

2020
def success?
@@ -24,7 +24,9 @@ def success?
2424
private
2525

2626
def extract_options!(options)
27-
valid_options = [:lat, :lon, :city, :country, :id, :units, :cnt, :APPID, :lang]
27+
valid_options = [ :id, :lat, :lon, :cnt, :city, :lang, :units, :APPID,
28+
:country]
29+
2830
options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }
2931

3032
if options[:city] || options[:country]
@@ -36,16 +38,17 @@ def extract_options!(options)
3638
options
3739
end
3840

39-
def parse_response
40-
@weather_info = JSON.parse(@response)
41-
@status = @weather_info["cod"]
42-
@message = @weather_info["message"] unless @status
41+
def parse_response(response)
42+
return if response.nil?
43+
@weather_info = JSON.parse(response)
44+
@status = @weather_info['cod']
45+
@message = @weather_info['message'] unless @status
4346
@weather_info
4447
end
4548

46-
def send_request(request)
47-
uri = URI(request.url)
48-
uri.query = URI.encode_www_form(request.options)
49+
def send_request
50+
uri = URI(@url)
51+
uri.query = URI.encode_www_form(options)
4952
Net::HTTP.get(uri)
5053
end
5154
end

lib/open_weather/current.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module OpenWeather
22
class Current < Base
33
def initialize(options = {})
4-
super("http://api.openweathermap.org/data/2.5/weather", options)
4+
super('http://api.openweathermap.org/data/2.5/weather', options)
55
end
66
end
77
end

lib/open_weather/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module OpenWeather
2-
VERSION = "0.11.0"
2+
VERSION = '0.11.0'
33
end

open_weather.gemspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
$:.push File.expand_path("../lib", __FILE__)
1+
$:.push File.expand_path('../lib', __FILE__)
22
require 'open_weather/version'
33

44
Gem::Specification.new do |gem|
5-
gem.name = "open-weather"
5+
gem.name = 'open-weather'
66
gem.version = OpenWeather::VERSION
77
gem.authors = ["HsPS [email protected]", "Deepak [email protected]"]
88
gem.licenses = ['MIT']
99
gem.email = ['[email protected]']
10-
gem.homepage = "https://github.com/coderhs/ruby_open_weather_map"
10+
gem.homepage = 'https://github.com/coderhs/ruby_open_weather_map'
1111
gem.summary = %q{ A ruby wrapper for Open Weather Map API. }
1212
gem.description = %q{ A ruby wrapper for Open Weather Map API. }
1313
gem.files = `git ls-files`.split("\n")

spec/integration/current_spec.rb

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
describe "Current weather information with APPID" do
1+
describe 'Current weather information with APPID' do
22
let(:options) do
3-
{ units: "metric", APPID: 1111111111 }
3+
{ units: 'metric', APPID: 1111111111 }
44
end
55

6-
describe "searching by city" do
7-
context "when the city is found" do
6+
describe 'searching by city' do
7+
context 'when the city is found' do
88
let(:weather) do
9-
VCR.use_cassette("integration/current_by_city") do
10-
OpenWeather::Current.city("Berlin, DE", options)
9+
VCR.use_cassette('integration/current_by_city') do
10+
OpenWeather::Current.city('Berlin, DE', options)
1111
end
1212
end
1313

14-
it "returns results" do
15-
expect(weather).to include("weather")
14+
it 'returns results' do
15+
expect(weather).to include('weather')
1616
end
1717
end
1818

19-
context "when the city is not found" do
19+
context 'when the city is not found' do
2020
let(:weather) do
21-
VCR.use_cassette("integration/current_not_found_city") do
22-
OpenWeather::Current.city("Berlin, DE", options)
21+
VCR.use_cassette('integration/current_not_found_city') do
22+
OpenWeather::Current.city('Berlin, DE', options)
2323
end
2424
end
2525

26-
it "returns an attribute with code 404" do
27-
expect(weather["cod"]).to eq("404")
26+
it 'returns an attribute with code 404' do
27+
expect(weather['cod']).to eq('404')
2828
end
2929
end
3030
end
3131

32-
describe "searching by geolocation" do
32+
describe 'searching by geolocation' do
3333
let(:weather) do
34-
VCR.use_cassette("integration/current_by_geocode") do
34+
VCR.use_cassette('integration/current_by_geocode') do
3535
OpenWeather::Current.geocode(48.140938, 11.582005, options)
3636
end
3737
end
3838

39-
it "returns results" do
40-
expect(weather).to include("weather")
39+
it 'returns results' do
40+
expect(weather).to include('weather')
4141
end
4242
end
4343

44-
describe "searching by city_id" do
44+
describe 'searching by city_id' do
4545
let(:weather) do
46-
VCR.use_cassette("integration/current_by_city_id") do
46+
VCR.use_cassette('integration/current_by_city_id') do
4747
OpenWeather::Current.city_id(524901, options)
4848
end
4949
end
5050

51-
it "returns results" do
52-
expect(weather).to include("weather")
51+
it 'returns results' do
52+
expect(weather).to include('weather')
5353
end
5454
end
5555
end

0 commit comments

Comments
 (0)