stac 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b7d893fbe52fe1413860d12610a933c957edc65baaa89a4e789b27c0547fd6b
4
- data.tar.gz: fe1a6d7cb2cc0151d59cdd8885f2e412e8474d5e2f37e4cc5a61c7a2259dfa33
3
+ metadata.gz: b2627d9a703e290a75afaa175182cffdb596a75e64219d5078b609747606edc7
4
+ data.tar.gz: b9fbc61200079233af6e820faaee550bb9eb3bf98cb5a4e30536342e6ac932fd
5
5
  SHA512:
6
- metadata.gz: 3e7fa4e010e317a49dab6f67244e89b0bd4d4839fb19253946a8f1fc751dcc257856725901596afe3ede6a8106568847c6cb85e2ec5eb4330791bbc3a1f30cc1
7
- data.tar.gz: 76ac97fe60ae5aeab13a65e4dfe7220b7fbe5501b7e3e582f4781b100605176284383177e7afd4a4e91c84645f286499996fe94202691c1ae969e75c09158340
6
+ metadata.gz: f2ea9eff6cfa3171f1a96ec8973184fd361226d7e6afaefd28d9e96286a4991f7c3e3968f5baa69b49330e98229bd927b53d70e1a2613f52dddbc7d9d12358a5
7
+ data.tar.gz: 3c556bac6620eef51f7756087a507236dd35cf97906751044d630df9d18c94faf20333d15c24f3d93e81c7fd417b9d0d0bf5ab8ab61464deb1fd786030481eec
data/.rubocop.yml CHANGED
@@ -6,6 +6,9 @@ AllCops:
6
6
  TargetRubyVersion: 3.0
7
7
  NewCops: enable
8
8
 
9
+ Style/GuardClause:
10
+ Enabled: false
11
+
9
12
  Style/TrailingCommaInArguments:
10
13
  EnforcedStyleForMultiline: consistent_comma
11
14
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2022-11-02
4
+
5
+ - Add `STAC::CommonMetadata` and make `Asset` and `Properties` include it.
6
+ - Make `http_client` instance variable of `STACObject` instead of class instance variable of `ObjectResolver`.
7
+ - Change `DefaultHTTPClient#get` return type: String => Hash (parsed JSON).
8
+ - Rename `DefaultHTTPClient` => `SimpleHTTPClient`.
9
+ - Enable to change the default HTTP client via `STAC.default_http_client`.
10
+
3
11
  ## [0.1.0] - 2022-10-09
4
12
 
5
13
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stac (0.1.0)
4
+ stac (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -123,4 +123,4 @@ DEPENDENCIES
123
123
  webmock
124
124
 
125
125
  BUNDLED WITH
126
- 2.3.22
126
+ 2.3.24
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # stac-ruby
2
2
 
3
- A Ruby library for working with [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/).
3
+ A Ruby library for working with [SpatioTemporal Asset Catalog (STAC)](https://stacspec.org/).\
4
+ See [satc-client-ruby](https://github.com/sankichi92/stac-client-ruby) for [STAC API](https://github.com/radiantearth/stac-api-spec) client.
4
5
 
5
- This gem's implementation refers to [pystac](https://github.com/stac-utils/pystac).
6
+ This gem's implementation refers to [PySTAC](https://github.com/stac-utils/pystac).
6
7
 
7
8
  ## Installation
8
9
 
@@ -14,7 +15,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
15
 
15
16
  $ gem install stac
16
17
 
17
- ## Usage
18
+ ## Getting Started
18
19
 
19
20
  ```ruby
20
21
  require 'stac'
@@ -55,7 +56,7 @@ end
55
56
  # ================
56
57
 
57
58
  # Get an Item by ID.
58
- item = catalog.find_item('proj-example', recursive: true)
59
+ item = catalog.find_item('CS3-20160503_132131_08')
59
60
 
60
61
  # Print core Item metadeata.
61
62
  puts 'geometry:'
@@ -69,6 +70,11 @@ p item.collection_id
69
70
 
70
71
  # Get actual Collection instance instead of ID.
71
72
  _collection = item.collection
73
+
74
+ # Print common metadata.
75
+ puts "instruments: #{item.properties.instruments}"
76
+ puts "platform: #{item.properties.platform}"
77
+ puts "gsd: #{item.properties.gsd}"
72
78
  ```
73
79
 
74
80
  ## Documentation
data/lib/stac/asset.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'common_metadata'
4
+
3
5
  module STAC
4
6
  # Represents \STAC asset object, which contains a link to data associated with an Item or Collection that can be
5
7
  # downloaded or streamed.
6
8
  class Asset
9
+ include CommonMetadata
10
+
7
11
  class << self
8
12
  # Deserializes an Asset from a Hash.
9
13
  def from_hash(hash)
@@ -11,7 +15,7 @@ module STAC
11
15
  end
12
16
  end
13
17
 
14
- attr_accessor :href, :title, :description, :type, :roles, :extra
18
+ attr_accessor :href, :title, :description, :type, :roles
15
19
 
16
20
  def initialize(href:, title: nil, description: nil, type: nil, roles: nil, **extra)
17
21
  @href = href
@@ -19,7 +23,7 @@ module STAC
19
23
  @description = description
20
24
  @type = type
21
25
  @roles = roles
22
- @extra = extra.transform_keys(&:to_s)
26
+ self.extra = extra.transform_keys(&:to_s)
23
27
  end
24
28
 
25
29
  # Serializes self to a Hash.
data/lib/stac/catalog.rb CHANGED
@@ -10,10 +10,11 @@ module STAC
10
10
  class Catalog < STAC::STACObject
11
11
  self.type = 'Catalog'
12
12
 
13
- attr_accessor :description, :title
13
+ attr_accessor :id, :description, :title
14
14
 
15
15
  def initialize(id:, description:, links:, title: nil, stac_extensions: nil, **extra)
16
- super(id: id, links: links, stac_extensions: stac_extensions, **extra)
16
+ super(links: links, stac_extensions: stac_extensions, **extra)
17
+ @id = id
17
18
  @description = description
18
19
  @title = title
19
20
  end
@@ -22,6 +23,7 @@ module STAC
22
23
  def to_h
23
24
  super.merge(
24
25
  {
26
+ 'id' => id,
25
27
  'title' => title,
26
28
  'description' => description,
27
29
  }.compact,
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module STAC
6
+ # Provides read/write methods for \STAC Common Metadata.
7
+ #
8
+ # These methods are shorthand accessors of #extra Hash.
9
+ # Asset and \Item Properties include this module.
10
+ #
11
+ # Specification: https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
12
+ module CommonMetadata
13
+ attr_accessor :extra
14
+
15
+ def title
16
+ extra['title']
17
+ end
18
+
19
+ def title=(str)
20
+ extra['title'] = str
21
+ end
22
+
23
+ def description
24
+ extra['description']
25
+ end
26
+
27
+ def description=(str)
28
+ extra['description'] = str
29
+ end
30
+
31
+ def created
32
+ if (str = extra['created'])
33
+ Time.iso8601(str)
34
+ end
35
+ end
36
+
37
+ def created=(time)
38
+ extra['created'] = case time
39
+ when Time
40
+ time.iso8601
41
+ else
42
+ time
43
+ end
44
+ end
45
+
46
+ def updated
47
+ if (str = extra['updated'])
48
+ Time.iso8601(str)
49
+ end
50
+ end
51
+
52
+ def updated=(time)
53
+ extra['updated'] = case time
54
+ when Time
55
+ time.iso8601
56
+ else
57
+ time
58
+ end
59
+ end
60
+
61
+ def start_datetime
62
+ if (str = extra['start_datetime'])
63
+ Time.iso8601(str)
64
+ end
65
+ end
66
+
67
+ def start_datetime=(time)
68
+ extra['start_datetime'] = case time
69
+ when Time
70
+ time.iso8601
71
+ else
72
+ time
73
+ end
74
+ end
75
+
76
+ def end_datetime
77
+ if (str = extra['end_datetime'])
78
+ Time.iso8601(str)
79
+ end
80
+ end
81
+
82
+ def end_datetime=(time)
83
+ extra['end_datetime'] = case time
84
+ when Time
85
+ time.iso8601
86
+ else
87
+ time
88
+ end
89
+ end
90
+
91
+ # Returns a range from #start_datetime to #end_datetime.
92
+ def datetime_range
93
+ if (start = start_datetime) && (last = end_datetime)
94
+ start..last
95
+ end
96
+ end
97
+
98
+ # Sets #start_datetime and #end_datetime by the given range.
99
+ def datetime_range=(time_range)
100
+ self.start_datetime = time_range.begin
101
+ self.end_datetime = time_range.end
102
+ end
103
+
104
+ def license
105
+ extra['license']
106
+ end
107
+
108
+ def license=(str)
109
+ extra['license'] = str
110
+ end
111
+
112
+ def providers
113
+ extra.fetch('providers', []).map do |provider_hash|
114
+ Provider.from_hash(provider_hash)
115
+ end
116
+ end
117
+
118
+ def providers=(arr)
119
+ extra['providers'] = arr.map(&:to_h)
120
+ end
121
+
122
+ def platform
123
+ extra['platform']
124
+ end
125
+
126
+ def platform=(str)
127
+ extra['platform'] = str
128
+ end
129
+
130
+ def instruments
131
+ extra['instruments']
132
+ end
133
+
134
+ def instruments=(arr)
135
+ extra['instruments'] = arr
136
+ end
137
+
138
+ def constellation
139
+ extra['constellation']
140
+ end
141
+
142
+ def constellation=(str)
143
+ extra['constellation'] = str
144
+ end
145
+
146
+ def mission
147
+ extra['mission']
148
+ end
149
+
150
+ def mission=(str)
151
+ extra['mission'] = str
152
+ end
153
+
154
+ def gsd
155
+ extra['gsd']
156
+ end
157
+
158
+ def gsd=(num)
159
+ extra['gsd'] = num
160
+ end
161
+ end
162
+ end
data/lib/stac/item.rb CHANGED
@@ -23,12 +23,13 @@ module STAC
23
23
  end
24
24
  end
25
25
 
26
- attr_accessor :geometry, :bbox, :properties, :assets, :collection_id
26
+ attr_accessor :id, :geometry, :bbox, :properties, :assets, :collection_id
27
27
 
28
28
  def initialize(
29
29
  id:, geometry:, properties:, links:, assets:, bbox: nil, collection: nil, stac_extensions: nil, **extra
30
30
  )
31
- super(id: id, links: links, stac_extensions: stac_extensions, **extra)
31
+ super(links: links, stac_extensions: stac_extensions, **extra)
32
+ @id = id
32
33
  @geometry = geometry
33
34
  @properties = properties
34
35
  @assets = assets
@@ -48,6 +49,7 @@ module STAC
48
49
  },
49
50
  ).merge(
50
51
  {
52
+ 'id' => id,
51
53
  'bbox' => bbox,
52
54
  'properties' => properties.to_h,
53
55
  'assets' => assets.transform_values(&:to_h),
data/lib/stac/link.rb CHANGED
@@ -53,18 +53,12 @@ module STAC
53
53
  # Returns a \STAC object resolved from HREF.
54
54
  #
55
55
  # When it could not assemble the absolute HREF, it returns nil.
56
- def target
56
+ def target(http_client: owner&.http_client || STAC.default_http_client)
57
57
  @target ||= if (url = absolute_href)
58
- object = resolver.resolve(url)
58
+ object = ObjectResolver.new(http_client: http_client).resolve(url)
59
59
  object.self_href = url
60
60
  object
61
61
  end
62
62
  end
63
-
64
- private
65
-
66
- def resolver
67
- @resolver ||= ObjectResolver.new
68
- end
69
63
  end
70
64
  end
@@ -3,30 +3,22 @@
3
3
  require 'json'
4
4
  require_relative 'catalog'
5
5
  require_relative 'collection'
6
- require_relative 'default_http_client'
7
6
  require_relative 'errors'
8
7
  require_relative 'item'
9
8
 
10
9
  module STAC
11
10
  # Resolves a \STAC object from a URL.
12
11
  class ObjectResolver
13
- RESOLVABLES = [Catalog, Collection, Item].freeze # :nodoc:
14
-
15
12
  class << self
16
- # Sets the default HTTP client.
17
- #
18
- # HTTP client must implement method `get: (URI uri) -> String,` which fetches the URI resource through HTTP.
19
- attr_writer :default_http_client
20
-
21
- # Returns the default HTTP client.
22
- def default_http_client
23
- @default_http_client ||= DefaultHTTPClient.new
24
- end
13
+ # Resolvable classes. Default is Catalog, Collection and Item.
14
+ attr_accessor :resolvables
25
15
  end
26
16
 
17
+ self.resolvables = [Catalog, Collection, Item]
18
+
27
19
  attr_reader :http_client
28
20
 
29
- def initialize(http_client: self.class.default_http_client)
21
+ def initialize(http_client:)
30
22
  @http_client = http_client
31
23
  end
32
24
 
@@ -41,12 +33,13 @@ module STAC
41
33
  # - STAC::UnknownURISchemeError when a URL with unsupported scheme was given
42
34
  # - STAC::TypeError when it could not resolve any \STAC objects
43
35
  def resolve(url)
44
- str = read(url)
45
- hash = JSON.parse(str)
46
- klass = RESOLVABLES.find { |c| c.type == hash['type'] }
36
+ hash = read(url)
37
+ klass = self.class.resolvables.find { |c| c.type == hash['type'] }
47
38
  raise TypeError, "unknown STAC object type: #{hash['type']}" unless klass
48
39
 
49
- klass.from_hash(hash)
40
+ object = klass.from_hash(hash)
41
+ object.http_client = http_client
42
+ object
50
43
  end
51
44
 
52
45
  private
@@ -57,7 +50,8 @@ module STAC
57
50
  when URI::HTTP
58
51
  http_client.get(uri)
59
52
  when URI::File
60
- File.read(uri.path.to_s)
53
+ str = File.read(uri.path.to_s)
54
+ JSON.parse(str)
61
55
  else
62
56
  raise UnknownURISchemeError, "unknown URI scheme: #{url}"
63
57
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
+ require_relative 'common_metadata'
4
5
 
5
6
  module STAC
6
7
  # Represents \STAC properties object, which is additional metadata for Item.
7
8
  #
8
9
  # Specification: https://github.com/radiantearth/stac-spec/blob/master/item-spec/item-spec.md#properties-object
9
10
  class Properties
11
+ include CommonMetadata
12
+
10
13
  class << self
11
14
  # Deserializes a Properties from a Hash.
12
15
  def from_hash(hash)
@@ -16,11 +19,11 @@ module STAC
16
19
  end
17
20
  end
18
21
 
19
- attr_accessor :datetime, :extra
22
+ attr_accessor :datetime
20
23
 
21
24
  def initialize(datetime:, **extra)
22
25
  @datetime = datetime
23
- @extra = extra.transform_keys(&:to_s)
26
+ self.extra = extra.transform_keys(&:to_s)
24
27
  end
25
28
 
26
29
  # Serializes self to a Hash.
@@ -1,23 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require 'open-uri'
4
5
  require_relative 'errors'
5
6
  require_relative 'version'
6
7
 
7
8
  module STAC
8
9
  # Simple HTTP Client using OpenURI.
9
- class DefaultHTTPClient
10
+ class SimpleHTTPClient
10
11
  attr_reader :options
11
12
 
12
13
  def initialize(options = { 'User-Agent' => "stac-ruby v#{VERSION}" })
13
14
  @options = options
14
15
  end
15
16
 
16
- # Makes a HTTP request and returns the response body as String.
17
+ # Makes a HTTP request and returns the responded JSON as Hash.
17
18
  #
18
19
  # Raises STAC::HTTPError when the response status is not 2XX.
19
- def get(uri)
20
- uri.read(options)
20
+ def get(url)
21
+ body = URI(url).read(options)
22
+ JSON.parse(body)
21
23
  rescue OpenURI::HTTPError => e
22
24
  raise HTTPError, e.message
23
25
  end
@@ -15,7 +15,7 @@ module STAC
15
15
  #
16
16
  # Raises ArgumentError when any required fields are missing.
17
17
  def from_hash(hash)
18
- raise TypeError, "type field is not 'Catalog': #{hash['type']}" if hash.fetch('type') != type
18
+ raise TypeError, "type field is not '#{type}': #{hash['type']}" if hash.fetch('type') != type
19
19
 
20
20
  transformed = hash.transform_keys(&:to_sym).except(:type, :stac_version)
21
21
  transformed[:links] = transformed.fetch(:links).map { |link| Link.from_hash(link) }
@@ -25,18 +25,21 @@ module STAC
25
25
  end
26
26
  end
27
27
 
28
- attr_accessor :id, :stac_extensions, :extra
28
+ attr_accessor :stac_extensions, :extra
29
+
30
+ # HTTP Client to fetch objects from HTTP HREF links.
31
+ attr_accessor :http_client
29
32
 
30
33
  attr_reader :links
31
34
 
32
- def initialize(id:, links:, stac_extensions: nil, **extra)
33
- @id = id
35
+ def initialize(links:, stac_extensions: nil, **extra)
34
36
  @links = []
35
37
  links.each do |link|
36
38
  add_link(link) # to set `owner`
37
39
  end
38
40
  @stac_extensions = stac_extensions
39
41
  @extra = extra.transform_keys(&:to_s)
42
+ @http_client = STAC.default_http_client
40
43
  end
41
44
 
42
45
  def type
@@ -49,7 +52,6 @@ module STAC
49
52
  'type' => type,
50
53
  'stac_version' => SPEC_VERSION,
51
54
  'stac_extensions' => stac_extensions,
52
- 'id' => id,
53
55
  'links' => links.map(&:to_h),
54
56
  }.merge(extra).compact
55
57
  end
@@ -79,12 +81,19 @@ module STAC
79
81
  add_link(self_link)
80
82
  end
81
83
 
82
- private
83
-
84
- def find_link(rel:)
85
- links.find { |link| link.rel == rel }
84
+ # Returns a link matching the arguments.
85
+ def find_link(rel:, type: nil)
86
+ links.find do |link|
87
+ if type
88
+ link.rel == rel && link.type == type
89
+ else
90
+ link.rel == rel
91
+ end
92
+ end
86
93
  end
87
94
 
95
+ private
96
+
88
97
  def remove_link(rel:)
89
98
  links.reject! { |link| link.rel == rel }
90
99
  end
data/lib/stac/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module STAC
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/stac.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'stac/simple_http_client'
3
4
  require_relative 'stac/object_resolver'
4
5
  require_relative 'stac/version'
5
6
 
@@ -8,6 +9,8 @@ require_relative 'stac/version'
8
9
  # Provides some utility methods.
9
10
  module STAC
10
11
  class << self
12
+ attr_accessor :default_http_client
13
+
11
14
  # Returns a \STAC object resolved from the given file path.
12
15
  def from_file(path)
13
16
  from_url("file://#{File.expand_path(path)}")
@@ -16,10 +19,12 @@ module STAC
16
19
  # Returns a \STAC object resolved from the given URL.
17
20
  #
18
21
  # When the resolved object does not have rel="self" link, adds a rel="self" link with the give url.
19
- def from_url(url, resolver: ObjectResolver.new)
20
- object = resolver.resolve(url)
22
+ def from_url(url, http_client: default_http_client)
23
+ object = ObjectResolver.new(http_client: http_client).resolve(url)
21
24
  object.self_href = url unless object.self_href
22
25
  object
23
26
  end
24
27
  end
28
+
29
+ self.default_http_client = SimpleHTTPClient.new
25
30
  end
data/sig/stac/asset.rbs CHANGED
@@ -1,5 +1,7 @@
1
1
  module STAC
2
2
  class Asset
3
+ include CommonMetadata
4
+
3
5
  def self.from_hash: (Hash[String, untyped] hash) -> Asset
4
6
 
5
7
  attr_accessor href: String
data/sig/stac/catalog.rbs CHANGED
@@ -2,6 +2,7 @@ module STAC
2
2
  class Catalog < STACObject
3
3
  def self.from_hash: (Hash[String, untyped] hash) -> Catalog
4
4
 
5
+ attr_accessor id: String
5
6
  attr_accessor description: String
6
7
  attr_accessor title: String?
7
8
 
@@ -0,0 +1,34 @@
1
+ module STAC
2
+ module CommonMetadata
3
+ attr_accessor extra: Hash[String, untyped]
4
+
5
+ def title: -> String?
6
+ def title=: (String) -> void
7
+ def description: -> String?
8
+ def description=: (String) -> void
9
+ def created: -> Time?
10
+ def created=: (Time | String) -> void
11
+ def updated: -> Time?
12
+ def updated=: (Time | String) -> void
13
+ def start_datetime: -> Time?
14
+ def start_datetime=: (Time | String) -> void
15
+ def end_datetime: -> Time?
16
+ def end_datetime=: (Time | String) -> void
17
+ def datetime_range: -> Range[Time]?
18
+ def datetime_range=: (Range[Time]) -> void
19
+ def license: -> String?
20
+ def license=: (String) -> void
21
+ def providers: -> Array[Provider]
22
+ def providers=: (Array[Provider]) -> void
23
+ def platform: -> String?
24
+ def platform=: (String) -> void
25
+ def instruments: -> Array[String]?
26
+ def instruments=: (Array[String]) -> void
27
+ def constellation: -> String?
28
+ def constellation=: (String) -> void
29
+ def mission: -> String?
30
+ def mission=: (String) -> void
31
+ def gsd: -> Numeric
32
+ def gsd=: (Numeric) -> void
33
+ end
34
+ end
data/sig/stac/item.rbs CHANGED
@@ -2,6 +2,7 @@ module STAC
2
2
  class Item < STACObject
3
3
  def self.from_hash: (Hash[String, untyped] hash) -> Item
4
4
 
5
+ attr_accessor id: String
5
6
  attr_accessor geometry: Hash[String, untyped]?
6
7
  attr_accessor properties: Properties
7
8
  attr_accessor assets: Hash[String, Asset]
data/sig/stac/link.rbs CHANGED
@@ -8,6 +8,7 @@ module STAC
8
8
  attr_accessor title: String?
9
9
  attr_accessor extra: Hash[String, untyped]
10
10
  attr_accessor owner: STACObject | nil
11
+ attr_accessor http_client: _HTTPClient
11
12
  @target: Catalog | Collection | Item | nil
12
13
  @resolver: ObjectResolver
13
14
 
@@ -15,7 +16,7 @@ module STAC
15
16
 
16
17
  def to_h: -> Hash[String, untyped]
17
18
  def absolute_href: -> String?
18
- def target: -> (Catalog | Collection | Item | nil)
19
+ def target: (?http_client: _HTTPClient) -> (Catalog | Collection | Item | nil)
19
20
 
20
21
  private
21
22
 
@@ -2,27 +2,23 @@ module STAC
2
2
  class ObjectResolver
3
3
  RESOLVABLES: Array[_STACObjectClass]
4
4
 
5
- attr_writer self.default_http_client: _HTTPClient
5
+ attr_accessor self.resolvables: Array[_STACObjectClass]
6
6
 
7
7
  def self.default_http_client: -> _HTTPClient
8
8
 
9
9
  attr_reader http_client: _HTTPClient
10
10
 
11
- def initialize: (?http_client: _HTTPClient) -> void
11
+ def initialize: (http_client: _HTTPClient) -> void
12
12
 
13
13
  def resolve: (String url) -> (Catalog | Collection | Item)
14
14
 
15
15
  private
16
16
 
17
- def read: (String url) -> String
17
+ def read: (String url) -> Hash[String, untyped]
18
18
  end
19
19
 
20
20
  interface _STACObjectClass
21
21
  def type: -> String
22
- def from_hash: (Hash[String, untyped] hash) -> (Catalog | Collection | Item)
23
- end
24
-
25
- interface _HTTPClient
26
- def get: (URI uri) -> String
22
+ def from_hash: (Hash[String, untyped] hash) -> untyped
27
23
  end
28
24
  end
@@ -1,5 +1,7 @@
1
1
  module STAC
2
2
  class Properties
3
+ include CommonMetadata
4
+
3
5
  def self.from_hash: (Hash[String, untyped] hash) -> Properties
4
6
 
5
7
  attr_accessor datetime: Time?
@@ -1,9 +1,9 @@
1
1
  module STAC
2
- class DefaultHTTPClient
2
+ class SimpleHTTPClient
3
3
  attr_reader options: Hash[String, String]
4
4
 
5
5
  def initialize: (?Hash[String, String] options) -> void
6
6
 
7
- def get: (URI uri) -> String
7
+ def get: (URI::Generic | String url) -> Hash[String, untyped]
8
8
  end
9
9
  end
@@ -4,13 +4,13 @@ module STAC
4
4
 
5
5
  def self.from_hash: (Hash[String, untyped]) -> STACObject
6
6
 
7
- attr_accessor id: String
8
7
  attr_accessor stac_extensions: Array[String]?
9
8
  attr_accessor extra: Hash[String, untyped]
9
+ attr_accessor http_client: _HTTPClient
10
10
  attr_reader links: Array[Link]
11
11
 
12
12
  def initialize: (
13
- id: String, links: Array[Link], ?stac_extensions: Array[String]?, **untyped
13
+ links: Array[Link], ?stac_extensions: Array[String]?, **untyped
14
14
  ) -> void
15
15
 
16
16
  def type: -> String
@@ -19,10 +19,10 @@ module STAC
19
19
  def add_link: (Link) -> Array[Link]
20
20
  def self_href: -> String?
21
21
  def self_href=: (String) -> void
22
+ def find_link: (rel: String, ?type: String?) -> Link?
22
23
 
23
24
  private
24
25
 
25
- def find_link: (rel: String) -> Link?
26
26
  def remove_link: (rel: String) -> Array[Link]?
27
27
  end
28
28
  end
data/sig/stac.rbs CHANGED
@@ -1,5 +1,11 @@
1
1
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
2
2
  module STAC
3
+ attr_accessor self.default_http_client: _HTTPClient
4
+
3
5
  def self.from_file: (String path) -> (Catalog | Collection | Item)
4
- %a{rbs:test:skip} def self.from_url: (String url, ?resolver: ObjectResolver) -> (Catalog | Collection | Item)
6
+ def self.from_url: (String url, ?http_client: _HTTPClient) -> (Catalog | Collection | Item)
7
+
8
+ interface _HTTPClient
9
+ def get: (URI::Generic | String url) -> Hash[String, untyped]
10
+ end
5
11
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Miyoshi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-09 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - takahiro-miyoshi@sankichi.net
16
16
  executables: []
@@ -31,7 +31,7 @@ files:
31
31
  - lib/stac/asset.rb
32
32
  - lib/stac/catalog.rb
33
33
  - lib/stac/collection.rb
34
- - lib/stac/default_http_client.rb
34
+ - lib/stac/common_metadata.rb
35
35
  - lib/stac/errors.rb
36
36
  - lib/stac/extent.rb
37
37
  - lib/stac/item.rb
@@ -39,6 +39,7 @@ files:
39
39
  - lib/stac/object_resolver.rb
40
40
  - lib/stac/properties.rb
41
41
  - lib/stac/provider.rb
42
+ - lib/stac/simple_http_client.rb
42
43
  - lib/stac/spec_version.rb
43
44
  - lib/stac/stac_object.rb
44
45
  - lib/stac/version.rb
@@ -47,7 +48,7 @@ files:
47
48
  - sig/stac/asset.rbs
48
49
  - sig/stac/catalog.rbs
49
50
  - sig/stac/collection.rbs
50
- - sig/stac/default_http_client.rbs
51
+ - sig/stac/common_metadata.rbs
51
52
  - sig/stac/errors.rbs
52
53
  - sig/stac/extent.rbs
53
54
  - sig/stac/item.rbs
@@ -55,6 +56,7 @@ files:
55
56
  - sig/stac/object_resolver.rbs
56
57
  - sig/stac/properties.rbs
57
58
  - sig/stac/provider.rbs
59
+ - sig/stac/simple_http_client.rbs
58
60
  - sig/stac/spec_version.rbs
59
61
  - sig/stac/stac_object.rbs
60
62
  - sig/stac/version.rbs
@@ -69,7 +71,7 @@ metadata:
69
71
  documentation_uri: https://sankichi92.github.io/stac-ruby/
70
72
  github_repo: https://github.com/sankichi92/stac-ruby.git
71
73
  rubygems_mfa_required: 'true'
72
- post_install_message:
74
+ post_install_message:
73
75
  rdoc_options: []
74
76
  require_paths:
75
77
  - lib
@@ -85,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  version: '0'
86
88
  requirements: []
87
89
  rubygems_version: 3.3.7
88
- signing_key:
90
+ signing_key:
89
91
  specification_version: 4
90
92
  summary: A library for working with SpatioTemporal Asset Catalog (STAC)
91
93
  test_files: []