Class: Uvcli::Cli::Application

Inherits:
Thor
  • Object
show all
Defined in:
lib/uvcli/cli.rb

Constant Summary collapse

@@settings =
Uvcli::Settings.new

Instance Method Summary collapse

Instance Method Details

#checkObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/uvcli/cli.rb', line 43

def check
  @@settings.sites.each do |site|
    client = UserVoice::Client.new(site['domain'], site['key'], site['secret'])
    tickets = client.get("/api/v1/tickets.json?per_page=10")
    if tickets
      puts "#{site['domain']}:"
      tickets['tickets'].each do |ticket|
        subject = ticket['subject'] #.truncate(25)
        last_message = ticket['messages'].first
        from = last_message['sender']['name']
        #body = last_message['body'].delete('\n') #.truncate(50)
        puts " #{from}: #{subject}\n"
      end
    else
      puts "Something went wrong"
    end
  end
end

#loginObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/uvcli/cli.rb', line 12

def 
  puts %{To login to your UserVoice account we'll need your domain, key and secret.

The domain is the part in front of your uservoice.com domain, e.g. dangercove.uservoice.com.

To create a key and secret login to your UserVoice account, head over to Settings, then Integrations and click Add API Key... Only enter a name and make sure TRUSTED is not checked.

}
  puts "Domain:"
  STDOUT.flush
  domain = STDIN.gets.chomp
  puts "Key:"
  STDOUT.flush
  key = STDIN.gets.chomp
  puts "Secret:"
  STDOUT.flush
  secret = STDIN.gets.chomp

  puts "\nLogging in..."

  client = UserVoice::Client.new(domain, key, secret)
  begin
    client.get("/api/v1/tickets.json")
    puts @@settings.add_site?(domain, key, secret) ? "Site saved" : "Something went wrong"
  rescue OAuth::Unauthorized
  rescue UserVoice::Unauthorized
    puts "Failed to login"
  end
end