Class: Trifle::Stats::Driver::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/trifle/stats/driver/api.rb

Defined Under Namespace

Classes: Error, NetHttpTransport

Constant Summary collapse

ENDPOINT =
URI('https://app.trifle.io/api/v1/metrics')
TIMEOUT =
10
ERROR_BODY_LIMIT =
1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, project_id:, transport: NetHttpTransport.new) ⇒ Api

Returns a new instance of Api.

Raises:

  • (ArgumentError)


45
46
47
48
49
50
51
52
# File 'lib/trifle/stats/driver/api.rb', line 45

def initialize(token:, project_id:, transport: NetHttpTransport.new)
  raise ArgumentError, 'token must not be empty' if token.to_s.strip.empty?
  raise ArgumentError, 'project_id must not be empty' if project_id.to_s.strip.empty?

  @token = token.to_s
  @project_id = project_id.to_s
  @transport = transport
end

Instance Attribute Details

#project_idObject (readonly)

Returns the value of attribute project_id.



43
44
45
# File 'lib/trifle/stats/driver/api.rb', line 43

def project_id
  @project_id
end

#tokenObject (readonly)

Returns the value of attribute token.



43
44
45
# File 'lib/trifle/stats/driver/api.rb', line 43

def token
  @token
end

Instance Method Details

#bypass_buffer?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/trifle/stats/driver/api.rb', line 58

def bypass_buffer?
  true
end

#descriptionObject



54
55
56
# File 'lib/trifle/stats/driver/api.rb', line 54

def description
  self.class.name
end

#direct_write(operation:, key:, at:, values:, untracked: false) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/trifle/stats/driver/api.rb', line 62

def direct_write(operation:, key:, at:, values:, untracked: false)
  payload = api_payload(operation, key, at, values, untracked)
  deliver(build_request(payload))
rescue Error
  raise
rescue StandardError => e
  raise Error.new("Trifle API request failed: #{e.message}", delivery_unknown: true), cause: e
end

#getObject



79
80
81
# File 'lib/trifle/stats/driver/api.rb', line 79

def get(*)
  unsupported!(:values)
end

#incObject



71
72
73
# File 'lib/trifle/stats/driver/api.rb', line 71

def inc(*)
  unsupported!(:track)
end

#pingObject



83
84
85
# File 'lib/trifle/stats/driver/api.rb', line 83

def ping(*)
  unsupported!(:beam)
end

#scanObject



87
88
89
# File 'lib/trifle/stats/driver/api.rb', line 87

def scan(*)
  unsupported!(:scan)
end

#setObject



75
76
77
# File 'lib/trifle/stats/driver/api.rb', line 75

def set(*)
  unsupported!(:assert)
end