Sha256: 93e8b7630c929a79b22bd6e393be3ee1cfb312f2c49345338181623ef23d8b1a

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module BlockScore
  class Client
    include HTTParty

    @ssl_path = File.expand_path(File.join(File.dirname(__FILE__), '../blockscore-cert.crt'))
    ssl_ca_file @ssl_path

    attr_reader :verification
    attr_reader :question_set

    def initialize(api_key, version, options = {})
      
      @api_key = api_key
      @auth = { :username => @api_key, :password => "" }
      @verification = BlockScore::Verification.new(self)
      @question_set = BlockScore::QuestionSet.new(self)
      @error_handler = BlockScore::ErrorHandler.new

      options[:base_uri] ||= "https://api.blockscore.com"
      options[:headers] = { 'Accept' => 'application/vnd.blockscore+json;version=' + version.to_s }
      
      options.each do |k,v|
        self.class.send k, v
      end
    end

    def get(path, options = {})

      options = { :body => options, :basic_auth => @auth }

      response = self.class.get(path, options)

      begin
        result = @error_handler.check_error(response)
      rescue BlockScore::BlockscoreError => e
        raise
      end

    end

    def post(path, options = {})

      options = { :body => options, :basic_auth => @auth }

      response = self.class.post(path, options)

      begin
        result = @error_handler.check_error(response)
      rescue BlockScore::BlockscoreError => e
        raise
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blockscore-2.0.1 lib/blockscore/client.rb