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 ⇒ Object
- #delete(token) ⇒ Object
- #disable(token) ⇒ Object
- #enable(token) ⇒ Object
- #expire(token) ⇒ Object
- #list ⇒ Object
Instance Method Details
#add ⇒ Object
14 15 16 17 |
# File 'lib/posty_client/command/api_key_command.rb', line 14 def add api_key = PostyClient::Resources::ApiKey.new("") api_key.create end |
#delete(token) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/posty_client/command/api_key_command.rb', line 50 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
30 31 32 33 34 35 36 37 |
# File 'lib/posty_client/command/api_key_command.rb', line 30 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
40 41 42 43 44 45 46 47 |
# File 'lib/posty_client/command/api_key_command.rb', line 40 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
20 21 22 23 24 25 26 27 |
# File 'lib/posty_client/command/api_key_command.rb', line 20 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 |