Class: Gigawatt::Commands::Start
- Inherits:
-
Object
- Object
- Gigawatt::Commands::Start
- Defined in:
- lib/gigawatt/commands/start.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(settings, options) ⇒ Start
constructor
A new instance of Start.
- #punch_in ⇒ Object
- #select_activity(project) ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/gigawatt/commands/start.rb', line 4 def @options end |
Class Method Details
.run!(settings) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gigawatt/commands/start.rb', line 6 def self.run!(settings) = Trollop:: do <<-EOS 88 Miles Command line application - http://88miles.net Punch into the project. Usage 88miles start [options] options: EOS opt :activity, "Select an activity", :type => :flag end instance = self.new(settings, ) begin return instance.punch_in rescue OAuth2::Error => e say "Access to your 88 Miles may have been revoked. Please run <%= color('88miles setup', BOLD) %> again." return INVALID_OAUTH_TOKEN_EXIT_CODE end end |
Instance Method Details
#punch_in ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gigawatt/commands/start.rb', line 54 def punch_in project = Gigawatt::ProjectFile.new.project if project activity = select_activity(project) opts = {} opts = { :body => { :activity_uuid => activity["uuid"] } } if activity response = JSON.parse(@access_key.post("/api/1/projects/#{project["uuid"]}/punch_in.json", opts).body) current = response["response"] ProjectFile.write(current) company = @cache.companies(true)[project["company_uuid"]] say("Punched in to #{company["name"]}: #{project["name"]}") return OK_EXIT_CODE else say("No project found. Did you remember to run <%= color('88miles init [directory]', BOLD) %>?") return NO_PROJECT_EXIT_CODE end end |
#select_activity(project) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gigawatt/commands/start.rb', line 40 def select_activity(project) return nil unless [:activity] return nil unless project["activities"] selected = nil choose do || .prompt = "Pick an Activity" project["activities"].each do |activity| .choice("#{activity["name"]}") { selected = activity } end end selected end |