-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Simply declare jMite as dependency:
<dependency>
<groupId>org.jmite</groupId>
<artifactId>org.jmite</groupId>
<version>0.1.0.RELEASE</version>
Setting up a client instance of Mite is as easy as using the Builder class inside MiteClient and configuring it according to your needs. You essentially have to provide two things.
- The server name (typically your Mite account URL)
- Authentication data
- Username / password combination
- An API key (go to http://youraccount.mite.yo.lk/myself to get one)
So the code might look something like this.
Mite mite = new MiteClient.Builder("http://youraccount.mite.yo.lk")
.withUsernameAndPassword("your@username.com","password").build();
Having achieved that you can pretty much navigate the resources as you would do via the URL. So retrieving all Services registered for your account would look like this:
List<Services> services = mite.services().all();
Service service = mite.services().get(4711);
service.setNote("My new note");
mite.services().save(service);
As you can see, getting a single Service can be done using the get method providing the id of the Service. Updating a new Service is just a matter of manipulating the retrieved instance and calling save on the Services resource. Creating new Service resources works the same way. Just provide a fresh instance to save().
Accessing all TimeEntries does not make much sense. Most often you want to filter TimeEntries by a specific project, time period or something like this. Hence the TimeEntries resources offers query() to return a TimeEntryQuery, that you configure as you like and call execute() then:
TimeEntryQuery query = mite.timeEntries().query();
List entries = query.withProject(4712).within(TimePeriod.THIS_MONTH).execute();
This query will return all entries for the given project within the current month. Time periods can be expressed via the TimePeriod enum, a start and end DateMidnight or a single DateMidnight to configure the query to return entries for the given single day.
Navigating between other resources and time entries works the same way. You create a new query, apply already retrieved resources to the appropriate role and execute the query.
TimeEntry entry = mite.timeEntries().get(4715);
Project project = mite.projects().get(4716);
TimeEntryQuery query = mite.timeEntries().query();
List entries = query.withCustomer(entry).execute();
List entries = query.with(project).execute();
The first query will return all entries of the customer that the reference entry was made for. The second query will return all entries for the project retrieved before.
To be implemented