Class: Gigawatt::Commands::Sync

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings, options) ⇒ Sync

Returns a new instance of Sync.



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

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/sync.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
30
# File 'lib/gigawatt/commands/sync.rb', line 6

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

88 Miles caches your company and project list to speed things up. Run this command if you add, edit or remove companies or projects

If run inside a directory with a linked project, the linked project will be updated too

Usage
  88miles sync
  EOS
  end

  instance = self.new(settings, options)
  begin
    instance.sync
    instance.sync_current
  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

  return 0
end

Instance Method Details

#syncObject



40
41
42
# File 'lib/gigawatt/commands/sync.rb', line 40

def sync
  @cache.refresh!
end

#sync_currentObject



44
45
46
47
48
49
50
# File 'lib/gigawatt/commands/sync.rb', line 44

def sync_current
  project = Gigawatt::ProjectFile.new.project
  if project
    response = JSON.parse(@access_key.get("/api/1/projects/#{project["uuid"]}.json").body)
    ProjectFile.write(response["response"])
  end
end