Skip to content

Commit

Permalink
MergeFix
Browse files Browse the repository at this point in the history
  • Loading branch information
coderhs committed Apr 25, 2015
2 parents 15564ee + 827c682 commit 1438973
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 95 deletions.
15 changes: 15 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### CONTRIBUTORS

[Harisankar P S](https://github.com/coderhs)

[Deepak Kumar](https://github.com/42races)

[Daniel Nitsikopoulos](https://github.com/dNitza)

[Yone Lacort Collado](https://github.com/yonelacort)

[iamdeuterium](https://github.com/iamdeuterium)

[ssendev](https://github.com/ssendev)

[Nithin Bekal](https://github.com/nithinbekal)
14 changes: 7 additions & 7 deletions lib/open_weather.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module OpenWeather
$LOAD_PATH<< "../lib"
$LOAD_PATH<< '../lib'

autoload :Base, "open_weather/base"
autoload :Current, "open_weather/current"
autoload :Forecast, "open_weather/forecast"
autoload :ForecastDaily, "open_weather/forecast_daily"
autoload :VERSION, "open_weather/version"
autoload :Base, 'open_weather/base'
autoload :Current, 'open_weather/current'
autoload :Forecast, 'open_weather/forecast'
autoload :ForecastDaily, 'open_weather/forecast_daily'
autoload :VERSION, 'open_weather/version'

require "open_weather/api.rb"
require 'open_weather/api.rb'
end
10 changes: 5 additions & 5 deletions lib/open_weather/api.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

module OpenWeather
module ClassMethods
#City format : Eg, Cochin,IN
#Useage: OpenWeather::Current.city('Cochin,In')
# City format : Eg, Cochin,IN
# Useage: OpenWeather::Current.city('Cochin,In')
def city(city, options = {})
new(options.merge(city: city)).retrive
end

#City Id, an integer value. Eg, 2172797
#Useage: OpenWeather::Current.city_id(2172797)
# City Id, an integer value. Eg, 2172797
# Useage: OpenWeather::Current.city_id(2172797)
def city_id(id, options = {})
new(options.merge(id: id)).retrive
end

#City Geographics Cordingates : Eg, lat 35 lon 139
# City Geographics Cordingates : Eg, lat 35 lon 139
def geocode(lat, lon, options = {})
new(options.merge(lat: lat, lon: lon)).retrive
end
Expand Down
29 changes: 16 additions & 13 deletions lib/open_weather/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class Base

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

def initialize url, options
@status = false
@url = url
def initialize(url, options)
@status = false
@url = url
@options = extract_options!(options)
end

def retrive
@response = send_request(self) unless @options.empty?
parse_response if @response
response = send_request unless @options.empty?
parse_response(response)
end

def success?
Expand All @@ -24,7 +24,9 @@ def success?
private

def extract_options!(options)
valid_options = [:lat, :lon, :city, :country, :id, :units, :cnt, :APPID, :lang]
valid_options = [ :id, :lat, :lon, :cnt, :city, :lang, :units, :APPID,
:country]

options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }

if options[:city] || options[:country]
Expand All @@ -36,16 +38,17 @@ def extract_options!(options)
options
end

def parse_response
@weather_info = JSON.parse(@response)
@status = @weather_info["cod"]
@message = @weather_info["message"] unless @status
def parse_response(response)
return if response.nil?
@weather_info = JSON.parse(response)
@status = @weather_info['cod']
@message = @weather_info['message'] unless @status
@weather_info
end

def send_request(request)
uri = URI(request.url)
uri.query = URI.encode_www_form(request.options)
def send_request
uri = URI(@url)
uri.query = URI.encode_www_form(options)
Net::HTTP.get(uri)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/current.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module OpenWeather
class Current < Base
def initialize(options = {})
super("http://api.openweathermap.org/data/2.5/weather", options)
super('http://api.openweathermap.org/data/2.5/weather', options)
end
end
end
2 changes: 1 addition & 1 deletion lib/open_weather/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OpenWeather
VERSION = "0.11.0"
VERSION = '0.11.0'
end
6 changes: 3 additions & 3 deletions open_weather.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
$:.push File.expand_path("../lib", __FILE__)
$:.push File.expand_path('../lib', __FILE__)
require 'open_weather/version'

Gem::Specification.new do |gem|
gem.name = "open-weather"
gem.name = 'open-weather'
gem.version = OpenWeather::VERSION
gem.authors = ["HsPS [email protected]", "Deepak [email protected]"]
gem.licenses = ['MIT']
gem.email = ['[email protected]']
gem.homepage = "https://github.com/coderhs/ruby_open_weather_map"
gem.homepage = 'https://github.com/coderhs/ruby_open_weather_map'
gem.summary = %q{ A ruby wrapper for Open Weather Map API. }
gem.description = %q{ A ruby wrapper for Open Weather Map API. }
gem.files = `git ls-files`.split("\n")
Expand Down
42 changes: 21 additions & 21 deletions spec/integration/current_spec.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
describe "Current weather information with APPID" do
describe 'Current weather information with APPID' do
let(:options) do
{ units: "metric", APPID: 1111111111 }
{ units: 'metric', APPID: 1111111111 }
end

describe "searching by city" do
context "when the city is found" do
describe 'searching by city' do
context 'when the city is found' do
let(:weather) do
VCR.use_cassette("integration/current_by_city") do
OpenWeather::Current.city("Berlin, DE", options)
VCR.use_cassette('integration/current_by_city') do
OpenWeather::Current.city('Berlin, DE', options)
end
end

it "returns results" do
expect(weather).to include("weather")
it 'returns results' do
expect(weather).to include('weather')
end
end

context "when the city is not found" do
context 'when the city is not found' do
let(:weather) do
VCR.use_cassette("integration/current_not_found_city") do
OpenWeather::Current.city("Berlin, DE", options)
VCR.use_cassette('integration/current_not_found_city') do
OpenWeather::Current.city('Berlin, DE', options)
end
end

it "returns an attribute with code 404" do
expect(weather["cod"]).to eq("404")
it 'returns an attribute with code 404' do
expect(weather['cod']).to eq('404')
end
end
end

describe "searching by geolocation" do
describe 'searching by geolocation' do
let(:weather) do
VCR.use_cassette("integration/current_by_geocode") do
VCR.use_cassette('integration/current_by_geocode') do
OpenWeather::Current.geocode(48.140938, 11.582005, options)
end
end

it "returns results" do
expect(weather).to include("weather")
it 'returns results' do
expect(weather).to include('weather')
end
end

describe "searching by city_id" do
describe 'searching by city_id' do
let(:weather) do
VCR.use_cassette("integration/current_by_city_id") do
VCR.use_cassette('integration/current_by_city_id') do
OpenWeather::Current.city_id(524901, options)
end
end

it "returns results" do
expect(weather).to include("weather")
it 'returns results' do
expect(weather).to include('weather')
end
end
end
Loading

0 comments on commit 1438973

Please sign in to comment.