Giter VIP home page Giter VIP logo

skybrud.social.toggl's Introduction

Skybrud.Social.Toggl

GitHub license NuGet NuGet

.NET API wrapper and implementation of the Toggl Track API.

License: MIT License
Target Framework: .NET 4.5, .NET 4.6, .NET 4.7, .NET Standard 2.0 and .NET8



Installation

The package is only available via NuGet. To install the package, you can either use the .NET CLI:

dotnet add package Skybrud.Social.Toggl --version 1.0.0-beta008

or the NuGet Package Manager:

Install-Package Skybrud.Social.Toggl -Version 1.0.0-beta008



Examples

Initialize a new HTTP service

The TogglHttpService class is the entry point for communicating with the Toggl Track API:

@using Skybrud.Social.Toggl
@{

    // Initialize from your API token
    TogglHttpService toggl = TogglHttpService.CreateFromApiToken("Your API token");

}

List all clients

@using Skybrud.Social.Toggl
@using Skybrud.Social.Toggl.Exceptions
@using Skybrud.Essentials.Json
@using Newtonsoft.Json.Linq
@using Skybrud.Social.Toggl.Responses.Track.Clients
@inherits UmbracoViewPage<Skybrud.Social.Toggl.TogglHttpService>
@{

    // Declare your workspace ID
    int workspaceId = 1234;

    // Initialize from your API token
    TogglHttpService toggl = TogglHttpService.CreateFromApiToken("Your API token");

    try {

        // Make the request to the API
        TogglClientListResponse response = toggl.Track.Clients.GetClients(workspaceId);

        <table class="table list">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                </tr>
            </thead>
            <tbody>
                @foreach (TogglClient client in response.Body) {
                    <tr>
                        <td>@client.Id</td>
                        <td>@client.Name</td>
                    </tr>
                }
            </tbody>
        </table>

    } catch (TogglHttpException ex) {

        <pre>@ex.Response.StatusCode @ex.Response.ResponseUri</pre>
    
        <pre>@(JsonUtils.TryParseJsonToken(ex.Response.Body, out JToken token) ? token : ex.Response.Body)</pre>

    }

}

List all projects

Projects are fetched via the Projects endpoint, and you must specify the ID of the workspace to retrieve projects for:

@using Skybrud.Social.Toggl
@using Skybrud.Social.Toggl.Exceptions
@using Skybrud.Essentials.Json
@using Newtonsoft.Json.Linq
@using Skybrud.Social.Toggl.Models.Track.Projects
@using Skybrud.Social.Toggl.Options.Track.Projects
@using Skybrud.Social.Toggl.Responses.Track.Projects
@inherits UmbracoViewPage<Skybrud.Social.Toggl.TogglHttpService>
@{

    // Declare your workspace ID
    int workspaceId = 1234;

    // Initialize from your API token
    TogglHttpService toggl = TogglHttpService.CreateFromApiToken("Your API token");

    try {

        // Make the request to the API
        TogglProjectListResponse response = toggl.Track.Workspaces.GetProjects(workspaceId);

        <table class="table list">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>ClientID</th>
                    <th>HEX</th>
                </tr>
            </thead>
            <tbody>
                @foreach (TogglProject project in response.Body) {
                    <tr>
                        <td>@project.Id</td>
                        <td>@project.Name</td>
                        <td>@project.ClientId</td>
                        <td>@project.HexColor</td>
                    </tr>
                }
            </tbody>
        </table>

    } catch (TogglHttpException ex) {

        <pre>@ex.Response.StatusCode @ex.Response.ResponseUri</pre>
    
        <pre>@(JsonUtils.TryParseJsonToken(ex.Response.Body, out JToken token) ? token : ex.Response.Body)</pre>

    }

}

skybrud.social.toggl's People

Contributors

abjerner avatar

Watchers

 avatar  avatar  avatar

Forkers

cmoski

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.