class APIWrapper
Constants
- DATUM
- DAYS
- EKEY
- INPUTS
From what I can tell, the ekey is ekey is verified against the cookie
- SESSION
Attributes
res[R]
Public Class Methods
new(lat:, lon:)
click to toggle source
# File lib/world_tides/api_wrapper.rb, line 26 def initialize(lat:, lon:) @lat = lat @lon = lon @res = make_request raise "Failed with #{@res['status']}" unless @res['status'] == 200 end
Public Instance Methods
highs_and_lows()
click to toggle source
# File lib/world_tides/api_wrapper.rb, line 33 def highs_and_lows @highs_and_lows ||= begin @res['extremes'].map do |record| { date: record['date'].to_time.to_s(:short), type: record['type'].downcase, height: record['height'] } end end end
highs_and_lows_csv(output_file)
click to toggle source
# File lib/world_tides/api_wrapper.rb, line 45 def highs_and_lows_csv(output_file) File.open("#{output_file}.csv", 'w') do |f| f << CSV.generate do |csv| csv << highs_and_lows.first.keys highs_and_lows.each { |h_a_l| csv << h_a_l.values } end end end
Private Instance Methods
headers()
click to toggle source
# File lib/world_tides/api_wrapper.rb, line 74 def headers { 'Cookie' => CookieHash.new.add_cookies( { WorldTidesInfoSession: SESSION } ).to_cookie_string } end
make_request()
click to toggle source
# File lib/world_tides/api_wrapper.rb, line 56 def make_request self.class.get('/api', query: query, headers: headers) end
query()
click to toggle source
# File lib/world_tides/api_wrapper.rb, line 60 def query { datum: DATUM, extremes: true, start: DAYS.days.ago.to_i, length: DAYS.days, step: 1800, lat: lat, lon: lon, stationDistance: 100, ekey: EKEY.strip } end