Sha256: 76cae72f0288b5cd3a98e8448454020780945e24f27b4884f0a343279f5667a3

Contents?: true

Size: 834 Bytes

Versions: 1

Compression:

Stored size: 834 Bytes

Contents

module Heft
  module Internal
    class HoistConnection
      def initialize(opts={})
        @internet = opts[:internet] || fail("You need to supply :internet")
        @api_key  = opts[:api_key]  || fail("You need to supply :api_key")
      end
      
      [:get, :post, :delete].each do |m|
        define_method m do |opts|
          execute m, opts
        end
      end

      private

      def execute(verb, opts={})
        @internet.execute T::Request.new(
          :headers  => headers,
          :uri      => opts[:uri],
          :verb     => verb,
          :body     => opts[:body]
        ) 
      end

      def headers
        {
          'Authorization' => "HOIST #{@api_key}",
          'Content-Type'  => 'application/json',
          'Accept'        => 'application/json'
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heft-0.0.2 lib/heft/internal/hoist_connection.rb