Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:amihaiemil/zold-java-client
- Loading branch information
Showing
9 changed files
with
321 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright (c) 2019, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of zold-java-client nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.zold; | ||
|
||
import java.net.URI; | ||
|
||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
|
||
/** | ||
* RESTful Zold network entry point. | ||
* @author Mihai Andronache (amihaiemil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @todo #11:30min implement body of interface methods. | ||
*/ | ||
public final class RestfulZoldWts implements ZoldWts { | ||
|
||
/** | ||
* Apache HttpClient which sends the requests. | ||
*/ | ||
private final HttpClient client; | ||
|
||
/** | ||
* Base URI. | ||
*/ | ||
private final URI baseUri; | ||
|
||
/** | ||
* Constructor. | ||
* @param baseUri Base URI. | ||
*/ | ||
public RestfulZoldWts(final URI baseUri) { | ||
this( | ||
HttpClients.custom() | ||
.setMaxConnPerRoute(10) | ||
.setMaxConnTotal(10) | ||
.build(), | ||
baseUri | ||
); | ||
} | ||
|
||
/** | ||
* Constructor. We recommend you to use the simple constructor | ||
* and let us configure the HttpClient for you. <br><br> | ||
* Use this constructor only if you know what you're doing. | ||
* | ||
* @param client Given HTTP Client. | ||
* @param baseUri Base URI. | ||
*/ | ||
public RestfulZoldWts(final HttpClient client, final URI baseUri) { | ||
this.client = client; | ||
this.baseUri = baseUri; | ||
} | ||
|
||
/** | ||
* Pull the wallet from the network. | ||
* @return Wallet object. | ||
* @todo #11:30min should avoid using null | ||
* (it's here for now till the body is implemented) | ||
* maybe should throw an exception when pull fails too | ||
*/ | ||
public Wallet pull() { | ||
return null; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/main/java/com/amihaiemil/zold/UserAgentRequestHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) 2019, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of zold-java-client nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.zold; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Collections; | ||
import java.util.Properties; | ||
import org.apache.http.HttpHeaders; | ||
import org.apache.http.client.protocol.RequestDefaultHeaders; | ||
import org.apache.http.message.BasicHeader; | ||
|
||
/** | ||
* User Agent Request Header Interceptor. | ||
* @author Ammar Atef (a_atef45@yahoo.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @todo #7:30min We should use this class wherever we are | ||
* instantiating an HttpClient in order to send the User-Agent | ||
* HTTP header. | ||
*/ | ||
final class UserAgentRequestHeader extends RequestDefaultHeaders { | ||
|
||
/** | ||
* Config properties file. | ||
*/ | ||
private static final String CONFIG_FILE = "config.properties"; | ||
|
||
/** | ||
* Version property key. | ||
*/ | ||
private static final String VERSION_KEY = "build.version"; | ||
|
||
/** | ||
* Ctor. | ||
*/ | ||
UserAgentRequestHeader() { | ||
super(Collections.singletonList( | ||
new BasicHeader( | ||
HttpHeaders.USER_AGENT, | ||
String.join( | ||
" ", | ||
"zold-java-client /", | ||
version(), | ||
"See https://github.com/amihaiemil/zold-java-client" | ||
) | ||
) | ||
)); | ||
} | ||
|
||
/** | ||
* Read current version from property file. | ||
* @return Build version. | ||
*/ | ||
private static String version() { | ||
final ClassLoader loader = | ||
Thread.currentThread().getContextClassLoader(); | ||
final String version; | ||
final Properties properties = new Properties(); | ||
try (final InputStream inputStream = | ||
loader.getResourceAsStream(CONFIG_FILE)){ | ||
properties.load(inputStream); | ||
version = properties.getProperty(VERSION_KEY); | ||
} catch (final IOException exception) { | ||
throw new RuntimeException( | ||
String.format("Missing %s file.", CONFIG_FILE) | ||
); | ||
} | ||
return version; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.amihaiemil.zold; | ||
|
||
/** | ||
* Zold Wallet. | ||
* @author Ammar Atef (ammar.atef45@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
*/ | ||
public interface Wallet { | ||
/** | ||
* Get the balance of the wallet. | ||
* @return Balance | ||
*/ | ||
double balance(); | ||
|
||
/** | ||
* Pay to another wallet. | ||
* @param keygap Sender keygap | ||
* @param user Recipient user id | ||
* @param amount Amount to be sent | ||
* @param details The details of transfer | ||
* @todo #11:30min solve checkstyle paramternumber error either by cahnging the | ||
* method structure or supressing the warning | ||
*/ | ||
void pay(String keygap, String user, double amount, String details); | ||
|
||
/** | ||
* Finds all payments that match this query and returns. | ||
* @param id Wallet id | ||
* @param details Regex of payment details | ||
*/ | ||
void find(String id, String details); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2019, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of zold-java-client nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.zold; | ||
|
||
/** | ||
* Zold network entry point. | ||
* @author Mihai Andronache (amihaiemil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
*/ | ||
public interface ZoldWts { | ||
/** | ||
* Pull the wallet from the network. | ||
* @return Wallet object. | ||
*/ | ||
Wallet pull(); | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build.version=${project.version} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) 2019, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of zold-java-client nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.zold; | ||
|
||
import java.net.URI; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for {@link RestfulZoldNet}. | ||
* @author Mihai Andronache (amihaiemil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
*/ | ||
public final class RestfulWtsTestCase { | ||
|
||
/** | ||
* {@link RestfulWts} can be instantiated. | ||
*/ | ||
@Test | ||
public void isInstantiated() { | ||
MatcherAssert.assertThat( | ||
new RestfulZoldWts(URI.create("localhost:8080/zold")), | ||
Matchers.instanceOf(ZoldWts.class) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.