require "faraday"
require "faraday_middleware"

require "justcoin/version"

class Justcoin

  DEFAULT_URI = "https://justcoin.com/api/v1"

  attr_reader :key, :options, :client

  def initialize(key, options={})
    @key = key
    @options = options
    @client = build_client
  end

  private

  def build_client
    Faraday.new options[:uri] || DEFAULT_URI do |f|
      f.request :json
      f.response :json, content_type: /\bjson$/
      f.response :logger, options[:logger] if options[:logger] || options[:log]
      f.response :raise_error
    end
  end

end

require "faraday"
require "faraday_middleware"

require "justcoin/version"

class Justcoin

  DEFAULT_URL = "https://justcoin.com/api/v1".freeze

  attr_reader :key, :options, :client

  def initialize(key, options={})
    @key = key

    options[:url] ||= DEFAULT_URL
    @options = options

    @client = build_client
  end

  private

  def client_options
    options.select { |k,v| Faraday::ConnectionOptions.members.include?(k) }
  end

  def build_client
    Faraday.new(client_options) do |f|
      f.request :json

      f.response :json, content_type: /\bjson$/
      f.response :logger, options[:logger] if options[:logger] || options[:log]
      f.response :raise_error

      f.adapter Faraday.default_adapter
    end
  end

end

Allow passing options to Faraday, set adapter
Allow passing options to Faraday, set adapter