Class: Uvcli::Cli::Application
- Inherits:
-
Thor
- Object
- Thor
- Uvcli::Cli::Application
- Defined in:
- lib/uvcli/cli.rb
Constant Summary collapse
- @@settings =
Uvcli::Settings.new
Instance Method Summary collapse
Instance Method Details
#check ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/uvcli/cli.rb', line 43 def check if(@@settings.sites.empty?) puts red("\nSetup a few sites first with 'uvcli login'") return end all_tickets = [] @@settings.sites.each do |site| client = UserVoice::Client.new(site['domain'], site['key'], site['secret']) response = client.get("/api/v1/tickets.json?state=open") if response puts "\n#{site['domain']}:" tickets = response['tickets'] if tickets.empty? puts green(" Inbox zero!") else tickets.each do |ticket| all_tickets << ticket subject = ticket['subject'][0...70] subject = "#{subject}..." if subject.length < ticket['subject'].length = ticket['messages'].first sender = ['sender']['name'] email = ['sender']['email'] body = ['plaintext_body'].gsub("\n", " ")[0...70] body = "#{body}..." if body.length < ['body'].length updated = DateTime.parse(['updated_at']) puts "\n [#{green(all_tickets.size)}] #{red(subject)}\n #{body}\n #{updated.strftime('%d/%m/%Y at %H:%M')} by #{green(sender)} <#{green(email)}>\n" end end else puts red(" Unable to retrieve tickets") end end return if all_tickets.empty? puts "\nOpen ticket (#{green('#')} for ticket, #{green('a')} for all, #{red('q')} to quit):" STDOUT.flush ticketid = STDIN.gets.chomp.downcase if(ticketid.to_i > 0 and ticketid.to_i.is_a? Integer) puts "Showing ticket #{ticketid.to_i}" `open #{all_tickets[ticketid.to_i]['url']}` elsif(ticketid == "a") if(all_tickets.size > 10) puts "\nAre you sure? This will open #{all_tickets.size} browser windows? [y/N]" STDOUT.flush sure = STDIN.gets.chomp.downcase if(sure == "y") puts "Showing all tickets" all_tickets.each do |ticket| `open #{ticket['url']}` sleep(1.0/10.0) end end end end end |
#login ⇒ Object
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 login puts %{\nTo 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 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) ? green("Site saved") : red("Something went wrong") rescue OAuth:: rescue UserVoice:: puts red("Failed to login") end end |