Git Product home page Git Product logo

harvest-client's Introduction

A Harvest Java Client

PullRequest codecov Known Vulnerabilities

harvest-client is a Java client for the Harvest REST API (https://help.getharvest.com/api-v2/)

Javadoc

Introduction

With harvest-client you can use the Harvest v2 API with a nice Java interface:

// Load configuration from application.conf in src/main/resources of your application
Harvest harvest = new Harvest();
// list all users
List<User> users = harvest.users().list();

for (User user : users) {
    log.debug("Found user: {}", user);
}
// create new user
User userInfo = ImmutableUser.builder()
                .firstName("first")
                .lastName("last")
                .email("[email protected]")
                .build();

User newUser = harvest.users().create(userInfo);

Have a look in the test folders for examples. Each API endpoint has a Create, List and Update test class.

Download

We use github package registry to publish this project

Packages

Gradle

implementation 'ch.aaap:harvest-client:$version'

Maven

<dependency>
  <groupId>ch.aaap</groupId>
  <artifactId>harvest-client</artifactId>
  <version>$version</version>
</dependency>

Getting started with Development

Using a build published on Github Packages

Packages for this project are first pushed to Github Package Registry (and then to maven central, not implemented yet). To use it as a dependency from there:

  1. add the following to your build.gradle file:
repositories {
    maven {
          name = "GitHubPackages"
          url = uri("https://maven.pkg.github.com/3ap-ag/harvest-client")
          credentials {
            username = project.findProperty("gpr.user") ?: System.getenv("GH_USERNAME")
            password = project.findProperty("gpr.key") ?: System.getenv("GH_TOKEN")
          }
          content {
            // this repository *only* contains artifacts with this group
            includeGroup "ch.aaap"
          }
        }
}

Using Github package repositories need authentication: see Installing a Package from Github Registry 2. You need to create a personal github token with the permissions: read:packages

  1. Then have it defined either as env. variables in GH_USERNAME and GH_TOKEN or you can add it as gradle properties, e.g. in ~/.gradle/gradle.properties using gpr.user and gpr.key.

  2. Add the dependency, e.g. add to build.gradle:

dependencies {
    implementation 'ch.aaap:harvest-client:1.1.4'
}

Publishing a new version manually

  1. Set new project.version in build.gradle
  2. Use a github token with at least these permissions: write:packages. See About Tokens
  3. Run gradle publish

Prerequisites

  • Java 8 (or higher)
  • Gradle

Run the build end tests

  • Clone or fork this repository
  • Get a personal access token from Harvest
    • Attention: unit tests assume admin access. Don't run them against a production account!
  • Configuring your Harvest account id and authentication token:
    • You will need 2 Harvest accounts with admin access (it's a limitation of the current Harvest API)
    • Either copy reference.conf to src/test/resources/admin{1,2}.conf and insert your credentials
    • Or set the following environment properties:
        $ export HARVEST_ACCOUNT_ID_ADMIN1=YOUR_ACCT_ID_1
        $ export HARVEST_AUTH_TOKEN_ADMIN1=YOUR_AUTH_TOKEN_1
        $ export HARVEST_ACCOUNT_ID_ADMIN2=YOUR_ACCT_ID_2
        $ export HARVEST_AUTH_TOKEN_ADMIN2=YOUR_AUTH_TOKEN_2
  • Run gradle build in the root directory of the repository

Creating a test Harvest account

Go to Harvest Sign up

  • Use your 3ap email with a "+" added to the name, e.g. [email protected] (this way you can create a filter in gmail to archive the emails you get)
  • Choose "Me and my team"
  • Select "Next Step" until the end.
  • Go to "Settings" -> "Chose Modules" -> Tick all modules
  • ! Only for the second account: Go to "Settings" -> "Edit Preferences" -> Set Time Mode to "Track time via start and end time"
  • Top left on your name -> My Profile -> link under work email to your Harvest ID settings -> Developers -> create new personal Token (name does not matter) Account ID and token are needed for authentication
  • Add your token to the local files admin1.conf and admin2.conf under src/test/resources/admin*.conf
  • Update the github secrets with these Id and tokens (you might need help from someone who has access to it on github)

Debugging

You can see the actual HTTP request and response by setting the log level for ch.aaap.harvestclient.core.Harvest.http to TRACE

Log4j2

<Logger name="ch.aaap.harvestclient.core.Harvest.http" level="trace" additivity="false">
    <AppenderRef ref="Console"/>
</Logger>

Found an Harvest Bug?

Check out TestSetupUtil.prepareForHarvestBugReport() to setup your logs before sending them to Harvest.

Contributing

We welcome contributions in the form of pull requests or bug reports! Please read Developers before submitting a pull request. If you plan a big change, please open an issue first so you can get early feedback on your design.

harvest-client's People

Contributors

auricgoldfinger avatar dan-m avatar giovannifilannino avatar mnembrini avatar predragmpetrovic avatar primaproxima avatar sboldur avatar spiewok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

harvest-client's Issues

Some tests are now failing

Some tests are currently failing:

Failures (6):
  JUnit Jupiter:UserAssignmentsApiCreateTest:createAllOptions()
    MethodSource [className = 'ch.aaap.harvestclient.impl.userAssignment.UserAssignmentsApiCreateTest', methodName = 'createAllOptions', methodParameterTypes = '']
    => java.lang.AssertionError:
Expecting value <220.0> in field <"hourlyRate"> but was <null> in <UserAssignment{user=UserReferenceDto{id=3097813, name=Marioanother Muster 71962}, active=false, projectManager=true, hourlyRate=null, budget=1111.0, id=228507658, createdAt=2020-01-14T15:41:37Z, updatedAt=2020-01-14T15:41:37Z}>.
Comparison was performed on all fields but <["id", "createdAt", "updatedAt"]>
       ch.aaap.harvestclient.impl.userAssignment.UserAssignmentsApiCreateTest.createAllOptions(UserAssignmentsApiCreateTest.java:67)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:436)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
       org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
       org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
       [...]
  JUnit Jupiter:UserAssignmentsApiUpdateTest:changeAll()
    MethodSource [className = 'ch.aaap.harvestclient.impl.userAssignment.UserAssignmentsApiUpdateTest', methodName = 'changeAll', methodParameterTypes = '']
    => java.lang.AssertionError:
Expecting value <110.0> in field <"hourlyRate"> but was <null> in <UserAssignment{user=UserReferenceDto{id=3097813, name=Marioanother Muster 71962}, active=true, projectManager=true, hourlyRate=null, budget=1.1111111E7, id=228507672, createdAt=2020-01-14T15:41:43Z, updatedAt=2020-01-14T15:41:44Z}>
       ch.aaap.harvestclient.impl.userAssignment.UserAssignmentsApiUpdateTest.changeAll(UserAssignmentsApiUpdateTest.java:65)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:436)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
       org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
       org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
       [...]
  JUnit Jupiter:ProjectsApiUpdateTest:changeBudgetByMinimal()
    MethodSource [className = 'ch.aaap.harvestclient.impl.project.ProjectsApiUpdateTest', methodName = 'changeBudgetByMinimal', methodParameterTypes = '']
    => ch.aaap.harvestclient.exception.RequestProcessingException: Name This project name is already used on another project.
       ch.aaap.harvestclient.impl.ExceptionHandler.callOrThrow(ExceptionHandler.java:56)
       ch.aaap.harvestclient.impl.ExceptionHandler.callOrThrow(ExceptionHandler.java:32)
       ch.aaap.harvestclient.impl.ProjectsApiImpl.create(ProjectsApiImpl.java:53)
       ch.aaap.harvestclient.impl.project.ProjectsApiUpdateTest.beforeEach(ProjectsApiUpdateTest.java:53)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:436)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       [...]
  JUnit Jupiter:TimesheetsApiListTest:listPaginated()
    MethodSource [className = 'ch.aaap.harvestclient.impl.timesheet.TimesheetsApiListTest', methodName = 'listPaginated', methodParameterTypes = '']
    => java.lang.AssertionError:
Expecting:
 <1>
to be greater than or equal to:
 <2>
       ch.aaap.harvestclient.impl.timesheet.TimesheetsApiListTest.listPaginated(TimesheetsApiListTest.java:108)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:436)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
       org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
       org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
       [...]
  JUnit Jupiter:ClientsApiCreateTest:createInvalidCurrency()
    MethodSource [className = 'ch.aaap.harvestclient.impl.client.ClientsApiCreateTest', methodName = 'createInvalidCurrency', methodParameterTypes = '']
    => org.junit.ComparisonFailure: expected:<"[USD]"> but was:<"[CHF]">
       sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       ch.aaap.harvestclient.impl.client.ClientsApiCreateTest.createInvalidCurrency(ClientsApiCreateTest.java:79)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:436)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       [...]
  JUnit Jupiter:InvoicesApiListTest:listByDateRange()
    MethodSource [className = 'ch.aaap.harvestclient.impl.invoice.InvoicesApiListTest', methodName = 'listByDateRange', methodParameterTypes = '']
    => ch.aaap.harvestclient.exception.RequestProcessingException: Issued at must be on or after 2000-01-14, Due at must be on or after 2000-01-14
       ch.aaap.harvestclient.impl.ExceptionHandler.callOrThrow(ExceptionHandler.java:56)
       ch.aaap.harvestclient.impl.ExceptionHandler.callOrThrow(ExceptionHandler.java:32)
       ch.aaap.harvestclient.impl.InvoicesApiImpl.create(InvoicesApiImpl.java:59)
       ch.aaap.harvestclient.impl.invoice.InvoicesApiListTest.listByDateRange(InvoicesApiListTest.java:157)
       sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke(Method.java:498)
       org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:436)
       org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
       [...]

investigate why

New Issue Checklist

Issue Description

Complete output
[INSERT LOGS HERE]

Environment

[INSERT OUTPUT HERE]

Extend the harvest client configuration to allow API rate limiting for Harvest Report APIs

New Issue Checklist

Issue Description

Harvest API reporting endpoints (such expenses, invoices) have different rate limits, then the other API endpoints. Basically Harvest classifies the endpoints into two groups, each having its own API limits.

Currently, the harvest client does not distinguish these two API limit types. It only allows to configure one pair of time window and maximum request for that time window.

This introduces a risk to hit the API limits when using the library in production, or when running the integration tests.
One way around this is creating a dedicated request Interceptor (from okhttp library) and configuration, in order to instantiate the Report APIs using the rate limiting setting.

Find more about the Harvest API v2 rate limits here

Complete output
n/a

Environment

There's nothing specific to the environment that is affecting the issue.

[INSERT OUTPUT HERE]

Update ExistingData mechanism

The ExistingData class in the test folder is used to setup some initial data the integration test rely on.
This has a manual step that is tedious: Think about a better method for this.

One option is to create a file to store the ids of the created objects: this should speed up successive tests run on the same environment. This feature should be opt-in for the developer:
by default everything should run out of the box without requiring any manual changes

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.