forecastr 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/forecastr.rb +2 -0
- data/lib/forecastr/client.rb +23 -0
- data/lib/forecastr/data_container.rb +21 -0
- data/lib/forecastr/forecast.rb +11 -11
- data/lib/forecastr/radar.rb +7 -13
- data/lib/forecastr/temperature.rb +4 -0
- data/lib/forecastr/version.rb +1 -1
- data/lib/forecastr/wind.rb +9 -5
- data/spec/forecastr/client_spec.rb +22 -0
- data/spec/forecastr/data_container_spec.rb +20 -0
- data/spec/forecastr/forecast_spec.rb +3 -2
- data/spec/forecastr/wind_spec.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9575109a60c5803a952035bf13e04107dd25f17a
|
4
|
+
data.tar.gz: fec0d1971cfbd5755ed2476f6720503cac9a021c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaf155808d600eb46cdae85b1f36607f7e5295176d9e11d1cf897898bfd2540c889c8b4e5042ed9216c18331a52aa1abf6f4a12777be95de39296830467c8f90
|
7
|
+
data.tar.gz: 1f1af391d6dc84c8662eae0c0f89bc1d05220c63f8079d00e007bd37dc4ebbc341556b7c919dc885f8f7697fa3aaa59013e98e2063435c3c85d947099adeeb35
|
data/lib/forecastr.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Forecastr
|
5
|
+
class Client
|
6
|
+
API_URL = "http://api.openweathermap.org/data/2.5/weather?"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def search_by_city(city_name)
|
10
|
+
uri = URI(API_URL + "q=" + city_name)
|
11
|
+
json = JSON.parse(Net::HTTP.get(uri))
|
12
|
+
Forecastr::DataContainer.new(json)
|
13
|
+
end
|
14
|
+
|
15
|
+
def search_by_coordinates(lat, lon)
|
16
|
+
uri = URI(API_URL + "lat=#{lat}&lon=#{lon}")
|
17
|
+
json = JSON.parse(Net::HTTP.get(uri))
|
18
|
+
Forecastr::DataContainer.new(json)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Forecastr
|
2
|
+
class DataContainer
|
3
|
+
|
4
|
+
attr_reader :city, :longitude, :latitude, :pressure, :humidity, :clouds,
|
5
|
+
:temperature, :min_temperature, :max_temperature, :wind_speed, :wind_angle
|
6
|
+
|
7
|
+
def initialize(json)
|
8
|
+
@city = json['name']
|
9
|
+
@longitude = json['coord']['lon']
|
10
|
+
@latitude = json['coord']['lat']
|
11
|
+
@temperature = json['main']['temp']
|
12
|
+
@pressure = json['main']['pressure']
|
13
|
+
@humidity = json['main']['humidity']
|
14
|
+
@min_temperature = json['main']['temp_min']
|
15
|
+
@max_temperature = json['main']['temp_max']
|
16
|
+
@clouds = json['clouds']['all']
|
17
|
+
@wind_speed = json['wind']['speed']
|
18
|
+
@wind_angle = json['wind']['deg']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/forecastr/forecast.rb
CHANGED
@@ -5,17 +5,17 @@ module Forecastr
|
|
5
5
|
:pressure, :humidity, :min_temperature,
|
6
6
|
:max_temperature, :clouds, :wind
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@city =
|
10
|
-
@longitude =
|
11
|
-
@latitude =
|
12
|
-
@temperature = Forecastr::Temperature.new(
|
13
|
-
@pressure =
|
14
|
-
@humidity =
|
15
|
-
@min_temperature = Forecastr::Temperature.new(
|
16
|
-
@max_temperature = Forecastr::Temperature.new(
|
17
|
-
@clouds =
|
18
|
-
@wind = Forecastr::Wind.new(
|
8
|
+
def initialize(data)
|
9
|
+
@city = data.city
|
10
|
+
@longitude = data.longitude
|
11
|
+
@latitude = data.latitude
|
12
|
+
@temperature = Forecastr::Temperature.new(data.temperature)
|
13
|
+
@pressure = data.pressure
|
14
|
+
@humidity = data.humidity
|
15
|
+
@min_temperature = Forecastr::Temperature.new(data.min_temperature)
|
16
|
+
@max_temperature = Forecastr::Temperature.new(data.max_temperature)
|
17
|
+
@clouds = data.clouds
|
18
|
+
@wind = Forecastr::Wind.new(data.wind_speed, data.wind_angle)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/lib/forecastr/radar.rb
CHANGED
@@ -3,30 +3,24 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Forecastr
|
5
5
|
class Radar
|
6
|
-
API_URL = "http://api.openweathermap.org/data/2.5/weather?"
|
7
|
-
|
8
6
|
class << self
|
9
7
|
def find_by_city(city_name)
|
10
|
-
|
11
|
-
radar.find_by_city(city_name)
|
8
|
+
new.find_by_city(city_name)
|
12
9
|
end
|
13
10
|
|
14
11
|
def find_by_coordinates(lat, lon)
|
15
|
-
|
16
|
-
radar.find_by_coordinates(lat, lon)
|
12
|
+
new.find_by_coordinates(lat, lon)
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
20
|
-
def find_by_city(
|
21
|
-
|
22
|
-
|
23
|
-
Forecastr::Forecast.new(@json)
|
16
|
+
def find_by_city(name)
|
17
|
+
data = Forecastr::Client.search_by_city(name)
|
18
|
+
Forecastr::Forecast.new(data)
|
24
19
|
end
|
25
20
|
|
26
21
|
def find_by_coordinates(lat, lon)
|
27
|
-
|
28
|
-
|
29
|
-
Forecastr::Forecast.new(@json)
|
22
|
+
data = Forecastr::Client.search_by_coordinates(lat, lon)
|
23
|
+
Forecastr::Forecast.new(data)
|
30
24
|
end
|
31
25
|
|
32
26
|
end
|
data/lib/forecastr/version.rb
CHANGED
data/lib/forecastr/wind.rb
CHANGED
@@ -4,18 +4,22 @@ module Forecastr
|
|
4
4
|
|
5
5
|
attr_reader :speed, :direction
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(speed, angle)
|
8
|
+
@speed = speed
|
9
|
+
@angle = angle
|
9
10
|
end
|
10
11
|
|
11
12
|
def speed
|
12
|
-
"#{@
|
13
|
+
"#{@speed} m/s"
|
13
14
|
end
|
14
15
|
|
15
16
|
def direction
|
16
|
-
|
17
|
-
val = ((degrees/22.5) + 0.5).to_i
|
17
|
+
val = ((@angle/22.5) + 0.5).to_i
|
18
18
|
DIRECTIONS[val % 16]
|
19
19
|
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"#{speed} #{direction}"
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forecastr::Client do
|
4
|
+
describe '#search_by_city' do
|
5
|
+
it 'gets data from API for city' do
|
6
|
+
stub_get("http://api.openweathermap.org/data/2.5/weather?q=London,UK").to_return(:body => fixture('london.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
7
|
+
results = Forecastr::Client.search_by_city('London,UK')
|
8
|
+
|
9
|
+
expect(results.city).to eq "London"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#search_by_coordinates' do
|
14
|
+
it 'gets data from API by coordinates' do
|
15
|
+
stub_get("http://api.openweathermap.org/data/2.5/weather?lat=42.0&lon=21.4333").to_return(:body => fixture('skopje.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
|
16
|
+
results = Forecastr::Client.search_by_coordinates(42.0, 21.4333)
|
17
|
+
|
18
|
+
expect(results.city).to eq "Opština Karpoš"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Forecastr::DataContainer do
|
4
|
+
let(:json) { JSON.parse(fixture('skopje.json').read) }
|
5
|
+
let(:container) { Forecastr::DataContainer.new(json) }
|
6
|
+
|
7
|
+
it 'contains json results' do
|
8
|
+
expect(container.city).to eq "Opština Karpoš"
|
9
|
+
expect(container.longitude).to eq 21.43
|
10
|
+
expect(container.latitude).to eq 42
|
11
|
+
expect(container.temperature).to eq 283.85
|
12
|
+
expect(container.pressure).to eq 1021
|
13
|
+
expect(container.humidity).to eq 70
|
14
|
+
expect(container.min_temperature).to eq 280.15
|
15
|
+
expect(container.max_temperature).to eq 285.93
|
16
|
+
expect(container.clouds).to eq 0
|
17
|
+
expect(container.wind_speed).to eq 1.16
|
18
|
+
expect(container.wind_angle).to eq 128.501
|
19
|
+
end
|
20
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Forecastr::Forecast do
|
4
4
|
let(:json) { JSON.parse(fixture('data.json').read) }
|
5
|
-
let(:
|
5
|
+
let(:data) { Forecastr::DataContainer.new(json) }
|
6
|
+
let(:forecast) { Forecastr::Forecast.new(data) }
|
6
7
|
|
7
8
|
it 'has a city' do
|
8
9
|
expect(forecast.city).to eq "Benghazi"
|
data/spec/forecastr/wind_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forecastr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ile Eftimov
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- forecastr.gemspec
|
82
82
|
- lib/forecastr.rb
|
83
|
+
- lib/forecastr/client.rb
|
84
|
+
- lib/forecastr/data_container.rb
|
83
85
|
- lib/forecastr/forecast.rb
|
84
86
|
- lib/forecastr/radar.rb
|
85
87
|
- lib/forecastr/temperature.rb
|
@@ -88,6 +90,8 @@ files:
|
|
88
90
|
- spec/fixtures/data.json
|
89
91
|
- spec/fixtures/london.json
|
90
92
|
- spec/fixtures/skopje.json
|
93
|
+
- spec/forecastr/client_spec.rb
|
94
|
+
- spec/forecastr/data_container_spec.rb
|
91
95
|
- spec/forecastr/forecast_spec.rb
|
92
96
|
- spec/forecastr/radar_spec.rb
|
93
97
|
- spec/forecastr/temperature_spec.rb
|
@@ -121,6 +125,8 @@ test_files:
|
|
121
125
|
- spec/fixtures/data.json
|
122
126
|
- spec/fixtures/london.json
|
123
127
|
- spec/fixtures/skopje.json
|
128
|
+
- spec/forecastr/client_spec.rb
|
129
|
+
- spec/forecastr/data_container_spec.rb
|
124
130
|
- spec/forecastr/forecast_spec.rb
|
125
131
|
- spec/forecastr/radar_spec.rb
|
126
132
|
- spec/forecastr/temperature_spec.rb
|