Sha256: 4232cf5ff344c0da28d2ebf3b5e5438d920a28197a42a131536f68239dd6df71

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

module BlockScore
  class Client
    include HTTParty

    attr_reader :verification, :question_set, :company, :watchlist_candidate, :watchlist

    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)
      @company = BlockScore::Company.new(self)
      @watchlist_candidate = BlockScore::WatchlistCandidate.new(self)
      @watchlist = BlockScore::Watchlist.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

    def put(path, options = {})
      options = { :body => options, :basic_auth => @auth }

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

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

    end

    def delete(path, options = {})
      options = { :body => options, :basic_auth => @auth }

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

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

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blockscore-3.0.1 lib/blockscore/client.rb
blockscore-3.0.0 lib/blockscore/client.rb