weather_forecaster 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0b45aca202ed34c35e8656e127836bf97e59111
4
+ data.tar.gz: 497d3e45aab893f018d1db804b3bfefaa8859af4
5
+ SHA512:
6
+ metadata.gz: a4665b20b1453f5ece36282e472b17471e71a0742a78968584c80943c41b0cae98003d8f98c14c43ba9792e93b60004dadac856867c65e6633e70a5e27f85ec9
7
+ data.tar.gz: 8b325362e0f968a4b24c52fa1ca9853f49dfc7d3d439ea069771620b4891d0e40f17b4a7a5eb409a781a1b132f0230e609b618fc10d6eb933a9e4fe8e9acf98b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather_forecaster.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 SANTOSH TURAMARI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ Weather Forecast finder by city name
2
+
3
+ Description
4
+
5
+ WeatherForecaster accepts the city name Ex: London or city name followed by country code Ex: London, GB
6
+ It can accept the number of days from the current day to get the weather details. It provides the weather information as follows.
7
+ - City name which you are searching for.
8
+ - Country code.
9
+ - Latitude, Longitude.
10
+ - Day and night temperature values in Kelvin.
11
+ - Pressure and humidity
12
+ - Weather Description.
13
+ - Current Date Time.
14
+
15
+ Installation
16
+
17
+ gem install weather_forecaster
18
+
19
+ or Add gem "weather_forecaster" in gemfile.
20
+
21
+ Usage
22
+
23
+ require 'WeatherForecaster'
24
+
25
+ # To get the weather forecast for 5 days from today, default is 1 day.
26
+ forecast = WeatherForecaster.forecast("London", 5)
27
+
28
+ forecast.city = London
29
+ forecast.country = GB
30
+ forecast.latitude = 51.50853
31
+ forecast.longitude = -0.12574
32
+ forecast.day_temp = 289.56
33
+ forecast.night_temp = 285.49
34
+ forecast.pressure = 1015.35
35
+ forecast.humidity = 76
36
+ forecast.weather_description = light rain
37
+ forecast.date
38
+
39
+ Author
40
+
41
+ Santosh Turamari
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weather_forecaster"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module WeatherForecaster
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'httparty'
2
+ require 'json'
3
+ require 'timeout'
4
+ require 'httparty'
5
+
6
+ module WeatherForecaster
7
+ class WeatherForecastApi
8
+ def initialize
9
+ @client = "http://api.openweathermap.org/data/2.5/forecast/daily"
10
+ end
11
+
12
+ def query(city, count)
13
+ result = {}
14
+ begin
15
+ status = Timeout::timeout(5){
16
+ result = HTTParty.get(@client, :query => {:q=> city, :cnt => count})
17
+ }
18
+ rescue Timeout::Error => e
19
+ puts "Taking too long time", :status => 500
20
+ return
21
+ end
22
+ return WeatherForecastResponse.new(result) if result
23
+ end
24
+ end
25
+
26
+ class WeatherForecastResponse
27
+ attr_reader :city, :day_temp, :pressure, :country, :list_details, :latitude, :longitude, :status
28
+
29
+ def initialize(result)
30
+ detail = result.parsed_response
31
+ @city = detail['city']['name']
32
+ @country = detail['city']['country']
33
+ @latitude = detail['city']['lat']
34
+ @longitude = detail['city']['lon']
35
+ @status = "ok"
36
+ @list_details = [ ]
37
+ detail['list'].each do |list|
38
+ @list_details << {
39
+ :date => DateTime.strptime(list['dt'].to_s,'%s'),
40
+ :day_temp => list['temp']['day'],
41
+ :night_temp => list['temp']['night'],
42
+ :weather_description => list['weather'][0]['description'],
43
+ :pressure => list['pressure'],
44
+ :humidity => list['humidity']
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ require "weather_forecaster/version"
2
+ require "weather_forecaster/weather_forecast_api"
3
+
4
+ module WeatherForecaster
5
+ def self.forecast(city, count_days=nil)
6
+ w = WeatherForecastApi.new
7
+ count_days ||= 1
8
+ w.query(city, count_days)
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weather_forecaster/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weather_forecaster"
8
+ spec.version = WeatherForecaster::VERSION
9
+ spec.authors = ["SANTOSH TURAMARI"]
10
+ spec.email = ["santosh.turamari85@gmail.com"]
11
+
12
+ spec.summary = %q{This gem gives the accurate weather forecast details of city}
13
+ spec.description = %q{WeatherForecaster accepts the city name Ex: London or city name followed by country code Ex: London, GB
14
+ It can accept the number of days from the current day to get the weather details. It provides the weather information as follows.
15
+ - City name which you are searching for.
16
+ - Country code.
17
+ - Latitude, Longitude.
18
+ - Day and night temperature values in Kelvin.
19
+ - Pressure and humidity
20
+ - Weather Description.
21
+ - Current Date Time.}
22
+ spec.homepage = ""
23
+ spec.license = "MIT"
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "httparty"
34
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_forecaster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - SANTOSH TURAMARI
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
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
+ description: "WeatherForecaster accepts the city name Ex: London or city name followed
70
+ by country code Ex: London, GB\n It can accept the number
71
+ of days from the current day to get the weather details. It provides the weather
72
+ information as follows.\n - City name which you are searching
73
+ for.\n - Country code.\n -
74
+ Latitude, Longitude.\n - Day and night temperature values
75
+ in Kelvin. \n - Pressure and humidity\n -
76
+ Weather Description.\n - Current Date Time."
77
+ email:
78
+ - santosh.turamari85@gmail.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".travis.yml"
86
+ - CODE_OF_CONDUCT.md
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - lib/weather_forecaster.rb
94
+ - lib/weather_forecaster/version.rb
95
+ - lib/weather_forecaster/weather_forecast_api.rb
96
+ - weather_forecaster.gemspec
97
+ homepage: ''
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: This gem gives the accurate weather forecast details of city
121
+ test_files: []