Class: VectorAmp::Source
- Inherits:
-
Object
- Object
- VectorAmp::Source
- Defined in:
- lib/vector_amp/source.rb
Overview
Base value object for ingestion source definitions.
Source objects can be passed to client.sources.create_source(source) to
create a source or to dataset.ingest_source(source) once they include an id
returned by the API.
Direct Known Subclasses
ConfluenceSource, FileUploadSource, GCSSource, GenericSource, GoogleDriveSource, JiraSource, S3Source, WebSource
Constant Summary collapse
- SUPPORTED_SOURCE_TYPES =
%w[s3 web gcs gdrive file_upload jira confluence].freeze
Instance Attribute Summary collapse
- #config ⇒ String, ... readonly
- #description ⇒ String, ... readonly
- #id ⇒ String, ... readonly
- #metadata ⇒ String, ... readonly
- #name ⇒ String, ... readonly
- #source_type ⇒ String, ... readonly
Class Method Summary collapse
-
.from_api(data) ⇒ GenericSource
Build a generic source object from an API response hash.
- .normalize_hash(value) ⇒ Object
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Read a source attribute by string or symbol key.
-
#initialize(source_type:, name:, config:, description: nil, metadata: nil, id: nil) ⇒ Source
constructor
Create a source value object.
- #inspect ⇒ Object
-
#to_create_body ⇒ Hash
Convert this source to an API create-source request body.
-
#to_h ⇒ Hash
(also: #to_hash)
Convert this source to a hash including the id when present.
Constructor Details
#initialize(source_type:, name:, config:, description: nil, metadata: nil, id: nil) ⇒ Source
Create a source value object.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vector_amp/source.rb', line 31 def initialize(source_type:, name:, config:, description: nil, metadata: nil, id: nil) raise ArgumentError, "source_type is required" if source_type.nil? || source_type.to_s.empty? raise ArgumentError, "name is required" if name.nil? || name.to_s.empty? raise ArgumentError, "config must be a Hash" unless config.is_a?(Hash) @id = id @source_type = source_type.to_s @name = name.to_s @description = description @config = config @metadata = end |
Instance Attribute Details
#config ⇒ String, ... (readonly)
21 22 23 |
# File 'lib/vector_amp/source.rb', line 21 def config @config end |
#description ⇒ String, ... (readonly)
21 22 23 |
# File 'lib/vector_amp/source.rb', line 21 def description @description end |
#id ⇒ String, ... (readonly)
21 22 23 |
# File 'lib/vector_amp/source.rb', line 21 def id @id end |
#metadata ⇒ String, ... (readonly)
21 22 23 |
# File 'lib/vector_amp/source.rb', line 21 def @metadata end |
#name ⇒ String, ... (readonly)
21 22 23 |
# File 'lib/vector_amp/source.rb', line 21 def name @name end |
#source_type ⇒ String, ... (readonly)
21 22 23 |
# File 'lib/vector_amp/source.rb', line 21 def source_type @source_type end |
Class Method Details
.from_api(data) ⇒ GenericSource
Build a generic source object from an API response hash.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vector_amp/source.rb', line 47 def self.from_api(data) hash = normalize_hash(data) GenericSource.new( id: hash["id"], source_type: hash.fetch("source_type"), name: hash.fetch("name"), description: hash["description"], config: hash.fetch("config", {}), metadata: hash["metadata"] ) end |
.normalize_hash(value) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/vector_amp/source.rb', line 96 def self.normalize_hash(value) case value when Hash value.each_with_object({}) { |(key, item), memo| memo[key.to_s] = item } else {} end end |
Instance Method Details
#[](key) ⇒ Object?
Read a source attribute by string or symbol key.
62 63 64 |
# File 'lib/vector_amp/source.rb', line 62 def [](key) to_h[key.to_sym] || to_h[key.to_s] end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/vector_amp/source.rb', line 92 def inspect "#<#{self.class} id=#{id.inspect} source_type=#{source_type.inspect} name=#{name.inspect}>" end |
#to_create_body ⇒ Hash
Convert this source to an API create-source request body.
82 83 84 85 86 87 88 89 90 |
# File 'lib/vector_amp/source.rb', line 82 def to_create_body Utils.compact_hash( source_type: source_type, name: name, description: description, config: config, metadata: ) end |
#to_h ⇒ Hash Also known as: to_hash
Convert this source to a hash including the id when present.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vector_amp/source.rb', line 68 def to_h Utils.compact_hash( id: id, source_type: source_type, name: name, description: description, config: config, metadata: ) end |