Class: DataSink::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/data_sink/client.rb

Constant Summary collapse

DEFAULTS =
{
  url: '',
  endpoint: '/archives',
  retry_max: 2,
  retry_interval: 0.1,
  retry_backoff_factor: 2,
  adapter: :excon,
  read_timeout: 5,
  open_timeout: 5,
  add_newlines: true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
# File 'lib/data_sink/client.rb', line 19

def initialize(options={})
  @options = DEFAULTS.merge(options)
  user = @options.fetch(:user)
  pass = @options.fetch(:pass)
  @client = options[:client] || create_client(user, pass)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



17
18
19
# File 'lib/data_sink/client.rb', line 17

def client
  @client
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/data_sink/client.rb', line 17

def options
  @options
end

Instance Method Details

#post(stream_id, body, partition_key: nil) ⇒ Object



26
27
28
# File 'lib/data_sink/client.rb', line 26

def post(stream_id, body, partition_key: nil)
  post_gzipped(stream_id, gzip(transform(body)), partition_key: partition_key)
end

#post_gzipped(stream_id, body, partition_key: nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/data_sink/client.rb', line 30

def post_gzipped(stream_id, body, partition_key: nil)
  client.post do |req|
    req.url endpoint(stream_id, partition_key)
    req.body = body
  end
end