Skip to content

webofthings/ThngDroid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ThngDroid

A Wrapper for the EVRYTHNG API that compiles with Dalvik to be used for your Android projects! This project is currently merely in a beta state! Don't expect extreme stability! ;-)

Usage in an Android projects

If you do not want to make changes to the library, simply use the latest build in the download section: https://github.com/domguinard/ThngDroid/downloads or build it from the sources (see below).

Add the library to your Android project (and make sure it is packaged by selecting it in "Order and Export") and use it from your activities/Android code.

Building the library

To generate a jar file that can be used in Android do:

mvn assembly:single

You can see this project in action in the FreezeMe app: https://github.com/webofthings/FreezeMe

Sample usage

public class Main {
	private static String EVRYTHNG_ROOT_URL_V3 = "URL";
	private static String EVRYTHNG_ROOT_URL_V2 = "https://evrythng.net/";
	private static String THNG_LI_URL = "URL";
	private static String API_KEY = "API-KEY";

	public static void main(String[] args) {
		EvrythngV2Wrapper wrapper = new EvrythngV2Wrapper(EVRYTHNG_ROOT_URL_V2, API_KEY);

		Thng thng = new Thng();
		thng.setName("Test from Android!");
		thng.setDescription("Hello Android World!");

		Thng newThng = wrapper.post("thngs", thng, Thng.class);
		Thng getThng = wrapper.get(String.format("thngs/%s", newThng.getId()), Thng.class);


		System.out.println("Created thng: " + newThng.getCreatedAt());
		System.out.println("Got thng: " + getThng.getCreatedAt());


		// Get properties
		Property<String> property = wrapper.get(String.format("thngs/%s/properties/%s", "4fdf251c0b1cdc017400009d", "ProductName"), Property.class);	
		System.out.println(property.getValue());

		// Get collection
		//http://evrythng.net/collections/4fdf2efe0b1cdc01700001e7
		ThngCollection collect = wrapper.get(String.format("collections/%s", "4fdf2efe0b1cdc01700001e7"), ThngCollection.class);
		System.out.println(collect.getDescription());

		// Add thng to collection
		ArrayList<String> thngs = new ArrayList<String>();
		thngs.add("4fdf251c0b1cdc017400009d");
		ArrayList<String> collectUpdated = wrapper.post(String.format("collections/%s/thngs", "4fdf2efe0b1cdc01700001e7"), thngs, ArrayList.class);
		System.out.println(collectUpdated);

		// Update time
		Property<String> updatedTime = new Property<String>("ExpiryDate", Calendar.getInstance().getTime().toString());
		Property<String> propertyUpdated = wrapper.put(String.format("thngs/%s/properties/%s", "4fdf251c0b1cdc017400009d", "ExpiryDate"), updatedTime, Property.class);
		System.out.println(propertyUpdated);
	}

}

About

Android Wrapper for the EVRYTHNG API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages