Sha256: c8acf2499c9e0ded70d2fc63aa420d86955946fcaf71a5ee65413bca6ce21cc7

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module GoogleBigquery
  class Client

    attr_accessor :options, :api, :client

    def initialize(opts = {})

      @api   ||= GoogleBigquery::Auth.api
      @client ||= GoogleBigquery::Auth.client
      #@auth.authorize # check expiration and cache ?

      self.tap do |client|
        client.options    ||= {}
        client.defaults_options(opts)
        client.options ||= opts
        yield client if block_given?
      end
    end

    def defaults_options(opts)

    end

    def parse_response(res)
      JSON.parse(res.body)
    end

    def self.parse_response(res)
      raise_detected_errors(res)
      JSON.parse(res.body)
    end

  private

    def merge_options(name, opts)
      @options.merge!  name => opts
    end

    def raise_detected_errors
      body = JSON.parse(@results.body)
      raise body["error"]["errors"].collect{|e| "#{e["reason"]}: #{e["message"]}" }.join(", ") if body.keys.include?("error")
    end

    def self.raise_detected_errors(res)
      body = JSON.parse(res.body)
      raise body["error"]["errors"].map{|o| "[BigQuery: #{o['domain']}]: #{o['reason']} #{o['message']}" }.join(", ") if body.has_key?("error")
    end

  end
end


Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bigbroda-0.0.7 lib/google_bigquery/client.rb
bigbroda-0.0.6 lib/google_bigquery/client.rb
bigbroda-0.0.5 lib/google_bigquery/client.rb
bigbroda-0.0.4 lib/google_bigquery/client.rb
bigbroda-0.0.3 lib/google_bigquery/client.rb
bigbroda-0.0.2 lib/google_bigquery/client.rb
bigbroda-0.0.1 lib/google_bigquery/client.rb