timestreamapp 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/ts +4 -0
- data/lib/timestream.rb +222 -0
- data/lib/timestream/version.rb +3 -0
- data/timestream.gemspec +25 -0
- metadata +114 -0
data/.DS_Store
ADDED
Binary file
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/ts
ADDED
data/lib/timestream.rb
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
require "timestream/version"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'thor'
|
4
|
+
require 'json'
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
module Timestream
|
8
|
+
|
9
|
+
class CLI < Thor
|
10
|
+
|
11
|
+
include Thor::Actions
|
12
|
+
include Thor::Shell
|
13
|
+
|
14
|
+
map "-C" => :current
|
15
|
+
map "-c" => :current
|
16
|
+
map "current" => :current
|
17
|
+
|
18
|
+
map "-L" => :login
|
19
|
+
map "-l" => :login
|
20
|
+
map "login" => :login
|
21
|
+
|
22
|
+
map "-N" => :new
|
23
|
+
map "-n" => :new
|
24
|
+
map "new" => :new
|
25
|
+
|
26
|
+
map "-T" => :today
|
27
|
+
map "-t" => :today
|
28
|
+
map "today" => :today
|
29
|
+
|
30
|
+
map "-S" => :search
|
31
|
+
map "-s" => :search
|
32
|
+
map "search" => :search
|
33
|
+
|
34
|
+
map "-D" => :date
|
35
|
+
map "-d" => :date
|
36
|
+
map "date" => :date
|
37
|
+
|
38
|
+
map "-CM" => :commit
|
39
|
+
map "-cm" => :commit
|
40
|
+
map "commit" => :commit
|
41
|
+
|
42
|
+
# Define some private functions
|
43
|
+
no_tasks do
|
44
|
+
# Used to check the credentials
|
45
|
+
|
46
|
+
def get_username
|
47
|
+
file_path = File.expand_path("~/.tsconfig")
|
48
|
+
parsed_config = JSON.parse(File.read(file_path))
|
49
|
+
return parsed_config['username']
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_password
|
53
|
+
file_path = File.expand_path("~/.tsconfig")
|
54
|
+
parsed_config = JSON.parse(File.read(file_path))
|
55
|
+
return parsed_config['password']
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_credentials
|
59
|
+
file_path = File.expand_path("~/.tsconfig")
|
60
|
+
if File.exists?(file_path)
|
61
|
+
return true
|
62
|
+
else
|
63
|
+
say("Please log in first.", :red)
|
64
|
+
login
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "login", "Login to your TimeStream account"
|
71
|
+
def login
|
72
|
+
# Ask for credentials
|
73
|
+
username = ask "Username:"
|
74
|
+
password = ask "Password:"
|
75
|
+
|
76
|
+
# Hit the login API and capture the response
|
77
|
+
response = HTTParty.post("https://timestreamapp.com/login.txt", :query => {:username => username, :password => password})
|
78
|
+
|
79
|
+
if response.body == 'Success: Valid credentials'
|
80
|
+
creds = {:username => username, :password => password}
|
81
|
+
create_file "~/.tsconfig", JSON.pretty_generate(creds), :force => true
|
82
|
+
say(response.body, :green)
|
83
|
+
else
|
84
|
+
say("Invalid credentials, please try again.", :red)
|
85
|
+
login
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
desc "new \"Some new status\"", "Add a new task"
|
91
|
+
def new(task)
|
92
|
+
|
93
|
+
check_credentials
|
94
|
+
|
95
|
+
if task == nil
|
96
|
+
say("Task can not be empty. Please supply a status to post.", :red)
|
97
|
+
else
|
98
|
+
response = HTTParty.post("https://timestreamapp.com/#{get_username}.txt", :query => {:password => get_password, :source => 'timestream_gem', :task => task})
|
99
|
+
|
100
|
+
if response.body == 'Success: New task successfully added.'
|
101
|
+
say(response.body, :green)
|
102
|
+
else
|
103
|
+
say(response.body, :red)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
desc "current", "Get your current task"
|
110
|
+
method_option :output, :type => :string, :aliases => '-o', :default => 'txt', :desc => 'Specify an output format: csv, json, pdf, rss, txt or xml'
|
111
|
+
method_option :format, :type => :string, :aliases => '-f', :default => 'task', :desc => 'Specify what you want: time, task, task-time, time-task. If specified, only returns txt.'
|
112
|
+
method_option :inline, :type => :boolean, :aliases => '-i', :default => false, :desc => 'Specify if you want the output inline, i.e. with NO newline after the output. Useful when scripting.'
|
113
|
+
def current
|
114
|
+
check_credentials
|
115
|
+
|
116
|
+
output_format = options[:output]
|
117
|
+
view_format = options[:format]
|
118
|
+
inline = options[:inline]
|
119
|
+
|
120
|
+
case view_format
|
121
|
+
when 'time'
|
122
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time.txt", :query => {:password => get_password})
|
123
|
+
when 'task-time'
|
124
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/task-time.txt", :query => {:password => get_password})
|
125
|
+
when 'time-task'
|
126
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time-task.txt", :query => {:password => get_password})
|
127
|
+
else
|
128
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current.#{output_format}", :query => {:password => get_password})
|
129
|
+
end
|
130
|
+
|
131
|
+
if inline == true
|
132
|
+
say(response.body, nil, false)
|
133
|
+
else
|
134
|
+
say(response.body, nil)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
desc "today", "Get a list of all of today's tasks"
|
139
|
+
method_option :output, :type => :string, :aliases => '-o', :default => 'txt', :desc => 'Specify an output format: csv, json, pdf, rss, txt or xml'
|
140
|
+
def today
|
141
|
+
check_credentials
|
142
|
+
|
143
|
+
output_format = options[:output]
|
144
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}.#{output_format}", :query => {:password => get_password})
|
145
|
+
say(response.body, nil)
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "search \"search terms\"", "Search tasks"
|
149
|
+
method_option :output, :type => :string, :aliases => '-o', :default => 'txt', :desc => 'Specify an output format: csv, json, pdf, rss, txt or xml'
|
150
|
+
def search(search_terms)
|
151
|
+
check_credentials
|
152
|
+
|
153
|
+
original_search_terms = search_terms
|
154
|
+
search_terms = search_terms.split
|
155
|
+
search_terms = search_terms.join("+")
|
156
|
+
|
157
|
+
output_format = options[:output]
|
158
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/search/#{search_terms}.#{output_format}", :query => {:password => get_password})
|
159
|
+
|
160
|
+
if response.body ==""
|
161
|
+
say("Sorry, no search results found for: #{original_search_terms}", :red)
|
162
|
+
else
|
163
|
+
say(response.body, nil)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
desc "date \"YYYY-MM-DD\"", "Show tasks for a specific date, uses typical formats, e.g.: YYYY-MM-DD, \"last monday\", MM/DD/YY"
|
168
|
+
method_option :output, :type => :string, :aliases => '-o', :default => 'txt', :desc => 'Specify an output format: csv, json, pdf, rss, txt or xml'
|
169
|
+
def date(requested_date)
|
170
|
+
check_credentials
|
171
|
+
|
172
|
+
original_requested_date = requested_date
|
173
|
+
requested_date = Date.parse(requested_date)
|
174
|
+
requested_date = requested_date.strftime("%F")
|
175
|
+
|
176
|
+
output_format = options[:output]
|
177
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/#{requested_date}.#{output_format}", :query => {:password => get_password})
|
178
|
+
|
179
|
+
if response.body ==""
|
180
|
+
say("Sorry, no entries found for: #{original_requested_date}", :red)
|
181
|
+
else
|
182
|
+
say(response.body, nil)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
desc "commit", "Commit and push up your Git changes to the remote master with your current TimeStream status as the commit message"
|
187
|
+
method_option :format, :type => :string, :aliases => '-f', :default => 'task', :desc => 'Specify the format of your commit message: time, task, task-time, time-task.'
|
188
|
+
method_option :push, :type => :boolean, :aliases => '-p', :default => true, :desc => 'Make false if you don\'t want to push up your changes, just add and commit.'
|
189
|
+
method_option :origin, :type => :string, :aliases => '-o', :default => 'origin', :desc => 'Specify the origin'
|
190
|
+
method_option :master, :type => :string, :aliases => '-m', :default => 'master', :desc => 'Specify the master'
|
191
|
+
def commit
|
192
|
+
check_credentials
|
193
|
+
|
194
|
+
view_format = options[:format]
|
195
|
+
push = options[:push]
|
196
|
+
origin = options[:origin]
|
197
|
+
master = options[:master]
|
198
|
+
|
199
|
+
case view_format
|
200
|
+
when 'time'
|
201
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time.txt", :query => {:password => get_password})
|
202
|
+
when 'task-time'
|
203
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/task-time.txt", :query => {:password => get_password})
|
204
|
+
when 'time-task'
|
205
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current/time-task.txt", :query => {:password => get_password})
|
206
|
+
else
|
207
|
+
response = HTTParty.get("https://timestreamapp.com/#{get_username}/current.txt", :query => {:password => get_password})
|
208
|
+
end
|
209
|
+
|
210
|
+
commit_message = response.body
|
211
|
+
|
212
|
+
system("git add .")
|
213
|
+
system("git commit -m \"#{commit_message}\"")
|
214
|
+
|
215
|
+
if push == true
|
216
|
+
system("git push #{origin} #{master}")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
data/timestream.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "timestream/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "timestreamapp"
|
7
|
+
s.version = Timestream::VERSION
|
8
|
+
s.authors = ["Ahmad Varoqua"]
|
9
|
+
s.email = ["ahmadvaroqua@timestreamapp.com"]
|
10
|
+
s.homepage = "https://timestreamapp.com"
|
11
|
+
s.summary = %q{This is a command line interface to the TimeStream web application.}
|
12
|
+
s.description = %q{This is a command line interface to the TimeStream web application.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "timestreamapp"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.executables = ['ts']
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "thor"
|
23
|
+
s.add_dependency "json"
|
24
|
+
s.add_dependency "httparty"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timestreamapp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ahmad Varoqua
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-29 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thor
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: json
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: httparty
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
description: This is a command line interface to the TimeStream web application.
|
63
|
+
email:
|
64
|
+
- ahmadvaroqua@timestreamapp.com
|
65
|
+
executables:
|
66
|
+
- ts
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .DS_Store
|
73
|
+
- .gitignore
|
74
|
+
- Gemfile
|
75
|
+
- Rakefile
|
76
|
+
- bin/ts
|
77
|
+
- lib/timestream.rb
|
78
|
+
- lib/timestream/version.rb
|
79
|
+
- timestream.gemspec
|
80
|
+
homepage: https://timestreamapp.com
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirements: []
|
107
|
+
|
108
|
+
rubyforge_project: timestreamapp
|
109
|
+
rubygems_version: 1.7.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: This is a command line interface to the TimeStream web application.
|
113
|
+
test_files: []
|
114
|
+
|