Sha256: 9838154c05befdf110b2d4e62dce5b8e7b411bf0137b89d466a33847051bdf67

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

require 'faraday'
require 'json'
require 'uri'

module Quintly
  class QQL < Struct.new(:configuration)
    SERVICE_URL = 'https://api.quintly.com'
    API_VERSION = 'v0.9'

    def metric(metric)
      call('metric', metric)
    end

    def query(qql_query)
      call('qqlQuery', qql_query)
    end

    private

    def api_client
      connection = Faraday.new(SERVICE_URL)
      connection.basic_auth(
        configuration.username, configuration.password
      )
      connection
    end

    def call(api, action)
      url = URI.parse(URI.encode(
        "/#{API_VERSION}/qql?#{api}=#{action}&" +
        "startTime=#{configuration.start_time}&" +
        "endTime=#{configuration.end_time}&" +
        "interval=#{configuration.interval}&" +
        "profileIds=#{configuration.profile_ids}")
      )
      response = api_client.get(url)
      response.success? ? JSON.parse(response.body)['data'] : reponse.body
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quintly-0.1.2 lib/quintly/qql.rb