Class: Push

Inherits:
Thor
  • Object
show all
Defined in:
lib/dscli/push.rb

Instance Method Summary collapse

Instance Method Details

#delete(id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dscli/push.rb', line 42

def delete(id)
  api = Dscli::API.new

  begin
    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 => e
    puts "Specified push subscription '#{id}' not found. It may have already been deleted."
  end
end

#get(id) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/dscli/push.rb', line 19

def get(id)
  begin
    api = Dscli::API.new
    response = api.push_get(id)
    puts response[:data].to_yaml
  rescue ApiResourceNotFoundError => e
    puts "Specified push subscription '#{id}' not found. It may have already been deleted."
  end
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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dscli/push.rb', line 60

def log(id = nil)
  api = Dscli::API.new

  begin
    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 => e
    puts "Specified push subscription '#{id}' not found. It may have been deleted."
  end
end

#stop(id) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/dscli/push.rb', line 30

def stop(id)
  begin
    api = Dscli::API.new
    api.push_stop(id)
  rescue ApiResourceNotFoundError => e
    puts "Specified push subscription '#{id}' not found. It may have been deleted."
  rescue BadRequestError => e
    puts "Specified push subscription '#{id}' could not be stopped. It may have already been stopped."
  end
end