Class: Chronicle::ETL::RestLoader

Inherits:
Loader
  • Object
show all
Defined in:
lib/chronicle/etl/loaders/rest_loader.rb

Instance Attribute Summary

Attributes included from Chronicle::ETL::Registry::SelfRegistering

#connector_registration

Instance Method Summary collapse

Methods inherited from Loader

#finish, #initialize, #start

Methods included from Chronicle::ETL::Registry::SelfRegistering

#register_connector

Methods included from Loaders::Helpers::EncodingHelper

#force_utf8

Methods included from Configurable

included

Constructor Details

This class inherits a constructor from Chronicle::ETL::Loader

Instance Method Details

#load(payload) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/chronicle/etl/loaders/rest_loader.rb', line 20

def load(payload)
  uri = URI.parse("#{@config.hostname}#{@config.endpoint}")

  header = {
    'Authorization' => "Bearer #{@config.access_token}",
    'Content-Type': 'application/json'
  }
  use_ssl = uri.scheme == 'https'

  Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
    request = Net::HTTP::Post.new(uri.request_uri, header)
    request.body = payload.to_json
    http.request(request)
  end
end