class Gigawatt::Commands::Sync

Attributes

options[RW]

Public Class Methods

new(settings, options) click to toggle source
# File lib/gigawatt/commands/sync.rb, line 36
def initialize(settings, options)
  @settings = settings
  @options = options

  @access_key = OAuth.token(@settings.access_key)
  @cache = Cache.new(settings, @access_key)
end
run!(settings) click to toggle source
# 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
          opt :project, "Only sync the linked project", :type => :flag, :default => false
        end

        instance = self.new(settings, options)
        begin
          instance.sync unless options[:project]
          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
        rescue Faraday::Error::ConnectionFailed => e
          say "Couldn't connect to the 88 Miles server. Please try again later."
          return CONNECTION_ERROR_EXIT_CODE
        end

        return 0
      end

Public Instance Methods

sync() click to toggle source
# File lib/gigawatt/commands/sync.rb, line 44
def sync
  @cache.refresh!
end
sync_current() click to toggle source
# File lib/gigawatt/commands/sync.rb, line 48
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