Sha256: 4b2b5e9963a72c24ac3acb9fc98ae32779cd4ea6c67618842e85c6206bb9edc0

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 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)
      puts JSON.parse(response.body)['data']
      response.success? ? JSON.parse(response.body)['data'] : []
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quintly-0.1.1 lib/quintly/qql.rb
quintly-0.1.0 lib/quintly/qql.rb