Skip to content

Commit

Permalink
use ' instead of " for fixed string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakkumarnd committed Apr 18, 2015
1 parent 058ea52 commit 0e26161
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 101 deletions.
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.10.0"
VERSION = '0.10.0'
end
18 changes: 9 additions & 9 deletions open_weather.gemspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
$:.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.authors = ['HsPS <[email protected]>', 'Deepak <[email protected]>']
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")
gem.test_files = gem.files.grep(/^(spec|test|features)/)
gem.executables = gem.files.grep(/^bin/).map{ |f| File.basename(f) }
gem.require_paths = ["lib"]
gem.add_development_dependency "rspec"
gem.add_development_dependency "vcr"
gem.add_development_dependency "webmock"
gem.add_runtime_dependency 'json'
gem.require_paths = ['lib']
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'vcr'
gem.add_development_dependency 'webmock'
gem.add_runtime_dependency 'json'
end
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 0e26161

Please sign in to comment.