stac 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +28 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +126 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +19 -0
- data/Steepfile +20 -0
- data/lib/stac/asset.rb +36 -0
- data/lib/stac/catalog.rb +69 -0
- data/lib/stac/collection.rb +66 -0
- data/lib/stac/default_http_client.rb +25 -0
- data/lib/stac/errors.rb +15 -0
- data/lib/stac/extent.rb +78 -0
- data/lib/stac/item.rb +85 -0
- data/lib/stac/link.rb +70 -0
- data/lib/stac/object_resolver.rb +66 -0
- data/lib/stac/properties.rb +33 -0
- data/lib/stac/provider.rb +35 -0
- data/lib/stac/spec_version.rb +5 -0
- data/lib/stac/stac_object.rb +92 -0
- data/lib/stac/version.rb +5 -0
- data/lib/stac.rb +25 -0
- data/sig/open-uri.rbs +8 -0
- data/sig/stac/asset.rbs +18 -0
- data/sig/stac/catalog.rbs +20 -0
- data/sig/stac/collection.rbs +29 -0
- data/sig/stac/default_http_client.rbs +9 -0
- data/sig/stac/errors.rbs +13 -0
- data/sig/stac/extent.rbs +35 -0
- data/sig/stac/item.rbs +27 -0
- data/sig/stac/link.rbs +24 -0
- data/sig/stac/object_resolver.rbs +28 -0
- data/sig/stac/properties.rbs +12 -0
- data/sig/stac/provider.rbs +15 -0
- data/sig/stac/spec_version.rbs +3 -0
- data/sig/stac/stac_object.rbs +28 -0
- data/sig/stac/version.rbs +3 -0
- data/sig/stac.rbs +5 -0
- data/stac.gemspec +42 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b7d893fbe52fe1413860d12610a933c957edc65baaa89a4e789b27c0547fd6b
|
4
|
+
data.tar.gz: fe1a6d7cb2cc0151d59cdd8885f2e412e8474d5e2f37e4cc5a61c7a2259dfa33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e7fa4e010e317a49dab6f67244e89b0bd4d4839fb19253946a8f1fc751dcc257856725901596afe3ede6a8106568847c6cb85e2ec5eb4330791bbc3a1f30cc1
|
7
|
+
data.tar.gz: 76ac97fe60ae5aeab13a65e4dfe7220b7fbe5501b7e3e582f4781b100605176284383177e7afd4a4e91c84645f286499996fe94202691c1ae969e75c09158340
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
NewCops: enable
|
8
|
+
|
9
|
+
Style/TrailingCommaInArguments:
|
10
|
+
EnforcedStyleForMultiline: consistent_comma
|
11
|
+
|
12
|
+
Style/TrailingCommaInArrayLiteral:
|
13
|
+
EnforcedStyleForMultiline: consistent_comma
|
14
|
+
|
15
|
+
Style/TrailingCommaInHashLiteral:
|
16
|
+
EnforcedStyleForMultiline: consistent_comma
|
17
|
+
|
18
|
+
Metrics:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
RSpec/DescribedClass:
|
22
|
+
EnforcedStyle: explicit
|
23
|
+
|
24
|
+
RSpec/ExampleLength:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
RSpec/MultipleExpectations:
|
28
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at takahiro-miyoshi@sankichi.net. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in stac.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'debug'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rbs'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop'
|
13
|
+
gem 'rubocop-rake'
|
14
|
+
gem 'rubocop-rspec'
|
15
|
+
gem 'ruby-lsp'
|
16
|
+
gem 'steep'
|
17
|
+
gem 'webmock'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
stac (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (7.0.4)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
14
|
+
addressable (2.8.1)
|
15
|
+
public_suffix (>= 2.0.2, < 6.0)
|
16
|
+
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.1.10)
|
18
|
+
crack (0.4.5)
|
19
|
+
rexml
|
20
|
+
debug (1.6.2)
|
21
|
+
irb (>= 1.3.6)
|
22
|
+
reline (>= 0.3.1)
|
23
|
+
diff-lcs (1.5.0)
|
24
|
+
ffi (1.15.5)
|
25
|
+
hashdiff (1.0.1)
|
26
|
+
i18n (1.12.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
io-console (0.5.11)
|
29
|
+
irb (1.4.2)
|
30
|
+
reline (>= 0.3.0)
|
31
|
+
json (2.6.2)
|
32
|
+
language_server-protocol (3.17.0.1)
|
33
|
+
listen (3.7.1)
|
34
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
35
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
36
|
+
minitest (5.16.3)
|
37
|
+
parallel (1.22.1)
|
38
|
+
parser (3.1.2.1)
|
39
|
+
ast (~> 2.4.1)
|
40
|
+
prettier_print (0.1.0)
|
41
|
+
public_suffix (5.0.0)
|
42
|
+
rainbow (3.1.1)
|
43
|
+
rake (13.0.6)
|
44
|
+
rb-fsevent (0.11.2)
|
45
|
+
rb-inotify (0.10.1)
|
46
|
+
ffi (~> 1.0)
|
47
|
+
rbs (2.6.0)
|
48
|
+
regexp_parser (2.6.0)
|
49
|
+
reline (0.3.1)
|
50
|
+
io-console (~> 0.5)
|
51
|
+
rexml (3.2.5)
|
52
|
+
rspec (3.11.0)
|
53
|
+
rspec-core (~> 3.11.0)
|
54
|
+
rspec-expectations (~> 3.11.0)
|
55
|
+
rspec-mocks (~> 3.11.0)
|
56
|
+
rspec-core (3.11.0)
|
57
|
+
rspec-support (~> 3.11.0)
|
58
|
+
rspec-expectations (3.11.1)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.11.0)
|
61
|
+
rspec-mocks (3.11.1)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.11.0)
|
64
|
+
rspec-support (3.11.1)
|
65
|
+
rubocop (1.36.0)
|
66
|
+
json (~> 2.3)
|
67
|
+
parallel (~> 1.10)
|
68
|
+
parser (>= 3.1.2.1)
|
69
|
+
rainbow (>= 2.2.2, < 4.0)
|
70
|
+
regexp_parser (>= 1.8, < 3.0)
|
71
|
+
rexml (>= 3.2.5, < 4.0)
|
72
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
73
|
+
ruby-progressbar (~> 1.7)
|
74
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
75
|
+
rubocop-ast (1.21.0)
|
76
|
+
parser (>= 3.1.1.0)
|
77
|
+
rubocop-rake (0.6.0)
|
78
|
+
rubocop (~> 1.0)
|
79
|
+
rubocop-rspec (2.13.2)
|
80
|
+
rubocop (~> 1.33)
|
81
|
+
ruby-lsp (0.3.3)
|
82
|
+
language_server-protocol (~> 3.17.0)
|
83
|
+
sorbet-runtime
|
84
|
+
syntax_tree (>= 3.4)
|
85
|
+
ruby-progressbar (1.11.0)
|
86
|
+
sorbet-runtime (0.5.10479)
|
87
|
+
steep (1.1.1)
|
88
|
+
activesupport (>= 5.1)
|
89
|
+
language_server-protocol (>= 3.15, < 4.0)
|
90
|
+
listen (~> 3.0)
|
91
|
+
parallel (>= 1.0.0)
|
92
|
+
parser (>= 3.1)
|
93
|
+
rainbow (>= 2.2.2, < 4.0)
|
94
|
+
rbs (>= 2.3.2)
|
95
|
+
terminal-table (>= 2, < 4)
|
96
|
+
syntax_tree (3.6.2)
|
97
|
+
prettier_print
|
98
|
+
terminal-table (3.0.2)
|
99
|
+
unicode-display_width (>= 1.1.1, < 3)
|
100
|
+
tzinfo (2.0.5)
|
101
|
+
concurrent-ruby (~> 1.0)
|
102
|
+
unicode-display_width (2.3.0)
|
103
|
+
webmock (3.18.1)
|
104
|
+
addressable (>= 2.8.0)
|
105
|
+
crack (>= 0.3.2)
|
106
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
107
|
+
|
108
|
+
PLATFORMS
|
109
|
+
x86_64-darwin-21
|
110
|
+
x86_64-linux
|
111
|
+
|
112
|
+
DEPENDENCIES
|
113
|
+
debug
|
114
|
+
rake
|
115
|
+
rbs
|
116
|
+
rspec
|
117
|
+
rubocop
|
118
|
+
rubocop-rake
|
119
|
+
rubocop-rspec
|
120
|
+
ruby-lsp
|
121
|
+
stac!
|
122
|
+
steep
|
123
|
+
webmock
|
124
|
+
|
125
|
+
BUNDLED WITH
|
126
|
+
2.3.22
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Takahiro Miyoshi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# stac-ruby
|
2
|
+
|
3
|
+
A Ruby library for working with [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/).
|
4
|
+
|
5
|
+
This gem's implementation refers to [pystac](https://github.com/stac-utils/pystac).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add stac
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install stac
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'stac'
|
21
|
+
|
22
|
+
# Reading a Catalog
|
23
|
+
# ================
|
24
|
+
|
25
|
+
# Read the example catalog.
|
26
|
+
catalog = STAC.from_url('https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/catalog.json')
|
27
|
+
|
28
|
+
# Print some basic metadata.
|
29
|
+
puts "ID: #{catalog.id}"
|
30
|
+
puts "Title: #{catalog.title}"
|
31
|
+
puts "Description: #{catalog.description}"
|
32
|
+
|
33
|
+
# Crawling Child Catalogs/Collections
|
34
|
+
# ================
|
35
|
+
|
36
|
+
# List Collections in the Catalog.
|
37
|
+
puts 'Collections IDs:'
|
38
|
+
catalog.collections.each do |collection|
|
39
|
+
puts "- #{collection.id}"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get a child Catalog or Collection by ID.
|
43
|
+
_collection = catalog.find_child('extensions-collection')
|
44
|
+
|
45
|
+
# Crawling Items
|
46
|
+
# ================
|
47
|
+
|
48
|
+
# List all items associated with the Catalog recursively.
|
49
|
+
puts 'Item IDs:'
|
50
|
+
catalog.all_items.each do |item|
|
51
|
+
puts "- #{item.id}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Item Metadata
|
55
|
+
# ================
|
56
|
+
|
57
|
+
# Get an Item by ID.
|
58
|
+
item = catalog.find_item('proj-example', recursive: true)
|
59
|
+
|
60
|
+
# Print core Item metadeata.
|
61
|
+
puts 'geometry:'
|
62
|
+
p item.geometry
|
63
|
+
puts 'bbox:'
|
64
|
+
p item.bbox
|
65
|
+
puts 'datetime:'
|
66
|
+
p item.datetime
|
67
|
+
puts 'collection_id:'
|
68
|
+
p item.collection_id
|
69
|
+
|
70
|
+
# Get actual Collection instance instead of ID.
|
71
|
+
_collection = item.collection
|
72
|
+
```
|
73
|
+
|
74
|
+
## Documentation
|
75
|
+
|
76
|
+
https://sankichi92.github.io/stac-ruby/
|
77
|
+
|
78
|
+
## Development
|
79
|
+
|
80
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
81
|
+
|
82
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sankichi92/stac-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sankichi92/stac-ruby/blob/main/CODE_OF_CONDUCT.md).
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
91
|
+
|
92
|
+
## Code of Conduct
|
93
|
+
|
94
|
+
Everyone interacting in the STAC Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sankichi92/stac/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
task default: %i[spec rubocop]
|
12
|
+
|
13
|
+
require 'rdoc/task'
|
14
|
+
RDoc::Task.new do |rdoc|
|
15
|
+
rdoc.rdoc_dir = 'doc'
|
16
|
+
rdoc.title = 'stac-ruby API docs'
|
17
|
+
rdoc.rdoc_files.include('README.md', 'CHANGELOG.md', 'lib/**/*.rb')
|
18
|
+
rdoc.main = 'README.md'
|
19
|
+
end
|
data/Steepfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
D = Steep::Diagnostic
|
4
|
+
|
5
|
+
target :lib do
|
6
|
+
signature 'sig'
|
7
|
+
|
8
|
+
check 'lib/**/*.rb'
|
9
|
+
|
10
|
+
# TODO: Add 'open-uri' and remove 'sig/open-uri.rbs' when 'open-uri' RBS is defined.
|
11
|
+
library 'json', 'pathname', 'time', 'uri'
|
12
|
+
|
13
|
+
configure_code_diagnostics do |hash|
|
14
|
+
hash[D::Ruby::ArgumentTypeMismatch] = :information
|
15
|
+
hash[D::Ruby::InsufficientKeywordArguments] = :hint
|
16
|
+
hash[D::Ruby::MethodBodyTypeMismatch] = :information
|
17
|
+
hash[D::Ruby::MethodDefinitionMissing] = nil # To supress noisy VS Code extension message.
|
18
|
+
hash[D::Ruby::UnsupportedSyntax] = :hint
|
19
|
+
end
|
20
|
+
end
|
data/lib/stac/asset.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module STAC
|
4
|
+
# Represents \STAC asset object, which contains a link to data associated with an Item or Collection that can be
|
5
|
+
# downloaded or streamed.
|
6
|
+
class Asset
|
7
|
+
class << self
|
8
|
+
# Deserializes an Asset from a Hash.
|
9
|
+
def from_hash(hash)
|
10
|
+
new(**hash.transform_keys(&:to_sym))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :href, :title, :description, :type, :roles, :extra
|
15
|
+
|
16
|
+
def initialize(href:, title: nil, description: nil, type: nil, roles: nil, **extra)
|
17
|
+
@href = href
|
18
|
+
@title = title
|
19
|
+
@description = description
|
20
|
+
@type = type
|
21
|
+
@roles = roles
|
22
|
+
@extra = extra.transform_keys(&:to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Serializes self to a Hash.
|
26
|
+
def to_h
|
27
|
+
{
|
28
|
+
'href' => href,
|
29
|
+
'title' => title,
|
30
|
+
'description' => description,
|
31
|
+
'type' => type,
|
32
|
+
'roles' => roles,
|
33
|
+
}.merge(extra).compact
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/stac/catalog.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'errors'
|
4
|
+
require_relative 'stac_object'
|
5
|
+
|
6
|
+
module STAC
|
7
|
+
# Represents \STAC catalog.
|
8
|
+
#
|
9
|
+
# \STAC \Catalog Specification: https://github.com/radiantearth/stac-spec/tree/master/catalog-spec
|
10
|
+
class Catalog < STAC::STACObject
|
11
|
+
self.type = 'Catalog'
|
12
|
+
|
13
|
+
attr_accessor :description, :title
|
14
|
+
|
15
|
+
def initialize(id:, description:, links:, title: nil, stac_extensions: nil, **extra)
|
16
|
+
super(id: id, links: links, stac_extensions: stac_extensions, **extra)
|
17
|
+
@description = description
|
18
|
+
@title = title
|
19
|
+
end
|
20
|
+
|
21
|
+
# Serializes self to a Hash.
|
22
|
+
def to_h
|
23
|
+
super.merge(
|
24
|
+
{
|
25
|
+
'title' => title,
|
26
|
+
'description' => description,
|
27
|
+
}.compact,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns catalog/collection objects from rel="child" links of this catalog.
|
32
|
+
def children
|
33
|
+
links.select { |link| link.rel == 'child' }.lazy.map(&:target)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Filters only collections from #children.
|
37
|
+
def collections
|
38
|
+
children.select { |child| child.type == 'Collection' }
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the child catalog/collection with the given ID if it exists.
|
42
|
+
#
|
43
|
+
# With option `recusive: true`, it will traverse all child catalogs/collections recursively.
|
44
|
+
def find_child(id, recursive: false)
|
45
|
+
targets = recursive ? children.chain(children.flat_map(&:children)) : children
|
46
|
+
targets.find { |child| child.id == id }
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns item objects from rel="item" links of this catalog.
|
50
|
+
def items
|
51
|
+
links.select { |link| link.rel == 'item' }.lazy.map(&:target)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns all items from this catalog and its child catalogs/collections recursively.
|
55
|
+
def all_items
|
56
|
+
# The last `.lazy` is not necessary with Ruby 3.1.
|
57
|
+
# But with Ruby 3.0, it is necessary because Enumerator::Lazy#chain returns Enumerator::Chain
|
58
|
+
# and RBS type check fails.
|
59
|
+
items.chain(children.flat_map(&:items)).lazy
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the item with the given ID if it exists.
|
63
|
+
#
|
64
|
+
# With option `recursive: true`, it will traverse all child catalogs/collections recursively.
|
65
|
+
def find_item(id, recursive: false)
|
66
|
+
(recursive ? all_items : items).find { |item| item.id == id }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'asset'
|
4
|
+
require_relative 'catalog'
|
5
|
+
require_relative 'extent'
|
6
|
+
require_relative 'provider'
|
7
|
+
|
8
|
+
module STAC
|
9
|
+
# Represents \STAC collection.
|
10
|
+
#
|
11
|
+
# \STAC \Collection Specification: https://github.com/radiantearth/stac-spec/tree/master/collection-spec
|
12
|
+
class Collection < Catalog
|
13
|
+
self.type = 'Collection'
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def from_hash(hash)
|
17
|
+
h = hash.dup
|
18
|
+
h['extent'] = Extent.from_hash(h.fetch('extent'))
|
19
|
+
h['providers'] = h['providers']&.map { |provider| Provider.from_hash(provider) }
|
20
|
+
h['assets'] = h['assets']&.transform_values { |v| Asset.from_hash(v) }
|
21
|
+
super(h)
|
22
|
+
rescue KeyError => e
|
23
|
+
raise ArgumentError, "required field not found: #{e.key}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_accessor :license, :extent, :keywords, :providers, :summaries, :assets
|
28
|
+
|
29
|
+
def initialize(
|
30
|
+
id:,
|
31
|
+
description:,
|
32
|
+
links:,
|
33
|
+
license:,
|
34
|
+
extent:,
|
35
|
+
title: nil,
|
36
|
+
keywords: nil,
|
37
|
+
providers: nil,
|
38
|
+
summaries: nil,
|
39
|
+
assets: nil,
|
40
|
+
stac_extensions: nil,
|
41
|
+
**extra
|
42
|
+
)
|
43
|
+
super(id: id, description: description, links: links, title: title, stac_extensions: stac_extensions, **extra)
|
44
|
+
@license = license
|
45
|
+
@extent = extent
|
46
|
+
@keywords = keywords
|
47
|
+
@providers = providers
|
48
|
+
@summaries = summaries
|
49
|
+
@assets = assets
|
50
|
+
end
|
51
|
+
|
52
|
+
# Serializes self to a Hash.
|
53
|
+
def to_h
|
54
|
+
super.merge(
|
55
|
+
{
|
56
|
+
'license' => license,
|
57
|
+
'keywords' => keywords,
|
58
|
+
'extent' => extent.to_h,
|
59
|
+
'providers' => providers&.map(&:to_h),
|
60
|
+
'summaries' => summaries,
|
61
|
+
'assets' => assets&.transform_values(&:to_h),
|
62
|
+
}.compact,
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require_relative 'errors'
|
5
|
+
require_relative 'version'
|
6
|
+
|
7
|
+
module STAC
|
8
|
+
# Simple HTTP Client using OpenURI.
|
9
|
+
class DefaultHTTPClient
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize(options = { 'User-Agent' => "stac-ruby v#{VERSION}" })
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
# Makes a HTTP request and returns the response body as String.
|
17
|
+
#
|
18
|
+
# Raises STAC::HTTPError when the response status is not 2XX.
|
19
|
+
def get(uri)
|
20
|
+
uri.read(options)
|
21
|
+
rescue OpenURI::HTTPError => e
|
22
|
+
raise HTTPError, e.message
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/stac/errors.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module STAC
|
4
|
+
# Base error class for this gem.
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
# Raised when unexpected "type" field was given.
|
8
|
+
class TypeError < Error; end
|
9
|
+
|
10
|
+
# Raised when URL with unsupported scheme was given.
|
11
|
+
class UnknownURISchemeError < Error; end
|
12
|
+
|
13
|
+
# Raised when a HTTP request failed.
|
14
|
+
class HTTPError < Error; end
|
15
|
+
end
|