Module: SifttterRedux

Defined in:
lib/sifttter-redux.rb,
lib/sifttter-redux/sifttter.rb,
lib/sifttter-redux/constants.rb,
lib/sifttter-redux/date-range-maker.rb,
lib/sifttter-redux/dropbox-uploader.rb

Overview

The SifttterRedux module, which wraps everything in this gem.

Defined Under Namespace

Modules: DateRangeMaker, Sifttter Classes: DropboxUploader

Constant Summary collapse

DEFAULT_DBU_CONFIG_FILEPATH =

The default configuration path for Dropbox Uploader

File.join(ENV['HOME'], '.dropbox_uploader')
DEFAULT_DBU_LOCAL_FILEPATH =

The default local filepath of the Dropbox-Uploader directory

'/usr/local/opt'
DEFAULT_DBU_MESSAGE =

The default message to display when Dropbox Uploader is running

'RUNNING DROPBOX UPLOADER'
DEFAULT_SRD_CONFIG_FILEPATH =

The default local filepath of the Siftter Redux config file

File.join(ENV['HOME'], '.sifttter_redux')
DEFAULT_SRD_LOG_FILEPATH =

The default local filepath of the Siftter Redux log file

File.join(ENV['HOME'], '.sifttter_redux_log')
DESCRIPTION =

The Gem’s description

'A customized IFTTT-to-Day One service that allows for smart installation and automated running on a standalone *NIX device (such as a Raspberry Pi).'
NEWEST_CONFIG_VERSION =

The last version to require a config update

'1.0.0'
PREF_FILES =

Hash of preference files

{
  'INIT' => File.join(File.dirname(__FILE__), '..', '..', 'res/preference_prompts.yaml')
}
SUMMARY =

The Gem’s summary

'Automated IFTTT to Day One engine.'
VERSION =

The Gem’s version

'1.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.initializedBoolean (readonly)

Stores whether initalization has completed.

Returns:

  • (Boolean)


12
13
14
# File 'lib/sifttter-redux.rb', line 12

def initialized
  @initialized
end

.verboseBoolean

Stores whether verbose output is turned on.

Returns:

  • (Boolean)


16
17
18
# File 'lib/sifttter-redux.rb', line 16

def verbose
  @verbose
end

Class Method Details

.cleanup_temp_filesvoid

This method returns an undefined value.

Removes temporary directories and their contents



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sifttter-redux.rb', line 21

def self.cleanup_temp_files
  dirs = [
    configuration.sifttter_redux[:dayone_local_filepath],
    configuration.sifttter_redux[:sifttter_local_filepath]
  ]

  messenger.info_block('Removing temporary local files...') do
    dirs.each do |d|
      FileUtils.rm_rf(d)
      messenger.debug("Removed directory: #{ d }")
    end
  end
end

.dbu_install_wizard(from_scratch = false) ⇒ void

This method returns an undefined value.

Runs a wizard that installs Dropbox Uploader on the local filesystem.

Parameters:

  • from_scratch (Boolean) (defaults to: false)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sifttter-redux.rb', line 39

def self.dbu_install_wizard(from_scratch = false)
  valid_path_chosen = false

  until valid_path_chosen
    # Prompt the user for a location to save Dropbox Uploader.
    if from_scratch && !configuration.db_uploader[:base_filepath].nil?
      default = configuration.db_uploader[:base_filepath]
    else
      default = DEFAULT_DBU_LOCAL_FILEPATH
    end
    path = messenger.prompt('Location for Dropbox-Uploader', default)
    path = default if path.empty?
    path.chop! if path.end_with?('/')

    # If the entered directory exists, clone the repository.
    if Dir.exists?(File.expand_path(path))
      valid_path_chosen = true

      dbu_path = File.join(path, 'Dropbox-Uploader')
      executable_path = File.join(dbu_path, 'dropbox_uploader.sh')

      if File.directory?(dbu_path)
        messenger.warn("Using pre-existing Dropbox Uploader at #{ dbu_path }...")
      else
        messenger.info_block("Downloading Dropbox Uploader to #{ dbu_path }...", 'Done.', true) do
          system "git clone https://github.com/andreafabrizi/Dropbox-Uploader.git #{ dbu_path }"
        end
      end

      # If the user has never configured Dropbox Uploader, have them do it here.
      unless File.exists?(DEFAULT_DBU_CONFIG_FILEPATH)
        messenger.info_block('Initializing Dropbox Uploader...') { system "#{ executable_path }" }
      end

      configuration.add_section(:db_uploader) unless configuration.data.key?(:db_uploader)
      configuration.db_uploader.merge!({
        base_filepath: path,
        dbu_filepath: dbu_path,
        exe_filepath: executable_path
      })
    else
      messenger.error("Sorry, but #{ path } isn't a valid directory.")
    end
  end
end

.get_dates_from_options(options) ⇒ Range

Creates a date range from the supplied command line options.

Parameters:

  • options (Hash)

    GLI command line options

Returns:

  • (Range)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/sifttter-redux.rb', line 89

def self.get_dates_from_options(options)
  if options[:c] || options[:n] || options[:w] || options[:y] || options[:f] || options[:t]
    # Yesterday
    r = DateRangeMaker.yesterday if options[:y]

    # Current Week
    r = DateRangeMaker.last_n_weeks(0, options[:i]) if options[:c]

    # Last N Days
    r = DateRangeMaker.last_n_days(options[:n].to_i, options[:i]) if options[:n]

    # Last N Weeks
    r = DateRangeMaker.last_n_weeks(options[:w].to_i, options[:i]) if options[:w]

    # Custom Range
    if (options[:f] || options[:t])
      _dates = DateRangeMaker.range(options[:f], options[:t], options[:i])

      if _dates.last > Date.today
        messenger.warn("Ignoring overextended end date and using today's date (#{ Date.today })...")
        r = (_dates.first..Date.today)
      else
        r = (_dates.first.._dates.last)
      end
    end
  else
    r = DateRangeMaker.today
  end

  messenger.debug { "Date range: #{ r }" }
  r
end

.init(from_scratch = false) ⇒ void

This method returns an undefined value.

Initializes Sifttter Redux by downloading and collecting all necessary items and info.

Parameters:

  • from_scratch (Boolean) (defaults to: false)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/sifttter-redux.rb', line 126

def self.init(from_scratch = false)
  if from_scratch
    configuration.reset
    configuration.add_section(:sifttter_redux)
  end

  configuration.sifttter_redux.merge!({
    config_location: configuration.config_path,
    log_level: 'WARN',
    version: SifttterRedux::VERSION,
  })

  # Run the wizard to download Dropbox Uploader.
  dbu_install_wizard(from_scratch = from_scratch)

  pm = CLIUtils::Prefs.new(SifttterRedux::PREF_FILES['INIT'], configuration)
  pm.ask
  configuration.ingest_prefs(pm)

  messenger.debug {"Collected configuration values: #{ configuration.data }" }
  configuration.save
  @initialized = true
end

.update_config_filevoid

This method returns an undefined value.

Notifies the user that the config file needs to be re-done and does it.



153
154
155
156
157
158
159
160
# File 'lib/sifttter-redux.rb', line 153

def self.update_config_file
  m = "This version needs to make some config changes. Don't worry; " \
      "when prompted, your current values for existing config options " \
      "will be presented (so it'll be easier to fly through the upgrade)."
  messenger.info(m)
  messenger.prompt('Press enter to continue')
  SifttterRedux.init(true)
end