Class: AirbyteRuby::Resources::Source

Inherits:
Base
  • Object
show all
Defined in:
lib/airbyte_ruby/resources/source.rb

Overview

Resource class for Airbyte Sources

Constant Summary collapse

ENDPOINTS =
OpenStruct.new(
  list: "/sources?includeDeleted=false&limit=20&offset=0",
  create: "/sources",
  get: "/sources/:source_id",
  update: "/sources/:source_id",
  delete: "/sources/:source_id"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, args = {}) ⇒ Source

TODO: Include Base module once ready rubocop:disable Lint/MissingSuper



19
20
21
22
23
24
25
# File 'lib/airbyte_ruby/resources/source.rb', line 19

def initialize(adapter, args = {})
  @id = args[:id]
  @name = args[:name]
  @workspace_id = args[:workspace_id]
  @connection_configuration = adapter.configuration
  @source_type = adapter.type
end

Instance Attribute Details

#connection_configurationObject (readonly)

Returns the value of attribute connection_configuration.



15
16
17
# File 'lib/airbyte_ruby/resources/source.rb', line 15

def connection_configuration
  @connection_configuration
end

#idObject (readonly)

Returns the value of attribute id.



15
16
17
# File 'lib/airbyte_ruby/resources/source.rb', line 15

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/airbyte_ruby/resources/source.rb', line 15

def name
  @name
end

#source_typeObject (readonly)

Returns the value of attribute source_type.



15
16
17
# File 'lib/airbyte_ruby/resources/source.rb', line 15

def source_type
  @source_type
end

#workspace_idObject (readonly)

Returns the value of attribute workspace_id.



15
16
17
# File 'lib/airbyte_ruby/resources/source.rb', line 15

def workspace_id
  @workspace_id
end

Instance Method Details

#fetchObject



44
45
46
47
# File 'lib/airbyte_ruby/resources/source.rb', line 44

def fetch
  url = replace_variable_in_url(ENDPOINTS.get, "source_id")
  get(url)
end

#fetch_allObject



36
37
38
# File 'lib/airbyte_ruby/resources/source.rb', line 36

def fetch_all
  list(ENDPOINTS.list)
end

#newObject



40
41
42
# File 'lib/airbyte_ruby/resources/source.rb', line 40

def new
  create(ENDPOINTS.create)
end

#removeObject



54
55
56
57
# File 'lib/airbyte_ruby/resources/source.rb', line 54

def remove
  url = replace_variable_in_url(ENDPOINTS.delete, "source_id")
  delete(url)
end

#to_json(*_args) ⇒ Object

rubocop:enable Lint/MissingSuper



28
29
30
31
32
33
34
# File 'lib/airbyte_ruby/resources/source.rb', line 28

def to_json(*_args)
  {
    name: @name,
    workspaceId: @workspace_id,
    configuration: @connection_configuration.merge(sourceType: @source_type)
  }.to_json
end

#updateObject



49
50
51
52
# File 'lib/airbyte_ruby/resources/source.rb', line 49

def update
  url = replace_variable_in_url(ENDPOINTS.update, "source_id")
  patch(url)
end