Class: Cdss::Client

Inherits:
Object
  • Object
show all
Includes:
AdminCalls, Analysis, Climate, GroundWater, ReferenceTables, Structures, SurfaceWater, Telemetry, WaterRights, HTTParty
Defined in:
lib/cdss/client.rb

Overview

Main client class for interacting with the CDSS API.

The Client class provides access to all CDSS API endpoints and handles authentication, request configuration, and response processing.

Examples:

Create a new client

client = Cdss::Client.new(api_key: "your-api-key")
client.get_climate_stations(county: "Denver")

Constant Summary

Constants included from ReferenceTables

ReferenceTables::VALID_TABLES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReferenceTables

#get_reference_table

Methods included from Utils

#batch_dates, #build_query, #fetch_paginated_data, #format_date, #format_query_param, #parse_timestamp, #safe_float, #safe_integer

Methods included from WaterRights

#get_water_rights_net_amounts, #get_water_rights_transactions

Methods included from Telemetry

#get_telemetry_stations, #get_telemetry_ts

Methods included from SurfaceWater

#get_sw_stations, #get_sw_ts

Methods included from Structures

#get_diversion_records_ts, #get_stage_volume_ts, #get_structures, #get_water_classes

Methods included from GroundWater

#get_geophysical_log_picks, #get_geophysical_log_wells, #get_water_level_wells, #get_well_measurements

Methods included from Climate

#get_climate_frost_dates, #get_climate_stations, #get_climate_ts, #get_climate_ts_day, #get_climate_ts_month

Methods included from Analysis

#get_call_analysis_gnisid, #get_call_analysis_wdid, #get_source_route_analysis, #get_source_route_framework

Methods included from AdminCalls

#get_admin_calls

Constructor Details

#initialize(api_key: nil, **options) ⇒ Client

Initialize a new CDSS API client.

Parameters:

  • api_key (String, nil) (defaults to: nil)

    API key for authentication

  • options (Hash)

    Additional options for configuring the client



38
39
40
41
42
# File 'lib/cdss/client.rb', line 38

def initialize(api_key: nil, **options)
  @options = options
  @api_key = api_key
  setup_client
end

Instance Attribute Details

#api_keyString?

Returns API key for authentication.

Returns:

  • (String, nil)

    API key for authentication



31
32
33
# File 'lib/cdss/client.rb', line 31

def api_key
  @api_key
end

#optionsHash (readonly)

Returns Additional options passed to the client.

Returns:

  • (Hash)

    Additional options passed to the client



28
29
30
# File 'lib/cdss/client.rb', line 28

def options
  @options
end

Class Method Details

.debug_request(endpoint, options) ⇒ void

This method returns an undefined value.

Logs detailed request information when debug mode is enabled.

Parameters:

  • endpoint (String)

    The API endpoint being called

  • options (Hash)

    Request options including query parameters and headers



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cdss/client.rb', line 104

def self.debug_request(endpoint, options)
  return unless Cdss.config.debug

  query_string = options[:query]&.map { |k, v| "#{k}=#{v}" }&.join("&")
  full_url = [base_uri, endpoint].join
  full_url += "?#{query_string}" if query_string

  puts "\n=== CDSS API Request ==="
  puts "URL: #{full_url}"
  puts "\nHeaders:"
  headers = default_options[:headers] || {}
  headers.merge!(options[:headers] || {})
  headers.each do |key, value|
    puts "  #{key}: #{value}"
  end
  puts "=====================\n"
end

.get(*args) ⇒ HTTParty::Response

Makes GET requests with debug logging support.

Parameters:

  • args (Array)

    The request arguments including path and options

Returns:

  • (HTTParty::Response)

    The API response



82
83
84
85
86
# File 'lib/cdss/client.rb', line 82

def self.get(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  debug_request(args.first, options)
  super(*args, options)
end