Class: FtgSync
- Inherits:
-
Object
- Object
- FtgSync
- Defined in:
- lib/ftg/ftg_sync.rb
Constant Summary collapse
- TOGGL_API_TOKEN =
'317c14d9c290d3c6cc1e4f35a2ad8c80'
- TIME_ENTRIES_URL =
'https://toggl.com/api/v8/time_entries'
- WORKSPACE_ID =
939576
- PIDS =
{ autres: 9800260, maintenance: 9800223, projects: 10669186, reu: 9800248, sprint: 9800218, support: 9800226, technical: 9800254 }
Instance Method Summary collapse
- #between_time_range ⇒ Object
- #create_entry(description, duration_sec, start_date, type) ⇒ Object
- #delete_entry ⇒ Object
- #get_jt_info(jt) ⇒ Object
-
#initialize ⇒ FtgSync
constructor
A new instance of FtgSync.
- #maintenance?(jt) ⇒ Boolean
- #me ⇒ Object
- #run ⇒ Object
- #workspace_projects ⇒ Object
Constructor Details
#initialize ⇒ FtgSync
Returns a new instance of FtgSync.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ftg/ftg_sync.rb', line 16 def initialize require 'uri' require 'httparty' @headers = { 'Content-Type' => 'application/json' } @credentials = { username: TOGGL_API_TOKEN, password: 'api_token' } @base_query = { user_agent: 'ftg', workspace_id: WORKSPACE_ID } @base_params = { headers: @headers, query: @base_query, basic_auth: @credentials } @base_params_jira = { headers: @headers, basic_auth: { username: 'benjamin.crouzier', password: 'morebabyplease' } } end |
Instance Method Details
#between_time_range ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/ftg/ftg_sync.rb', line 87 def between_time_range start_date = Time.new(2014, 01, 01).iso8601 end_date = Time.now.iso8601 # URI.encode(...) does not escape ':' for some reason params = "?start_date=#{CGI.escape(start_date)}&end_date=#{CGI.escape(end_date)}" response = HTTParty.get(TIME_ENTRIES_URL + params, @base_params.merge({body: params.to_json})) binding.pry end |
#create_entry(description, duration_sec, start_date, type) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ftg/ftg_sync.rb', line 58 def create_entry(description, duration_sec, start_date, type) puts "creating entry #{description}, #{duration_sec}, #{start_date}, #{type}" params = { "time_entry" => { "description" => description, "tags" => [], "duration" => duration_sec, "start" => start_date.iso8601, "pid" => PIDS[type], "created_with" => "ftg" } } HTTParty.post(TIME_ENTRIES_URL, @base_params.merge({body: params.to_json})) end |
#delete_entry ⇒ Object
71 72 73 74 |
# File 'lib/ftg/ftg_sync.rb', line 71 def delete_entry response = HTTParty.delete(TIME_ENTRIES_URL + '/279467425', @base_params.merge({})) end |
#get_jt_info(jt) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/ftg/ftg_sync.rb', line 80 def get_jt_info(jt) HTTParty.get( "https://jobteaser.atlassian.net/rest/api/2/issue/#{jt.upcase}", @base_params_jira.merge({}) ) end |
#maintenance?(jt) ⇒ Boolean
76 77 78 |
# File 'lib/ftg/ftg_sync.rb', line 76 def maintenance?(jt) get_jt_info(jt)['fields']['customfield_10400']['value'] == 'Maintenance' rescue nil end |
#me ⇒ Object
104 105 106 107 108 109 |
# File 'lib/ftg/ftg_sync.rb', line 104 def me HTTParty.get( 'https://toggl.com/api/v8/me', @base_params.merge({}) ) end |
#run ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ftg/ftg_sync.rb', line 47 def run # current_user_id = me['data']['id'] abort('no') binding.pry # workspace_users # between_time_range end |
#workspace_projects ⇒ Object
97 98 99 100 101 102 |
# File 'lib/ftg/ftg_sync.rb', line 97 def workspace_projects response = HTTParty.get( "https://toggl.com/api/v8/workspaces/#{WORKSPACE_ID}/projects", @base_params.merge({}) ) end |