class PostyClient::Command::ApiKeyCommand

Public Instance Methods

add(expires_at) click to toggle source
# File lib/posty_client/command/api_key_command.rb, line 14
def add(expires_at)
  api_key = PostyClient::Resources::ApiKey.new("")
  api_key.attributes['expires_at'] = expires_at
  api_key.create
end
delete(token) click to toggle source
# File lib/posty_client/command/api_key_command.rb, line 51
def delete(token)
  if yes?("Delete #{name}?")
    transport = PostyClient::Resources::Transport.new(token)
    unless transport.delete
      say transport.errors.inspect, :red
      exit 1
    end
  end
end
disable(token) click to toggle source
# File lib/posty_client/command/api_key_command.rb, line 31
def disable(token)
  api_key = PostyClient::Resources::ApiKey.new(token)
  api_key.attributes['active'] = false
  unless api_key.save
    say api_key.errors.inspect, :red
    exit 1
  end
end
enable(token) click to toggle source
# File lib/posty_client/command/api_key_command.rb, line 41
def enable(token)
  api_key = PostyClient::Resources::ApiKey.new(token)
  api_key.attributes['active'] = true
  unless api_key.save
    say api_key.errors.inspect, :red
    exit 1
  end
end
expire(token) click to toggle source
# File lib/posty_client/command/api_key_command.rb, line 21
def expire(token)
  api_key = PostyClient::Resources::ApiKey.new(token)
  api_key.attributes['expires_at'] = DateTime.now
  unless api_key.save
    say api_key.errors.inspect, :red
    exit 1
  end
end
list() click to toggle source
# File lib/posty_client/command/api_key_command.rb, line 7
def list
  api_keys = PostyClient::Resources::ApiKey.all.map {|d| [d.attributes["access_token"], set_color(d.attributes["expires_at"], d.expired? ? :red : :green), set_color(d.attributes["active"], d.active? ? :green : :red)]}
  api_keys.unshift(["API Key", "Expires at", "Active"])
  print_table(api_keys)
end