Skip to content

Commit

Permalink
add maven's example
Browse files Browse the repository at this point in the history
  • Loading branch information
mnovozhylov committed Oct 12, 2015
1 parent 5704b99 commit 733f01d
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 0 deletions.
8 changes: 8 additions & 0 deletions example-maven/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
41 changes: 41 additions & 0 deletions example-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.Upwork</groupId>
<artifactId>test-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>test-api</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.Upwork</groupId>
<artifactId>api</artifactId>
<version>1.0.1</version>
<exclusions>
<exclusion>
<artifactId>httpcore</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.3</version>
</dependency>
</dependencies>
</project>
86 changes: 86 additions & 0 deletions example-maven/src/main/java/com/Upwork/test_api/App.java
Original file line number Diff line number Diff line change
@@ -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<String, String> 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();
}
}
}
38 changes: 38 additions & 0 deletions example-maven/src/test/java/com/Upwork/test_api/AppTest.java
Original file line number Diff line number Diff line change
@@ -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 );
}
}
2 changes: 2 additions & 0 deletions example-maven/upwork.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
consumerKey=xxxxxxxxxxxxxxxxxxxxxxxxxxx
consumerSecret=xxxxxxxxxxxxx

0 comments on commit 733f01d

Please sign in to comment.