require_relative 'service' require 'singleton' module Zzlink # Client of zzEnv service. class Env < Service include Singleton def name 'zzEnv' end def version 'v1.0' end # Get a environment variable's value. # @param name [String] name of the environment variable. # @return [String] value of the variable. def get_env(name) resp = get("/env/#{name}") resp = JSON.parse(resp) resp[name] end # Get a zzLink ticket. # @param ttl_in_sec [Integer] TTL (in seconds) of the new ticket. # @return [String] a ticket which is URL-safe encoded. def new_ticket(ttl_in_sec = 60) resp = get('/ticket', ttl: ttl_in_sec) resp = JSON.parse(resp) resp['ticket'] end # Check a zzLink ticket. # @param ticket [String] the string representation of the ticket. # @return [Boolean] whether the ticket is valid. def check_ticket(ticket) resp = put('/ticket', ticket: ticket); resp = JSON.parse(resp) resp['status'] end end end