Class: PostyClient::Command::ApiKeyCommand
- Inherits:
-
Thor
- Object
- Thor
- PostyClient::Command::ApiKeyCommand
- Includes:
- Resources
- Defined in:
- lib/posty_client/command/api_key_command.rb
Instance Method Summary collapse
- #add(expires_at) ⇒ Object
- #delete(token) ⇒ Object
- #disable(token) ⇒ Object
- #enable(token) ⇒ Object
- #expire(token) ⇒ Object
- #list ⇒ Object
Instance Method Details
#add(expires_at) ⇒ Object
14 15 16 17 18 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
41 42 43 44 45 46 47 48 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 |
# 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 ⇒ Object
7 8 9 10 11 |
# 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 |