Class: Stormglass::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/stormglass/response.rb

Overview

Responses from Stormglass API are wrapped in this class

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Response

Returns a new instance of Response.



10
11
12
# File 'lib/stormglass/response.rb', line 10

def initialize(src)
  @src = JSON.parse(src)
end

Instance Method Details

#find(string) ⇒ Object

takes a string like “7PM EST” and returns the relevant hour if found



41
42
43
# File 'lib/stormglass/response.rb', line 41

def find(string)
  hours.find{|h| h.time == Time.parse(string)}
end

#firstObject



32
33
34
# File 'lib/stormglass/response.rb', line 32

def first
  hours.first
end

#hoursObject

an array of Stormglass::Hour instances



15
16
17
18
19
20
# File 'lib/stormglass/response.rb', line 15

def hours
  @hours ||= []
  return @hours if !@hours.empty?
  src['hours'].each{|h| @hours << Stormglass::Hour.new(h) }
  @hours
end

#inspectObject



26
27
28
29
30
# File 'lib/stormglass/response.rb', line 26

def inspect
  string = '#<' + "#{self.class.to_s} remaining_requests=#{remaining_requests}, "
  string +="hours=#{hours.to_s}> "
  string
end

#lastObject



36
37
38
# File 'lib/stormglass/response.rb', line 36

def last
  hours.last
end

#metaObject



45
46
47
# File 'lib/stormglass/response.rb', line 45

def meta
  src['meta']
end

#remaining_requestsObject



49
50
51
# File 'lib/stormglass/response.rb', line 49

def remaining_requests
   meta['dailyQuota'] - meta['requestCount']
end

#srcObject



22
23
24
# File 'lib/stormglass/response.rb', line 22

def src
  @src
end