Sha256: 060b47af200a11aba34d245721bb0ca1ff761169b137b54cf695046acf310ba6

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module BigBroda
  class Client

    attr_accessor :options, :api, :client

    def initialize(opts = {})

      @api   ||= BigBroda::Auth.api
      @client ||= BigBroda::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

1 entries across 1 versions & 1 rubygems

Version Path
bigbroda-0.1.0.pre lib/bigbroda/client.rb