class Stytch::Client

def api_host(env)

def api_host(env)
  case env
  when :live
    'https://api.stytch.com'
  when :test
    'https://test.stytch.com'
  else
    raise ArgumentError, "Invalid value for env (#{@env}): should be live or test"
  end
end

def build_default_connection(builder)

def build_default_connection(builder)
  builder.options[:timeout] = Stytch::Middleware::NETWORK_TIMEOUT
  builder.headers = Stytch::Middleware::NETWORK_HEADERS
  builder.request :json
  builder.use Stytch::Middleware
  builder.response :json, content_type: /\bjson$/
  builder.adapter Faraday.default_adapter
end

def create_connection

def create_connection
  @connection = Faraday.new(url: @api_host) do |builder|
    block_given? ? yield(builder) : build_default_connection(builder)
  end
  @connection.basic_auth(@project_id, @secret)
end

def initialize(env:, project_id:, secret:, &block)

def initialize(env:, project_id:, secret:, &block)
  @api_host   = api_host(env)
  @project_id = project_id
  @secret     = secret
  create_connection(&block)
  @users = Stytch::Users.new(@connection)
  @magic_links = Stytch::MagicLinks.new(@connection)
  @otps = Stytch::OTPs.new(@connection)
end