Class: Timestream::CLI
- Inherits:
-
Thor
- Object
- Thor
- Timestream::CLI
- Includes:
- Thor::Actions, Thor::Shell
- Defined in:
- lib/timestream.rb
Instance Method Summary collapse
- #commit ⇒ Object
- #current ⇒ Object
- #date(requested_date) ⇒ Object
- #info ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #new(task) ⇒ Object
- #search(search_terms) ⇒ Object
- #task_time ⇒ Object
- #time ⇒ Object
- #time_task ⇒ Object
- #today ⇒ Object
- #version ⇒ Object
- #web ⇒ Object
Instance Method Details
#commit ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/timestream.rb', line 284 def commit check_credentials view_format = [:format] push = [:push] origin = [:origin] master = [:master] case view_format when 'time' response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time.txt", :query => {:password => get_password}, :verify => false) when 'task-time' response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/task-time.txt", :query => {:password => get_password}, :verify => false) when 'time-task' response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time-task.txt", :query => {:password => get_password}, :verify => false) else response = HTTParty.get("https://timestreamapp.com/#{get_username}/current.txt", :query => {:password => get_password}, :verify => false) end = response.body system("git add .") system("git commit -m \"#{}\"") if push == true # system("git push #{origin} #{master}") system("git push") end end |
#current ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/timestream.rb', line 158 def current check_credentials output_format = [:output] view_format = [:format] inline = [:inline] case view_format when 'time' response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time.txt", :query => {:password => get_password}, :verify => false) when 'task-time' response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/task-time.txt", :query => {:password => get_password}, :verify => false) when 'time-task' response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time-task.txt", :query => {:password => get_password}, :verify => false) else response = HTTParty.get("https://timestreamapp.com/#{get_username}/current.#{output_format}", :query => {:password => get_password}, :verify => false) end if inline == true say(response.body, nil, false) else say(response.body, nil) end end |
#date(requested_date) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/timestream.rb', line 262 def date(requested_date) check_credentials original_requested_date = requested_date requested_date = Date.parse(requested_date) requested_date = requested_date.strftime("%F") output_format = [:output] response = HTTParty.get("https://timestreamapp.com/#{get_username}/#{requested_date}.#{output_format}", :query => {:password => get_password}, :verify => false) if response.body =="" say("Sorry, no entries found for: #{original_requested_date}", :red) else say(response.body, nil) end end |
#info ⇒ Object
326 327 328 329 330 331 332 333 |
# File 'lib/timestream.rb', line 326 def info say("Welcome to TimeStream! TimeStream is a minimalist, web-based time-tracking system.") say("You can learn more at: https://timestreamapp.com") if yes?("Would you like to go TimeStreamApp.com now?", :green) system("open https://timestreamapp.com") end end |
#login ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/timestream.rb', line 108 def login # Ask for credentials username = ask "Username:" # password = ask "Password:" password = ask_password "Password:" # Hit the login API and capture the response response = HTTParty.post("https://timestreamapp.com/login.txt", :query => {:username => username, :password => password}, :verify => false) if response.body == 'Success: Valid credentials' creds = {:username => username, :password => password} # create_file "~/.tsconfig", JSON.pretty_generate(creds), :force => true create_file "~/.tsconfig", JSON.pretty_generate(creds), {:force => true, :verbose => false} say("Storing creds under ~/.tsconfig") say(response.body, :green) else say("Invalid credentials, please try again.", :red) login end end |
#logout ⇒ Object
130 131 132 133 |
# File 'lib/timestream.rb', line 130 def logout remove_file "~/.tsconfig", {:verbose => false} say("You are now logged out.", :red) end |
#new(task) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/timestream.rb', line 136 def new(task) check_credentials if task == nil say("Task can not be empty. Please supply a status to post.", :red) else response = HTTParty.post("https://timestreamapp.com/#{get_username}.txt", :query => {:password => get_password, :source => 'timestream_gem', :task => task}, :verify => false) if response.body == 'Success: New task successfully added.' say(response.body, :green) else say(response.body, :red) end end end |
#search(search_terms) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/timestream.rb', line 243 def search(search_terms) check_credentials original_search_terms = search_terms search_terms = search_terms.split search_terms = search_terms.join("+") output_format = [:output] response = HTTParty.get("https://timestreamapp.com/#{get_username}/search/#{search_terms}.#{output_format}", :query => {:password => get_password}, :verify => false) if response.body =="" say("Sorry, no search results found for: #{original_search_terms}", :red) else say(response.body, nil) end end |
#task_time ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/timestream.rb', line 217 def task_time check_credentials inline = [:inline] response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/task-time.txt", :query => {:password => get_password}, :verify => false) if inline == true say(response.body, nil, false) else say(response.body, nil) end end |
#time ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/timestream.rb', line 185 def time check_credentials inline = [:inline] response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time.txt", :query => {:password => get_password}, :verify => false) if inline == true say(response.body, nil, false) else say(response.body, nil) end end |
#time_task ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/timestream.rb', line 201 def time_task check_credentials inline = [:inline] response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time-task.txt", :query => {:password => get_password}, :verify => false) if inline == true say(response.body, nil, false) else say(response.body, nil) end end |
#today ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/timestream.rb', line 233 def today check_credentials output_format = [:output] response = HTTParty.get("https://timestreamapp.com/#{get_username}.#{output_format}", :query => {:password => get_password}, :verify => false) say(response.body, nil) end |
#version ⇒ Object
320 321 322 323 |
# File 'lib/timestream.rb', line 320 def version say(Timestream::VERSION) # VERSION end |
#web ⇒ Object
315 316 317 |
# File 'lib/timestream.rb', line 315 def web system("open https://timestreamapp.com/#{get_username}") end |