GithubHelp home page GithubHelp logo

kamil-rudnicki / timecamp-api-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rupkoe/timecamp-api

0.0 1.0 0.0 32 KB

A partial client for the TimeCamp API

License: MIT License

Go 100.00%

timecamp-api-1's Introduction

Go TimeCamp API Client

Go

A partial client for the TimeCamp API.

The api package currently supports fetching tasks and time entries from the api. The optional parser package helps with processing the retrieved data.

API

Provides raw data from the TimeCamp API. Supports currently only fetching tasks and time entries.

Sample Usage

package main

import 	(
	"github.com/rupkoe/timecamp-api"
	"time"
)

func main() {
    connection := api.Connection{
        ApiUrl: "https://www.timecamp.com/third_party/api",
        Token:  "secret-token",
    }

    tasks, err := api.GetTasks(connection, api.TaskParams{})
    //...
    
    from, _ := time.Parse(time.RFC822, "01 Jan 21 00:00 CET")
    to, _ := time.Parse(time.RFC822, "31 Jan 21 00:00 CET")
    entries, err := api.GetTimeEntries(connection, api.TimeEntryParams{From: from, To: to})
    //...
}

Parser

The parser package allows to work on data retrieved from the TimeCamp API.

As a prerequisite, get the desired data from the API. Use filters to your liking.

// get time entries from api
timeEntries, err := api.GetTimeEntries(connection, api.TimeEntryParams{})
if err != nil {
    ...
}

// get tasks from api
tasks, err := api.GetTasks(connection, api.TaskParams{})
if err != nil {
    ...
}

If you retrieved all tasks, you may get the projects (=top-level tasks) by using

projectList := parser.GetProjectList(tasks)

Walk the task tree starting at a given (root) node, providing a callback function that is called for every task being visited.

parser.WalkTaskTree(tasks, project, true, printit)

func printit(task api.Task, parentIds map[int]string) {
    for i := 1; i < task.LevelParsed(); i++ {
        fmt.Print("-")
    }
    fmt.Println(task.Level, task.TaskID, task.Name, parentIds)
}

Summarize the times spent on tasks and return a map with total and billable times per task, summarized all the way up to the root node.

tasktotals := parser.SummarizeTaskTree(tasks, timeEntries, project)

TimeCamp API Oddness

Documents unexpected behaviour of the TimeCamp API for further reference / future development.

  • API returns different id value types:
    • string for Task
    • number for TimeEntry
  • Task JSON has variable, redundant keys (TaskID)

timecamp-api-1's People

Contributors

dfritschy avatar rupkoe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.