Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/tenkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'tenkit/config'
require_relative 'tenkit/version'
require_relative 'tenkit/weather'
require_relative 'tenkit/weather_alert'
require_relative 'tenkit/tenkit_error'

module Tenkit
Expand Down
7 changes: 4 additions & 3 deletions lib/tenkit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'openssl'
require 'httparty'
require_relative './weather_response'
require_relative './weather_alert_response'

module Tenkit
class Client
Expand Down Expand Up @@ -35,9 +36,9 @@ def weather(lat, lon, data_sets: [:current_weather], language: 'en')
end

def weather_alert(id, language: 'en')
puts 'TODO: implement weather alert endpoint'
puts language
puts id
path = "/weatherAlert/#{language}/#{id}"
response = get(path)
WeatherAlertResponse.new(response)
end

private
Expand Down
24 changes: 23 additions & 1 deletion lib/tenkit/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Tenkit
class Container
def initialize(contents)
return if contents.nil? || !contents.is_a?(Hash)
return unless contents.is_a?(Hash)

contents.each do |key, val|
name = Tenkit::Utils.snake(key)
Expand All @@ -13,6 +13,12 @@ def initialize(contents)
val.map { |e| DayWeatherConditions.new(e) }
elsif key == "hours"
val.map { |e| HourWeatherConditions.new(e) }
elsif key == "features"
val.map { |e| Feature.new(e) }
elsif key == "messages"
val.map { |e| Message.new(e) }
elsif key == "coordinates"
Coordinates.new(val)
else
val.map { |e| Container.new(e) }
end
Expand All @@ -25,6 +31,10 @@ def initialize(contents)
OvernightForecast.new(val)
elsif key == "restOfDayForecast"
RestOfDayForecast.new(val)
elsif key == "area"
Area.new(val)
elsif key == "geometry"
Geometry.new(val)
else
Container.new(val)
end
Expand All @@ -40,8 +50,16 @@ class HourlyForecast < Container; end

class DailyForecast < Container; end

class WeatherAlertSummary < Container; end

class HourWeatherConditions < Container; end

class Feature < Container; end

class Message < Container; end

class Coordinates < Array; end

class DayWeatherConditions < Container; end

class Metadata < Container; end
Expand All @@ -51,4 +69,8 @@ class DaytimeForecast < Container; end
class OvernightForecast < Container; end

class RestOfDayForecast < Container; end

class Area < Container; end

class Geometry < Container; end
end
10 changes: 10 additions & 0 deletions lib/tenkit/weather_alert.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Tenkit
class WeatherAlert
attr_reader :summary

def initialize(response)
parsed_response = JSON.parse(response.body)
@summary = WeatherAlertSummary.new(parsed_response)
end
end
end
2 changes: 0 additions & 2 deletions lib/tenkit/weather_alert_collection.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_relative './weather_alert_summary'

module Tenkit
class WeatherAlertCollection
attr_reader :alerts, :details_url
Expand Down
11 changes: 11 additions & 0 deletions lib/tenkit/weather_alert_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative "response"

module Tenkit
class WeatherAlertResponse < Response
attr_reader :weather_alert
def initialize(response)
super
@weather_alert = Tenkit::WeatherAlert.new(response)
end
end
end
39 changes: 0 additions & 39 deletions lib/tenkit/weather_alert_summary.rb

This file was deleted.

Loading