class Catchpoint

Public Class Methods

new(opts={}) click to toggle source
# File lib/catchpoint.rb, line 17
def initialize opts={}
  @key    = opts["key"] || ENV['CATCHPOINT_KEY']
  @secret = opts["secret"] || ENV['CATCHPOINT_SECRET']
  @token_url = '/ui/api/token'
  @prefix = '/ui/api/v1'
  @host = 'https://io.catchpoint.com'
  @version = 1
  @token = nil
end

Public Instance Methods

delete(endpoint,opts={}) click to toggle source
# File lib/catchpoint.rb, line 48
def delete endpoint,opts={}
  fetch_token unless @token
  res = @token.delete("#{@prefix}#{endpoint}",opts)
  JSON.parse(res.body)
end
fetch_token() click to toggle source
# File lib/catchpoint.rb, line 27
def fetch_token
  client = OAuth2::Client.new(@key,@secret, site: @host, :token_url => @token_url)
  @token = client.client_credentials.get_token()
end
get(endpoint,opts={}) click to toggle source
# File lib/catchpoint.rb, line 32
def get endpoint,opts={}
  fetch_token unless @token
  res = @token.get("#{@prefix}#{endpoint}",opts)
  JSON.parse(res.body)
end
post(endpoint,opts={}) click to toggle source
# File lib/catchpoint.rb, line 38
def post endpoint,opts={}
  fetch_token unless @token
  res = @token.post("#{@prefix}#{endpoint}",opts)
  JSON.parse(res.body)
end
put(endpoint,opts={}) click to toggle source
# File lib/catchpoint.rb, line 43
def put endpoint,opts={}
  fetch_token unless @token
  res = @token.put("#{@prefix}#{endpoint}",opts)
  JSON.parse(res.body)
end