diff --git a/example-maven/.classpath b/example-maven/.classpath new file mode 100644 index 0000000..f362f73 --- /dev/null +++ b/example-maven/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/example-maven/pom.xml b/example-maven/pom.xml new file mode 100644 index 0000000..83363e5 --- /dev/null +++ b/example-maven/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + + com.Upwork + test-api + 0.0.1-SNAPSHOT + jar + + test-api + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + com.Upwork + api + 1.0.1 + + + httpcore + org.apache.httpcomponents + + + + + org.apache.httpcomponents + httpcore + 4.4.3 + + + diff --git a/example-maven/src/main/java/com/Upwork/test_api/App.java b/example-maven/src/main/java/com/Upwork/test_api/App.java new file mode 100644 index 0000000..3ed9258 --- /dev/null +++ b/example-maven/src/main/java/com/Upwork/test_api/App.java @@ -0,0 +1,86 @@ +package com.Upwork.test_api; + +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Scanner; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.Upwork.api.OAuthClient; +import com.Upwork.api.Routers.Organization.Users; + +/** + * Hello world! Test Upwork API + * + */ +public class App +{ + @SuppressWarnings("unused") + public static void main( String[] args ) + { + //assign access token-secret pair if they are already known + //this process is up to application how to save and store + //in secure token's data + //String aToken = "xxxxxxxxxxxxxxxxxxxxxxxxx"; + //String aSecret = "xxxxxxxxxxx"; + + //by default token and secret are unknown + //and application must follow authorization process + String aToken = null; + String aSecret = null; + + OAuthClient client = new OAuthClient(null); + + // authorize application and get access token + if (aToken == null && aSecret == null) { + Scanner scanner = new Scanner(System.in); + String authzUrl = client.getAuthorizationUrl(); + System.out.println(authzUrl); + + System.out.println("1. Copy paste the following url in your browser : "); + System.out.println(authzUrl); + System.out.println("2. Grant access "); + System.out.println("3. Copy paste the oauth_verifier parameter here :"); + + String oauth_verifier = scanner.nextLine(); + + String verifier = null; + try { + verifier = URLDecoder.decode(oauth_verifier,"UTF-8"); + } + catch (Exception e) { + e.printStackTrace(); + } + + HashMap token = client.getAccessTokenSet(verifier); + + scanner.close(); + System.out.println(token); + } else { + // set known access token-secret pair + client.setTokenWithSecret(aToken, aSecret); + } + + JSONObject json1 = null; + try { + // Get info of authenticated user + Users users = new Users(client); + json1 = users.getMyInfo(); + + // get my uid + String myId = null; + try { + JSONObject user = json1.getJSONObject("user"); + myId = user.getString("id"); + System.out.println(myId); + } + catch (JSONException e) { + e.printStackTrace(); + } + } + catch (JSONException e) { + e.printStackTrace(); + } + } +} diff --git a/example-maven/src/test/java/com/Upwork/test_api/AppTest.java b/example-maven/src/test/java/com/Upwork/test_api/AppTest.java new file mode 100644 index 0000000..449f94c --- /dev/null +++ b/example-maven/src/test/java/com/Upwork/test_api/AppTest.java @@ -0,0 +1,38 @@ +package com.Upwork.test_api; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/example-maven/upwork.properties b/example-maven/upwork.properties new file mode 100644 index 0000000..4fe4d7e --- /dev/null +++ b/example-maven/upwork.properties @@ -0,0 +1,2 @@ +consumerKey=xxxxxxxxxxxxxxxxxxxxxxxxxxx +consumerSecret=xxxxxxxxxxxxx