Class: Orsos::Commands::Api

Inherits:
Thor
  • Object
show all
Defined in:
lib/orsos/commands/api.rb

Constant Summary collapse

ROOT_URL =
"http://hack-oregon-prototype.herokuapp.com"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



29
30
31
# File 'lib/orsos/commands/api.rb', line 29

def self.banner(command, namespace = nil, subcommand = false)
  "#{basename} #{@package_name} #{command.usage}"
end

Instance Method Details

#candidatesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/orsos/commands/api.rb', line 9

def candidates
  url = "#{ROOT_URL}/api/candidates.json"
  response = RestClient.get(url)
  if options[:text]
    json = JSON.parse(response.body)
    puts "Candidates"
    puts "----------"
    puts "id\tballot name\tparty\temail"
    puts "-------------------------"
    json["candidates"].each do |candidate|
      puts "#{candidate["id"]}\t#{candidate["ballot_name"]}\t#{candidate["party_affiliation"]}\t#{candidate["email"]}"
    end
  else
    puts JSON.pretty_generate(JSON.parse(response.body))
  end
end