open-weather-map 0.0.2

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: a758180107342eccde25af16b37d2233f4a676b3
4
+ data.tar.gz: f460673a46d346337a5f3c8cec3f3543c5d270dc
5
+ SHA512:
6
+ metadata.gz: e23d30655b2e313cd5d19f1c3b7e27f0e8a3e97a2e062e9df41f4d2abe202ead1655f959360b28c2cd9c6ac5430be0959a8fc2400501c1de3d2d58e5c5bb1a8f
7
+ data.tar.gz: c776c2c18d95f95b8ebb645e4542634212a4efc7218f1af4c44d34ab417fca0bd36c1ab263f68df8f18fd31f17322669601eb5f549410d0a1c0831ce8e87aa3f
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in open-weather-map-api.gemspec
4
+ gem 'httparty'
5
+
6
+ group :test do
7
+ gem 'webmock'
8
+ gem 'vcr'
9
+ gem 'turn'
10
+ gem 'rake'
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 pdebelak
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Openweathermap
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'openweathermap'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install openweathermap
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/openweathermap/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['spec/lib/*_spec.rb']
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,4 @@
1
+ require "httparty"
2
+ Dir[File.dirname(__FILE__) + '/openweathermap/*.rb'].each do |file|
3
+ require file
4
+ end
@@ -0,0 +1,17 @@
1
+ module OpenWeatherMap
2
+ module CityMethods
3
+ def city(city)
4
+ new(city: city)
5
+ end
6
+
7
+ def city_id(city_id)
8
+ new(city_id: city_id)
9
+ end
10
+
11
+ def geolocate(args)
12
+ lat = args.respond_to?(:lat) ? args.lat : args[:lat]
13
+ lng = args.respond_to?(:lng) ? args.lng : args[:lng]
14
+ new(lat: lat, lng: lng)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module OpenWeatherMap
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'city_methods'
2
+
3
+ module OpenWeatherMap
4
+
5
+ class Weather
6
+ include HTTParty
7
+ extend CityMethods
8
+ attr_reader :city, :city_id, :lat, :lng
9
+
10
+ base_uri 'http://api.openweathermap.org/data/2.5'
11
+
12
+ def initialize(args)
13
+ @city = args[:city]
14
+ @city_id = args[:city_id]
15
+ @lat = args[:lat]
16
+ @lng = args[:lng]
17
+ end
18
+
19
+ def forecast(options={})
20
+ defaults = {
21
+ daily: false,
22
+ units: 'imperial',
23
+ count: 16
24
+ }
25
+ options = defaults.merge(options)
26
+ @forecast ||= get_forecast(options)
27
+ end
28
+
29
+ private
30
+
31
+ def get_forecast(options)
32
+ options[:daily] ? daily_forecast(options) : three_hour_forecast(options)
33
+ end
34
+
35
+ def daily_forecast(options)
36
+ return self.class.get "/forecast/daily?id=#{city_id}&cnt=#{options[:count]}&units=#{options[:units]}" if city_id
37
+ return self.class.get "/forecast/daily?q=#{city}&cnt=#{options[:count]}&units=#{options[:units]}" if city
38
+ return self.class.get "/forecast/daily?lat=#{lat}&lon=#{lng}&cnt=#{options[:count]}&units=#{options[:units]}" if lat && lng
39
+ end
40
+
41
+ def three_hour_forecast(options)
42
+ return self.class.get "/forecast?id=#{city_id}&units=#{options[:units]}" if city_id
43
+ return self.class.get "/forecast?q=#{city}&units=#{options[:units]}" if city
44
+ return self.class.get "/forecast?lat=#{lat}&lon=#{lng}&units=#{options[:units]}" if lat && lng
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'openweathermap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "open-weather-map"
8
+ spec.version = OpenWeatherMap::VERSION
9
+ spec.authors = ["Peter Debelak"]
10
+ spec.email = ["pdebelak@gmail.com"]
11
+ spec.summary = %q{Gem to wrap http://openweathermap.org/api}
12
+ spec.description = %q{Gem to wrap http://openweathermap.org/api}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "webmock"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "turn"
26
+
27
+ spec.add_dependency "httparty"
28
+ end
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.openweathermap.org/data/2.5/forecast?id=524901&units=imperial
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Mon, 05 Jan 2015 19:58:13 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Source:
32
+ - back
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Credentials:
36
+ - 'true'
37
+ Access-Control-Allow-Methods:
38
+ - GET, POST
39
+ body:
40
+ encoding: UTF-8
41
+ string: |
42
+ {"cod":"200","message":0.3356,"city":{"id":524901,"name":"Moscow","coord":{"lon":37.615555,"lat":55.75222},"country":"RU","population":1000000},"cnt":35,"list":[{"dt":1420480800,"main":{"temp":6.15,"temp_min":4.63,"temp_max":6.15,"pressure":997.39,"sea_level":1018.78,"grnd_level":997.39,"humidity":77,"temp_kf":0.85},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":10.54,"deg":354.504},"snow":{"3h":0.175},"sys":{"pod":"n"},"dt_txt":"2015-01-05 18:00:00"},{"dt":1420491600,"main":{"temp":5.81,"temp_min":4.36,"temp_max":5.81,"pressure":999.35,"sea_level":1020.85,"grnd_level":999.35,"humidity":78,"temp_kf":0.8},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":92},"wind":{"speed":10.93,"deg":356.004},"snow":{"3h":0.25},"sys":{"pod":"n"},"dt_txt":"2015-01-05 21:00:00"},{"dt":1420502400,"main":{"temp":6.17,"temp_min":4.79,"temp_max":6.17,"pressure":1001.13,"sea_level":1022.74,"grnd_level":1001.13,"humidity":76,"temp_kf":0.76},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":88},"wind":{"speed":11.45,"deg":359.5},"snow":{"3h":0.125},"sys":{"pod":"n"},"dt_txt":"2015-01-06 00:00:00"},{"dt":1420513200,"main":{"temp":4.71,"temp_min":3.41,"temp_max":4.71,"pressure":1003.51,"sea_level":1025.12,"grnd_level":1003.51,"humidity":81,"temp_kf":0.72},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":76},"wind":{"speed":12.38,"deg":357.504},"snow":{"3h":0.25},"sys":{"pod":"n"},"dt_txt":"2015-01-06 03:00:00"},{"dt":1420524000,"main":{"temp":3.2,"temp_min":1.99,"temp_max":3.2,"pressure":1005.46,"sea_level":1027.27,"grnd_level":1005.46,"humidity":78,"temp_kf":0.68},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":44},"wind":{"speed":11.73,"deg":355.504},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-06 06:00:00"},{"dt":1420534800,"main":{"temp":5.5,"temp_min":4.36,"temp_max":5.5,"pressure":1006.79,"sea_level":1028.56,"grnd_level":1006.79,"humidity":78,"temp_kf":0.64},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":48},"wind":{"speed":11.6,"deg":353.507},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-06 09:00:00"},{"dt":1420545600,"main":{"temp":4.44,"temp_min":3.38,"temp_max":4.44,"pressure":1008.33,"sea_level":1030.12,"grnd_level":1008.33,"humidity":82,"temp_kf":0.59},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":36},"wind":{"speed":11.56,"deg":356.002},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-06 12:00:00"},{"dt":1420556400,"main":{"temp":1.4,"temp_min":0.41,"temp_max":1.4,"pressure":1010.83,"sea_level":1032.77,"grnd_level":1010.83,"humidity":73,"temp_kf":0.55},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":36},"wind":{"speed":9.66,"deg":357.007},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-06 15:00:00"},{"dt":1420567200,"main":{"temp":0.91,"temp_min":-0,"temp_max":0.91,"pressure":1009.27,"sea_level":1031.39,"grnd_level":1009.27,"humidity":75,"temp_kf":0.51},"weather":[{"id":601,"main":"Snow","description":"snow","icon":"13n"}],"clouds":{"all":12},"wind":{"speed":9.44,"deg":5.50281},"snow":{"3h":4.25},"sys":{"pod":"n"},"dt_txt":"2015-01-06 18:00:00"},{"dt":1420578000,"main":{"temp":-5.49,"temp_min":-6.33,"temp_max":-5.49,"pressure":1011.68,"sea_level":1033.87,"grnd_level":1011.68,"humidity":72,"temp_kf":0.47},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":32},"wind":{"speed":9.57,"deg":358.501},"snow":{"3h":0.25},"sys":{"pod":"n"},"dt_txt":"2015-01-06 21:00:00"},{"dt":1420588800,"main":{"temp":-6.54,"temp_min":-7.29,"temp_max":-6.54,"pressure":1013.5,"sea_level":1035.87,"grnd_level":1013.5,"humidity":76,"temp_kf":0.42},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":32},"wind":{"speed":9.01,"deg":355.003},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-07 00:00:00"},{"dt":1420599600,"main":{"temp":-5.98,"temp_min":-6.67,"temp_max":-5.98,"pressure":1013.84,"sea_level":1036.3,"grnd_level":1013.84,"humidity":74,"temp_kf":0.38},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":32},"wind":{"speed":8.99,"deg":350.001},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-07 03:00:00"},{"dt":1420610400,"main":{"temp":-7.01,"temp_min":-7.62,"temp_max":-7.01,"pressure":1014.71,"sea_level":1037.15,"grnd_level":1014.71,"humidity":77,"temp_kf":0.34},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":8.45,"deg":348.003},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-07 06:00:00"},{"dt":1420621200,"main":{"temp":-3.37,"temp_min":-3.9,"temp_max":-3.37,"pressure":1015.43,"sea_level":1037.8,"grnd_level":1015.43,"humidity":78,"temp_kf":0.3},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":36},"wind":{"speed":7.71,"deg":346.003},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-07 09:00:00"},{"dt":1420632000,"main":{"temp":-1.21,"temp_min":-1.66,"temp_max":-1.21,"pressure":1015.78,"sea_level":1038.12,"grnd_level":1015.78,"humidity":81,"temp_kf":0.25},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":20},"wind":{"speed":9.09,"deg":354.002},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-07 12:00:00"},{"dt":1420642800,"main":{"temp":-5.15,"temp_min":-5.54,"temp_max":-5.15,"pressure":1017.37,"sea_level":1039.83,"grnd_level":1017.37,"humidity":70,"temp_kf":0.21},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":9.42,"deg":357.5},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-07 15:00:00"},{"dt":1420653600,"main":{"temp":-6.11,"temp_min":-6.41,"temp_max":-6.11,"pressure":1017.52,"sea_level":1040.07,"grnd_level":1017.52,"humidity":73,"temp_kf":0.17},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"clouds":{"all":24},"wind":{"speed":7.47,"deg":343.006},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-07 18:00:00"},{"dt":1420664400,"main":{"temp":0.99,"temp_min":0.76,"temp_max":0.99,"pressure":1016.68,"sea_level":1039.32,"grnd_level":1016.68,"humidity":73,"temp_kf":0.13},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":76},"wind":{"speed":8.45,"deg":324.502},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-07 21:00:00"},{"dt":1420675200,"main":{"temp":5.38,"temp_min":5.22,"temp_max":5.38,"pressure":1017.14,"sea_level":1039.61,"grnd_level":1017.14,"humidity":84,"temp_kf":0.08},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":56},"wind":{"speed":9.55,"deg":357.004},"snow":{"3h":0.5},"sys":{"pod":"n"},"dt_txt":"2015-01-08 00:00:00"},{"dt":1420686000,"main":{"temp":6.58,"temp_min":6.51,"temp_max":6.58,"pressure":1017.9,"sea_level":1040.5,"grnd_level":1017.9,"humidity":80,"temp_kf":0.04},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":56},"wind":{"speed":8.55,"deg":357.004},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-08 03:00:00"},{"dt":1420696800,"main":{"temp":6.33,"temp_min":6.33,"temp_max":6.33,"pressure":1018.96,"sea_level":1041.65,"grnd_level":1018.96,"humidity":80},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":56},"wind":{"speed":7.56,"deg":346.002},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-08 06:00:00"},{"dt":1420707600,"main":{"temp":7.62,"temp_min":7.62,"temp_max":7.62,"pressure":1019.6,"sea_level":1042,"grnd_level":1019.6,"humidity":83},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":56},"wind":{"speed":6.18,"deg":332.002},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-08 09:00:00"},{"dt":1420718400,"main":{"temp":7.71,"temp_min":7.71,"temp_max":7.71,"pressure":1019.69,"sea_level":1041.96,"grnd_level":1019.69,"humidity":83},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"clouds":{"all":24},"wind":{"speed":5.34,"deg":317.501},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-08 12:00:00"},{"dt":1420729200,"main":{"temp":-3.26,"temp_min":-3.26,"temp_max":-3.26,"pressure":1019.96,"sea_level":1042.48,"grnd_level":1019.96,"humidity":76},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":5.51,"deg":289.5},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-08 15:00:00"},{"dt":1420740000,"main":{"temp":-13.44,"temp_min":-13.44,"temp_max":-13.44,"pressure":1018.71,"sea_level":1041.36,"grnd_level":1018.71,"humidity":53},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"01n"}],"clouds":{"all":0},"wind":{"speed":2.59,"deg":220},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-08 18:00:00"},{"dt":1420750800,"main":{"temp":-15.93,"temp_min":-15.93,"temp_max":-15.93,"pressure":1016.88,"sea_level":1039.46,"grnd_level":1016.88,"humidity":47},"weather":[{"id":800,"main":"Clear","description":"sky is clear","icon":"02n"}],"clouds":{"all":8},"wind":{"speed":3.39,"deg":200.501},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-08 21:00:00"},{"dt":1420761600,"main":{"temp":-3.53,"temp_min":-3.53,"temp_max":-3.53,"pressure":1014.54,"sea_level":1036.97,"grnd_level":1014.54,"humidity":76},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":36},"wind":{"speed":7.67,"deg":212.501},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-09 00:00:00"},{"dt":1420772400,"main":{"temp":2.29,"temp_min":2.29,"temp_max":2.29,"pressure":1011.28,"sea_level":1033.34,"grnd_level":1011.28,"humidity":77},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":64},"wind":{"speed":9.31,"deg":202.001},"snow":{"3h":0},"sys":{"pod":"n"},"dt_txt":"2015-01-09 03:00:00"},{"dt":1420783200,"main":{"temp":6,"temp_min":6,"temp_max":6,"pressure":1006.93,"sea_level":1028.77,"grnd_level":1006.93,"humidity":81},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":76},"wind":{"speed":12.14,"deg":192.5},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-09 06:00:00"},{"dt":1420794000,"main":{"temp":10.12,"temp_min":10.12,"temp_max":10.12,"pressure":1002.51,"sea_level":1024.04,"grnd_level":1002.51,"humidity":80},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":76},"wind":{"speed":14.93,"deg":189.501},"snow":{"3h":0},"sys":{"pod":"d"},"dt_txt":"2015-01-09 09:00:00"},{"dt":1420804800,"main":{"temp":12.25,"temp_min":12.25,"temp_max":12.25,"pressure":998.23,"sea_level":1019.56,"grnd_level":998.23,"humidity":85},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13d"}],"clouds":{"all":80},"wind":{"speed":16.46,"deg":191.501},"snow":{"3h":1.5},"sys":{"pod":"d"},"dt_txt":"2015-01-09 12:00:00"},{"dt":1420815600,"main":{"temp":12.47,"temp_min":12.47,"temp_max":12.47,"pressure":995.48,"sea_level":1016.81,"grnd_level":995.48,"humidity":83},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":88},"wind":{"speed":14.73,"deg":197.502},"snow":{"3h":1.5},"sys":{"pod":"n"},"dt_txt":"2015-01-09 15:00:00"},{"dt":1420826400,"main":{"temp":14.55,"temp_min":14.55,"temp_max":14.55,"pressure":992.32,"sea_level":1013.62,"grnd_level":992.32,"humidity":81},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":12.36,"deg":191.505},"snow":{"3h":0.5},"sys":{"pod":"n"},"dt_txt":"2015-01-09 18:00:00"},{"dt":1420837200,"main":{"temp":19.5,"temp_min":19.5,"temp_max":19.5,"pressure":990.29,"sea_level":1011.37,"grnd_level":990.29,"humidity":87},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":92},"wind":{"speed":8.88,"deg":193.501},"snow":{"3h":0.5},"sys":{"pod":"n"},"dt_txt":"2015-01-09 21:00:00"},{"dt":1420848000,"main":{"temp":26.74,"temp_min":26.74,"temp_max":26.74,"pressure":990.12,"sea_level":1011.03,"grnd_level":990.12,"humidity":90},"weather":[{"id":600,"main":"Snow","description":"light snow","icon":"13n"}],"clouds":{"all":80},"wind":{"speed":7.8,"deg":226.501},"snow":{"3h":0.5},"sys":{"pod":"n"},"dt_txt":"2015-01-10 00:00:00"}]}
43
+ http_version:
44
+ recorded_at: Mon, 05 Jan 2015 19:58:13 GMT
45
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,94 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe OpenWeatherMap::Weather do
4
+
5
+ describe "default attributes" do
6
+
7
+ it "must include httparty methods" do
8
+ OpenWeatherMap::Weather.must_include HTTParty
9
+ end
10
+
11
+ it "must have the base url set to the Open Weather Map api endpoint" do
12
+ OpenWeatherMap::Weather.base_uri.must_equal 'http://api.openweathermap.org/data/2.5'
13
+ end
14
+ end
15
+
16
+ describe 'location initializing methods' do
17
+
18
+ describe "#city" do
19
+
20
+ it "sets the name of the city" do
21
+ OpenWeatherMap::Weather.city("London").city.must_equal "London"
22
+ end
23
+
24
+ it "returns an instance of OpenWeatherMap::Weather class" do
25
+ OpenWeatherMap::Weather.city("London").must_be_instance_of OpenWeatherMap::Weather
26
+ end
27
+ end
28
+
29
+ describe "#city_id" do
30
+
31
+ it "sets the city id" do
32
+ OpenWeatherMap::Weather.city_id(12345).city_id.must_equal 12345
33
+ end
34
+
35
+ it "returns an instance of OpenWeatherMap::Weather class" do
36
+ OpenWeatherMap::Weather.city_id(12345).must_be_instance_of OpenWeatherMap::Weather
37
+ end
38
+ end
39
+
40
+ describe "#geolocate" do
41
+
42
+ it "sets the lat" do
43
+ OpenWeatherMap::Weather.geolocate(lat: 12.345, lng: 54.321).lat.must_equal 12.345
44
+ end
45
+
46
+ it "sets the lng" do
47
+ OpenWeatherMap::Weather.geolocate(lat: 12.345, lng: 54.321).lng.must_equal 54.321
48
+ end
49
+
50
+ it "returns an instance of OpenWeatherMap::Weather class" do
51
+ OpenWeatherMap::Weather.geolocate(lat: 12.345, lng: 54.321).must_be_instance_of OpenWeatherMap::Weather
52
+ end
53
+
54
+ it "accepts an object that responds to lat and lng" do
55
+ class LatLng
56
+ def lat
57
+ 12.345
58
+ end
59
+ def lng
60
+ 54.321
61
+ end
62
+ end
63
+
64
+ location = OpenWeatherMap::Weather.geolocate(LatLng.new)
65
+ location.lat.must_equal 12.345
66
+ location.lng.must_equal 54.321
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'forecast' do
72
+ let(:location) { OpenWeatherMap::Weather.city_id(524901) }
73
+
74
+ before do
75
+ VCR.insert_cassette 'forecast', :record => :new_episodes
76
+ end
77
+
78
+ after do
79
+ VCR.eject_cassette
80
+ end
81
+
82
+ it 'must have a forecast method' do
83
+ location.must_respond_to :forecast
84
+ end
85
+
86
+ it 'must parse the api froms from JSON to Hash' do
87
+ location.forecast.must_be_instance_of Hash
88
+ end
89
+
90
+ it 'must preform the request and get the data' do
91
+ location.forecast['city']['name'].must_equal 'Moscow'
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../lib/openweathermap'
2
+
3
+ require 'minitest/autorun'
4
+ require 'webmock/minitest'
5
+ require 'vcr'
6
+ require 'turn'
7
+
8
+ Turn.config do |c|
9
+ c.format = :outline
10
+ c.trace = true
11
+ c.natural = true
12
+ end
13
+
14
+ VCR.configure do |c|
15
+ c.cassette_library_dir = 'spec/fixtures/openweathermap_cassettes'
16
+ c.hook_into :webmock
17
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open-weather-map
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Peter Debelak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-05 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
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: vcr
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
+ - !ruby/object:Gem::Dependency
70
+ name: turn
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Gem to wrap http://openweathermap.org/api
98
+ email:
99
+ - pdebelak@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/openweathermap.rb
110
+ - lib/openweathermap/city_methods.rb
111
+ - lib/openweathermap/version.rb
112
+ - lib/openweathermap/weather.rb
113
+ - openweathermap.gemspec
114
+ - spec/fixtures/openweathermap_cassettes/forecast.yml
115
+ - spec/lib/weather_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Gem to wrap http://openweathermap.org/api
141
+ test_files:
142
+ - spec/fixtures/openweathermap_cassettes/forecast.yml
143
+ - spec/lib/weather_spec.rb
144
+ - spec/spec_helper.rb