Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 733f01d

Browse files
committed
add maven's example
1 parent 5704b99 commit 733f01d

File tree

5 files changed

+175
-0
lines changed

5 files changed

+175
-0
lines changed

example-maven/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
4+
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
6+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
7+
<classpathentry kind="output" path="target/classes"/>
8+
</classpath>

example-maven/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.Upwork</groupId>
6+
<artifactId>test-api</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>test-api</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>3.8.1</version>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>com.Upwork</groupId>
26+
<artifactId>api</artifactId>
27+
<version>1.0.1</version>
28+
<exclusions>
29+
<exclusion>
30+
<artifactId>httpcore</artifactId>
31+
<groupId>org.apache.httpcomponents</groupId>
32+
</exclusion>
33+
</exclusions>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.apache.httpcomponents</groupId>
37+
<artifactId>httpcore</artifactId>
38+
<version>4.4.3</version>
39+
</dependency>
40+
</dependencies>
41+
</project>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.Upwork.test_api;
2+
3+
import java.net.URLDecoder;
4+
import java.util.HashMap;
5+
import java.util.Scanner;
6+
7+
import org.json.JSONException;
8+
import org.json.JSONObject;
9+
10+
import com.Upwork.api.OAuthClient;
11+
import com.Upwork.api.Routers.Organization.Users;
12+
13+
/**
14+
* Hello world! Test Upwork API
15+
*
16+
*/
17+
public class App
18+
{
19+
@SuppressWarnings("unused")
20+
public static void main( String[] args )
21+
{
22+
//assign access token-secret pair if they are already known
23+
//this process is up to application how to save and store
24+
//in secure token's data
25+
//String aToken = "xxxxxxxxxxxxxxxxxxxxxxxxx";
26+
//String aSecret = "xxxxxxxxxxx";
27+
28+
//by default token and secret are unknown
29+
//and application must follow authorization process
30+
String aToken = null;
31+
String aSecret = null;
32+
33+
OAuthClient client = new OAuthClient(null);
34+
35+
// authorize application and get access token
36+
if (aToken == null && aSecret == null) {
37+
Scanner scanner = new Scanner(System.in);
38+
String authzUrl = client.getAuthorizationUrl();
39+
System.out.println(authzUrl);
40+
41+
System.out.println("1. Copy paste the following url in your browser : ");
42+
System.out.println(authzUrl);
43+
System.out.println("2. Grant access ");
44+
System.out.println("3. Copy paste the oauth_verifier parameter here :");
45+
46+
String oauth_verifier = scanner.nextLine();
47+
48+
String verifier = null;
49+
try {
50+
verifier = URLDecoder.decode(oauth_verifier,"UTF-8");
51+
}
52+
catch (Exception e) {
53+
e.printStackTrace();
54+
}
55+
56+
HashMap<String, String> token = client.getAccessTokenSet(verifier);
57+
58+
scanner.close();
59+
System.out.println(token);
60+
} else {
61+
// set known access token-secret pair
62+
client.setTokenWithSecret(aToken, aSecret);
63+
}
64+
65+
JSONObject json1 = null;
66+
try {
67+
// Get info of authenticated user
68+
Users users = new Users(client);
69+
json1 = users.getMyInfo();
70+
71+
// get my uid
72+
String myId = null;
73+
try {
74+
JSONObject user = json1.getJSONObject("user");
75+
myId = user.getString("id");
76+
System.out.println(myId);
77+
}
78+
catch (JSONException e) {
79+
e.printStackTrace();
80+
}
81+
}
82+
catch (JSONException e) {
83+
e.printStackTrace();
84+
}
85+
}
86+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.Upwork.test_api;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

example-maven/upwork.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
consumerKey=xxxxxxxxxxxxxxxxxxxxxxxxxxx
2+
consumerSecret=xxxxxxxxxxxxx

0 commit comments

Comments
 (0)