mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
first version
This commit is contained in:
parent
c70541d29f
commit
32dd693868
7 changed files with 249 additions and 2 deletions
32
api/src/main/java/io/bitsquare/api/ApiApplication.java
Normal file
32
api/src/main/java/io/bitsquare/api/ApiApplication.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package io.bitsquare.api;
|
||||
|
||||
import io.dropwizard.Application;
|
||||
import io.dropwizard.setup.Bootstrap;
|
||||
import io.dropwizard.setup.Environment;
|
||||
|
||||
public class ApiApplication extends Application<ApiConfiguration> {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new ApiApplication().run(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "hello-world";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Bootstrap<ApiConfiguration> bootstrap) {
|
||||
// nothing to do yet
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApiConfiguration configuration,
|
||||
Environment environment) {
|
||||
final ApiResource resource = new ApiResource(
|
||||
configuration.getTemplate(),
|
||||
configuration.getDefaultName()
|
||||
);
|
||||
environment.jersey().register(resource);
|
||||
}
|
||||
|
||||
}
|
33
api/src/main/java/io/bitsquare/api/ApiConfiguration.java
Normal file
33
api/src/main/java/io/bitsquare/api/ApiConfiguration.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package io.bitsquare.api;
|
||||
|
||||
import io.dropwizard.Configuration;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
public class ApiConfiguration extends Configuration {
|
||||
@NotEmpty
|
||||
private String template;
|
||||
|
||||
@NotEmpty
|
||||
private String defaultName = "Stranger";
|
||||
|
||||
@JsonProperty
|
||||
public String getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
public void setTemplate(String template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
public String getDefaultName() {
|
||||
return defaultName;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
public void setDefaultName(String name) {
|
||||
this.defaultName = name;
|
||||
}
|
||||
}
|
110
api/src/main/java/io/bitsquare/api/ApiModule.java
Normal file
110
api/src/main/java/io/bitsquare/api/ApiModule.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.api;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import io.bitsquare.alert.AlertModule;
|
||||
import io.bitsquare.app.AppModule;
|
||||
import io.bitsquare.app.BitsquareEnvironment;
|
||||
import io.bitsquare.arbitration.ArbitratorModule;
|
||||
import io.bitsquare.btc.BitcoinModule;
|
||||
import io.bitsquare.common.Clock;
|
||||
import io.bitsquare.common.crypto.KeyRing;
|
||||
import io.bitsquare.common.crypto.KeyStorage;
|
||||
import io.bitsquare.crypto.EncryptionServiceModule;
|
||||
import io.bitsquare.filter.FilterModule;
|
||||
import io.bitsquare.p2p.P2PModule;
|
||||
import io.bitsquare.storage.Storage;
|
||||
import io.bitsquare.trade.TradeModule;
|
||||
import io.bitsquare.trade.offer.OfferModule;
|
||||
import io.bitsquare.user.Preferences;
|
||||
import io.bitsquare.user.User;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static com.google.inject.name.Names.named;
|
||||
|
||||
class ApiModule extends AppModule {
|
||||
private static final Logger log = LoggerFactory.getLogger(ApiModule.class);
|
||||
|
||||
public ApiModule(Environment env) {
|
||||
super(env);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(KeyStorage.class).in(Singleton.class);
|
||||
bind(KeyRing.class).in(Singleton.class);
|
||||
bind(User.class).in(Singleton.class);
|
||||
bind(Preferences.class).in(Singleton.class);
|
||||
bind(Clock.class).in(Singleton.class);
|
||||
|
||||
File storageDir = new File(env.getRequiredProperty(Storage.DIR_KEY));
|
||||
bind(File.class).annotatedWith(named(Storage.DIR_KEY)).toInstance(storageDir);
|
||||
|
||||
File keyStorageDir = new File(env.getRequiredProperty(KeyStorage.DIR_KEY));
|
||||
bind(File.class).annotatedWith(named(KeyStorage.DIR_KEY)).toInstance(keyStorageDir);
|
||||
|
||||
bind(BitsquareEnvironment.class).toInstance((BitsquareEnvironment) env);
|
||||
|
||||
// ordering is used for shut down sequence
|
||||
install(tradeModule());
|
||||
install(encryptionServiceModule());
|
||||
install(arbitratorModule());
|
||||
install(offerModule());
|
||||
install(torModule());
|
||||
install(bitcoinModule());
|
||||
install(alertModule());
|
||||
install(filterModule());
|
||||
}
|
||||
|
||||
private TradeModule tradeModule() {
|
||||
return new TradeModule(env);
|
||||
}
|
||||
|
||||
private EncryptionServiceModule encryptionServiceModule() {
|
||||
return new EncryptionServiceModule(env);
|
||||
}
|
||||
|
||||
private ArbitratorModule arbitratorModule() {
|
||||
return new ArbitratorModule(env);
|
||||
}
|
||||
|
||||
private AlertModule alertModule() {
|
||||
return new AlertModule(env);
|
||||
}
|
||||
|
||||
private FilterModule filterModule() {
|
||||
return new FilterModule(env);
|
||||
}
|
||||
|
||||
private OfferModule offerModule() {
|
||||
return new OfferModule(env);
|
||||
}
|
||||
|
||||
private P2PModule torModule() {
|
||||
return new P2PModule(env);
|
||||
}
|
||||
|
||||
private BitcoinModule bitcoinModule() {
|
||||
return new BitcoinModule(env);
|
||||
}
|
||||
}
|
32
api/src/main/java/io/bitsquare/api/ApiResource.java
Normal file
32
api/src/main/java/io/bitsquare/api/ApiResource.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package io.bitsquare.api;
|
||||
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.Optional;
|
||||
|
||||
@Path("/hello-world")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class ApiResource {
|
||||
private final String template;
|
||||
private final String defaultName;
|
||||
private final AtomicLong counter;
|
||||
|
||||
public ApiResource(String template, String defaultName) {
|
||||
this.template = template;
|
||||
this.defaultName = defaultName;
|
||||
this.counter = new AtomicLong();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Timed
|
||||
public Saying sayHello(@QueryParam("name") Optional<String> name) {
|
||||
final String value = String.format(template, name.orElse(defaultName));
|
||||
return new Saying(counter.incrementAndGet(), value);
|
||||
}
|
||||
}
|
9
api/src/main/java/io/bitsquare/api/BitsquareProxy.java
Normal file
9
api/src/main/java/io/bitsquare/api/BitsquareProxy.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package io.bitsquare.api;
|
||||
|
||||
/**
|
||||
* This class is a proxy for all bitsquare features the api will use.
|
||||
*
|
||||
* No methods/representations used in the interface layers (REST/Socket/...) should be used in this class.
|
||||
*/
|
||||
public class BitsquareProxy {
|
||||
}
|
30
api/src/main/java/io/bitsquare/api/Saying.java
Normal file
30
api/src/main/java/io/bitsquare/api/Saying.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package io.bitsquare.api;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
public class Saying {
|
||||
private long id;
|
||||
|
||||
@Length(max = 3)
|
||||
private String content;
|
||||
|
||||
public Saying() {
|
||||
// Jackson deserialization
|
||||
}
|
||||
|
||||
public Saying(long id, String content) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
5
pom.xml
5
pom.xml
|
@ -38,6 +38,7 @@
|
|||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>api</module>
|
||||
<module>common</module>
|
||||
<module>core</module>
|
||||
<module>jsocks</module>
|
||||
|
@ -160,12 +161,12 @@
|
|||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
|
||||
<!--unit test-->
|
||||
|
|
Loading…
Add table
Reference in a new issue