Module: Sredder
- Defined in:
- lib/sredder.rb,
lib/sredder/util.rb,
lib/sredder/version.rb,
lib/sredder/sredderc.rb,
lib/sredder/arg_parser.rb,
lib/sredder/wrike_auth.rb,
lib/sredder/github_auth.rb,
lib/sredder/wrike_request.rb,
lib/sredder/github_request.rb
Defined Under Namespace
Modules: Util Classes: ArgParser, GithubAuth, GithubRequest, Sredderc, WrikeAuth, WrikeRequest
Constant Summary collapse
- VERSION =
"0.0.5"
- WRIKE_OAUTH_OPTIONS =
{ :site => 'https://www.wrike.com', :authorize_path => '/rest/auth/authorize', :access_token_path => '/rest/auth/access_token', :request_token_path => '/rest/auth/request_token' }
Class Method Summary collapse
-
.create_task(access, title, description, parent_folder_ids) ⇒ Object
Create a Wrike task and return its ID.
-
.create_timelog(access, date, task_id, hours, comment = '') ⇒ Object
Attaches a timelog entry to a Wrike task.
-
.get_access_token ⇒ Object
gets an authenticated OAuth access token by loading the users .sredderc or prompting them to authenticate in their browser.
-
.get_folder(access, folder) ⇒ Object
Fetches the ID of a wrike folder by name.
-
.get_pull_request(options) ⇒ Object
Github.
- .run_command(argv) ⇒ Object
Class Method Details
.create_task(access, title, description, parent_folder_ids) ⇒ Object
Create a Wrike task and return its ID
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sredder.rb', line 56 def self.create_task(access, title, description, parent_folder_ids) request = WrikeRequest.new(access) request.post('/api/json/v2/wrike.task.add', { title: title, description: description, status: 1, parents: parent_folder_ids }) request.json["task"]["id"] if request.success? end |
.create_timelog(access, date, task_id, hours, comment = '') ⇒ Object
Attaches a timelog entry to a Wrike task
68 69 70 71 72 73 74 75 76 |
# File 'lib/sredder.rb', line 68 def self.create_timelog(access, date, task_id, hours, comment='') request = WrikeRequest.new(access) request.post('/api/json/v2/wrike.timelog.add', { date: date, taskId: task_id, hours: hours, comment: comment }) end |
.get_access_token ⇒ Object
gets an authenticated OAuth access token by loading the users .sredderc or prompting them to authenticate in their browser
33 34 35 36 37 |
# File 'lib/sredder.rb', line 33 def self.get_access_token auth = WrikeAuth.new auth.run_oauth_procedure unless auth. auth.oauth_access_token end |
.get_folder(access, folder) ⇒ Object
Fetches the ID of a wrike folder by name. Currently this is limited to subfolders of “SRED Time Tracking/”
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sredder.rb', line 41 def self.get_folder(access, folder) request = WrikeRequest.new(access) request.post('/api/json/v2/wrike.folder.tree', {}) regex = Regexp.new(Regexp.escape("SRED Time Tracking/#{folder}")) if request.success? request.json["foldersTree"]["folders"].each_with_object([]) do |folder, arr| arr << folder['id'].to_i if folder['fullPath'] =~ regex end else puts request.json puts 'Invalid response from Wrike' end end |
.get_pull_request(options) ⇒ Object
Github
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sredder.rb', line 79 def self.get_pull_request() auth = GithubAuth.new auth.run_oauth_procedure unless auth. request = GithubRequest.new(auth.token) request.get("https://api.github.com/repos/cloudClinic/cloudClinic-Server/pulls/#{[:github_id]}") [:title] = request.json["title"] [:message] = request.json["body"] end |
.run_command(argv) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sredder.rb', line 12 def self.run_command(argv) args_parser = ArgParser.new args_parser.parse(argv) args_parser.validate! = args_parser. # Github if [:github_id] get_pull_request() end # Wrike access = get_access_token folder_ids = get_folder(access, [:folder]) task_id = create_task(access, [:title], [:message], folder_ids) create_timelog(access, [:date], task_id, [:hours]) end |