Class: Gigawatt::Commands::Stop

Inherits:
Object
  • Object
show all
Defined in:
lib/gigawatt/commands/stop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings, options) ⇒ Stop

Returns a new instance of Stop.



31
32
33
34
35
36
37
# File 'lib/gigawatt/commands/stop.rb', line 31

def initialize(settings, options)
  @settings = settings
  @options = options

  @access_key = OAuth.token(@settings.access_key)
  @cache = Cache.new(settings, @access_key)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/gigawatt/commands/stop.rb', line 4

def options
  @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
# File 'lib/gigawatt/commands/stop.rb', line 6

def self.run!(settings)
  options = Trollop::options do
    banner <<-EOS
88 Miles Command line application - http://88miles.net

Punch out of the project.

Usage
  88miles stop [options]

options:
    EOS
    opt :notes, "Save notes against the shift", :type => :string
    opt :tags, "Allocate tags to the shift", :type => :string
  end

  instance = self.new(settings, options)
  begin
    return instance.punch_out
  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_outObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gigawatt/commands/stop.rb', line 39

def punch_out
  project = Gigawatt::ProjectFile.new.project

  if project
    response = JSON.parse(@access_key.post("/api/1/projects/#{project["uuid"]}/punch_out.json", { :params => { :notes => options.notes.to_s } }).body)
    current = response["response"]
    ProjectFile.write(current)

    company = @cache.companies(true)[project["company_uuid"]]
    say("Punched out of #{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