Module: Cts::Mpx::Services::Ingest

Defined in:
lib/cts/mpx/services/ingest.rb

Overview

Collection of methods to interact with the ingest services

Class Method Summary collapse

Class Method Details

.[](key = nil) ⇒ Service[], Service

Addressable method, indexed by ingest service title

Parameters:

  • key (String) (defaults to: nil)

    ingest service title to look up the service object

Returns:

  • (Service[])

    if no key, return the entire array of services

  • (Service)

    a service

Raises:

  • (ArgumentError)

    if the key is not a service name

  • (ArgumentError)

    if the key is not a string



14
15
16
17
18
19
20
21
22
23
# File 'lib/cts/mpx/services/ingest.rb', line 14

def [](key = nil)
  return services unless key

  Driver::Exceptions.raise_unless_argument_error?(key, String)

  service = services.find { |e| e.name == key }
  Driver::Exceptions.raise_unless_argument_error?(service, Driver::Service)

  service
end

.post(user: nil, account: nil, service: nil, endpoint: nil, headers: {}, payload: nil, extra_path: nil) ⇒ Response

Procedural method to interact with an ingest service via POST

Parameters:

  • user (User) (defaults to: nil)

    user to make calls with

  • headers (Hash) (defaults to: {})

    additional headers to attach to the http call

  • account (String) (defaults to: nil)

    account context, can be id or name

  • endpoint (String) (defaults to: nil)

    endpoint to make the call against

  • extra_path (String) (defaults to: nil)

    additional part to add to the path

  • payload (String) (defaults to: nil)

    string to send to ingest

  • service (String) (defaults to: nil)

    title of a service

Returns:

  • (Response)

    Response of the call

Raises:

  • (ArgumentError)

    if headers is not a [Hash]

  • (ArgumentError)

    if the list of [User], service or endpoint is not included

  • (ArgumentError)

    if the [User] does not have a token

  • (ArgumentError)

    if the user is not a user object

  • (ArgumentError)

    if the account_id is not valid

  • (ArgumentError)

    if the data is not a valid hash

  • (ArgumentError)

    if the account_id is not valid



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cts/mpx/services/ingest.rb', line 45

def post(user: nil, account: nil, service: nil, endpoint: nil, headers: {}, payload: nil, extra_path: nil)
  Driver::Helpers.required_arguments ['user', 'service', 'endpoint'], binding
  Driver::Helpers.raise_if_not_a_hash [headers]
  user.token!

  Registry.fetch_and_store_domain(user, ) unless self[service].url?

  host = Driver::Assemblers.host user: user, service: service
  path = Driver::Assemblers.path service: service, endpoint: endpoint, extra_path: extra_path

  request = Driver::Request.create(method: :post, url: [host, path].join, payload: payload, headers: headers)
  request.call
end

.servicesServices[]

Ingest service list

Returns:

  • (Services[])

    Array of ingest services



27
28
29
# File 'lib/cts/mpx/services/ingest.rb', line 27

def services
  Services[].select { |s| s.type == 'ingest' }
end