class STAC::Client
Client for interacting with the root of a STAC API.
Constants
- VERSION
Attributes
catalog[R]
STAC::Catalog instance of a STAC API landing page.
http_client[R]
Public Class Methods
from_url(url, params: {}, headers: {}, **http_options)
click to toggle source
Returns a Client
instance from STAC API landing page URL.
Raises STAC::TypeError when the fetched JSON from the given URL is not STAC Catalog.
# File lib/stac/client.rb, line 23 def from_url(url, params: {}, headers: {}, **http_options) http_client = HTTPClient.new(params: params, headers: headers, **http_options.merge(url: url)) obj = STAC.from_url(url, http_client: http_client) unless obj.instance_of?(Catalog) raise TypeError, "could not resolve fetched JSON into STAC::Catalog: #{obj.class}" end new(obj, http_client: http_client) end
new(catalog, http_client: HTTPClient.new)
click to toggle source
# File lib/stac/client.rb, line 41 def initialize(catalog, http_client: HTTPClient.new) @catalog = catalog @http_client = http_client end
Public Instance Methods
conformances()
click to toggle source
Returns the value of “conformsTo” field.
# File lib/stac/client.rb, line 47 def conformances catalog.extra.fetch('conformsTo', []) end
conforms_to?(conformance)
click to toggle source
Returns wether the API conforms to the given standard.
The argument should be a constant of Conformance
.
# File lib/stac/client.rb, line 54 def conforms_to?(conformance) conformances.any? { |c| conformance.match?(c) } end
search(**params)
click to toggle source
Queries the /search endpoint with the given parameters and returns ItemSearch
.
Raises NotImplementedError when the Catalog have no rel=“search” links.
# File lib/stac/client.rb, line 61 def search(**params) search_links = catalog.links.select do |link| link.rel == 'search' && link.type == 'application/geo+json' end raise NotImplementedError, 'catalog does not have rel="search" links' if search_links.empty? support_post = search_links.any? { |link| link.extra['method'] == 'POST' } ItemSearch.new( client: self, url: search_links.first.href, method: support_post ? 'POST' : 'GET', params: params, ).tap { |item_search| item_search.pages.first } end