Skip to content

Commit 067d3f2

Browse files
committed
add QBAPIHelper
1 parent 40ee12b commit 067d3f2

File tree

20 files changed

+1482
-0
lines changed

20 files changed

+1482
-0
lines changed

ipp-java-qbapihelper/pom.xml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>ipp-v3-java-devkit-pom</artifactId>
6+
<groupId>com.intuit.quickbooks-online</groupId>
7+
<version>2.9.0</version>
8+
</parent>
9+
<artifactId>ipp-java-qbapihelper</artifactId>
10+
<version>2.9.0</version>
11+
<packaging>jar</packaging>
12+
<name>Quickbooks API Helper for Oauth</name>
13+
<description>Quickbooks API Helper Project for OAuth, Disconnect and Reconnect</description>
14+
15+
<profiles>
16+
<profile>
17+
<properties>
18+
<test.suite>testng.xml</test.suite>
19+
</properties>
20+
</profile>
21+
</profiles>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>oauth.signpost</groupId>
26+
<artifactId>signpost-core</artifactId>
27+
<version>1.2.1.1</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>oauth.signpost</groupId>
31+
<artifactId>signpost-commonshttp4</artifactId>
32+
<version>1.2</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>net.sf.kxml</groupId>
36+
<artifactId>kxml2</artifactId>
37+
<version>2.2.2</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.testng</groupId>
41+
<artifactId>testng</artifactId>
42+
<version>6.1.1</version>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>javax.servlet</groupId>
47+
<artifactId>servlet-api</artifactId>
48+
<version>2.4</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.apache.httpcomponents</groupId>
53+
<artifactId>httpcore</artifactId>
54+
<version>4.4.5</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.apache.httpcomponents</groupId>
58+
<artifactId>httpclient</artifactId>
59+
<version>4.5.2</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.openid4java</groupId>
63+
<artifactId>openid4java</artifactId>
64+
<version>0.9.8</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.slf4j</groupId>
68+
<artifactId>slf4j-api</artifactId>
69+
<version>1.6.4</version>
70+
</dependency>
71+
72+
</dependencies>
73+
74+
<build>
75+
<!--<finalName>ipp-java-qbhelper</finalName> -->
76+
<testResources>
77+
<testResource>
78+
<directory>${basedir}/src/test/resources</directory>
79+
</testResource>
80+
</testResources>
81+
<resources>
82+
<resource>
83+
<directory>${basedir}/src/main/resources</directory>
84+
</resource>
85+
</resources>
86+
87+
<plugins>
88+
<!-- This plug-in instructs to use the mentioned JDK for compilation Reference:-
89+
http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html -->
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-compiler-plugin</artifactId>
93+
<version>2.5.1</version>
94+
<configuration>
95+
<source>1.6</source>
96+
<target>1.6</target>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<artifactId>maven-jar-plugin</artifactId>
101+
<configuration>
102+
<archive>
103+
<manifest>
104+
<mainClass>fully.qualified.MainClass
105+
</mainClass>
106+
</manifest>
107+
</archive>
108+
</configuration>
109+
</plugin>
110+
<plugin>
111+
<artifactId>maven-assembly-plugin</artifactId>
112+
<configuration>
113+
<finalName>${project.artifactId}-${project.version}</finalName>
114+
<descriptorRefs>
115+
<descriptorRef>jar-with-dependencies</descriptorRef>
116+
</descriptorRefs>
117+
</configuration>
118+
<executions>
119+
<execution>
120+
<id>qb-helper</id>
121+
<phase>package</phase>
122+
<goals>
123+
<goal>single</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
</plugins>
129+
</build>
130+
</project>
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
package com.intuit.ia.connection;
2+
3+
/**
4+
* @author: Aditi
5+
*
6+
* This class exposes APIs for disconnect (disconnect) and fetching blue dot menu dropdown(getAppMenu)
7+
*/
8+
9+
import java.util.List;
10+
import java.util.Map;
11+
12+
import org.openid4java.discovery.Identifier;
13+
14+
import com.intuit.ia.exception.ConnectionException;
15+
import com.intuit.ia.exception.OAuthException;
16+
import com.intuit.ia.exception.OpenIdException;
17+
18+
public class IAPlatformClient {
19+
20+
private PlatformHttpClient httpClient;
21+
22+
private OAuthHelper oAuthHelper;
23+
private OpenIdHelper openIdHelper;
24+
25+
public IAPlatformClient() {
26+
openIdHelper = new OpenIdHelper();
27+
oAuthHelper = new OAuthHelper();
28+
}
29+
30+
/**
31+
* Disconnects the user from quickbooks
32+
*
33+
* @throws ConnectionException
34+
*/
35+
public PlatformResponse disconnect(String consumerKey, String consumerSecret,
36+
String accessToken, String accessTokenSecret)
37+
throws ConnectionException {
38+
httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
39+
accessToken, accessTokenSecret);
40+
return this.httpClient.disconnect();
41+
}
42+
/**
43+
* getCurrentUser the user from quickbooks
44+
*
45+
* @throws ConnectionException
46+
*/
47+
public User getcurrentUser(String consumerKey, String consumerSecret,
48+
String accessToken, String accessTokenSecret)
49+
throws ConnectionException {
50+
httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
51+
accessToken, accessTokenSecret);
52+
User user = null;;
53+
try {
54+
user = this.httpClient.getCurrentUser();
55+
} catch (Exception e) {
56+
e.printStackTrace();
57+
}
58+
return user;
59+
}
60+
61+
/**
62+
* Get App Menu returns list of all the applications that are linked with
63+
* the selected company
64+
*
65+
* @return List<String>: Returns HTML as a list of Strings
66+
* @throws ConnectionException
67+
*
68+
*/
69+
public List<String> getAppMenu(String consumerKey, String consumerSecret,
70+
String accessToken, String accessTokenSecret)
71+
throws ConnectionException {
72+
try {
73+
List<String> menulist;
74+
httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
75+
accessToken, accessTokenSecret);
76+
menulist = this.httpClient.getAppMenu();
77+
return menulist;
78+
} catch (ConnectionException conEx) {
79+
throw conEx;
80+
} catch (Exception e) {
81+
throw new ConnectionException("Failed to fetch appmenu: "
82+
+ e.getMessage());
83+
}
84+
}
85+
86+
public Map<String, String> getRequestTokenAndSecret(String consumerKey,
87+
String consumerSecret) throws OAuthException {
88+
return oAuthHelper.getRequestToken(consumerKey, consumerSecret);
89+
}
90+
91+
/**
92+
*
93+
* @param requestToken
94+
* @return authorizeUrl
95+
* @throws OAuthException
96+
*
97+
* This API will prepare the authorization URL and return it back
98+
*/
99+
100+
public String getOauthAuthorizeUrl(String requestToken)
101+
throws OAuthException {
102+
103+
return oAuthHelper.getAuthorizeUrl(requestToken);
104+
105+
}
106+
107+
/**
108+
*
109+
* Gets the accesstoken and accesstokensecret
110+
*
111+
* @param verofierCode
112+
* @param requestToken
113+
* (After the user authorization)
114+
* @param requestTokensecret
115+
* @return Map<String> : where accesstoken will be in the key "accessToken"
116+
* and accesstokensecret will be in key "accessTokenSecret"
117+
*
118+
*/
119+
120+
public Map<String, String> getOAuthAccessToken(String verifierCode,
121+
String requestToken, String requestTokenSecret, String consumerKey,
122+
String consumerSecret) throws OAuthException {
123+
124+
return oAuthHelper.getAccessToken(verifierCode, requestToken,
125+
requestTokenSecret, consumerKey, consumerSecret);
126+
}
127+
128+
/**
129+
* Gets the authorization url for OpenId
130+
*
131+
* @throws
132+
*
133+
*
134+
*/
135+
136+
public String getOpenIdAuthorizeUrl() throws OpenIdException {
137+
138+
return openIdHelper.initOpenIdFlow();
139+
}
140+
141+
/**
142+
*
143+
* @param receivingUrl
144+
* @param parameterMap
145+
* @return Identifier : the OpenId Identifier
146+
* @throws OpenIdException
147+
*/
148+
public Identifier verifyOpenIdResponse(String receivingUrl,
149+
Map<String, String[]> parameterMap) throws OpenIdException {
150+
return openIdHelper.verifyResponse(receivingUrl, parameterMap);
151+
}
152+
153+
/**
154+
*
155+
* @param consumerKey
156+
* @param consumerSecret
157+
* @param accessToken
158+
* @param accessTokenSecret
159+
* @throws ConnectionException
160+
*/
161+
public PlatformResponse reConnect(String consumerKey, String consumerSecret,
162+
String accessToken, String accessTokenSecret)
163+
throws ConnectionException {
164+
165+
httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
166+
accessToken, accessTokenSecret);
167+
return this.httpClient.reConnect();
168+
}
169+
}

0 commit comments

Comments
 (0)