Sha256: ffcf6bf426de5c9508f21fb8a97797e9492332abdcf2fd643c1f83d2e86823b0

Contents?: true

Size: 835 Bytes

Versions: 3

Compression:

Stored size: 835 Bytes

Contents

require "rest-client"

module Danger
  class ApiClient
    def initialize(user_name, api_token, organization_id)
      @user_name = user_name
      @api_token = api_token
      @organization_id = organization_id
    end

    def get(card_ids)
      cards = []
      card_ids.each do |id|
        response = request(id)
        cards << Card.new(id, response.nil? ? "<i>(unknown)</i>" : response["entities"][0]["name"])
      end
      cards
    end

    private

    def request(card_id)
      response = RestClient::Request.execute method: :get, url: "https://favro.com/api/v1/cards?cardSequentialId=#{card_id}&unique=true&limit=1", headers: { accept: :json, organizationId: @organization_id }, user: @user_name, password: @api_token
      JSON.parse(response)
    rescue RestClient::ExceptionWithResponse
      nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
danger-favro-1.0.2 lib/favro/api_client.rb
danger-favro-1.0.1 lib/favro/api_client.rb
danger-favro-1.0.0 lib/favro/api_client.rb