Class: Push
- Inherits:
-
Thor
- Object
- Thor
- Push
- Defined in:
- lib/dscli/push.rb
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #get(id) ⇒ Object
- #list(page = 1) ⇒ Object
- #log(id = nil) ⇒ Object
- #pause(id) ⇒ Object
- #resume(id) ⇒ Object
- #stop(id) ⇒ Object
Instance Method Details
#delete(id) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dscli/push.rb', line 38 def delete(id) api = Dscli::API.new response = api.push_delete(id) if response[:http][:status] == 204 puts "Push subscription #{id} deleted successfully" else # TODO: How do we handle a different code? response end rescue ApiResourceNotFoundError puts "Specified push subscription '#{id}' not found. It may have already been deleted." end |
#get(id) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dscli/push.rb', line 19 def get(id) api = Dscli::API.new response = api.push_get(id) puts response[:data].to_yaml rescue ApiResourceNotFoundError puts "Specified push subscription '#{id}' not found. It may have been deleted." end |
#list(page = 1) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/dscli/push.rb', line 4 def list(page = 1) api = Dscli::API.new results = api.push_list(page) puts "\nTotal Subscriptions: #{results[:subscriptions].count}\n\n" if results[:subscriptions].count > 0 puts 'ID | Name | Output Type | Created | Status ' puts '--------------------------------------------------------------------------------------------------------------' results[:subscriptions].each { |s| puts "#{s[:id]} | #{ '%-20.20s' % s[:name] } | #{ '%-11.11s' % s[:output_type] } | #{Time.at(s[:created_at])} | #{s[:status]}" } puts "\n" end end |
#log(id = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/dscli/push.rb', line 53 def log(id = nil) api = Dscli::API.new results = api.push_log(id) puts "\nMessage count: #{results[:count]}\n\n" if results[:count] > 0 puts ' Time | Subscription ID | Message ' puts '-----------------------------------------------------------------------------------------------------------------' results[:log_entries].each { |s| puts "#{Time.at(s[:request_time]) } | #{s[:subscription_id]} | #{ '%-50.50s' % s[:message] }" } puts "\n" end rescue ApiResourceNotFoundError puts "Specified push subscription '#{id}' not found. It may have been deleted." end |
#pause(id) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dscli/push.rb', line 71 def pause(id) api = Dscli::API.new response = api.push_pause(id) if response[:http][:status] == 204 puts "Push subscription #{id} paused successfully" else response end rescue ApiResourceNotFoundError puts "Specified push subscription '#{id}' not found." end |
#resume(id) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dscli/push.rb', line 85 def resume(id) api = Dscli::API.new response = api.push_resume(id) if response[:http][:status] == 204 puts "Push subscription #{id} resumed successfully" else response end rescue ApiResourceNotFoundError puts "Specified push subscription '#{id}' not found." end |
#stop(id) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/dscli/push.rb', line 28 def stop(id) api = Dscli::API.new api.push_stop(id) rescue ApiResourceNotFoundError puts "Specified push subscription '#{id}' not found. It may have been deleted." rescue BadRequestError puts "Specified push subscription '#{id}' could not be stopped. It may have already been stopped." end |