Class: OpenTopo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/open_topo/client.rb

Constant Summary collapse

API_KEY_NAME =
"OPEN_TOPOGRAPHY_API_KEY"

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/open_topo/client.rb', line 7

def initialize(api_key = nil)
  api_key ||= ENV.fetch(API_KEY_NAME)
  @request = Net::Request.new(api_key)
end

Instance Method Details

#catalog(west: nil, south: nil, east: nil, north: nil, polygon: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/open_topo/client.rb', line 51

def catalog(west: nil, south: nil, east: nil, north: nil, polygon: nil)
  params = Net::Params::CatalogParams.new(west:, south:, east:, north:, polygon:)
  params.validate!

  response = request.catalog(params)

  if response.success?
    Services::ResponseToCatalogListConverter.call(response.body)
  else
    raise ::OpenTopo::Errors::ResponseError, response.body
  end
end

#elevation(long:, lat:, dataset: :srtmgl3) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/open_topo/client.rb', line 38

def elevation(long:, lat:, dataset: :srtmgl3)
  params = Net::Params::ElevationParams.new(long:, lat:, dataset:)
  params.validate!

  response = request.elevation(params)

  if response.success?
    Services::ResponseToPointConverter.call(response)
  else
    raise ::OpenTopo::Errors::ResponseError, response.body
  end
end

#globaldem(south:, north:, west:, east:, demtype: :srtmgl3, output_format: :tif) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/open_topo/client.rb', line 12

def globaldem(south:, north:, west:, east:, demtype: :srtmgl3, output_format: :tif)
  params = Net::Params::GlobaldemParams.new(south:, north:, west:, east:, demtype:, output_format:)
  params.validate!

  response = request.globaldem(params)

  if response.success?
    Services::ResponseToDemConverter.call(response, dem_type: demtype, output_format:)
  else
    raise ::OpenTopo::Errors::ResponseError, response.body
  end
end

#usgsdem(south:, north:, west:, east:, dataset_name: :usgs10m, output_format: :tif) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/open_topo/client.rb', line 25

def usgsdem(south:, north:, west:, east:, dataset_name: :usgs10m, output_format: :tif)
  params = Net::Params::UsgsdemParams.new(south:, north:, west:, east:, dataset_name:, output_format:)
  params.validate!

  response = request.usgsdem(params)

  if response.success?
    Services::ResponseToDemConverter.call(response, dem_type: dataset_name, output_format:)
  else
    raise ::OpenTopo::Errors::ResponseError, response.body
  end
end