Class: LogBrew::Client

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, sdk:, max_retries:) ⇒ Client

Returns a new instance of Client.



731
732
733
734
735
736
737
# File 'lib/logbrew.rb', line 731

def initialize(api_key:, sdk:, max_retries:)
  @api_key = api_key
  @sdk = sdk
  @max_retries = max_retries
  @events = []
  @closed = false
end

Class Method Details

.create(api_key:, sdk_name:, sdk_version:, max_retries: 2) ⇒ Object

Raises:



718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/logbrew.rb', line 718

def self.create(api_key:, sdk_name:, sdk_version:, max_retries: 2)
  Validation.require_non_empty("api_key", api_key)
  Validation.require_non_empty("sdk_name", sdk_name)
  Validation.require_non_empty("sdk_version", sdk_version)
  raise SdkError.new("validation_error", "max_retries must be non-negative") if max_retries.negative?

  new(
    api_key: api_key,
    sdk: { "name" => sdk_name, "language" => "ruby", "version" => sdk_version },
    max_retries: max_retries
  )
end

Instance Method Details

#action(id, timestamp, attributes) ⇒ Object



767
768
769
# File 'lib/logbrew.rb', line 767

def action(id, timestamp, attributes)
  push_event("action", id, timestamp, validate_action(attributes))
end

#environment(id, timestamp, attributes) ⇒ Object



751
752
753
# File 'lib/logbrew.rb', line 751

def environment(id, timestamp, attributes)
  push_event("environment", id, timestamp, validate_environment(attributes))
end

#flush(transport) ⇒ Object

Raises:



771
772
773
774
775
# File 'lib/logbrew.rb', line 771

def flush(transport)
  raise SdkError.new("shutdown_error", "client is already shut down") if @closed

  flush_internal(transport)
end

#issue(id, timestamp, attributes) ⇒ Object



755
756
757
# File 'lib/logbrew.rb', line 755

def issue(id, timestamp, attributes)
  push_event("issue", id, timestamp, validate_issue(attributes))
end

#log(id, timestamp, attributes) ⇒ Object



759
760
761
# File 'lib/logbrew.rb', line 759

def log(id, timestamp, attributes)
  push_event("log", id, timestamp, validate_log(attributes))
end

#pending_eventsObject



739
740
741
# File 'lib/logbrew.rb', line 739

def pending_events
  @events.length
end

#preview_jsonObject



743
744
745
# File 'lib/logbrew.rb', line 743

def preview_json
  JSON.pretty_generate("sdk" => @sdk, "events" => @events)
end

#release(id, timestamp, attributes) ⇒ Object



747
748
749
# File 'lib/logbrew.rb', line 747

def release(id, timestamp, attributes)
  push_event("release", id, timestamp, validate_release(attributes))
end

#shutdown(transport) ⇒ Object

Raises:



777
778
779
780
781
782
783
# File 'lib/logbrew.rb', line 777

def shutdown(transport)
  raise SdkError.new("shutdown_error", "client is already shut down") if @closed

  response = flush_internal(transport)
  @closed = true
  response
end

#span(id, timestamp, attributes) ⇒ Object



763
764
765
# File 'lib/logbrew.rb', line 763

def span(id, timestamp, attributes)
  push_event("span", id, timestamp, validate_span(attributes))
end