class Chronicle::ETL::RestLoader
Public Class Methods
new( options={} )
click to toggle source
Calls superclass method
Chronicle::ETL::Loader::new
# File lib/chronicle/etl/loaders/rest_loader.rb, line 8 def initialize( options={} ) super(options) end
Public Instance Methods
load(record)
click to toggle source
# File lib/chronicle/etl/loaders/rest_loader.rb, line 12 def load(record) payload = Chronicle::ETL::Utils::JSONAPI.serialize(record) # have the outer data key that json-api expects payload = { data: payload } unless payload[:data] uri = URI.parse("#{@options[:hostname]}#{@options[:endpoint]}") header = { "Authorization" => "Bearer #{@options[: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