Class: Perfm::Client

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

Constant Summary collapse

HTTPS =
"https".freeze
DEFAULT_TIMEOUT =
10

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/perfm/client.rb', line 9

def initialize(config)
  @api_url = config.api_url
  @api_key = config.api_key
  @timeout = DEFAULT_TIMEOUT
  @mutex = Mutex.new
  @connections = []
  @headers = {
    "Content-Type" => "application/json",
    "Authorization" => "Bearer #{@api_key}",
    "X-Perfm-Version" => Perfm::VERSION,
  }
end

Instance Method Details

#post(path, data) ⇒ Object



22
23
24
25
26
27
# File 'lib/perfm/client.rb', line 22

def post(path, data)
  uri = URI(@api_url + path)
  request = Net::HTTP::Post.new(uri.path, @headers)
  request.body = data.to_json
  transmit(request)
end