Sha256: 4dce63eae4c33d81d86973f230d3188a3521357363f6e199d6bfcaa9c0387886
Contents?: true
Size: 792 Bytes
Versions: 4
Compression:
Stored size: 792 Bytes
Contents
require 'faraday' require 'json' module Librato class Client < Struct.new(:user, :token) HOST = 'https://metrics-api.librato.com' [:get, :put, :post, :delete].each do |method| define_method(method) { |*args| request(method, *args) } end private def request(method, path, data = nil) # puts "#{method.to_s.upcase} #{path}" args = [method, path] args << JSON.dump(data) if data response = client.send(*args) { |r| r.headers['Content-Type'] = 'application/json' } fail "#{response.status} #{response.body}" if response.status >= 299 response end def client Faraday.new(HOST) do |c| c.basic_auth(user, token) c.use Faraday::Adapter::NetHttp end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
librato-0.0.7 | lib/librato/client.rb |
librato-0.0.6 | lib/librato/client.rb |
librato-0.0.5 | lib/librato/client.rb |
librato-0.0.4 | lib/librato/client.rb |