Sha256: 67fa5a1524e9fba91aa8a800dc98c75f8ab62bf2279bf9756755cc1adc2de61c

Contents?: true

Size: 697 Bytes

Versions: 3

Compression:

Stored size: 697 Bytes

Contents

require 'net/http'
require 'uri'
require 'json'

module Chronicle
  module ETL
    class RestLoader < Chronicle::ETL::Loader
      def initialize(options={})
        super(options)
      end

      def load(result)
        uri = URI.parse("#{@options[:hostname]}#{@options[:endpoint]}")

        header = {
          "Authorization" => "Bearer #{@options[:access_token]}",
          "Content-Type": 'application/json'
        }

        http = Net::HTTP.new(uri.host, uri.port)
        request = Net::HTTP::Post.new(uri.request_uri, header)

        obj = {data: result} unless result[:data]
        request.body = obj.to_json

        response = http.request(request)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chronicle-etl-0.2.3 lib/chronicle/etl/loaders/rest_loader.rb
chronicle-etl-0.2.2 lib/chronicle/etl/loaders/rest_loader.rb
chronicle-etl-0.2.1 lib/chronicle/etl/loaders/rest_loader.rb