Sha256: e92c50912e30b4569e45aad13d57cacf567219c84ea2d7266e40fe4183369060
Contents?: true
Size: 991 Bytes
Versions: 2
Compression:
Stored size: 991 Bytes
Contents
require 'net/http' require 'uri' require 'json' module Chronicle module ETL class RestLoader < Chronicle::ETL::Loader register_connector do |r| r.description = 'a REST endpoint' end def initialize( options={} ) super(options) end def load(record) payload = Chronicle::ETL::JSONAPISerializer.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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chronicle-etl-0.3.1 | lib/chronicle/etl/loaders/rest_loader.rb |
chronicle-etl-0.3.0 | lib/chronicle/etl/loaders/rest_loader.rb |