-
Notifications
You must be signed in to change notification settings - Fork 7
Update library to use Phaxio API to use v2.1 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| <groupId>com.phaxio</groupId> | ||
| <artifactId>phaxio-java</artifactId> | ||
| <version>0.3.8</version> | ||
| <version>0.4.0</version> | ||
|
|
||
| <name>Phaxio Java Client</name> | ||
| <description>The official Phaxio client for the JVM</description> | ||
|
|
@@ -37,8 +37,8 @@ | |
| <connection>scm:git:[email protected]:phaxio/phaxio-java.git</connection> | ||
| <developerConnection>scm:git:[email protected]:phaxio/phaxio-java.git</developerConnection> | ||
| <url>[email protected]:phaxio/phaxio-java.git</url> | ||
| <tag>phaxio-java-0.3.4</tag> | ||
| </scm> | ||
| <tag>phaxio-java-0.4.0</tag> | ||
| </scm> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.phaxio.entities; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| public class Barcode { | ||
| @JsonProperty("type") | ||
| public String type; | ||
|
|
||
| @JsonProperty("page") | ||
| public int page; | ||
|
|
||
| @JsonProperty("value") | ||
| public String value; | ||
|
|
||
| @JsonProperty("identifier") | ||
| public String identifier; | ||
|
|
||
| @JsonProperty("metadata") | ||
| public String metadata; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,15 +13,15 @@ | |
| public class RestClient { | ||
| private static final int TIMEOUT = 30000; | ||
| private final String endpoint; | ||
| private BasicAuthentication auth; | ||
| private BasicAuthorization auth; | ||
| final private Proxy proxy; | ||
|
|
||
| public RestClient(String endpoint,Proxy proxy) { | ||
| public RestClient(String endpoint, Proxy proxy) { | ||
| this.endpoint = endpoint; | ||
| this.proxy = proxy; | ||
| } | ||
|
|
||
| public void setAuthentication(BasicAuthentication auth) { | ||
| public void setAuthorization(BasicAuthorization auth) { | ||
| this.auth = auth; | ||
| } | ||
|
|
||
|
|
@@ -101,7 +101,7 @@ public RestResponse execute(RestRequest request) { | |
| dos.writeBytes("--\r\n"); | ||
| dos.flush(); | ||
| dos.close(); | ||
| } else { | ||
| } else if (!request.parameters.isEmpty()) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were always sending at least the authorization parameters, so this client never had to deal with an empty body. This allows that. |
||
| byte[] body = getQueryString(request).substring(1).getBytes("UTF-8"); | ||
|
|
||
| conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | ||
|
|
@@ -113,6 +113,8 @@ public RestResponse execute(RestRequest request) { | |
| dos.write(body); | ||
| dos.flush(); | ||
| dos.close(); | ||
| } else { | ||
| conn.setRequestProperty("Content-Length", "0"); | ||
| } | ||
|
|
||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.phaxio.helpers; | ||
|
|
||
| import com.github.tomakehurst.wiremock.matching.StringValuePattern; | ||
| import com.phaxio.restclient.BasicAuthorization; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; | ||
|
|
||
| public class Auth { | ||
| public static final String VALID_KEY = "KEY"; | ||
| public static final String VALID_SECRET = "SECRET"; | ||
| public static final StringValuePattern VALID_AUTH_MATCHER = equalTo(new BasicAuthorization(VALID_KEY, VALID_SECRET).toHeader()); | ||
|
|
||
| public static StringValuePattern authMatcher(String username, String password) { | ||
| return equalTo(new BasicAuthorization(username, password).toHeader()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
| import com.phaxio.Phaxio; | ||
| import com.phaxio.entities.Account; | ||
| import com.phaxio.helpers.Auth; | ||
| import com.phaxio.helpers.Responses; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
@@ -22,13 +23,14 @@ public class AccountRepositoryTest { | |
| public void getsAccountStatus () throws IOException { | ||
| String json = Responses.json("/account_status.json"); | ||
|
|
||
| stubFor(get(urlEqualTo("/v2/account/status?api_secret=SECRET&api_key=KEY")) | ||
| stubFor(get(urlEqualTo("/ver/account/status")) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the version string isn't really important, I'm just faking it with the placeholder |
||
| .withHeader("Authorization", Auth.VALID_AUTH_MATCHER) | ||
| .willReturn(aResponse() | ||
| .withStatus(200) | ||
| .withHeader("Content-Type", "application/json; charset=utf-8") | ||
| .withBody(json))); | ||
|
|
||
| Phaxio phaxio = new Phaxio("KEY", "SECRET", "http://localhost:%s/v2/", TEST_PORT); | ||
| Phaxio phaxio = new Phaxio(Auth.VALID_KEY, Auth.VALID_SECRET, "http://localhost:%s/ver/", TEST_PORT); | ||
|
|
||
| Account account = phaxio.account.status(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTTP calls this Authorization, not Authentication.