Class: SmoScottishLidar::Client
- Inherits:
-
Object
- Object
- SmoScottishLidar::Client
- Defined in:
- lib/smo_scottish_lidar/client.rb
Overview
Low-level S3 client. Uses only Ruby stdlib net/http. Accesses the public (unsigned) srsp-open-data bucket directly over HTTPS.
Constant Summary collapse
- MAX_KEYS =
1000
Instance Method Summary collapse
-
#download_object(key, local_path, &progress_block) ⇒ Object
Downloads a single S3 object key to a local file path.
-
#initialize(verbose: false) ⇒ Client
constructor
A new instance of Client.
-
#list_objects(prefix) ⇒ Object
Lists all object keys under a given S3 prefix.
Constructor Details
#initialize(verbose: false) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/smo_scottish_lidar/client.rb', line 12 def initialize(verbose: false) @verbose = verbose end |
Instance Method Details
#download_object(key, local_path, &progress_block) ⇒ Object
Downloads a single S3 object key to a local file path. Follows redirects, streams in chunks to avoid loading into memory. Returns true on success, raises on error.
39 40 41 42 43 44 45 46 |
# File 'lib/smo_scottish_lidar/client.rb', line 39 def download_object(key, local_path, &progress_block) url = "#{BASE_URL}/#{key}" log "Downloading: #{url} -> #{local_path}" uri = URI.parse(url) fetch_with_redirect(uri, local_path, &progress_block) true end |
#list_objects(prefix) ⇒ Object
Lists all object keys under a given S3 prefix. Handles S3 pagination (continuation tokens) automatically. Returns an Array of Hashes: [{ key:, size:, last_modified: }, …]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/smo_scottish_lidar/client.rb', line 19 def list_objects(prefix) objects = [] continuation_token = nil loop do xml = fetch_list_page(prefix, continuation_token) page_objects, next_token, truncated = parse_list_response(xml) objects.concat(page_objects) break unless truncated continuation_token = next_token end objects end |