├── .github └── workflows │ ├── publish_bintray.yml │ └── publish_maven_central.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── VERSION ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ └── com │ └── getbase │ ├── BaseCRM.java │ ├── Client.java │ ├── Configuration.java │ ├── exceptions │ ├── BaseError.java │ ├── BaseException.java │ ├── ConfigurationException.java │ ├── ConnectionException.java │ ├── RateLimitException.java │ ├── RequestException.java │ ├── ResourceException.java │ ├── SerializationException.java │ ├── ServerException.java │ └── UnknownResponseException.java │ ├── http │ ├── HttpClient.java │ ├── HttpMethod.java │ ├── Request.java │ ├── Response.java │ └── jersey │ │ ├── Builder.java │ │ └── HttpClient.java │ ├── models │ ├── Account.java │ ├── Address.java │ ├── AssociatedContact.java │ ├── Call.java │ ├── CallOutcome.java │ ├── Collaboration.java │ ├── Contact.java │ ├── Deal.java │ ├── DealUnqualifiedReason.java │ ├── Lead.java │ ├── LeadUnqualifiedReason.java │ ├── LineItem.java │ ├── LossReason.java │ ├── Note.java │ ├── Order.java │ ├── Pipeline.java │ ├── Price.java │ ├── Product.java │ ├── Source.java │ ├── Stage.java │ ├── Tag.java │ ├── Task.java │ ├── TextMessage.java │ ├── User.java │ ├── Visit.java │ └── VisitOutcome.java │ ├── serializer │ ├── JacksonProvider.java │ ├── JsonDeserializer.java │ ├── JsonSerializer.java │ └── Views.java │ ├── services │ ├── AccountsService.java │ ├── AssociatedContactsService.java │ ├── BaseService.java │ ├── CallOutcomesService.java │ ├── CallsService.java │ ├── CollaborationsService.java │ ├── ContactsService.java │ ├── DealUnqualifiedReasonsService.java │ ├── DealsService.java │ ├── LeadSourcesService.java │ ├── LeadUnqualifiedReasonsService.java │ ├── LeadsService.java │ ├── LineItemsService.java │ ├── LossReasonsService.java │ ├── NotesService.java │ ├── OrdersService.java │ ├── PipelinesService.java │ ├── ProductsService.java │ ├── SourcesService.java │ ├── StagesService.java │ ├── TagsService.java │ ├── TasksService.java │ ├── TextMessagesService.java │ ├── UsersService.java │ ├── VisitOutcomesService.java │ └── VisitsService.java │ ├── sync │ ├── Meta.java │ ├── Queue.java │ ├── Session.java │ ├── SessionManager.java │ ├── Sync.java │ ├── SyncProcess.java │ └── SyncService.java │ └── utils │ ├── BiPredicate.java │ ├── Joiner.java │ ├── Lists.java │ ├── Precondition.java │ ├── Predicate.java │ └── Word.java └── test └── groovy └── com └── getbase ├── exceptions └── ExceptionsSpec.groovy ├── http ├── CustomAuthorizationHttpClientTest.groovy ├── HttpClientTest.groovy ├── JsonDeserializerTest.groovy └── JsonSerializerTest.groovy ├── services ├── AccountsServiceTest.groovy ├── AssociatedContactsServiceTest.groovy ├── BaseSpecification.groovy ├── CallsServiceTest.groovy ├── CollaborationsServiceTest.groovy ├── ContactsServiceTest.groovy ├── DealUnqualifiedReasonsServiceTest.groovy ├── DealsServiceTest.groovy ├── LeadSourcesServiceTest.groovy ├── LeadUnqualifiedReasonsServiceTest.groovy ├── LeadsServiceTest.groovy ├── LineItemsServiceTest.groovy ├── LossReasonsServiceTest.groovy ├── NotesServiceTest.groovy ├── OrdersServiceTest.groovy ├── PipelinesServiceTest.groovy ├── ProductsServiceTest.groovy ├── SourcesServiceTest.groovy ├── StagesServiceTest.groovy ├── TagsServiceTest.groovy ├── TasksServiceTest.groovy ├── TextMessagesServiceTest.groovy ├── UsersServiceTest.groovy ├── VisitOutcomesServiceTest.groovy └── VisitsServiceTest.groovy ├── sync ├── SyncProcessTest.groovy ├── SyncServiceTest.groovy └── SyncTest.groovy └── utils └── JoinerSpec.groovy /.github/workflows/publish_bintray.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Publish package to bintray 5 | 6 | on: 7 | push: 8 | tags: v* 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: zendesk/checkout@v2 16 | - name: Set up JDK 1.8 17 | uses: zendesk/setup-java@v1 18 | with: 19 | java-version: 1.8 20 | - name: Grant execute permission for gradlew 21 | run: chmod +x gradlew 22 | - name: Upload to bintray 23 | env: 24 | BINTRAY_USER: ${{ secrets.BINTRAY_USER }} 25 | BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }} 26 | run: ./gradlew bintrayUpload 27 | -------------------------------------------------------------------------------- /.github/workflows/publish_maven_central.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Gradle 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 3 | 4 | name: Publish package to Maven central 5 | 6 | on: 7 | push: 8 | tags: v* 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: zendesk/checkout@v2 16 | - name: Set up JDK 1.8 17 | uses: zendesk/setup-java@v1 18 | with: 19 | java-version: 1.8 20 | - name: Grant execute permission for gradlew 21 | run: chmod +x gradlew 22 | - name: Prepare environment 23 | env: 24 | GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }} 25 | run: | 26 | git fetch --unshallow 27 | echo "$GPG_KEY_CONTENTS" | base64 -d > $HOME/.keyring.gpg 28 | - name: Publish to MavenCentral 29 | run: | 30 | export SIGNING_SECRET_KEY_RING_FILE=$HOME/.keyring.gpg 31 | ./gradlew publish 32 | env: 33 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 34 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 35 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} 36 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} 37 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ IDEA 2 | .idea/ 3 | *.iml 4 | *.iws 5 | *.ipr 6 | 7 | # Gradle 8 | build/ 9 | .gradle/ 10 | gradle.properties 11 | 12 | # Misc 13 | bin/ 14 | log/ 15 | *.log 16 | 17 | # Does not ignore anything is source folders 18 | !**/src/** 19 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 1.5.2 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zendesk/basecrm-java/9788932dcb983817214a352964224f5925788393/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'basecrm-java' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/BaseCRM.java: -------------------------------------------------------------------------------- 1 | package com.getbase; 2 | 3 | public abstract class BaseCRM { 4 | 5 | public static final String VERSION = "1.5.2"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/Configuration.java: -------------------------------------------------------------------------------- 1 | package com.getbase; 2 | 3 | import static com.getbase.BaseCRM.VERSION; 4 | 5 | public class Configuration { 6 | 7 | public static final String PRODUCTION_URL = "https://api.getbase.com"; 8 | public static final String DEFAULT_USER_AGENT = "BaseCRM/v2 Java/" + VERSION; 9 | public static final int DEFAULT_TIMEOUT = 30; 10 | 11 | private String accessToken; 12 | private String baseUrl; 13 | private String userAgent; 14 | private int timeout; 15 | private boolean verifySSL; 16 | private boolean verbose; 17 | 18 | public static Configuration getDefault() { 19 | return new Configuration(System.getenv("BASECRM_ACCESS_TOKEN"), 20 | PRODUCTION_URL, 21 | DEFAULT_USER_AGENT, 22 | DEFAULT_TIMEOUT, 23 | true, 24 | false); 25 | } 26 | 27 | private Configuration(String accessToken, String baseUrl, String userAgent, int timeout, boolean verifySSL, boolean verbose) { 28 | this.accessToken = accessToken; 29 | this.baseUrl = baseUrl; 30 | this.userAgent = userAgent; 31 | this.timeout = timeout; 32 | this.verifySSL = verifySSL; 33 | this.verbose = verbose; 34 | } 35 | 36 | public boolean isVerbose() { 37 | return verbose; 38 | } 39 | 40 | public String getBaseUrl() { 41 | return baseUrl; 42 | } 43 | 44 | public String getUserAgent() { 45 | return userAgent; 46 | } 47 | 48 | public int getTimeout() { 49 | return timeout; 50 | } 51 | 52 | public boolean isVerifySSL() { 53 | return verifySSL; 54 | } 55 | 56 | public String getAccessToken() { 57 | return accessToken; 58 | } 59 | 60 | public static final class Builder { 61 | private Configuration config; 62 | 63 | public Builder() { 64 | this.config = getDefault(); 65 | } 66 | 67 | public Builder verbose(boolean verbose) { 68 | this.config.verbose = verbose; 69 | return this; 70 | } 71 | 72 | public Builder verbose() { 73 | return verbose(true); 74 | } 75 | 76 | public Builder baseUrl(String baseUrl) { 77 | this.config.baseUrl = baseUrl; 78 | return this; 79 | } 80 | 81 | public Builder timeout(int timeout) { 82 | this.config.timeout = timeout; 83 | return this; 84 | } 85 | 86 | public Builder verifySSL(boolean verifySSL) { 87 | this.config.verifySSL = verifySSL; 88 | return this; 89 | } 90 | 91 | public Builder verifySSL() { 92 | return verifySSL(true); 93 | } 94 | 95 | public Builder userAgent(String userAgent) { 96 | this.config.userAgent = userAgent; 97 | return this; 98 | } 99 | 100 | public Builder accessToken(String accessToken) { 101 | this.config.accessToken = accessToken; 102 | return this; 103 | } 104 | 105 | public Configuration build() { 106 | return this.config; 107 | } 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/BaseError.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | public class BaseError { 4 | private String code; 5 | private String message; 6 | private String details; 7 | private String resource; 8 | private String field; 9 | 10 | public String getCode() { 11 | return code; 12 | } 13 | 14 | public String getMessage() { 15 | return message; 16 | } 17 | 18 | public String getDetails() { 19 | return details; 20 | } 21 | 22 | public String getResource() { 23 | return resource; 24 | } 25 | 26 | public String getField() { 27 | return field; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object o) { 32 | if (this == o) return true; 33 | if (o == null || getClass() != o.getClass()) return false; 34 | 35 | BaseError error = (BaseError) o; 36 | 37 | if (!code.equals(error.code)) return false; 38 | if (!message.equals(error.message)) return false; 39 | if (details != null ? !details.equals(error.details) : error.details != null) return false; 40 | if (resource != null ? !resource.equals(error.resource) : error.resource != null) return false; 41 | return !(field != null ? !field.equals(error.field) : error.field != null); 42 | 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "BaseError{" + 48 | "code='" + code + '\'' + 49 | ", message='" + message + '\'' + 50 | ", details='" + details + '\'' + 51 | ", resource='" + resource + '\'' + 52 | ", field='" + field + '\'' + 53 | '}'; 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | int result = code.hashCode(); 59 | result = 31 * result + message.hashCode(); 60 | result = 31 * result + (details != null ? details.hashCode() : 0); 61 | result = 31 * result + (resource != null ? resource.hashCode() : 0); 62 | result = 31 * result + (field != null ? field.hashCode() : 0); 63 | return result; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/BaseException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | import com.getbase.http.HttpMethod; 4 | 5 | import java.util.List; 6 | 7 | import static com.getbase.utils.Joiner.join; 8 | 9 | public abstract class BaseException extends RuntimeException { 10 | 11 | private final int httpStatus; 12 | private final String logref; 13 | private final HttpMethod httpMethod; 14 | private final String url; 15 | private final List errors; 16 | 17 | public BaseException(int httpStatus, String logref, HttpMethod httpMethod, String url, List errors) { 18 | super(buildMessage(httpStatus, logref, httpMethod, url, errors)); 19 | this.httpStatus = httpStatus; 20 | this.logref = logref; 21 | this.httpMethod = httpMethod; 22 | this.url = url; 23 | this.errors = errors; 24 | } 25 | 26 | public int getHttpStatus() { 27 | return this.httpStatus; 28 | } 29 | 30 | public String getLogref() { 31 | return this.logref; 32 | } 33 | 34 | public String getRequestId() { 35 | return this.logref; 36 | } 37 | 38 | public HttpMethod getHttpMethod() { 39 | return httpMethod; 40 | } 41 | 42 | public String getUrl() { 43 | return url; 44 | } 45 | 46 | public List getErrors() { 47 | return this.errors; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return new StringBuilder() 53 | .append(getClass()) 54 | .append('{') 55 | .append(buildMessage(httpStatus, logref, httpMethod, url, errors)) 56 | .append('}') 57 | .toString(); 58 | } 59 | 60 | private static String buildMessage(int httpStatus, String logref, HttpMethod httpMethod, String url, List errors) { 61 | return new StringBuilder() 62 | .append("httpStatus=").append(httpStatus) 63 | .append(", logref='").append(logref) 64 | .append("', httpMethod=").append(httpMethod) 65 | .append(", url=").append(url) 66 | .append(", errors=").append(join(";", errors)) 67 | .toString(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/ConfigurationException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | public class ConfigurationException extends Exception { 4 | public ConfigurationException(String message) { 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/ConnectionException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | public class ConnectionException extends RuntimeException { 4 | public ConnectionException(String message) { 5 | super(message); 6 | } 7 | 8 | public ConnectionException(Throwable cause) { 9 | super(cause); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/RateLimitException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | public class RateLimitException extends RuntimeException { 4 | public RateLimitException(String message) { 5 | super(message); 6 | } 7 | 8 | public RateLimitException() { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/RequestException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | import com.getbase.http.HttpMethod; 4 | 5 | import java.util.List; 6 | 7 | public class RequestException extends BaseException { 8 | public RequestException(int httpStatus, String logref, HttpMethod httpMethod, String url, List errors) { 9 | super(httpStatus, logref, httpMethod, url, errors); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/ResourceException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | import com.getbase.http.HttpMethod; 4 | 5 | import java.util.List; 6 | 7 | public class ResourceException extends BaseException { 8 | public ResourceException(int httpStatus, String logref, HttpMethod httpMethod, String url, List errors) { 9 | super(httpStatus, logref, httpMethod, url, errors); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/SerializationException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | public class SerializationException extends RuntimeException { 4 | public SerializationException() { 5 | } 6 | 7 | public SerializationException(String message) { 8 | super(message); 9 | } 10 | 11 | public SerializationException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | public SerializationException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/ServerException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | import com.getbase.http.HttpMethod; 4 | 5 | import java.util.List; 6 | 7 | public class ServerException extends BaseException { 8 | public ServerException(int httpStatus, String logref, HttpMethod httpMethod, String url, List errors) { 9 | super(httpStatus, logref, httpMethod, url, errors); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/exceptions/UnknownResponseException.java: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions; 2 | 3 | import com.getbase.http.Response; 4 | 5 | public class UnknownResponseException extends RuntimeException { 6 | private Response response; 7 | 8 | public UnknownResponseException(String message, Response response) { 9 | super(message); 10 | this.response = response; 11 | } 12 | 13 | public Response getResponse() { 14 | return response; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/http/HttpClient.java: -------------------------------------------------------------------------------- 1 | package com.getbase.http; 2 | 3 | import com.getbase.Configuration; 4 | import com.getbase.exceptions.*; 5 | import com.getbase.serializer.JsonDeserializer; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import static java.util.Collections.emptyList; 13 | 14 | public abstract class HttpClient { 15 | private static final Logger log = LoggerFactory.getLogger(HttpClient.class); 16 | 17 | public static final String X_REQUEST_ID = "X-Request-Id"; 18 | 19 | protected final Configuration config; 20 | 21 | public HttpClient(Configuration config) { 22 | this.config = config; 23 | } 24 | 25 | public Response get(String url, Map params) throws ResourceException, RequestException, ServerException { 26 | return request(HttpMethod.GET, url, params, null); 27 | } 28 | 29 | public Response post(String url, String body) throws ResourceException, RequestException, ServerException { 30 | return request(HttpMethod.POST, url, null, body); 31 | } 32 | 33 | 34 | public Response put(String url, String body) throws ResourceException, RequestException, ServerException { 35 | return request(HttpMethod.PUT, url, null, body); 36 | } 37 | 38 | public Response delete(String url, Map params) throws ResourceException, RequestException, ServerException { 39 | return request(HttpMethod.DELETE, url, params, null); 40 | } 41 | 42 | 43 | public Response request(HttpMethod method, 44 | String url, 45 | Map params, 46 | String body) throws RequestException, ResourceException, ServerException { 47 | return request(method, url, params, null, body); 48 | } 49 | 50 | public Response request(HttpMethod method, 51 | String url, 52 | Map params, 53 | Map headers, 54 | String body) { 55 | Request.Builder builder = new Request.Builder(). 56 | method(method). 57 | url(this.config.getBaseUrl() + url); 58 | 59 | if (params != null) { 60 | for (Map.Entry q : params.entrySet()) { 61 | builder.param(q.getKey(), q.getValue()); 62 | } 63 | } 64 | 65 | applyAuthorization(builder) 66 | .header("Accept", "application/json") 67 | .header("User-Agent", this.config.getUserAgent()) 68 | .header("X-Client-Type", "api"); 69 | 70 | if (body != null) { 71 | builder.header("Content-Type", "application/json").body(body); 72 | } 73 | 74 | if (headers != null) { 75 | builder.headers(headers); 76 | } 77 | 78 | Response response = rawRequest(builder.build()); 79 | 80 | if (response.getHttpStatus() < 200 || response.getHttpStatus() >= 300) { 81 | handleErrorResponse(response, method, url); 82 | } 83 | 84 | return response; 85 | } 86 | 87 | // Override this method if you want to use custom authorization method 88 | protected Request.Builder applyAuthorization(Request.Builder requestBuilder) { 89 | return requestBuilder.header("Authorization", "Bearer " + this.config.getAccessToken()); 90 | } 91 | 92 | public abstract Response rawRequest(Request request); 93 | 94 | private void handleErrorResponse(Response response, HttpMethod httpMethod, String url) 95 | throws ResourceException, RequestException, ServerException { 96 | 97 | int responseCode = response.getHttpStatus(); 98 | 99 | if (responseCode == 422) { 100 | throw new ResourceException(responseCode, tryGetRequestId(response), httpMethod, url, tryGetErrors(response)); 101 | } else if (responseCode == 429) { 102 | throw new RateLimitException(); 103 | } else if (responseCode >= 400 && responseCode < 500) { 104 | throw new RequestException(responseCode, tryGetRequestId(response), httpMethod, url, tryGetErrors(response)); 105 | } else if (responseCode >= 500 && responseCode < 600) { 106 | throw new ServerException(responseCode, tryGetRequestId(response), httpMethod, url, tryGetErrors(response)); 107 | } else { 108 | throw new UnknownResponseException("Unhandled HTTP error " + response, response); 109 | } 110 | } 111 | 112 | private String tryGetRequestId(Response response) { 113 | final String requestId = response.getHeaders().get(X_REQUEST_ID); 114 | return requestId != null ? requestId : "unknown"; 115 | } 116 | 117 | private List tryGetErrors(Response response) { 118 | if (response.isJSON()) { 119 | return JsonDeserializer.deserializeErrors(response.getBody()); 120 | } else { 121 | return emptyList(); 122 | } 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/http/HttpMethod.java: -------------------------------------------------------------------------------- 1 | package com.getbase.http; 2 | 3 | import java.util.EnumSet; 4 | 5 | public enum HttpMethod { 6 | HEAD, 7 | GET, 8 | POST, 9 | PUT, 10 | PATCH, 11 | DELETE; 12 | 13 | private static final EnumSet bodySupported = EnumSet.of(POST, PUT, PATCH); 14 | 15 | public boolean isBodySupported() { 16 | return bodySupported.contains(this); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/http/Request.java: -------------------------------------------------------------------------------- 1 | package com.getbase.http; 2 | 3 | import com.getbase.utils.Joiner; 4 | 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import static com.getbase.utils.Precondition.checkNotNull; 10 | 11 | public class Request { 12 | private HttpMethod method = HttpMethod.GET; 13 | private String url; 14 | private Map queryParameters = new HashMap(); 15 | private Map headers = new HashMap(); 16 | private String body; 17 | 18 | private Request() { 19 | } 20 | 21 | public HttpMethod getMethod() { 22 | return method; 23 | } 24 | 25 | public String getUrl() { 26 | return url; 27 | } 28 | 29 | public Map getQueryParameters() { 30 | return queryParameters; 31 | } 32 | 33 | public Map getHeaders() { 34 | return headers; 35 | } 36 | 37 | public String getBody() { 38 | return body; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return "Request{" + 44 | "method=" + method + 45 | ", url='" + url + '\'' + 46 | ", queryParameters=" + queryParameters + 47 | ", headers=" + headers + 48 | ", body='" + body + '\'' + 49 | '}'; 50 | } 51 | 52 | public static final class Builder { 53 | private final Request request; 54 | 55 | public Builder() { 56 | this.request = new Request(); 57 | } 58 | 59 | public Builder method(HttpMethod method) { 60 | this.request.method = method; 61 | return this; 62 | } 63 | 64 | public Builder url(String url) { 65 | this.request.url = url; 66 | return this; 67 | } 68 | 69 | public Builder param(String key, Object value) { 70 | checkNotNull(key, "Parameter key must not be null"); 71 | 72 | this.request.queryParameters.put(key, value); 73 | return this; 74 | } 75 | 76 | public Builder param(String key, List values) { 77 | checkNotNull(key, "Parameter key must not be null"); 78 | checkNotNull(values, "values must not be null"); 79 | 80 | if (values.isEmpty()) { 81 | return this; 82 | } 83 | 84 | String value = Joiner.join(",", values); 85 | this.request.queryParameters.put(key, value); 86 | 87 | return this; 88 | } 89 | 90 | public Builder header(String key, String value) { 91 | this.request.headers.put(key, value); 92 | return this; 93 | } 94 | 95 | public Builder headers(Map headers) { 96 | this.request.headers.putAll(headers); 97 | return this; 98 | } 99 | 100 | public Builder body(String body) { 101 | this.request.body = body; 102 | return this; 103 | } 104 | 105 | public Request build() { 106 | return this.request; 107 | } 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/http/Response.java: -------------------------------------------------------------------------------- 1 | package com.getbase.http; 2 | 3 | import java.util.Map; 4 | 5 | public class Response { 6 | private int httpStatus; 7 | private String body; 8 | 9 | private Map headers; 10 | 11 | public Response(int httpStatus, String body, Map headers) { 12 | this.httpStatus = httpStatus; 13 | this.body = body; 14 | this.headers = headers; 15 | } 16 | 17 | public Response(int httpStatus, String body) { 18 | this.httpStatus = httpStatus; 19 | this.body = body; 20 | } 21 | 22 | public Response(int httpStatus) { 23 | this.httpStatus = httpStatus; 24 | } 25 | 26 | public int getHttpStatus() { 27 | return httpStatus; 28 | } 29 | 30 | public Map getHeaders() { 31 | return headers; 32 | } 33 | 34 | public boolean isJSON() { 35 | return this.body != null && 36 | this.headers.get("Content-Type") != null && 37 | this.headers.get("Content-Type").contains("json"); 38 | } 39 | 40 | public String getBody() { 41 | return body; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "Response{" + 47 | "httpStatus=" + httpStatus + 48 | ", body='" + body + '\'' + 49 | ", headers=" + headers + 50 | '}'; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/http/jersey/Builder.java: -------------------------------------------------------------------------------- 1 | package com.getbase.http.jersey; 2 | 3 | import com.getbase.Configuration; 4 | 5 | import javax.ws.rs.client.Client; 6 | 7 | public interface Builder { 8 | Client build(Configuration configuration); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Account.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class Account { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 14 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 15 | protected @JsonView(Views.ReadWrite.class) String currency; 16 | protected @JsonView(Views.ReadWrite.class) String name; 17 | protected @JsonView(Views.ReadWrite.class) String phone; 18 | protected @JsonView(Views.ReadWrite.class) String timeFormat; 19 | protected @JsonView(Views.ReadWrite.class) String timezone; 20 | 21 | public Account() { 22 | } 23 | 24 | public Long getId() { 25 | return this.id; 26 | } 27 | 28 | public DateTime getCreatedAt() { 29 | return this.createdAt; 30 | } 31 | 32 | public DateTime getUpdatedAt() { 33 | return this.updatedAt; 34 | } 35 | 36 | public String getCurrency() { 37 | return this.currency; 38 | } 39 | 40 | public String getName() { 41 | return this.name; 42 | } 43 | 44 | public String getPhone() { 45 | return this.phone; 46 | } 47 | 48 | public String getTimeFormat() { 49 | return this.timeFormat; 50 | } 51 | 52 | public String getTimezone() { 53 | return this.timezone; 54 | } 55 | 56 | public void setCurrency(String currency) { 57 | this.currency = currency; 58 | } 59 | 60 | public void setName(String name) { 61 | this.name = name; 62 | } 63 | 64 | public void setPhone(String phone) { 65 | this.phone = phone; 66 | } 67 | 68 | public void setTimeFormat(String timeFormat) { 69 | this.timeFormat = timeFormat; 70 | } 71 | 72 | public void setTimezone(String timezone) { 73 | this.timezone = timezone; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Account{" + 79 | "id=" + id + 80 | ", createdAt=" + createdAt + 81 | ", updatedAt=" + updatedAt + 82 | ", currency='" + currency + '\'' + 83 | ", name='" + name + '\'' + 84 | ", phone='" + phone + '\'' + 85 | ", timeFormat='" + timeFormat + '\'' + 86 | ", timezone='" + timezone + '\'' + 87 | "}"; 88 | } 89 | 90 | @Override 91 | public boolean equals(Object o) { 92 | if (this == o) return true; 93 | if (o == null || getClass() != o.getClass()) return false; 94 | 95 | Account account = (Account) o; 96 | 97 | if (id != null ? !id.equals(account.id) : account.id != null) return false; 98 | if (createdAt != null ? !createdAt.equals(account.createdAt) : account.createdAt != null) return false; 99 | if (updatedAt != null ? !updatedAt.equals(account.updatedAt) : account.updatedAt != null) return false; 100 | if (currency != null ? !currency.equals(account.currency) : account.currency != null) return false; 101 | if (name != null ? !name.equals(account.name) : account.name != null) return false; 102 | if (phone != null ? !phone.equals(account.phone) : account.phone != null) return false; 103 | if (timeFormat != null ? !timeFormat.equals(account.timeFormat) : account.timeFormat != null) return false; 104 | if (timezone != null ? !timezone.equals(account.timezone) : account.timezone != null) return false; 105 | 106 | return true; 107 | } 108 | 109 | @Override 110 | public int hashCode() { 111 | int result = id != null ? id.hashCode() : 0; 112 | result = 31 * result + (id != null ? id.hashCode() : 0); 113 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 114 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 115 | result = 31 * result + (currency != null ? currency.hashCode() : 0); 116 | result = 31 * result + (name != null ? name.hashCode() : 0); 117 | result = 31 * result + (phone != null ? phone.hashCode() : 0); 118 | result = 31 * result + (timeFormat != null ? timeFormat.hashCode() : 0); 119 | result = 31 * result + (timezone != null ? timezone.hashCode() : 0); 120 | return result; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Address.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | 8 | 9 | 10 | public class Address { 11 | protected @JsonView(Views.ReadWrite.class) String city; 12 | protected @JsonView(Views.ReadWrite.class) String country; 13 | protected @JsonView(Views.ReadWrite.class) String line1; 14 | protected @JsonView(Views.ReadWrite.class) String postalCode; 15 | protected @JsonView(Views.ReadWrite.class) String state; 16 | 17 | public Address() { 18 | } 19 | 20 | public String getCity() { 21 | return this.city; 22 | } 23 | 24 | public String getCountry() { 25 | return this.country; 26 | } 27 | 28 | public String getLine1() { 29 | return this.line1; 30 | } 31 | 32 | public String getPostalCode() { 33 | return this.postalCode; 34 | } 35 | 36 | public String getState() { 37 | return this.state; 38 | } 39 | 40 | public void setCity(String city) { 41 | this.city = city; 42 | } 43 | 44 | public void setCountry(String country) { 45 | this.country = country; 46 | } 47 | 48 | public void setLine1(String line1) { 49 | this.line1 = line1; 50 | } 51 | 52 | public void setPostalCode(String postalCode) { 53 | this.postalCode = postalCode; 54 | } 55 | 56 | public void setState(String state) { 57 | this.state = state; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return "Address{" + 63 | "city='" + city + '\'' + 64 | ", country='" + country + '\'' + 65 | ", line1='" + line1 + '\'' + 66 | ", postalCode='" + postalCode + '\'' + 67 | ", state='" + state + '\'' + 68 | "}"; 69 | } 70 | 71 | @Override 72 | public boolean equals(Object o) { 73 | if (this == o) return true; 74 | if (o == null || getClass() != o.getClass()) return false; 75 | 76 | Address address = (Address) o; 77 | 78 | if (city != null ? !city.equals(address.city) : address.city != null) return false; 79 | if (country != null ? !country.equals(address.country) : address.country != null) return false; 80 | if (line1 != null ? !line1.equals(address.line1) : address.line1 != null) return false; 81 | if (postalCode != null ? !postalCode.equals(address.postalCode) : address.postalCode != null) return false; 82 | if (state != null ? !state.equals(address.state) : address.state != null) return false; 83 | 84 | return true; 85 | } 86 | 87 | @Override 88 | public int hashCode() { 89 | int result = 0; 90 | result = 31 * result + (city != null ? city.hashCode() : 0); 91 | result = 31 * result + (country != null ? country.hashCode() : 0); 92 | result = 31 * result + (line1 != null ? line1.hashCode() : 0); 93 | result = 31 * result + (postalCode != null ? postalCode.hashCode() : 0); 94 | result = 31 * result + (state != null ? state.hashCode() : 0); 95 | return result; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/AssociatedContact.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class AssociatedContact { 12 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 13 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 14 | protected @JsonView(Views.ReadWrite.class) Long contactId; 15 | protected @JsonView(Views.ReadWrite.class) String role; 16 | 17 | public AssociatedContact() { 18 | } 19 | 20 | public DateTime getCreatedAt() { 21 | return this.createdAt; 22 | } 23 | 24 | public DateTime getUpdatedAt() { 25 | return this.updatedAt; 26 | } 27 | 28 | public Long getContactId() { 29 | return this.contactId; 30 | } 31 | 32 | public String getRole() { 33 | return this.role; 34 | } 35 | 36 | public void setContactId(long contactId) { 37 | this.contactId = contactId; 38 | } 39 | 40 | public void setRole(String role) { 41 | this.role = role; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "AssociatedContact{" + 47 | "createdAt=" + createdAt + 48 | ", updatedAt=" + updatedAt + 49 | ", contactId=" + contactId + 50 | ", role='" + role + '\'' + 51 | "}"; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | if (this == o) return true; 57 | if (o == null || getClass() != o.getClass()) return false; 58 | 59 | AssociatedContact associatedContact = (AssociatedContact) o; 60 | 61 | if (createdAt != null ? !createdAt.equals(associatedContact.createdAt) : associatedContact.createdAt != null) return false; 62 | if (updatedAt != null ? !updatedAt.equals(associatedContact.updatedAt) : associatedContact.updatedAt != null) return false; 63 | if (contactId != null ? !contactId.equals(associatedContact.contactId) : associatedContact.contactId != null) return false; 64 | if (role != null ? !role.equals(associatedContact.role) : associatedContact.role != null) return false; 65 | 66 | return true; 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | int result = 0; 72 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 73 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 74 | result = 31 * result + (contactId != null ? contactId.hashCode() : 0); 75 | result = 31 * result + (role != null ? role.hashCode() : 0); 76 | return result; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/CallOutcome.java: -------------------------------------------------------------------------------- 1 | package com.getbase.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.getbase.serializer.Views; 5 | import org.joda.time.DateTime; 6 | 7 | public class CallOutcome { 8 | protected @JsonView(Views.ReadOnly.class) Long id; 9 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 10 | protected @JsonView(Views.ReadOnly.class) String name; 11 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 12 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 13 | 14 | public CallOutcome() { 15 | } 16 | 17 | public Long getId() { 18 | return id; 19 | } 20 | 21 | public Long getCreatorId() { 22 | return creatorId; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public DateTime getCreatedAt() { 30 | return createdAt; 31 | } 32 | 33 | public DateTime getUpdatedAt() { 34 | return updatedAt; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object o) { 39 | if (this == o) return true; 40 | if (o == null || getClass() != o.getClass()) return false; 41 | 42 | CallOutcome that = (CallOutcome) o; 43 | 44 | if (id != null ? !id.equals(that.id) : that.id != null) return false; 45 | if (creatorId != null ? !creatorId.equals(that.creatorId) : that.creatorId != null) return false; 46 | if (name != null ? !name.equals(that.name) : that.name != null) return false; 47 | if (createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null) return false; 48 | return updatedAt != null ? updatedAt.equals(that.updatedAt) : that.updatedAt == null; 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | int result = id != null ? id.hashCode() : 0; 54 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 55 | result = 31 * result + (name != null ? name.hashCode() : 0); 56 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 57 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 58 | return result; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "CallOutcome{" + 64 | "id=" + id + 65 | ", creatorId=" + creatorId + 66 | ", name=" + name + 67 | ", createdAt=" + createdAt + 68 | ", updatedAt=" + updatedAt + 69 | '}'; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Collaboration.java: -------------------------------------------------------------------------------- 1 | package com.getbase.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.getbase.serializer.Views; 5 | import org.joda.time.DateTime; 6 | 7 | public class Collaboration { 8 | 9 | protected @JsonView(Views.ReadOnly.class) Long id; 10 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 11 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 12 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 13 | protected @JsonView(Views.ReadWrite.class) String resourceType; 14 | protected @JsonView(Views.ReadWrite.class) Long resourceId; 15 | protected @JsonView(Views.ReadWrite.class) Long collaboratorId; 16 | 17 | public Long getId() { 18 | return id; 19 | } 20 | 21 | public Long getCreatorId() { 22 | return creatorId; 23 | } 24 | 25 | public DateTime getCreatedAt() { 26 | return createdAt; 27 | } 28 | 29 | public DateTime getUpdatedAt() { 30 | return updatedAt; 31 | } 32 | 33 | public String getResourceType() { 34 | return resourceType; 35 | } 36 | 37 | public void setResourceType(String resourceType) { 38 | this.resourceType = resourceType; 39 | } 40 | 41 | public Long getResourceId() { 42 | return resourceId; 43 | } 44 | 45 | public void setResourceId(Long resourceId) { 46 | this.resourceId = resourceId; 47 | } 48 | 49 | public Long getCollaboratorId() { 50 | return collaboratorId; 51 | } 52 | 53 | public void setCollaboratorId(Long collaboratorId) { 54 | this.collaboratorId = collaboratorId; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "Collaboration{" + 60 | "id=" + id + 61 | ", creatorId=" + creatorId + 62 | ", createdAt=" + createdAt + 63 | ", updatedAt=" + updatedAt + 64 | ", resourceType='" + resourceType + '\'' + 65 | ", resourceId=" + resourceId + 66 | ", collaboratorId=" + collaboratorId + 67 | '}'; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object o) { 72 | if (this == o) return true; 73 | if (o == null || getClass() != o.getClass()) return false; 74 | 75 | Collaboration that = (Collaboration) o; 76 | 77 | if (id != null ? !id.equals(that.id) : that.id != null) return false; 78 | if (creatorId != null ? !creatorId.equals(that.creatorId) : that.creatorId != null) return false; 79 | if (createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null) return false; 80 | if (updatedAt != null ? !updatedAt.equals(that.updatedAt) : that.updatedAt != null) return false; 81 | if (resourceType != null ? !resourceType.equals(that.resourceType) : that.resourceType != null) return false; 82 | if (resourceId != null ? !resourceId.equals(that.resourceId) : that.resourceId != null) return false; 83 | return collaboratorId != null ? collaboratorId.equals(that.collaboratorId) : that.collaboratorId == null; 84 | } 85 | 86 | @Override 87 | public int hashCode() { 88 | int result = id != null ? id.hashCode() : 0; 89 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 90 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 91 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 92 | result = 31 * result + (resourceType != null ? resourceType.hashCode() : 0); 93 | result = 31 * result + (resourceId != null ? resourceId.hashCode() : 0); 94 | result = 31 * result + (collaboratorId != null ? collaboratorId.hashCode() : 0); 95 | return result; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/DealUnqualifiedReason.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class DealUnqualifiedReason { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 14 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 15 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 16 | protected @JsonView(Views.ReadWrite.class) String name; 17 | 18 | public DealUnqualifiedReason() { 19 | } 20 | 21 | public Long getId() { 22 | return this.id; 23 | } 24 | 25 | public Long getCreatorId() { 26 | return this.creatorId; 27 | } 28 | 29 | public DateTime getCreatedAt() { 30 | return this.createdAt; 31 | } 32 | 33 | public DateTime getUpdatedAt() { 34 | return this.updatedAt; 35 | } 36 | 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "DealUnqualifiedReason{" + 48 | "id=" + id + 49 | ", creatorId=" + creatorId + 50 | ", createdAt=" + createdAt + 51 | ", updatedAt=" + updatedAt + 52 | ", name='" + name + '\'' + 53 | "}"; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object o) { 58 | if (this == o) return true; 59 | if (o == null || getClass() != o.getClass()) return false; 60 | 61 | DealUnqualifiedReason dealUnqualifiedReason = (DealUnqualifiedReason) o; 62 | 63 | if (id != null ? !id.equals(dealUnqualifiedReason.id) : dealUnqualifiedReason.id != null) return false; 64 | if (creatorId != null ? !creatorId.equals(dealUnqualifiedReason.creatorId) : dealUnqualifiedReason.creatorId != null) return false; 65 | if (createdAt != null ? !createdAt.equals(dealUnqualifiedReason.createdAt) : dealUnqualifiedReason.createdAt != null) return false; 66 | if (updatedAt != null ? !updatedAt.equals(dealUnqualifiedReason.updatedAt) : dealUnqualifiedReason.updatedAt != null) return false; 67 | if (name != null ? !name.equals(dealUnqualifiedReason.name) : dealUnqualifiedReason.name != null) return false; 68 | 69 | return true; 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | int result = id != null ? id.hashCode() : 0; 75 | result = 31 * result + (id != null ? id.hashCode() : 0); 76 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 77 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 78 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 79 | result = 31 * result + (name != null ? name.hashCode() : 0); 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/LeadUnqualifiedReason.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class LeadUnqualifiedReason { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 14 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 15 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 16 | protected @JsonView(Views.ReadWrite.class) String name; 17 | 18 | public LeadUnqualifiedReason() { 19 | } 20 | 21 | public Long getId() { 22 | return this.id; 23 | } 24 | 25 | public Long getCreatorId() { 26 | return this.creatorId; 27 | } 28 | 29 | public DateTime getCreatedAt() { 30 | return this.createdAt; 31 | } 32 | 33 | public DateTime getUpdatedAt() { 34 | return this.updatedAt; 35 | } 36 | 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "LeadUnqualifiedReason{" + 48 | "id=" + id + 49 | ", creatorId=" + creatorId + 50 | ", createdAt=" + createdAt + 51 | ", updatedAt=" + updatedAt + 52 | ", name='" + name + '\'' + 53 | "}"; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object o) { 58 | if (this == o) return true; 59 | if (o == null || getClass() != o.getClass()) return false; 60 | 61 | LeadUnqualifiedReason leadUnqualifiedReason = (LeadUnqualifiedReason) o; 62 | 63 | if (id != null ? !id.equals(leadUnqualifiedReason.id) : leadUnqualifiedReason.id != null) return false; 64 | if (creatorId != null ? !creatorId.equals(leadUnqualifiedReason.creatorId) : leadUnqualifiedReason.creatorId != null) return false; 65 | if (createdAt != null ? !createdAt.equals(leadUnqualifiedReason.createdAt) : leadUnqualifiedReason.createdAt != null) return false; 66 | if (updatedAt != null ? !updatedAt.equals(leadUnqualifiedReason.updatedAt) : leadUnqualifiedReason.updatedAt != null) return false; 67 | if (name != null ? !name.equals(leadUnqualifiedReason.name) : leadUnqualifiedReason.name != null) return false; 68 | 69 | return true; 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | int result = id != null ? id.hashCode() : 0; 75 | result = 31 * result + (id != null ? id.hashCode() : 0); 76 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 77 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 78 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 79 | result = 31 * result + (name != null ? name.hashCode() : 0); 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/LossReason.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class LossReason { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 14 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 15 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 16 | protected @JsonView(Views.ReadWrite.class) String name; 17 | 18 | public LossReason() { 19 | } 20 | 21 | public Long getId() { 22 | return this.id; 23 | } 24 | 25 | public Long getCreatorId() { 26 | return this.creatorId; 27 | } 28 | 29 | public DateTime getCreatedAt() { 30 | return this.createdAt; 31 | } 32 | 33 | public DateTime getUpdatedAt() { 34 | return this.updatedAt; 35 | } 36 | 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "LossReason{" + 48 | "id=" + id + 49 | ", creatorId=" + creatorId + 50 | ", createdAt=" + createdAt + 51 | ", updatedAt=" + updatedAt + 52 | ", name='" + name + '\'' + 53 | "}"; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object o) { 58 | if (this == o) return true; 59 | if (o == null || getClass() != o.getClass()) return false; 60 | 61 | LossReason lossReason = (LossReason) o; 62 | 63 | if (id != null ? !id.equals(lossReason.id) : lossReason.id != null) return false; 64 | if (creatorId != null ? !creatorId.equals(lossReason.creatorId) : lossReason.creatorId != null) return false; 65 | if (createdAt != null ? !createdAt.equals(lossReason.createdAt) : lossReason.createdAt != null) return false; 66 | if (updatedAt != null ? !updatedAt.equals(lossReason.updatedAt) : lossReason.updatedAt != null) return false; 67 | if (name != null ? !name.equals(lossReason.name) : lossReason.name != null) return false; 68 | 69 | return true; 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | int result = id != null ? id.hashCode() : 0; 75 | result = 31 * result + (id != null ? id.hashCode() : 0); 76 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 77 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 78 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 79 | result = 31 * result + (name != null ? name.hashCode() : 0); 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Note.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class Note { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 14 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 15 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 16 | protected @JsonView(Views.ReadWrite.class) Long resourceId; 17 | protected @JsonView(Views.ReadWrite.class) String content; 18 | protected @JsonView(Views.ReadWrite.class) String resourceType; 19 | protected @JsonView(Views.ReadWrite.class) String type; 20 | 21 | public Note() { 22 | } 23 | 24 | public Long getId() { 25 | return this.id; 26 | } 27 | 28 | public Long getCreatorId() { 29 | return this.creatorId; 30 | } 31 | 32 | public DateTime getCreatedAt() { 33 | return this.createdAt; 34 | } 35 | 36 | public DateTime getUpdatedAt() { 37 | return this.updatedAt; 38 | } 39 | 40 | public Long getResourceId() { 41 | return this.resourceId; 42 | } 43 | 44 | public String getContent() { 45 | return this.content; 46 | } 47 | 48 | public String getResourceType() { 49 | return this.resourceType; 50 | } 51 | 52 | public void setResourceId(long resourceId) { 53 | this.resourceId = resourceId; 54 | } 55 | 56 | public String getType() { 57 | return this.type; 58 | } 59 | 60 | public void setType(String type) { 61 | this.type = type; 62 | } 63 | 64 | public void setContent(String content) { 65 | this.content = content; 66 | } 67 | 68 | public void setResourceType(String resourceType) { 69 | this.resourceType = resourceType; 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "Note{" + 75 | "id=" + id + 76 | ", creatorId=" + creatorId + 77 | ", createdAt=" + createdAt + 78 | ", updatedAt=" + updatedAt + 79 | ", resourceId=" + resourceId + 80 | ", content='" + content + '\'' + 81 | ", resourceType='" + resourceType + '\'' + 82 | ", type='" + type + '\'' + 83 | "}"; 84 | } 85 | 86 | @Override 87 | public boolean equals(Object o) { 88 | if (this == o) return true; 89 | if (o == null || getClass() != o.getClass()) return false; 90 | 91 | Note note = (Note) o; 92 | 93 | if (id != null ? !id.equals(note.id) : note.id != null) return false; 94 | if (creatorId != null ? !creatorId.equals(note.creatorId) : note.creatorId != null) return false; 95 | if (createdAt != null ? !createdAt.equals(note.createdAt) : note.createdAt != null) return false; 96 | if (updatedAt != null ? !updatedAt.equals(note.updatedAt) : note.updatedAt != null) return false; 97 | if (resourceId != null ? !resourceId.equals(note.resourceId) : note.resourceId != null) return false; 98 | if (content != null ? !content.equals(note.content) : note.content != null) return false; 99 | if (type != null ? !type.equals(note.type) : note.type != null) return false; 100 | if (resourceType != null ? !resourceType.equals(note.resourceType) : note.resourceType != null) return false; 101 | 102 | return true; 103 | } 104 | 105 | @Override 106 | public int hashCode() { 107 | int result = id != null ? id.hashCode() : 0; 108 | result = 31 * result + (id != null ? id.hashCode() : 0); 109 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 110 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 111 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 112 | result = 31 * result + (resourceId != null ? resourceId.hashCode() : 0); 113 | result = 31 * result + (content != null ? content.hashCode() : 0); 114 | result = 31 * result + (resourceType != null ? resourceType.hashCode() : 0); 115 | result = 31 * result + (type != null ? type.hashCode() : 0); 116 | return result; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Order.java: -------------------------------------------------------------------------------- 1 | package com.getbase.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.getbase.serializer.Views; 5 | import org.joda.time.DateTime; 6 | 7 | public class Order { 8 | 9 | protected @JsonView(Views.ReadOnly.class) Long id; 10 | protected @JsonView(Views.ReadWrite.class) Long dealId; 11 | protected @JsonView(Views.ReadWrite.class) Long discount; 12 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 13 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 14 | 15 | public Long getId() { 16 | return id; 17 | } 18 | 19 | public Long getDealId() { 20 | return dealId; 21 | } 22 | 23 | public void setDealId(Long dealId) { 24 | this.dealId = dealId; 25 | } 26 | 27 | public Long getDiscount() { 28 | return discount; 29 | } 30 | 31 | public void setDiscount(Long discount) { 32 | this.discount = discount; 33 | } 34 | 35 | public DateTime getCreatedAt() { 36 | return createdAt; 37 | } 38 | 39 | public DateTime getUpdatedAt() { 40 | return updatedAt; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "Order{" + 46 | "id=" + id + 47 | ", dealId=" + dealId + 48 | ", discount=" + discount + 49 | ", createdAt=" + createdAt + 50 | ", updatedAt=" + updatedAt + 51 | '}'; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | if (this == o) return true; 57 | if (o == null || getClass() != o.getClass()) return false; 58 | 59 | Order order = (Order) o; 60 | 61 | if (id != null ? !id.equals(order.id) : order.id != null) return false; 62 | if (dealId != null ? !dealId.equals(order.dealId) : order.dealId != null) return false; 63 | if (discount != null ? !discount.equals(order.discount) : order.discount != null) return false; 64 | if (createdAt != null ? !createdAt.equals(order.createdAt) : order.createdAt != null) return false; 65 | return updatedAt != null ? updatedAt.equals(order.updatedAt) : order.updatedAt == null; 66 | 67 | } 68 | 69 | @Override 70 | public int hashCode() { 71 | int result = id != null ? id.hashCode() : 0; 72 | result = 31 * result + (dealId != null ? dealId.hashCode() : 0); 73 | result = 31 * result + (discount != null ? discount.hashCode() : 0); 74 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 75 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 76 | return result; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Pipeline.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class Pipeline { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 14 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 15 | protected @JsonView(Views.ReadWrite.class) String name; 16 | protected @JsonView(Views.ReadWrite.class) Boolean disabled; 17 | 18 | public Pipeline() { 19 | } 20 | 21 | public Long getId() { 22 | return this.id; 23 | } 24 | 25 | public DateTime getCreatedAt() { 26 | return this.createdAt; 27 | } 28 | 29 | public DateTime getUpdatedAt() { 30 | return this.updatedAt; 31 | } 32 | 33 | public String getName() { 34 | return this.name; 35 | } 36 | 37 | public Boolean getDisabled() { 38 | return this.disabled; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "Pipeline{" + 48 | "id=" + id + 49 | ", createdAt=" + createdAt + 50 | ", updatedAt=" + updatedAt + 51 | ", name='" + name + '\'' + 52 | ", disabled='" + disabled + '\'' + 53 | "}"; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object o) { 58 | if (this == o) return true; 59 | if (o == null || getClass() != o.getClass()) return false; 60 | 61 | Pipeline pipeline = (Pipeline) o; 62 | 63 | if (id != null ? !id.equals(pipeline.id) : pipeline.id != null) return false; 64 | if (createdAt != null ? !createdAt.equals(pipeline.createdAt) : pipeline.createdAt != null) return false; 65 | if (updatedAt != null ? !updatedAt.equals(pipeline.updatedAt) : pipeline.updatedAt != null) return false; 66 | if (name != null ? !name.equals(pipeline.name) : pipeline.name != null) return false; 67 | if (disabled != null ? !disabled.equals(pipeline.disabled) : pipeline.disabled != null) return false; 68 | 69 | return true; 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | int result = id != null ? id.hashCode() : 0; 75 | result = 31 * result + (id != null ? id.hashCode() : 0); 76 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 77 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 78 | result = 31 * result + (name != null ? name.hashCode() : 0); 79 | result = 31 * result + (disabled != null ? disabled.hashCode() : 0); 80 | return result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Price.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | 8 | import java.math.BigDecimal; 9 | 10 | 11 | public class Price { 12 | protected @JsonView(Views.ReadWrite.class) BigDecimal amount; 13 | protected @JsonView(Views.ReadWrite.class) String currency; 14 | 15 | public Price() { 16 | } 17 | 18 | public BigDecimal getAmount() { 19 | return this.amount; 20 | } 21 | 22 | public String getCurrency() { 23 | return this.currency; 24 | } 25 | 26 | public void setAmount(BigDecimal amount) { 27 | this.amount = amount; 28 | } 29 | 30 | public void setCurrency(String currency) { 31 | this.currency = currency; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "Price{" + 37 | "amount=" + amount + 38 | ", currency='" + currency + '\'' + 39 | "}"; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object o) { 44 | if (this == o) return true; 45 | if (o == null || getClass() != o.getClass()) return false; 46 | 47 | Price price = (Price) o; 48 | 49 | if (amount != null ? !amount.equals(price.amount) : price.amount != null) return false; 50 | if (currency != null ? !currency.equals(price.currency) : price.currency != null) return false; 51 | 52 | return true; 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | int result = 0; 58 | result = 31 * result + (amount != null ? amount.hashCode() : 0); 59 | result = 31 * result + (currency != null ? currency.hashCode() : 0); 60 | return result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Source.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | 8 | 9 | 10 | public class Source { 11 | protected @JsonView(Views.ReadOnly.class) Long id; 12 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 13 | protected @JsonView(Views.ReadOnly.class) String createdAt; 14 | protected @JsonView(Views.ReadOnly.class) String updatedAt; 15 | protected @JsonView(Views.ReadWrite.class) String name; 16 | protected @JsonView(Views.ReadWrite.class) String resourceType; 17 | 18 | public Source() { 19 | } 20 | 21 | public Long getId() { 22 | return this.id; 23 | } 24 | 25 | public Long getCreatorId() { 26 | return this.creatorId; 27 | } 28 | 29 | public String getCreatedAt() { 30 | return this.createdAt; 31 | } 32 | 33 | public String getUpdatedAt() { 34 | return this.updatedAt; 35 | } 36 | 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public String getResourceType() { 46 | return this.resourceType; 47 | } 48 | 49 | public void setResourceType(String resourceType) { 50 | this.resourceType = resourceType; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Source{" + 56 | "id=" + id + 57 | ", creatorId=" + creatorId + 58 | ", createdAt='" + createdAt + '\'' + 59 | ", updatedAt='" + updatedAt + '\'' + 60 | ", name='" + name + '\'' + 61 | ", resourceType='" + resourceType + '\'' + 62 | "}"; 63 | } 64 | 65 | @Override 66 | public boolean equals(Object o) { 67 | if (this == o) return true; 68 | if (o == null || getClass() != o.getClass()) return false; 69 | 70 | Source source = (Source) o; 71 | 72 | if (id != null ? !id.equals(source.id) : source.id != null) return false; 73 | if (creatorId != null ? !creatorId.equals(source.creatorId) : source.creatorId != null) return false; 74 | if (createdAt != null ? !createdAt.equals(source.createdAt) : source.createdAt != null) return false; 75 | if (updatedAt != null ? !updatedAt.equals(source.updatedAt) : source.updatedAt != null) return false; 76 | if (name != null ? !name.equals(source.name) : source.name != null) return false; 77 | if (resourceType != null ? !resourceType.equals(source.resourceType) : source.resourceType != null) return false; 78 | return true; 79 | } 80 | 81 | @Override 82 | public int hashCode() { 83 | int result = id != null ? id.hashCode() : 0; 84 | result = 31 * result + (id != null ? id.hashCode() : 0); 85 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 86 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 87 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 88 | result = 31 * result + (name != null ? name.hashCode() : 0); 89 | result = 31 * result + (resourceType != null ? resourceType.hashCode() : 0); 90 | return result; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Stage.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class Stage { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 14 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 15 | protected @JsonView(Views.ReadWrite.class) Long pipelineId; 16 | protected @JsonView(Views.ReadWrite.class) Boolean active; 17 | protected @JsonView(Views.ReadWrite.class) String category; 18 | protected @JsonView(Views.ReadWrite.class) Long likelihood; 19 | protected @JsonView(Views.ReadWrite.class) String name; 20 | protected @JsonView(Views.ReadWrite.class) Long position; 21 | 22 | public Stage() { 23 | } 24 | 25 | public Long getId() { 26 | return this.id; 27 | } 28 | 29 | public DateTime getCreatedAt() { 30 | return this.createdAt; 31 | } 32 | 33 | public DateTime getUpdatedAt() { 34 | return this.updatedAt; 35 | } 36 | 37 | public Long getPipelineId() { 38 | return this.pipelineId; 39 | } 40 | 41 | public Boolean getActive() { 42 | return this.active; 43 | } 44 | 45 | public String getCategory() { 46 | return this.category; 47 | } 48 | 49 | public Long getLikelihood() { 50 | return this.likelihood; 51 | } 52 | 53 | public String getName() { 54 | return this.name; 55 | } 56 | 57 | public Long getPosition() { 58 | return this.position; 59 | } 60 | 61 | public void setPipelineId(long pipelineId) { 62 | this.pipelineId = pipelineId; 63 | } 64 | 65 | public void setActive(boolean active) { 66 | this.active = active; 67 | } 68 | 69 | public void setCategory(String category) { 70 | this.category = category; 71 | } 72 | 73 | public void setLikelihood(long likelihood) { 74 | this.likelihood = likelihood; 75 | } 76 | 77 | public void setName(String name) { 78 | this.name = name; 79 | } 80 | 81 | public void setPosition(long position) { 82 | this.position = position; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "Stage{" + 88 | "id=" + id + 89 | ", createdAt=" + createdAt + 90 | ", updatedAt=" + updatedAt + 91 | ", pipelineId=" + pipelineId + 92 | ", active=" + active + 93 | ", category='" + category + '\'' + 94 | ", likelihood=" + likelihood + 95 | ", name='" + name + '\'' + 96 | ", position=" + position + 97 | "}"; 98 | } 99 | 100 | @Override 101 | public boolean equals(Object o) { 102 | if (this == o) return true; 103 | if (o == null || getClass() != o.getClass()) return false; 104 | 105 | Stage stage = (Stage) o; 106 | 107 | if (id != null ? !id.equals(stage.id) : stage.id != null) return false; 108 | if (createdAt != null ? !createdAt.equals(stage.createdAt) : stage.createdAt != null) return false; 109 | if (updatedAt != null ? !updatedAt.equals(stage.updatedAt) : stage.updatedAt != null) return false; 110 | if (pipelineId != null ? !pipelineId.equals(stage.pipelineId) : stage.pipelineId != null) return false; 111 | if (active != null ? !active.equals(stage.active) : stage.active != null) return false; 112 | if (category != null ? !category.equals(stage.category) : stage.category != null) return false; 113 | if (likelihood != null ? !likelihood.equals(stage.likelihood) : stage.likelihood != null) return false; 114 | if (name != null ? !name.equals(stage.name) : stage.name != null) return false; 115 | if (position != null ? !position.equals(stage.position) : stage.position != null) return false; 116 | 117 | return true; 118 | } 119 | 120 | @Override 121 | public int hashCode() { 122 | int result = id != null ? id.hashCode() : 0; 123 | result = 31 * result + (id != null ? id.hashCode() : 0); 124 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 125 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 126 | result = 31 * result + (pipelineId != null ? pipelineId.hashCode() : 0); 127 | result = 31 * result + (active != null ? active.hashCode() : 0); 128 | result = 31 * result + (category != null ? category.hashCode() : 0); 129 | result = 31 * result + (likelihood != null ? likelihood.hashCode() : 0); 130 | result = 31 * result + (name != null ? name.hashCode() : 0); 131 | result = 31 * result + (position != null ? position.hashCode() : 0); 132 | return result; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/Tag.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class Tag { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) Long creatorId; 14 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 15 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 16 | protected @JsonView(Views.ReadWrite.class) String name; 17 | protected @JsonView(Views.ReadWrite.class) String resourceType; 18 | 19 | public Tag() { 20 | } 21 | 22 | public Long getId() { 23 | return this.id; 24 | } 25 | 26 | public Long getCreatorId() { 27 | return this.creatorId; 28 | } 29 | 30 | public DateTime getCreatedAt() { 31 | return this.createdAt; 32 | } 33 | 34 | public DateTime getUpdatedAt() { 35 | return this.updatedAt; 36 | } 37 | 38 | public String getName() { 39 | return this.name; 40 | } 41 | 42 | public String getResourceType() { 43 | return this.resourceType; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public void setResourceType(String resourceType) { 51 | this.resourceType = resourceType; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "Tag{" + 57 | "id=" + id + 58 | ", creatorId=" + creatorId + 59 | ", createdAt=" + createdAt + 60 | ", updatedAt=" + updatedAt + 61 | ", name='" + name + '\'' + 62 | ", resourceType='" + resourceType + '\'' + 63 | "}"; 64 | } 65 | 66 | @Override 67 | public boolean equals(Object o) { 68 | if (this == o) return true; 69 | if (o == null || getClass() != o.getClass()) return false; 70 | 71 | Tag tag = (Tag) o; 72 | 73 | if (id != null ? !id.equals(tag.id) : tag.id != null) return false; 74 | if (creatorId != null ? !creatorId.equals(tag.creatorId) : tag.creatorId != null) return false; 75 | if (createdAt != null ? !createdAt.equals(tag.createdAt) : tag.createdAt != null) return false; 76 | if (updatedAt != null ? !updatedAt.equals(tag.updatedAt) : tag.updatedAt != null) return false; 77 | if (name != null ? !name.equals(tag.name) : tag.name != null) return false; 78 | if (resourceType != null ? !resourceType.equals(tag.resourceType) : tag.resourceType != null) return false; 79 | 80 | return true; 81 | } 82 | 83 | @Override 84 | public int hashCode() { 85 | int result = id != null ? id.hashCode() : 0; 86 | result = 31 * result + (id != null ? id.hashCode() : 0); 87 | result = 31 * result + (creatorId != null ? creatorId.hashCode() : 0); 88 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 89 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 90 | result = 31 * result + (name != null ? name.hashCode() : 0); 91 | result = 31 * result + (resourceType != null ? resourceType.hashCode() : 0); 92 | return result; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/models/VisitOutcome.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.models; 4 | 5 | import com.fasterxml.jackson.annotation.JsonView; 6 | import com.getbase.serializer.Views; 7 | import org.joda.time.DateTime; 8 | 9 | 10 | 11 | public class VisitOutcome { 12 | protected @JsonView(Views.ReadOnly.class) Long id; 13 | protected @JsonView(Views.ReadOnly.class) DateTime createdAt; 14 | protected @JsonView(Views.ReadOnly.class) String name; 15 | protected @JsonView(Views.ReadOnly.class) DateTime updatedAt; 16 | 17 | public VisitOutcome() { 18 | } 19 | 20 | public Long getId() { 21 | return this.id; 22 | } 23 | 24 | public DateTime getCreatedAt() { 25 | return this.createdAt; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public DateTime getUpdatedAt() { 33 | return this.updatedAt; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "VisitOutcome{" + 39 | "id=" + id + 40 | ", createdAt=" + createdAt + 41 | ", name='" + name + '\'' + 42 | ", updatedAt=" + updatedAt + 43 | "}"; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) return true; 49 | if (o == null || getClass() != o.getClass()) return false; 50 | 51 | VisitOutcome visitOutcome = (VisitOutcome) o; 52 | 53 | if (id != null ? !id.equals(visitOutcome.id) : visitOutcome.id != null) return false; 54 | if (createdAt != null ? !createdAt.equals(visitOutcome.createdAt) : visitOutcome.createdAt != null) return false; 55 | if (name != null ? !name.equals(visitOutcome.name) : visitOutcome.name != null) return false; 56 | if (updatedAt != null ? !updatedAt.equals(visitOutcome.updatedAt) : visitOutcome.updatedAt != null) return false; 57 | 58 | return true; 59 | } 60 | 61 | @Override 62 | public int hashCode() { 63 | int result = id != null ? id.hashCode() : 0; 64 | result = 31 * result + (id != null ? id.hashCode() : 0); 65 | result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0); 66 | result = 31 * result + (name != null ? name.hashCode() : 0); 67 | result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0); 68 | return result; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/serializer/JacksonProvider.java: -------------------------------------------------------------------------------- 1 | package com.getbase.serializer; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.databind.DeserializationFeature; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.fasterxml.jackson.databind.PropertyNamingStrategy; 7 | import com.fasterxml.jackson.databind.SerializationFeature; 8 | import com.fasterxml.jackson.datatype.joda.JodaModule; 9 | 10 | abstract class JacksonProvider { 11 | private static final ObjectMapper mapper; 12 | 13 | static { 14 | mapper = new ObjectMapper(); 15 | 16 | mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); 17 | mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 18 | mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); 19 | mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 20 | 21 | mapper.registerModule(new JodaModule()); 22 | } 23 | 24 | private JacksonProvider() { 25 | } 26 | 27 | public static ObjectMapper getMapper() { 28 | return mapper; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/serializer/JsonDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.getbase.serializer; 2 | 3 | import com.fasterxml.jackson.core.type.TypeReference; 4 | import com.fasterxml.jackson.databind.JsonNode; 5 | import com.getbase.exceptions.BaseError; 6 | import com.getbase.exceptions.SerializationException; 7 | 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public abstract class JsonDeserializer { 15 | 16 | private JsonDeserializer(){ 17 | } 18 | 19 | public static Map deserializeRaw(String s) { 20 | try { 21 | return JacksonProvider.getMapper().readValue(s, new TypeReference>() {}); 22 | } catch (IOException e) { 23 | throw new SerializationException(e); 24 | } 25 | } 26 | 27 | public static T deserialize(String s, Class type) { 28 | JsonNode node = null; 29 | try { 30 | node = JacksonProvider.getMapper().readTree(s).get("data"); 31 | } catch (IOException e) { 32 | throw new SerializationException(e); 33 | } 34 | return JacksonProvider.getMapper().convertValue(node, type); 35 | } 36 | 37 | public static T deserialize(Map attributes, Class type) { 38 | return JacksonProvider.getMapper().convertValue(attributes, type); 39 | } 40 | 41 | public static List deserializeList(String s, Class type) { 42 | JsonNode itemsNode = null; 43 | try { 44 | itemsNode = JacksonProvider.getMapper().readTree(s).get("items"); 45 | } catch (IOException e) { 46 | throw new SerializationException(e); 47 | } 48 | 49 | List items = new ArrayList(); 50 | if (itemsNode != null) { 51 | for (JsonNode listItemNode : itemsNode) { 52 | T item = JacksonProvider.getMapper().convertValue(listItemNode.get("data"), type); 53 | items.add(item); 54 | } 55 | } 56 | 57 | return items; 58 | } 59 | 60 | public static List deserializeErrors(String s) { 61 | JsonNode errorsNode = null; 62 | try { 63 | errorsNode = JacksonProvider.getMapper().readTree(s).get("errors"); 64 | } catch (IOException e) { 65 | throw new SerializationException(e); 66 | } 67 | 68 | List errors = new ArrayList(); 69 | if (errorsNode != null) { 70 | for (JsonNode errorNode : errorsNode) { 71 | BaseError error = JacksonProvider.getMapper().convertValue(errorNode.get("error"), BaseError.class); 72 | errors.add(error); 73 | } 74 | } 75 | 76 | return errors; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/serializer/JsonSerializer.java: -------------------------------------------------------------------------------- 1 | package com.getbase.serializer; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.ObjectWriter; 6 | import com.getbase.exceptions.SerializationException; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | public abstract class JsonSerializer { 12 | 13 | private JsonSerializer(){ 14 | } 15 | 16 | public static String serialize(Object entity, Class viewClass) { 17 | return serialize(entity, viewClass, null); 18 | } 19 | 20 | public static String serialize(Object entity) { 21 | return serialize(entity, null, null); 22 | } 23 | 24 | public static String serialize(Object entity, String typeName) { 25 | return serialize(entity, null, typeName); 26 | } 27 | 28 | public static String serialize(Object entity, Class viewClass, String typeName) { 29 | try { 30 | Envelope envelope = typeName == null ? 31 | new Envelope(entity) : 32 | new MetaEnvelope(entity, typeName); 33 | 34 | return getObjectWriter(viewClass).writeValueAsString(envelope); 35 | 36 | } catch (JsonProcessingException e) { 37 | throw new SerializationException(e); 38 | } 39 | } 40 | 41 | private static ObjectWriter getObjectWriter(Class viewClass) { 42 | return viewClass == null ? 43 | JacksonProvider.getMapper().writer() : 44 | JacksonProvider.getMapper().writerWithView(viewClass); 45 | } 46 | 47 | static class Envelope { 48 | @JsonView(Views.ReadWrite.class) 49 | Object data; 50 | 51 | Envelope(Object entity) { 52 | this.data = entity; 53 | } 54 | } 55 | 56 | static class MetaEnvelope extends Envelope{ 57 | @JsonView(Views.ReadWrite.class) 58 | Map meta = new HashMap(1); 59 | 60 | MetaEnvelope(Object entity, String type) { 61 | super(entity); 62 | meta.put("type", type); 63 | 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/serializer/Views.java: -------------------------------------------------------------------------------- 1 | package com.getbase.serializer; 2 | 3 | public final class Views { 4 | public static final class ReadOnly {} 5 | public static final class WriteOnly {} 6 | public static final class ReadWrite {} 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/AccountsService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.Account; 7 | import com.getbase.serializer.JsonDeserializer; 8 | 9 | 10 | public class AccountsService extends BaseService { 11 | public AccountsService(HttpClient httpClient) { 12 | super(httpClient); 13 | } 14 | 15 | public Account self() { 16 | return JsonDeserializer.deserialize(this.httpClient.get("/v2/accounts/self", null).getBody(), Account.class); 17 | } 18 | 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/AssociatedContactsService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.AssociatedContact; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | 11 | import java.util.*; 12 | 13 | import static com.getbase.utils.Precondition.checkArgument; 14 | import static com.getbase.utils.Precondition.checkNotNull; 15 | 16 | 17 | public class AssociatedContactsService extends BaseService { 18 | public AssociatedContactsService(HttpClient httpClient) { 19 | super(httpClient); 20 | } 21 | 22 | public List list(long dealId, Map params) { 23 | checkArgument(dealId > 0, "dealId must be a valid id"); 24 | 25 | String url = String.format(Locale.US, "/v2/deals/%d/associated_contacts", dealId); 26 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), AssociatedContact.class); 27 | } 28 | 29 | public List list(long dealId, SearchCriteria criteria) { 30 | return list(dealId, criteria.asMap()); 31 | } 32 | 33 | 34 | public AssociatedContact create(long dealId, AssociatedContact associatedContact) { 35 | checkArgument(dealId > 0, "dealId must be a valid id"); 36 | checkNotNull(associatedContact, "associatedContact parameter must not be null"); 37 | 38 | String url = String.format(Locale.US, "/v2/deals/%d/associated_contacts", dealId); 39 | String serialized = JsonSerializer.serialize(associatedContact, Views.ReadWrite.class); 40 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), AssociatedContact.class); 41 | } 42 | 43 | public AssociatedContact create(long dealId, Map attributes) { 44 | checkArgument(dealId > 0, "dealId must be a valid id"); 45 | checkNotNull(attributes, "attributes parameter must not be null"); 46 | 47 | String url = String.format(Locale.US, "/v2/deals/%d/associated_contacts", dealId); 48 | String serialized = JsonSerializer.serialize(attributes); 49 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), AssociatedContact.class); 50 | } 51 | 52 | 53 | public boolean delete(long dealId, long contactId) { 54 | checkArgument(dealId > 0, "dealId must be a valid id"); 55 | checkArgument(contactId > 0, "contactId must be a valid id"); 56 | 57 | String url = String.format(Locale.US, "/v2/deals/%d/associated_contacts/%d", dealId, contactId); 58 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 59 | } 60 | 61 | 62 | public static class SearchCriteria { 63 | private Map queryParams; 64 | 65 | public SearchCriteria() { 66 | this.queryParams = new HashMap(); 67 | } 68 | 69 | public SearchCriteria page(long page) { 70 | queryParams.put("page", page); 71 | return this; 72 | } 73 | 74 | public SearchCriteria perPage(long perPage) { 75 | queryParams.put("per_page", perPage); 76 | return this; 77 | } 78 | 79 | public SearchCriteria sortBy(String criteria, String order) { 80 | queryParams.put("sort_by", criteria + ":" + order); 81 | return this; 82 | } 83 | 84 | public SearchCriteria sortBy(String criteria) { 85 | return sortBy(criteria, "asc"); 86 | } 87 | 88 | public Map asMap() { 89 | return Collections.unmodifiableMap(queryParams); 90 | } 91 | } 92 | 93 | } 94 | 95 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | 5 | public abstract class BaseService { 6 | protected final HttpClient httpClient; 7 | 8 | public BaseService(HttpClient httpClient) { 9 | this.httpClient = httpClient; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/CallOutcomesService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | import com.getbase.models.CallOutcome; 5 | import com.getbase.serializer.JsonDeserializer; 6 | 7 | import java.util.Collections; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | public class CallOutcomesService extends BaseService { 13 | 14 | public CallOutcomesService(HttpClient httpClient) { 15 | super(httpClient); 16 | } 17 | 18 | public List list(Map params) { 19 | return JsonDeserializer.deserializeList(this.httpClient.get("/v2/call_outcomes", params).getBody(), CallOutcome.class); 20 | } 21 | 22 | public List list(SearchCriteria criteria) { 23 | return list(criteria.asMap()); 24 | } 25 | 26 | public static class SearchCriteria { 27 | private Map queryParams; 28 | 29 | public SearchCriteria() { 30 | this.queryParams = new HashMap(); 31 | } 32 | 33 | public SearchCriteria page(long page) { 34 | queryParams.put("page", page); 35 | return this; 36 | } 37 | 38 | public SearchCriteria perPage(long perPage) { 39 | queryParams.put("per_page", perPage); 40 | return this; 41 | } 42 | 43 | public Map asMap() { 44 | return Collections.unmodifiableMap(queryParams); 45 | } 46 | } 47 | 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/CallsService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | import com.getbase.models.Call; 5 | import com.getbase.serializer.JsonDeserializer; 6 | import com.getbase.serializer.JsonSerializer; 7 | import com.getbase.serializer.Views; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Locale; 14 | import java.util.Map; 15 | 16 | import static com.getbase.utils.Lists.asList; 17 | import static com.getbase.utils.Precondition.checkArgument; 18 | import static com.getbase.utils.Precondition.checkNotNull; 19 | 20 | 21 | public class CallsService extends BaseService { 22 | 23 | private static final String URI = "/v2/calls"; 24 | 25 | private static final String URI_WITH_ID = "/v2/calls/%d"; 26 | 27 | public CallsService(HttpClient httpClient) { 28 | super(httpClient); 29 | } 30 | 31 | public List list(Map params) { 32 | return JsonDeserializer.deserializeList(this.httpClient.get(URI, params).getBody(), Call.class); 33 | } 34 | 35 | public List list(SearchCriteria criteria) { 36 | return list(criteria.asMap()); 37 | } 38 | 39 | 40 | public Call create(Call call) { 41 | checkNotNull(call, "call parameter must not be null"); 42 | 43 | String serialized = JsonSerializer.serialize(call, Views.ReadWrite.class); 44 | return JsonDeserializer.deserialize(this.httpClient.post(URI, serialized).getBody(), Call.class); 45 | } 46 | 47 | public Call create(Map attributes) { 48 | checkNotNull(attributes, "attributes parameter must not be null"); 49 | 50 | String serialized = JsonSerializer.serialize(attributes); 51 | return JsonDeserializer.deserialize(this.httpClient.post(URI, serialized).getBody(), Call.class); 52 | } 53 | 54 | 55 | public Call get(long id) { 56 | checkArgument(id > 0, "id must be a valid id"); 57 | 58 | String url = String.format(Locale.US, URI_WITH_ID, id); 59 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), Call.class); 60 | } 61 | 62 | public Call update(long id, Map attributes) { 63 | checkArgument(id > 0, "id must be a valid id"); 64 | checkNotNull(attributes, "attributes parameter must not be null"); 65 | 66 | String url = String.format(Locale.US, URI_WITH_ID, id); 67 | String serialized = JsonSerializer.serialize(attributes); 68 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Call.class); 69 | } 70 | 71 | 72 | public boolean delete(long id) { 73 | checkArgument(id > 0, "id must be a valid id"); 74 | 75 | String url = String.format(Locale.US, URI_WITH_ID, id); 76 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 77 | } 78 | 79 | public static class SearchCriteria { 80 | private Map queryParams; 81 | 82 | public SearchCriteria() { 83 | this.queryParams = new HashMap(); 84 | } 85 | 86 | public SearchCriteria page(long page) { 87 | queryParams.put("page", page); 88 | return this; 89 | } 90 | 91 | public SearchCriteria perPage(long perPage) { 92 | queryParams.put("per_page", perPage); 93 | return this; 94 | } 95 | 96 | public SearchCriteria ids(List ids) { 97 | queryParams.put("ids", Joiner.join(",", ids)); 98 | return this; 99 | } 100 | 101 | public SearchCriteria ids(Long... ids) { 102 | return ids(asList(ids)); 103 | } 104 | 105 | public SearchCriteria resourceType(String resourceType) { 106 | queryParams.put("resource_type", resourceType); 107 | return this; 108 | } 109 | 110 | public SearchCriteria resourceId(long resourceId) { 111 | queryParams.put("resource_id", resourceId); 112 | return this; 113 | } 114 | 115 | public SearchCriteria associatedDealId(long associatedDealId) { 116 | queryParams.put("associated_deal_id", associatedDealId); 117 | return this; 118 | } 119 | 120 | public Map asMap() { 121 | return Collections.unmodifiableMap(queryParams); 122 | } 123 | } 124 | 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/CollaborationsService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | import com.getbase.models.Collaboration; 5 | import com.getbase.serializer.JsonDeserializer; 6 | import com.getbase.serializer.JsonSerializer; 7 | import com.getbase.serializer.Views; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Locale; 14 | import java.util.Map; 15 | 16 | import static com.getbase.utils.Lists.asList; 17 | import static com.getbase.utils.Precondition.checkArgument; 18 | import static com.getbase.utils.Precondition.checkNotNull; 19 | 20 | public class CollaborationsService extends BaseService { 21 | 22 | private static final String URI = "/v2/collaborations"; 23 | 24 | private static final String URI_WITH_ID = URI + "/%d"; 25 | 26 | public CollaborationsService(HttpClient httpClient) { 27 | super(httpClient); 28 | } 29 | 30 | public List list(CollaborationsService.SearchCriteria criteria) { 31 | return list(criteria.asMap()); 32 | } 33 | 34 | public List list(Map params) { 35 | return JsonDeserializer.deserializeList(this.httpClient.get(URI, params).getBody(), Collaboration.class); 36 | } 37 | 38 | public Collaboration create(Collaboration collaboration) { 39 | checkNotNull(collaboration, "collaboration parameter must not be null"); 40 | 41 | String serialized = JsonSerializer.serialize(collaboration, Views.ReadWrite.class, "collaboration"); 42 | return JsonDeserializer.deserialize(this.httpClient.post(URI, serialized).getBody(), Collaboration.class); 43 | } 44 | 45 | public Collaboration create(Map attributes) { 46 | checkNotNull(attributes, "attributes parameter must not be null"); 47 | 48 | String serialized = JsonSerializer.serialize(attributes, "collaboration"); 49 | return JsonDeserializer.deserialize(this.httpClient.post(URI, serialized).getBody(), Collaboration.class); 50 | } 51 | 52 | public Collaboration get(long id) { 53 | checkArgument(id > 0, "id must be a valid id"); 54 | 55 | String uri = String.format(Locale.US, URI_WITH_ID, id); 56 | return JsonDeserializer.deserialize(this.httpClient.get(uri, null).getBody(), Collaboration.class); 57 | } 58 | 59 | public boolean delete(long id) { 60 | checkArgument(id > 0, "id must be a valid id"); 61 | 62 | String uri = String.format(Locale.US, URI_WITH_ID, id); 63 | return this.httpClient.delete(uri, null).getHttpStatus() == 204; 64 | } 65 | 66 | public static class SearchCriteria { 67 | 68 | private Map queryParams; 69 | 70 | public SearchCriteria() { 71 | this.queryParams = new HashMap(); 72 | } 73 | 74 | public SearchCriteria page(long page) { 75 | queryParams.put("page", page); 76 | return this; 77 | } 78 | 79 | public SearchCriteria perPage(long perPage) { 80 | queryParams.put("per_page", perPage); 81 | return this; 82 | } 83 | 84 | public SearchCriteria sortBy(String criteria, String order) { 85 | queryParams.put("sort_by", criteria + ":" + order); 86 | return this; 87 | } 88 | 89 | public SearchCriteria ids(List ids) { 90 | queryParams.put("ids", Joiner.join(",", ids)); 91 | return this; 92 | } 93 | 94 | public SearchCriteria ids(Long... ids) { 95 | return ids(asList(ids)); 96 | } 97 | 98 | public SearchCriteria creatorId(long creatorId) { 99 | queryParams.put("creator_id", creatorId); 100 | return this; 101 | } 102 | 103 | public SearchCriteria resourceType(String resourceType) { 104 | queryParams.put("resource_type", resourceType); 105 | return this; 106 | } 107 | 108 | public SearchCriteria resourceId(long resourceId) { 109 | queryParams.put("resource_id", resourceId); 110 | return this; 111 | } 112 | 113 | public Map asMap() { 114 | return Collections.unmodifiableMap(queryParams); 115 | } 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/LeadSourcesService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | import com.getbase.models.Source; 5 | import com.getbase.serializer.JsonDeserializer; 6 | import com.getbase.serializer.JsonSerializer; 7 | import com.getbase.serializer.Views; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Locale; 14 | import java.util.Map; 15 | 16 | import static com.getbase.utils.Lists.asList; 17 | import static com.getbase.utils.Precondition.checkArgument; 18 | import static com.getbase.utils.Precondition.checkNotNull; 19 | 20 | 21 | public class LeadSourcesService extends BaseService { 22 | public LeadSourcesService(HttpClient httpClient) { 23 | super(httpClient); 24 | } 25 | 26 | public List list(Map params) { 27 | String url = "/v2/lead_sources"; 28 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Source.class); 29 | } 30 | 31 | public List list(SearchCriteria criteria) { 32 | return list(criteria.asMap()); 33 | } 34 | 35 | 36 | public Source create(Source source) { 37 | checkNotNull(source, "source parameter must not be null"); 38 | 39 | String url = "/v2/lead_sources"; 40 | String serialized = JsonSerializer.serialize(source, Views.ReadWrite.class); 41 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Source.class); 42 | } 43 | 44 | public Source create(Map attributes) { 45 | checkNotNull(attributes, "attributes parameter must not be null"); 46 | 47 | String url = "/v2/lead_sources"; 48 | String serialized = JsonSerializer.serialize(attributes); 49 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Source.class); 50 | } 51 | 52 | 53 | public Source get(long id) { 54 | checkArgument(id > 0, "id must be a valid id"); 55 | 56 | String url = String.format(Locale.US, "/v2/lead_sources/%d", id); 57 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), Source.class); 58 | } 59 | 60 | 61 | public Source update(Source source) { 62 | checkNotNull(source, "source parameter must not be null"); 63 | checkNotNull(source.getId(), "source must have id attribute set"); 64 | checkArgument(source.getId() > 0, "source id must be a valid id"); 65 | 66 | String url = String.format(Locale.US, "/v2/lead_sources/%d", source.getId()); 67 | String serialized = JsonSerializer.serialize(source, Views.ReadWrite.class); 68 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Source.class); 69 | } 70 | 71 | public Source update(long id, Map attributes) { 72 | checkArgument(id > 0, "id must be a valid id"); 73 | checkNotNull(attributes, "attributes parameter must not be null"); 74 | 75 | String url = String.format(Locale.US, "/v2/lead_sources/%d", id); 76 | String serialized = JsonSerializer.serialize(attributes); 77 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Source.class); 78 | } 79 | 80 | 81 | public boolean delete(long id) { 82 | checkArgument(id > 0, "id must be a valid id"); 83 | 84 | String url = String.format(Locale.US, "/v2/lead_sources/%d", id); 85 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 86 | } 87 | 88 | 89 | 90 | public static class SearchCriteria { 91 | private Map queryParams; 92 | 93 | public SearchCriteria() { 94 | this.queryParams = new HashMap(); 95 | } 96 | 97 | public SearchCriteria page(long page) { 98 | queryParams.put("page", page); 99 | return this; 100 | } 101 | 102 | public SearchCriteria perPage(long perPage) { 103 | queryParams.put("per_page", perPage); 104 | return this; 105 | } 106 | 107 | public SearchCriteria sortBy(String criteria, String order) { 108 | queryParams.put("sort_by", criteria + ":" + order); 109 | return this; 110 | } 111 | 112 | public SearchCriteria sortBy(String criteria) { 113 | return sortBy(criteria, "asc"); 114 | } 115 | 116 | public SearchCriteria ids(List ids) { 117 | queryParams.put("ids", Joiner.join(",", ids)); 118 | return this; 119 | } 120 | 121 | public SearchCriteria ids(Long... ids) { 122 | return ids(asList(ids)); 123 | } 124 | 125 | public SearchCriteria name(String name) { 126 | queryParams.put("name", name); 127 | return this; 128 | } 129 | 130 | public Map asMap() { 131 | return Collections.unmodifiableMap(queryParams); 132 | } 133 | } 134 | 135 | } 136 | 137 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/LeadUnqualifiedReasonsService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.LeadUnqualifiedReason; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | import static com.getbase.utils.Lists.asList; 16 | 17 | 18 | public class LeadUnqualifiedReasonsService extends BaseService { 19 | public LeadUnqualifiedReasonsService(HttpClient httpClient) { 20 | super(httpClient); 21 | } 22 | 23 | public List list(Map params) { 24 | String url = "/v2/lead_unqualified_reasons"; 25 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), LeadUnqualifiedReason.class); 26 | } 27 | 28 | public List list(SearchCriteria criteria) { 29 | return list(criteria.asMap()); 30 | } 31 | 32 | 33 | 34 | public static class SearchCriteria { 35 | private Map queryParams; 36 | 37 | public SearchCriteria() { 38 | this.queryParams = new HashMap(); 39 | } 40 | 41 | public SearchCriteria page(long page) { 42 | queryParams.put("page", page); 43 | return this; 44 | } 45 | 46 | public SearchCriteria perPage(long perPage) { 47 | queryParams.put("per_page", perPage); 48 | return this; 49 | } 50 | 51 | public SearchCriteria sortBy(String criteria, String order) { 52 | queryParams.put("sort_by", criteria + ":" + order); 53 | return this; 54 | } 55 | 56 | public SearchCriteria sortBy(String criteria) { 57 | return sortBy(criteria, "asc"); 58 | } 59 | 60 | public SearchCriteria ids(List ids) { 61 | queryParams.put("ids", Joiner.join(",", ids)); 62 | return this; 63 | } 64 | 65 | public SearchCriteria ids(Long... ids) { 66 | return ids(asList(ids)); 67 | } 68 | 69 | public Map asMap() { 70 | return Collections.unmodifiableMap(queryParams); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/LineItemsService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | import com.getbase.models.LineItem; 5 | import com.getbase.serializer.JsonDeserializer; 6 | import com.getbase.serializer.JsonSerializer; 7 | import com.getbase.serializer.Views; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.math.BigDecimal; 11 | import java.util.Collections; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Locale; 15 | import java.util.Map; 16 | 17 | import static com.getbase.utils.Lists.asList; 18 | import static com.getbase.utils.Precondition.checkArgument; 19 | import static com.getbase.utils.Precondition.checkNotNull; 20 | 21 | public class LineItemsService extends BaseService { 22 | 23 | public LineItemsService(HttpClient httpClient) { 24 | super(httpClient); 25 | } 26 | 27 | public List list(long orderId, SearchCriteria criteria) { 28 | return list(orderId, criteria.asMap()); 29 | } 30 | 31 | public List list(long orderId, Map params) { 32 | String url = String.format(Locale.US, "/v2/orders/%d/line_items", orderId); 33 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), LineItem.class); 34 | } 35 | 36 | public LineItem create(long orderId, LineItem lineItem) { 37 | checkArgument(orderId > 0, "orderId must be a valid id"); 38 | checkNotNull(lineItem, "lineItem parameter must not be null"); 39 | 40 | String url = String.format(Locale.US, "/v2/orders/%d/line_items", orderId); 41 | String serialized = JsonSerializer.serialize(lineItem, Views.ReadWrite.class, "line_item"); 42 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), LineItem.class); 43 | } 44 | 45 | public LineItem create(long orderId, Map attributes) { 46 | checkArgument(orderId > 0, "orderId must be a valid id"); 47 | checkNotNull(attributes, "attributes parameter must not be null"); 48 | 49 | String url = String.format("/v2/orders/%d/line_items", orderId); 50 | String serialized = JsonSerializer.serialize(attributes, "line_item"); 51 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), LineItem.class); 52 | } 53 | 54 | public LineItem get(long orderId, long id) { 55 | checkArgument(orderId > 0, "orderId must be a valid id"); 56 | checkArgument(id > 0, "id must be a valid id"); 57 | 58 | String url = String.format(Locale.US, "/v2/orders/%d/line_items/%d", orderId, id); 59 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), LineItem.class); 60 | } 61 | 62 | public boolean delete(long orderId, long id) { 63 | checkArgument(orderId > 0, "orderId must be a valid id"); 64 | checkArgument(id > 0, "id must be a valid id"); 65 | 66 | String url = String.format(Locale.US, "/v2/orders/%d/line_items/%d", orderId, id); 67 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 68 | } 69 | 70 | public static class SearchCriteria { 71 | 72 | private Map queryParams; 73 | 74 | public SearchCriteria() { 75 | this.queryParams = new HashMap(); 76 | } 77 | 78 | public SearchCriteria page(long page) { 79 | queryParams.put("page", page); 80 | return this; 81 | } 82 | 83 | public SearchCriteria perPage(long perPage) { 84 | queryParams.put("per_page", perPage); 85 | return this; 86 | } 87 | 88 | public SearchCriteria sortBy(String criteria, String order) { 89 | queryParams.put("sort_by", criteria + ":" + order); 90 | return this; 91 | } 92 | 93 | public SearchCriteria ids(List ids) { 94 | queryParams.put("ids", Joiner.join(",", ids)); 95 | return this; 96 | } 97 | 98 | public SearchCriteria ids(Long... ids) { 99 | return ids(asList(ids)); 100 | } 101 | 102 | public SearchCriteria quantity(long quantity) { 103 | queryParams.put("quantity", quantity); 104 | return this; 105 | } 106 | 107 | public SearchCriteria value(BigDecimal value) { 108 | queryParams.put("value", value); 109 | return this; 110 | } 111 | 112 | public Map asMap() { 113 | return Collections.unmodifiableMap(queryParams); 114 | } 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/LossReasonsService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.LossReason; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | import com.getbase.utils.Joiner; 11 | 12 | import java.util.*; 13 | 14 | import static com.getbase.utils.Lists.asList; 15 | import static com.getbase.utils.Precondition.*; 16 | 17 | 18 | public class LossReasonsService extends BaseService { 19 | public LossReasonsService(HttpClient httpClient) { 20 | super(httpClient); 21 | } 22 | 23 | public List list(Map params) { 24 | String url = "/v2/loss_reasons"; 25 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), LossReason.class); 26 | } 27 | 28 | public List list(SearchCriteria criteria) { 29 | return list(criteria.asMap()); 30 | } 31 | 32 | 33 | public LossReason create(LossReason lossReason) { 34 | checkNotNull(lossReason, "lossReason parameter must not be null"); 35 | 36 | String url = "/v2/loss_reasons"; 37 | String serialized = JsonSerializer.serialize(lossReason, Views.ReadWrite.class); 38 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), LossReason.class); 39 | } 40 | 41 | public LossReason create(Map attributes) { 42 | checkNotNull(attributes, "attributes parameter must not be null"); 43 | 44 | String url = "/v2/loss_reasons"; 45 | String serialized = JsonSerializer.serialize(attributes); 46 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), LossReason.class); 47 | } 48 | 49 | 50 | public LossReason get(long id) { 51 | checkArgument(id > 0, "id must be a valid id"); 52 | 53 | String url = String.format(Locale.US, "/v2/loss_reasons/%d", id); 54 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), LossReason.class); 55 | } 56 | 57 | 58 | public LossReason update(LossReason lossReason) { 59 | checkNotNull(lossReason, "lossReason parameter must not be null"); 60 | checkNotNull(lossReason.getId(), "lossReason must have id attribute set"); 61 | checkArgument(lossReason.getId() > 0, "lossReason id must be a valid id"); 62 | 63 | String url = String.format(Locale.US, "/v2/loss_reasons/%d", lossReason.getId()); 64 | String serialized = JsonSerializer.serialize(lossReason, Views.ReadWrite.class); 65 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), LossReason.class); 66 | } 67 | 68 | public LossReason update(long id, Map attributes) { 69 | checkArgument(id > 0, "id must be a valid id"); 70 | checkNotNull(attributes, "attributes parameter must not be null"); 71 | 72 | String url = String.format(Locale.US, "/v2/loss_reasons/%d", id); 73 | String serialized = JsonSerializer.serialize(attributes); 74 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), LossReason.class); 75 | } 76 | 77 | 78 | public boolean delete(long id) { 79 | checkArgument(id > 0, "id must be a valid id"); 80 | 81 | String url = String.format(Locale.US, "/v2/loss_reasons/%d", id); 82 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 83 | } 84 | 85 | 86 | 87 | public static class SearchCriteria { 88 | private Map queryParams; 89 | 90 | public SearchCriteria() { 91 | this.queryParams = new HashMap(); 92 | } 93 | 94 | public SearchCriteria page(long page) { 95 | queryParams.put("page", page); 96 | return this; 97 | } 98 | 99 | public SearchCriteria perPage(long perPage) { 100 | queryParams.put("per_page", perPage); 101 | return this; 102 | } 103 | 104 | public SearchCriteria sortBy(String criteria, String order) { 105 | queryParams.put("sort_by", criteria + ":" + order); 106 | return this; 107 | } 108 | 109 | public SearchCriteria sortBy(String criteria) { 110 | return sortBy(criteria, "asc"); 111 | } 112 | 113 | public SearchCriteria ids(List ids) { 114 | queryParams.put("ids", Joiner.join(",", ids)); 115 | return this; 116 | } 117 | 118 | public SearchCriteria ids(Long... ids) { 119 | return ids(asList(ids)); 120 | } 121 | 122 | public SearchCriteria name(String name) { 123 | queryParams.put("name", name); 124 | return this; 125 | } 126 | 127 | public Map asMap() { 128 | return Collections.unmodifiableMap(queryParams); 129 | } 130 | } 131 | 132 | } 133 | 134 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/OrdersService.java: -------------------------------------------------------------------------------- 1 | package com.getbase.services; 2 | 3 | import com.getbase.http.HttpClient; 4 | import com.getbase.models.Order; 5 | import com.getbase.serializer.JsonDeserializer; 6 | import com.getbase.serializer.JsonSerializer; 7 | import com.getbase.serializer.Views; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Locale; 14 | import java.util.Map; 15 | 16 | import static com.getbase.utils.Lists.asList; 17 | import static com.getbase.utils.Precondition.checkArgument; 18 | import static com.getbase.utils.Precondition.checkNotNull; 19 | 20 | public class OrdersService extends BaseService { 21 | 22 | public OrdersService(HttpClient httpClient) { 23 | super(httpClient); 24 | } 25 | 26 | public List list(SearchCriteria criteria) { 27 | return list(criteria.asMap()); 28 | } 29 | 30 | public List list(Map params) { 31 | String url = "/v2/orders"; 32 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Order.class); 33 | } 34 | 35 | public Order create(Order order) { 36 | checkNotNull(order, "order parameter must not be null"); 37 | 38 | String url = "/v2/orders"; 39 | String serialized = JsonSerializer.serialize(order, Views.ReadWrite.class, "order"); 40 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Order.class); 41 | } 42 | 43 | public Order create(Map attributes) { 44 | checkNotNull(attributes, "attributes parameter must not be null"); 45 | 46 | String url = "/v2/orders"; 47 | String serialized = JsonSerializer.serialize(attributes, "order"); 48 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Order.class); 49 | } 50 | 51 | public Order get(long id) { 52 | checkArgument(id > 0, "id must be a valid id"); 53 | 54 | String url = String.format(Locale.US, "/v2/orders/%d", id); 55 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), Order.class); 56 | } 57 | 58 | public Order update(Order order) { 59 | checkNotNull(order, "order parameter must not be null"); 60 | checkNotNull(order.getId(), "order must have id attribute set"); 61 | checkArgument(order.getId() > 0, "order id must be a valid id"); 62 | 63 | String url = String.format(Locale.US, "/v2/orders/%d", order.getId()); 64 | String serialized = JsonSerializer.serialize(order, Views.ReadWrite.class); 65 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Order.class); 66 | } 67 | 68 | public Order update(long id, Map attributes) { 69 | checkArgument(id > 0, "id must be a valid id"); 70 | checkNotNull(attributes, "attributes parameter must not be null"); 71 | 72 | String url = String.format(Locale.US, "/v2/orders/%d", id); 73 | String serialized = JsonSerializer.serialize(attributes); 74 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Order.class); 75 | } 76 | 77 | public boolean delete(long id) { 78 | checkArgument(id > 0, "id must be a valid id"); 79 | 80 | String url = String.format(Locale.US, "/v2/orders/%d", id); 81 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 82 | } 83 | 84 | public static class SearchCriteria { 85 | 86 | private Map queryParams; 87 | 88 | public SearchCriteria() { 89 | this.queryParams = new HashMap(); 90 | } 91 | 92 | public SearchCriteria page(long page) { 93 | queryParams.put("page", page); 94 | return this; 95 | } 96 | 97 | public SearchCriteria perPage(long perPage) { 98 | queryParams.put("per_page", perPage); 99 | return this; 100 | } 101 | 102 | public SearchCriteria sortBy(String criteria, String order) { 103 | queryParams.put("sort_by", criteria + ":" + order); 104 | return this; 105 | } 106 | 107 | public SearchCriteria ids(List ids) { 108 | queryParams.put("ids", Joiner.join(",", ids)); 109 | return this; 110 | } 111 | 112 | public SearchCriteria ids(Long... ids) { 113 | return ids(asList(ids)); 114 | } 115 | 116 | public SearchCriteria dealId(long dealId) { 117 | queryParams.put("deal_id", dealId); 118 | return this; 119 | } 120 | 121 | public Map asMap() { 122 | return Collections.unmodifiableMap(queryParams); 123 | } 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/PipelinesService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.Pipeline; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | import static com.getbase.utils.Lists.asList; 16 | 17 | 18 | public class PipelinesService extends BaseService { 19 | public PipelinesService(HttpClient httpClient) { 20 | super(httpClient); 21 | } 22 | 23 | public List list(Map params) { 24 | String url = "/v2/pipelines"; 25 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Pipeline.class); 26 | } 27 | 28 | public List list(SearchCriteria criteria) { 29 | return list(criteria.asMap()); 30 | } 31 | 32 | 33 | 34 | public static class SearchCriteria { 35 | private Map queryParams; 36 | 37 | public SearchCriteria() { 38 | this.queryParams = new HashMap(); 39 | } 40 | 41 | public SearchCriteria page(long page) { 42 | queryParams.put("page", page); 43 | return this; 44 | } 45 | 46 | public SearchCriteria perPage(long perPage) { 47 | queryParams.put("per_page", perPage); 48 | return this; 49 | } 50 | 51 | public SearchCriteria sortBy(String criteria, String order) { 52 | queryParams.put("sort_by", criteria + ":" + order); 53 | return this; 54 | } 55 | 56 | public SearchCriteria sortBy(String criteria) { 57 | return sortBy(criteria, "asc"); 58 | } 59 | 60 | public SearchCriteria ids(List ids) { 61 | queryParams.put("ids", Joiner.join(",", ids)); 62 | return this; 63 | } 64 | 65 | public SearchCriteria ids(Long... ids) { 66 | return ids(asList(ids)); 67 | } 68 | 69 | public SearchCriteria name(String name) { 70 | queryParams.put("name", name); 71 | return this; 72 | } 73 | 74 | public Map asMap() { 75 | return Collections.unmodifiableMap(queryParams); 76 | } 77 | } 78 | 79 | } 80 | 81 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/SourcesService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.Source; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | import com.getbase.utils.Joiner; 11 | 12 | import java.util.*; 13 | 14 | import static com.getbase.utils.Lists.asList; 15 | import static com.getbase.utils.Precondition.*; 16 | 17 | 18 | public class SourcesService extends BaseService { 19 | public SourcesService(HttpClient httpClient) { 20 | super(httpClient); 21 | } 22 | 23 | public List list(Map params) { 24 | String url = "/v2/sources"; 25 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Source.class); 26 | } 27 | 28 | public List list(SearchCriteria criteria) { 29 | return list(criteria.asMap()); 30 | } 31 | 32 | 33 | public Source create(Source source) { 34 | checkNotNull(source, "source parameter must not be null"); 35 | 36 | String url = "/v2/sources"; 37 | String serialized = JsonSerializer.serialize(source, Views.ReadWrite.class); 38 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Source.class); 39 | } 40 | 41 | public Source create(Map attributes) { 42 | checkNotNull(attributes, "attributes parameter must not be null"); 43 | 44 | String url = "/v2/sources"; 45 | String serialized = JsonSerializer.serialize(attributes); 46 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Source.class); 47 | } 48 | 49 | 50 | public Source get(long id) { 51 | checkArgument(id > 0, "id must be a valid id"); 52 | 53 | String url = String.format(Locale.US, "/v2/sources/%d", id); 54 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), Source.class); 55 | } 56 | 57 | 58 | public Source update(Source source) { 59 | checkNotNull(source, "source parameter must not be null"); 60 | checkNotNull(source.getId(), "source must have id attribute set"); 61 | checkArgument(source.getId() > 0, "source id must be a valid id"); 62 | 63 | String url = String.format(Locale.US, "/v2/sources/%d", source.getId()); 64 | String serialized = JsonSerializer.serialize(source, Views.ReadWrite.class); 65 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Source.class); 66 | } 67 | 68 | public Source update(long id, Map attributes) { 69 | checkArgument(id > 0, "id must be a valid id"); 70 | checkNotNull(attributes, "attributes parameter must not be null"); 71 | 72 | String url = String.format(Locale.US, "/v2/sources/%d", id); 73 | String serialized = JsonSerializer.serialize(attributes); 74 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Source.class); 75 | } 76 | 77 | 78 | public boolean delete(long id) { 79 | checkArgument(id > 0, "id must be a valid id"); 80 | 81 | String url = String.format(Locale.US, "/v2/sources/%d", id); 82 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 83 | } 84 | 85 | 86 | 87 | public static class SearchCriteria { 88 | private Map queryParams; 89 | 90 | public SearchCriteria() { 91 | this.queryParams = new HashMap(); 92 | } 93 | 94 | public SearchCriteria page(long page) { 95 | queryParams.put("page", page); 96 | return this; 97 | } 98 | 99 | public SearchCriteria perPage(long perPage) { 100 | queryParams.put("per_page", perPage); 101 | return this; 102 | } 103 | 104 | public SearchCriteria sortBy(String criteria, String order) { 105 | queryParams.put("sort_by", criteria + ":" + order); 106 | return this; 107 | } 108 | 109 | public SearchCriteria sortBy(String criteria) { 110 | return sortBy(criteria, "asc"); 111 | } 112 | 113 | public SearchCriteria ids(List ids) { 114 | queryParams.put("ids", Joiner.join(",", ids)); 115 | return this; 116 | } 117 | 118 | public SearchCriteria ids(Long... ids) { 119 | return ids(asList(ids)); 120 | } 121 | 122 | public SearchCriteria name(String name) { 123 | queryParams.put("name", name); 124 | return this; 125 | } 126 | 127 | public Map asMap() { 128 | return Collections.unmodifiableMap(queryParams); 129 | } 130 | } 131 | 132 | } 133 | 134 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/StagesService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.Stage; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.Collections; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | import static com.getbase.utils.Lists.asList; 16 | 17 | 18 | public class StagesService extends BaseService { 19 | public StagesService(HttpClient httpClient) { 20 | super(httpClient); 21 | } 22 | 23 | public List list(Map params) { 24 | String url = "/v2/stages"; 25 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Stage.class); 26 | } 27 | 28 | public List list(SearchCriteria criteria) { 29 | return list(criteria.asMap()); 30 | } 31 | 32 | 33 | 34 | public static class SearchCriteria { 35 | private Map queryParams; 36 | 37 | public SearchCriteria() { 38 | this.queryParams = new HashMap(); 39 | } 40 | 41 | public SearchCriteria page(long page) { 42 | queryParams.put("page", page); 43 | return this; 44 | } 45 | 46 | public SearchCriteria perPage(long perPage) { 47 | queryParams.put("per_page", perPage); 48 | return this; 49 | } 50 | 51 | public SearchCriteria sortBy(String criteria, String order) { 52 | queryParams.put("sort_by", criteria + ":" + order); 53 | return this; 54 | } 55 | 56 | public SearchCriteria sortBy(String criteria) { 57 | return sortBy(criteria, "asc"); 58 | } 59 | 60 | public SearchCriteria ids(List ids) { 61 | queryParams.put("ids", Joiner.join(",", ids)); 62 | return this; 63 | } 64 | 65 | public SearchCriteria ids(Long... ids) { 66 | return ids(asList(ids)); 67 | } 68 | 69 | public SearchCriteria pipelineId(long pipelineId) { 70 | queryParams.put("pipeline_id", pipelineId); 71 | return this; 72 | } 73 | 74 | public SearchCriteria active(boolean active) { 75 | queryParams.put("active", active); 76 | return this; 77 | } 78 | 79 | public SearchCriteria name(String name) { 80 | queryParams.put("name", name); 81 | return this; 82 | } 83 | 84 | public Map asMap() { 85 | return Collections.unmodifiableMap(queryParams); 86 | } 87 | } 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/TagsService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.Tag; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | import com.getbase.utils.Joiner; 11 | 12 | import java.util.*; 13 | 14 | import static com.getbase.utils.Lists.asList; 15 | import static com.getbase.utils.Precondition.*; 16 | 17 | 18 | public class TagsService extends BaseService { 19 | public TagsService(HttpClient httpClient) { 20 | super(httpClient); 21 | } 22 | 23 | public List list(Map params) { 24 | String url = "/v2/tags"; 25 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Tag.class); 26 | } 27 | 28 | public List list(SearchCriteria criteria) { 29 | return list(criteria.asMap()); 30 | } 31 | 32 | 33 | public Tag create(Tag tag) { 34 | checkNotNull(tag, "tag parameter must not be null"); 35 | 36 | String url = "/v2/tags"; 37 | String serialized = JsonSerializer.serialize(tag, Views.ReadWrite.class); 38 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Tag.class); 39 | } 40 | 41 | public Tag create(Map attributes) { 42 | checkNotNull(attributes, "attributes parameter must not be null"); 43 | 44 | String url = "/v2/tags"; 45 | String serialized = JsonSerializer.serialize(attributes); 46 | return JsonDeserializer.deserialize(this.httpClient.post(url, serialized).getBody(), Tag.class); 47 | } 48 | 49 | 50 | public Tag get(long id) { 51 | checkArgument(id > 0, "id must be a valid id"); 52 | 53 | String url = String.format(Locale.US, "/v2/tags/%d", id); 54 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), Tag.class); 55 | } 56 | 57 | 58 | public Tag update(Tag tag) { 59 | checkNotNull(tag, "tag parameter must not be null"); 60 | checkNotNull(tag.getId(), "tag must have id attribute set"); 61 | checkArgument(tag.getId() > 0, "tag id must be a valid id"); 62 | 63 | String url = String.format(Locale.US, "/v2/tags/%d", tag.getId()); 64 | String serialized = JsonSerializer.serialize(tag, Views.ReadWrite.class); 65 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Tag.class); 66 | } 67 | 68 | public Tag update(long id, Map attributes) { 69 | checkArgument(id > 0, "id must be a valid id"); 70 | checkNotNull(attributes, "attributes parameter must not be null"); 71 | 72 | String url = String.format(Locale.US, "/v2/tags/%d", id); 73 | String serialized = JsonSerializer.serialize(attributes); 74 | return JsonDeserializer.deserialize(this.httpClient.put(url, serialized).getBody(), Tag.class); 75 | } 76 | 77 | 78 | public boolean delete(long id) { 79 | checkArgument(id > 0, "id must be a valid id"); 80 | 81 | String url = String.format(Locale.US, "/v2/tags/%d", id); 82 | return this.httpClient.delete(url, null).getHttpStatus() == 204; 83 | } 84 | 85 | 86 | 87 | public static class SearchCriteria { 88 | private Map queryParams; 89 | 90 | public SearchCriteria() { 91 | this.queryParams = new HashMap(); 92 | } 93 | 94 | public SearchCriteria page(long page) { 95 | queryParams.put("page", page); 96 | return this; 97 | } 98 | 99 | public SearchCriteria perPage(long perPage) { 100 | queryParams.put("per_page", perPage); 101 | return this; 102 | } 103 | 104 | public SearchCriteria sortBy(String criteria, String order) { 105 | queryParams.put("sort_by", criteria + ":" + order); 106 | return this; 107 | } 108 | 109 | public SearchCriteria sortBy(String criteria) { 110 | return sortBy(criteria, "asc"); 111 | } 112 | 113 | public SearchCriteria ids(List ids) { 114 | queryParams.put("ids", Joiner.join(",", ids)); 115 | return this; 116 | } 117 | 118 | public SearchCriteria ids(Long... ids) { 119 | return ids(asList(ids)); 120 | } 121 | 122 | public SearchCriteria creatorId(long creatorId) { 123 | queryParams.put("creator_id", creatorId); 124 | return this; 125 | } 126 | 127 | public SearchCriteria name(String name) { 128 | queryParams.put("name", name); 129 | return this; 130 | } 131 | 132 | public SearchCriteria resourceType(String resourceType) { 133 | queryParams.put("resource_type", resourceType); 134 | return this; 135 | } 136 | 137 | public Map asMap() { 138 | return Collections.unmodifiableMap(queryParams); 139 | } 140 | } 141 | 142 | } 143 | 144 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/TextMessagesService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.TextMessage; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | 11 | import java.util.*; 12 | 13 | import static com.getbase.utils.Lists.asList; 14 | import static com.getbase.utils.Precondition.*; 15 | 16 | public class TextMessagesService extends BaseService { 17 | public TextMessagesService(HttpClient httpClient) { 18 | super(httpClient); 19 | } 20 | 21 | public List list(Map params) { 22 | String url = "/v2/text_messages"; 23 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), TextMessage.class); 24 | } 25 | 26 | public List list(SearchCriteria criteria) { 27 | return list(criteria.asMap()); 28 | } 29 | 30 | 31 | public TextMessage get(long id) { 32 | checkArgument(id > 0, "id must be a valid id"); 33 | 34 | String url = String.format(Locale.US, "/v2/text_messages/%d", id); 35 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), TextMessage.class); 36 | } 37 | 38 | 39 | 40 | public static class SearchCriteria { 41 | private Map queryParams; 42 | 43 | public SearchCriteria() { 44 | this.queryParams = new HashMap(); 45 | } 46 | 47 | public SearchCriteria page(long page) { 48 | queryParams.put("page", page); 49 | return this; 50 | } 51 | 52 | public SearchCriteria perPage(long perPage) { 53 | queryParams.put("per_page", perPage); 54 | return this; 55 | } 56 | 57 | public SearchCriteria sortBy(String criteria, String order) { 58 | queryParams.put("sort_by", criteria + ":" + order); 59 | return this; 60 | } 61 | 62 | public SearchCriteria sortBy(String criteria) { 63 | return sortBy(criteria, "asc"); 64 | } 65 | 66 | public SearchCriteria ids(List ids) { 67 | queryParams.put("ids", ids); 68 | return this; 69 | } 70 | 71 | public SearchCriteria ids(Long... ids) { 72 | return ids(asList(ids)); 73 | } 74 | 75 | public SearchCriteria resourceId(long resourceId) { 76 | queryParams.put("resource_id", resourceId); 77 | return this; 78 | } 79 | 80 | public SearchCriteria resourceType(String resourceType) { 81 | queryParams.put("resource_type", resourceType); 82 | return this; 83 | } 84 | 85 | public Map asMap() { 86 | return Collections.unmodifiableMap(queryParams); 87 | } 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/UsersService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.User; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.utils.Joiner; 9 | 10 | import java.util.*; 11 | 12 | import static com.getbase.utils.Lists.asList; 13 | import static com.getbase.utils.Precondition.checkArgument; 14 | 15 | 16 | public class UsersService extends BaseService { 17 | public UsersService(HttpClient httpClient) { 18 | super(httpClient); 19 | } 20 | 21 | public List list(Map params) { 22 | String url = "/v2/users"; 23 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), User.class); 24 | } 25 | 26 | public List list(SearchCriteria criteria) { 27 | return list(criteria.asMap()); 28 | } 29 | 30 | 31 | public User get(long id) { 32 | checkArgument(id > 0, "id must be a valid id"); 33 | 34 | String url = String.format(Locale.US, "/v2/users/%d", id); 35 | return JsonDeserializer.deserialize(this.httpClient.get(url, null).getBody(), User.class); 36 | } 37 | 38 | 39 | public User self() { 40 | return JsonDeserializer.deserialize(this.httpClient.get("/v2/users/self", null).getBody(), User.class); 41 | } 42 | 43 | 44 | 45 | public static class SearchCriteria { 46 | private Map queryParams; 47 | 48 | public SearchCriteria() { 49 | this.queryParams = new HashMap(); 50 | } 51 | 52 | public SearchCriteria page(long page) { 53 | queryParams.put("page", page); 54 | return this; 55 | } 56 | 57 | public SearchCriteria perPage(long perPage) { 58 | queryParams.put("per_page", perPage); 59 | return this; 60 | } 61 | 62 | public SearchCriteria sortBy(String criteria, String order) { 63 | queryParams.put("sort_by", criteria + ":" + order); 64 | return this; 65 | } 66 | 67 | public SearchCriteria sortBy(String criteria) { 68 | return sortBy(criteria, "asc"); 69 | } 70 | 71 | public SearchCriteria ids(List ids) { 72 | queryParams.put("ids", Joiner.join(",", ids)); 73 | return this; 74 | } 75 | 76 | public SearchCriteria ids(Long... ids) { 77 | return ids(asList(ids)); 78 | } 79 | 80 | public SearchCriteria confirmed(boolean confirmed) { 81 | queryParams.put("confirmed", confirmed); 82 | return this; 83 | } 84 | 85 | public SearchCriteria email(String email) { 86 | queryParams.put("email", email); 87 | return this; 88 | } 89 | 90 | public SearchCriteria name(String name) { 91 | queryParams.put("name", name); 92 | return this; 93 | } 94 | 95 | public SearchCriteria role(String role) { 96 | queryParams.put("role", role); 97 | return this; 98 | } 99 | 100 | public SearchCriteria status(String status) { 101 | queryParams.put("status", status); 102 | return this; 103 | } 104 | 105 | /** 106 | * WARNING! 107 | * This search param is a subject to change. Use only when really necessary. 108 | */ 109 | public SearchCriteria zendeskUserIds(List ids) { 110 | queryParams.put("zendesk_user_ids", Joiner.join(",", ids)); 111 | return this; 112 | } 113 | 114 | /** 115 | * WARNING! 116 | * This search param is a subject to change. Use only when really necessary. 117 | */ 118 | public SearchCriteria zendeskUserIds(Long... ids) { 119 | return zendeskUserIds(asList(ids)); 120 | } 121 | 122 | public Map asMap() { 123 | return Collections.unmodifiableMap(queryParams); 124 | } 125 | } 126 | 127 | } 128 | 129 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/VisitOutcomesService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.VisitOutcome; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | 11 | import java.util.*; 12 | 13 | import static com.getbase.utils.Lists.asList; 14 | import static com.getbase.utils.Precondition.*; 15 | 16 | public class VisitOutcomesService extends BaseService { 17 | public VisitOutcomesService(HttpClient httpClient) { 18 | super(httpClient); 19 | } 20 | 21 | public List list(Map params) { 22 | String url = "/v2/visit_outcomes"; 23 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), VisitOutcome.class); 24 | } 25 | 26 | public List list(SearchCriteria criteria) { 27 | return list(criteria.asMap()); 28 | } 29 | 30 | 31 | 32 | public static class SearchCriteria { 33 | private Map queryParams; 34 | 35 | public SearchCriteria() { 36 | this.queryParams = new HashMap(); 37 | } 38 | 39 | public SearchCriteria page(long page) { 40 | queryParams.put("page", page); 41 | return this; 42 | } 43 | 44 | public SearchCriteria perPage(long perPage) { 45 | queryParams.put("per_page", perPage); 46 | return this; 47 | } 48 | 49 | public SearchCriteria sortBy(String criteria, String order) { 50 | queryParams.put("sort_by", criteria + ":" + order); 51 | return this; 52 | } 53 | 54 | public SearchCriteria sortBy(String criteria) { 55 | return sortBy(criteria, "asc"); 56 | } 57 | 58 | public SearchCriteria ids(List ids) { 59 | queryParams.put("ids", ids); 60 | return this; 61 | } 62 | 63 | public SearchCriteria ids(Long... ids) { 64 | return ids(asList(ids)); 65 | } 66 | 67 | public Map asMap() { 68 | return Collections.unmodifiableMap(queryParams); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/services/VisitsService.java: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services; 4 | 5 | import com.getbase.http.HttpClient; 6 | import com.getbase.models.Visit; 7 | import com.getbase.serializer.JsonDeserializer; 8 | import com.getbase.serializer.JsonSerializer; 9 | import com.getbase.serializer.Views; 10 | 11 | import java.util.*; 12 | 13 | import static com.getbase.utils.Lists.asList; 14 | import static com.getbase.utils.Precondition.*; 15 | 16 | public class VisitsService extends BaseService { 17 | public VisitsService(HttpClient httpClient) { 18 | super(httpClient); 19 | } 20 | 21 | public List list(Map params) { 22 | String url = "/v2/visits"; 23 | return JsonDeserializer.deserializeList(this.httpClient.get(url, params).getBody(), Visit.class); 24 | } 25 | 26 | public List list(SearchCriteria criteria) { 27 | return list(criteria.asMap()); 28 | } 29 | 30 | 31 | 32 | public static class SearchCriteria { 33 | private Map queryParams; 34 | 35 | public SearchCriteria() { 36 | this.queryParams = new HashMap(); 37 | } 38 | 39 | public SearchCriteria page(long page) { 40 | queryParams.put("page", page); 41 | return this; 42 | } 43 | 44 | public SearchCriteria perPage(long perPage) { 45 | queryParams.put("per_page", perPage); 46 | return this; 47 | } 48 | 49 | public SearchCriteria sortBy(String criteria, String order) { 50 | queryParams.put("sort_by", criteria + ":" + order); 51 | return this; 52 | } 53 | 54 | public SearchCriteria sortBy(String criteria) { 55 | return sortBy(criteria, "asc"); 56 | } 57 | 58 | public SearchCriteria ids(List ids) { 59 | queryParams.put("ids", ids); 60 | return this; 61 | } 62 | 63 | public SearchCriteria ids(Long... ids) { 64 | return ids(asList(ids)); 65 | } 66 | 67 | public SearchCriteria creatorId(long creatorId) { 68 | queryParams.put("creator_id", creatorId); 69 | return this; 70 | } 71 | 72 | public SearchCriteria outcomeId(long outcomeId) { 73 | queryParams.put("outcome_id", outcomeId); 74 | return this; 75 | } 76 | 77 | public SearchCriteria resourceId(long resourceId) { 78 | queryParams.put("resource_id", resourceId); 79 | return this; 80 | } 81 | 82 | public SearchCriteria repLocationVerificationStatus(String repLocationVerificationStatus) { 83 | queryParams.put("rep_location_verification_status", repLocationVerificationStatus); 84 | return this; 85 | } 86 | 87 | public SearchCriteria resourceType(String resourceType) { 88 | queryParams.put("resource_type", resourceType); 89 | return this; 90 | } 91 | 92 | public Map asMap() { 93 | return Collections.unmodifiableMap(queryParams); 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/sync/Queue.java: -------------------------------------------------------------------------------- 1 | package com.getbase.sync; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.getbase.serializer.Views; 5 | 6 | public class Queue { 7 | protected @JsonView(Views.ReadOnly.class) String name; 8 | protected @JsonView(Views.ReadOnly.class) Long pages; 9 | protected @JsonView(Views.ReadOnly.class) Long totalCount; 10 | 11 | public Queue() { 12 | } 13 | 14 | public Queue(String name, Long pages, Long totalCount) { 15 | this.name = name; 16 | this.pages = pages; 17 | this.totalCount = totalCount; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public Long getPages() { 25 | return pages; 26 | } 27 | 28 | public Long getTotalCount() { 29 | return totalCount; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public void setPages(Long pages) { 37 | this.pages = pages; 38 | } 39 | 40 | public void setTotalCount(Long totalCount) { 41 | this.totalCount = totalCount; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object o) { 46 | if (this == o) return true; 47 | if (o == null || getClass() != o.getClass()) return false; 48 | 49 | Queue queue = (Queue) o; 50 | 51 | if (!name.equals(queue.name)) return false; 52 | if (!pages.equals(queue.pages)) return false; 53 | return totalCount.equals(queue.totalCount); 54 | 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | int result = name.hashCode(); 60 | result = 31 * result + pages.hashCode(); 61 | result = 31 * result + totalCount.hashCode(); 62 | return result; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "Queue{" + 68 | "name='" + name + '\'' + 69 | ", pages=" + pages + 70 | ", totalCount=" + totalCount + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/sync/Session.java: -------------------------------------------------------------------------------- 1 | package com.getbase.sync; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.getbase.serializer.Views; 5 | 6 | import java.util.List; 7 | 8 | public class Session { 9 | protected @JsonView(Views.ReadOnly.class) String id; 10 | protected @JsonView(Views.ReadOnly.class) List queues; 11 | 12 | public Session() { 13 | } 14 | 15 | public Session(String id, List queues) { 16 | this.id = id; 17 | this.queues = queues; 18 | } 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public List getQueues() { 25 | return queues; 26 | } 27 | 28 | public void setId(String id) { 29 | this.id = id; 30 | } 31 | 32 | public void setQueues(List queues) { 33 | this.queues = queues; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object o) { 38 | if (this == o) return true; 39 | if (o == null || getClass() != o.getClass()) return false; 40 | 41 | Session session = (Session) o; 42 | 43 | return id.equals(session.id); 44 | 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | return id.hashCode(); 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Session{" + 55 | "id='" + id + '\'' + 56 | ", queues=" + queues + 57 | '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/sync/SessionManager.java: -------------------------------------------------------------------------------- 1 | package com.getbase.sync; 2 | 3 | /** 4 | * Manages Sync session instances. 5 | * 6 | * It could be extended for sharing single Sync session between many threads / processes / nodes. 7 | * Default implementation is a dummy base for extensions and it literally does nothing. 8 | * 9 | */ 10 | public class SessionManager { 11 | 12 | public Session getSession(String deviceUUID) { 13 | return null; 14 | } 15 | 16 | public void setSession(String deviceUUID, Session session) { 17 | // intentionally left blank 18 | } 19 | 20 | public void clearSession(String deviceUUID) { 21 | // intentionally left blank 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/sync/Sync.java: -------------------------------------------------------------------------------- 1 | package com.getbase.sync; 2 | 3 | import com.getbase.Client; 4 | import com.getbase.serializer.JsonDeserializer; 5 | import com.getbase.utils.BiPredicate; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | import static com.getbase.utils.Precondition.checkNotNull; 11 | 12 | public class Sync { 13 | protected final Client client; 14 | protected final String deviceUUID; 15 | protected final long timeToRunInMillis; 16 | 17 | protected final StreamObservable streamObservable; 18 | private SessionManager sessionManager; 19 | 20 | public Sync(Client client, String deviceUUID) { 21 | this(client, deviceUUID, Long.MAX_VALUE); 22 | } 23 | 24 | public Sync(Client client, String deviceUUID, long timeToRunInMillis) { 25 | this.client = client; 26 | this.deviceUUID = deviceUUID; 27 | this.timeToRunInMillis = timeToRunInMillis; 28 | this.streamObservable = new StreamObservable(); 29 | sessionManager = new SessionManager(); 30 | } 31 | 32 | public Sync subscribe(Class type, BiPredicate predicate) { 33 | this.streamObservable.subscribe(type, predicate); 34 | return this; 35 | } 36 | 37 | public Sync setSessionManager(SessionManager sessionManager) { 38 | checkNotNull(sessionManager, "sessionManager parameter must not be null"); 39 | 40 | this.sessionManager = sessionManager; 41 | return this; 42 | } 43 | 44 | public boolean fetch() { 45 | // there are no observers attached, fetching won't ack fetched data 46 | if (this.streamObservable.isEmpty()) { 47 | throw new IllegalStateException("you have no observers attached - use subscribe first"); 48 | } 49 | 50 | return fetchInternal(this.streamObservable); 51 | } 52 | 53 | public boolean fetch(BiPredicate> predicate) { 54 | // validate if a user intentionally used this method 55 | if (!this.streamObservable.isEmpty()) { 56 | throw new IllegalStateException("you have got observers attached - use fetch method without input arguments"); 57 | } 58 | 59 | return fetchInternal(predicate); 60 | } 61 | 62 | protected boolean fetchInternal(BiPredicate> predicate) { 63 | return newSyncProcess(predicate).run(); 64 | } 65 | 66 | private SyncProcess newSyncProcess(BiPredicate> predicate) { 67 | checkNotNull(predicate, "predicate parameter must not be null"); 68 | 69 | return new SyncProcess(client, deviceUUID, sessionManager, predicate, timeToRunInMillis); 70 | } 71 | 72 | private static class StreamObservable implements BiPredicate> { 73 | private final Map observers = new HashMap(); 74 | 75 | public void subscribe(Class type, BiPredicate predicate) { 76 | this.observers.put(type, predicate); 77 | } 78 | 79 | public boolean notify(Meta meta, Map data) { 80 | // if the data represents a type we don't support, don't ack. We might get a new library version 81 | // with support for the new type, and handle the data later on. 82 | if (!meta.getType().isSupported()) { 83 | return false; 84 | } 85 | 86 | try { 87 | return notifyPredicate(meta, data); 88 | } catch (ClassNotFoundException e) { 89 | return false; 90 | } 91 | } 92 | 93 | @SuppressWarnings("unchecked") 94 | private boolean notifyPredicate(Meta meta, Map data) throws ClassNotFoundException { 95 | Class clazz = meta.getType().getClassType(); 96 | BiPredicate predicate = this.observers.get(clazz); 97 | 98 | // we haven't seen predicate for that type, skip ack, give it a try next time 99 | return predicate != null && predicate.test(meta, JsonDeserializer.deserialize(data, clazz)); 100 | } 101 | 102 | public boolean isEmpty(){ 103 | return this.observers.isEmpty(); 104 | } 105 | 106 | @Override 107 | public boolean test(Meta meta, Map data) { 108 | return notify(meta, data); 109 | } 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/sync/SyncProcess.java: -------------------------------------------------------------------------------- 1 | package com.getbase.sync; 2 | 3 | import com.getbase.Client; 4 | import com.getbase.serializer.JsonDeserializer; 5 | import com.getbase.utils.BiPredicate; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import static java.lang.System.currentTimeMillis; 12 | 13 | public class SyncProcess { 14 | 15 | private Client client; 16 | private String deviceUUID; 17 | private SessionManager sessionManager; 18 | private BiPredicate> predicate; 19 | 20 | private Session session; 21 | private List> nextItems; 22 | 23 | private long timeToRunInMillis; 24 | 25 | public SyncProcess(Client client, String deviceUUID, SessionManager sessionManager, 26 | BiPredicate> predicate) { 27 | this(client, deviceUUID, sessionManager, predicate, Long.MAX_VALUE); 28 | } 29 | 30 | public SyncProcess(Client client, String deviceUUID, SessionManager sessionManager, 31 | BiPredicate> predicate, 32 | long timeToRunInMillis) { 33 | this.client = client; 34 | this.deviceUUID = deviceUUID; 35 | this.sessionManager = sessionManager; 36 | this.predicate = predicate; 37 | this.timeToRunInMillis = timeToRunInMillis; 38 | } 39 | 40 | /** 41 | * @return true if sync was full - there are no more elements to fetch, false otherwise 42 | */ 43 | public boolean run() { 44 | long startTime = currentTimeMillis(); 45 | 46 | try { 47 | if (!init()) { 48 | return true; 49 | } 50 | 51 | while (fetchMore()) { 52 | if (currentTimeMillis() - startTime >= timeToRunInMillis) { 53 | return false; 54 | } 55 | process(); 56 | } 57 | 58 | return true; 59 | } finally { 60 | sessionManager.clearSession(deviceUUID); 61 | } 62 | } 63 | 64 | private boolean init() { 65 | // Set up a new synchronization session for a UUID for the device 66 | session = sessionManager.getSession(deviceUUID); 67 | if (session == null) { 68 | session = client.sync().start(deviceUUID); 69 | } 70 | 71 | // Check if there is anything to synchronize 72 | if (session != null && session.getId() != null) { 73 | sessionManager.setSession(deviceUUID, session); 74 | return true; 75 | } 76 | return false; 77 | } 78 | 79 | private boolean fetchMore() { 80 | nextItems = this.client.sync().fetch(this.deviceUUID, session.getId()); 81 | 82 | return nextItems != null; 83 | } 84 | 85 | // Drain the main queue until there is no more data (empty array) 86 | private void process() { 87 | List ackKeys = new ArrayList(nextItems.size()); 88 | 89 | // Notify about new data 90 | for (Map item : nextItems) { 91 | processItem(ackKeys, item); 92 | } 93 | 94 | // As we fetch new data, we need to send acknowledgement keys, if any ... 95 | this.client.sync().ack(this.deviceUUID, ackKeys); 96 | } 97 | 98 | @SuppressWarnings("unchecked") 99 | private void processItem(List ackKeys, Map item) { 100 | // Extract meta data and deserialize to POJO 101 | Map metaAttributes = (Map) item.get("meta"); 102 | Meta meta = JsonDeserializer.deserialize(metaAttributes, Meta.class); 103 | 104 | // Insanity check 105 | if (meta != null && meta.getSync() != null && meta.getSync().getAckKey() != null) { 106 | 107 | // Extract data 108 | Map data = (Map) item.get("data"); 109 | 110 | // Notify observer 111 | if (this.predicate.test(meta, data)) { 112 | // Add to acknowledged objects 113 | ackKeys.add(meta.getSync().getAckKey()); 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/utils/BiPredicate.java: -------------------------------------------------------------------------------- 1 | package com.getbase.utils; 2 | 3 | public interface BiPredicate { 4 | boolean test(T t, U u); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/utils/Joiner.java: -------------------------------------------------------------------------------- 1 | package com.getbase.utils; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | 6 | public abstract class Joiner { 7 | private Joiner() { 8 | } 9 | 10 | public static String join(String on, List values) { 11 | if (values == null || values.isEmpty()) { 12 | return ""; 13 | } 14 | 15 | if (values.size() == 1) { 16 | return String.valueOf(values.get(0)); 17 | } 18 | 19 | if (on == null) { 20 | on = ""; 21 | } 22 | 23 | StringBuilder builder = new StringBuilder(); 24 | 25 | Iterator iterator = values.iterator(); 26 | builder.append(String.valueOf(iterator.next())); 27 | 28 | while(iterator.hasNext()) { 29 | builder 30 | .append(on) 31 | .append(String.valueOf(iterator.next())); 32 | } 33 | 34 | return builder.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/utils/Lists.java: -------------------------------------------------------------------------------- 1 | package com.getbase.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import static com.getbase.utils.Precondition.checkNotNull; 7 | 8 | public class Lists { 9 | 10 | public static List asList(T[] items) { 11 | checkNotNull(items, "items must not be null"); 12 | 13 | List itemsList = new ArrayList(items.length); 14 | for(T item : items) { 15 | itemsList.add(item); 16 | } 17 | 18 | return itemsList; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/utils/Precondition.java: -------------------------------------------------------------------------------- 1 | package com.getbase.utils; 2 | 3 | public abstract class Precondition { 4 | public static T checkNotNull(T reference, String message) { 5 | if (reference == null) { 6 | throw new IllegalArgumentException(message); 7 | } 8 | return reference; 9 | } 10 | 11 | public static void checkArgument(boolean expression, String message) { 12 | if (!expression) { 13 | throw new IllegalArgumentException(message); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/utils/Predicate.java: -------------------------------------------------------------------------------- 1 | package com.getbase.utils; 2 | 3 | public interface Predicate { 4 | boolean test(T t); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/getbase/utils/Word.java: -------------------------------------------------------------------------------- 1 | package com.getbase.utils; 2 | 3 | public abstract class Word { 4 | private Word() { 5 | } 6 | 7 | public static String capitalize(String underscored) { 8 | if (underscored == null || underscored.isEmpty()) { 9 | return ""; 10 | } 11 | 12 | String[] parts = underscored.split("_"); 13 | 14 | StringBuilder builder = new StringBuilder(); 15 | for (String part : parts) { 16 | if (!part.isEmpty()) 17 | builder.append(part.substring(0, 1).toUpperCase() + part.substring(1)); 18 | } 19 | 20 | return builder.toString().trim(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/exceptions/ExceptionsSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.exceptions 2 | 3 | import com.getbase.http.HttpMethod 4 | import spock.lang.Specification 5 | import spock.lang.Unroll 6 | 7 | 8 | class ExceptionsSpec extends Specification { 9 | 10 | @Unroll 11 | def 'exception string for #exception.class contains detailed message'() { 12 | expect: 13 | exception.getMessage() == expected 14 | 15 | where: 16 | exception | expected 17 | new RequestException(401, "logref", HttpMethod.GET, "/v2/contact", [ baseError() ]) | "httpStatus=401, logref='logref', httpMethod=GET, url=/v2/contact, errors=BaseError{code='111', message='error message', details='error details', resource='error resource', field='null'}" 18 | new ResourceException(422, "logref", HttpMethod.GET, "/v2/contact", [ baseError() ]) | "httpStatus=422, logref='logref', httpMethod=GET, url=/v2/contact, errors=BaseError{code='111', message='error message', details='error details', resource='error resource', field='null'}" 19 | new ServerException(506, "logref", HttpMethod.GET, "/v2/contact", [ baseError() ]) | "httpStatus=506, logref='logref', httpMethod=GET, url=/v2/contact, errors=BaseError{code='111', message='error message', details='error details', resource='error resource', field='null'}" 20 | } 21 | 22 | def baseError() { 23 | def error = new BaseError() 24 | error.code = 111 25 | error.details = 'error details' 26 | error.message = 'error message' 27 | error.resource = 'error resource' 28 | error 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/http/CustomAuthorizationHttpClientTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.http 2 | 3 | import com.getbase.Configuration 4 | import spock.lang.Specification 5 | 6 | class CustomAuthorizationHttpClientTest extends Specification { 7 | 8 | def authorizationHeader = "CustomAuthorizationHeader" 9 | def testToken = "this-1s-t3st-t0ken" 10 | 11 | def "Authorization strategy replaces Authorization header"() { 12 | given: 13 | def client = new CustomAuthorizationHttpClient() 14 | 15 | when: 16 | client.request(HttpMethod.GET, "/dummy.json", [:], null) 17 | 18 | then: 19 | client.requestCaptured.headers[authorizationHeader] == testToken 20 | client.requestCaptured.headers["Authorization"] == null 21 | } 22 | 23 | class CustomAuthorizationHttpClient extends com.getbase.http.jersey.HttpClient { 24 | 25 | Request requestCaptured 26 | 27 | CustomAuthorizationHttpClient() { 28 | super(Configuration.getDefault()) 29 | } 30 | 31 | @Override 32 | protected Request.Builder applyAuthorization(Request.Builder requestBuilder) { 33 | return requestBuilder.header(authorizationHeader, testToken); 34 | } 35 | 36 | @Override 37 | Response rawRequest(Request request) { 38 | requestCaptured = request 39 | return new Response(201, null); 40 | } 41 | 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/http/JsonDeserializerTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.http 2 | 3 | import com.getbase.models.Lead 4 | import com.getbase.serializer.JsonDeserializer 5 | import org.joda.time.DateTime 6 | import spock.lang.Specification 7 | 8 | import static org.joda.time.DateTimeZone.UTC 9 | 10 | class JsonDeserializerTest extends Specification { 11 | def "Deserialize"() { 12 | given: 13 | def json = '{"data": {"id": 1, "first_name": "Mark", "last_name": "Johnson", "organization_name": null, "address": {"line1": "2726 Smith Street"}, "tags": ["important"], "created_at": "2014-08-27T16:32:56Z", "custom_fields": {"known_via": "Tom"}}, "meta": {"type": "lead"}}' 14 | 15 | when: 16 | def lead = JsonDeserializer.deserialize(json, Lead.class) 17 | 18 | then: 19 | lead."$method"() == expectedValue 20 | 21 | where: 22 | method | expectedValue 23 | "getId" | 1 24 | "getFirstName" | "Mark" 25 | "getLastName" | "Johnson" 26 | "getOrganizationName" | null 27 | "getTags" | ["important"] 28 | "getCreatedAt" | new DateTime(2014, 8, 27, 16, 32, 56, UTC) 29 | "getCustomFields" | ["known_via": "Tom"] 30 | } 31 | 32 | def "DeserializeList"() { 33 | when: 34 | def items = JsonDeserializer.deserializeList(json, expectedType) 35 | 36 | then: 37 | items.size() == expectedLen 38 | 39 | items.each { item -> 40 | assert item.class == expectedType 41 | } 42 | 43 | def idx = 0 44 | expectedIds.each { id -> 45 | assert id == items[idx].getId() 46 | idx++ 47 | } 48 | 49 | where: 50 | expectedType | expectedLen | expectedIds | json 51 | Lead.class | 2 | [1, 2] | '{"items": [{"data": {"id": 1}, "meta": {"type": "lead"}}, {"data": {"id": 2}, "meta": {"type": "lead"}}], "meta": {"length": 2}}' 52 | } 53 | 54 | def "DeserializeErrors"() { 55 | when: 56 | def errors = JsonDeserializer.deserializeErrors(json) 57 | 58 | then: 59 | errors.size() == expectedLen 60 | 61 | def id = 0 62 | expectedCodes.each { code -> 63 | assert code == errors[id].getCode() 64 | id++ 65 | } 66 | 67 | where: 68 | expectedLen | expectedCodes | json 69 | 1 | ["blank"] | '{"errors": [{"error": {"resource": "contact", "field": "/data/last_name", "code": "blank"}}]}' 70 | } 71 | 72 | def "DeserializeRaw"() { 73 | given: 74 | def json = '{"data":{"id": 1}}' 75 | 76 | when: 77 | def attributes = JsonDeserializer.deserializeRaw(json) 78 | 79 | then: 80 | attributes == ["data": ["id": 1]] 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/http/JsonSerializerTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.http 2 | 3 | import com.fasterxml.jackson.annotation.JsonView 4 | import com.getbase.models.Lead 5 | import com.getbase.serializer.JsonSerializer 6 | import com.getbase.serializer.Views 7 | import spock.lang.Specification 8 | 9 | class JsonSerializerTest extends Specification { 10 | static class Tag { 11 | @JsonView(Views.ReadOnly.class) long id; 12 | @JsonView(Views.ReadWrite.class) String name; 13 | 14 | Tag(long id, String name) { 15 | this.id = id 16 | this.name = name 17 | } 18 | 19 | long getId() { 20 | return id 21 | } 22 | 23 | void setId(long id) { 24 | this.id = id 25 | } 26 | 27 | String getName() { 28 | return name 29 | } 30 | 31 | void setName(String name) { 32 | this.name = name 33 | } 34 | 35 | } 36 | 37 | def "Serialize - serializes entity"() { 38 | given: 39 | def tag = new Tag(1, "important") 40 | 41 | when: 42 | def json = JsonSerializer.serialize(tag, Views.ReadWrite.class) 43 | 44 | then: 45 | json == '{"data":{"name":"important"}}' 46 | } 47 | 48 | def "Serialize - entity with lots of attributes"() { 49 | given: 50 | def lead = new Lead() 51 | lead.firstName = "Mark" 52 | lead.lastName = "Johnson" 53 | 54 | when: 55 | def json = JsonSerializer.serialize(lead, Views.ReadWrite.class) 56 | 57 | then: 58 | json == '{"data":{"first_name":"Mark","last_name":"Johnson","tags":[],"custom_fields":{}}}' 59 | } 60 | 61 | def "Serialize - HashMap attributes"() { 62 | given: 63 | def attributes = ["id": 1, "name": "important"] 64 | 65 | when: 66 | def json = JsonSerializer.serialize(attributes) 67 | 68 | then: 69 | json == '{"data":{"id":1,"name":"important"}}' 70 | } 71 | 72 | def "Serialize - HashMap attributes with type name"() { 73 | given: 74 | def attributes = ["id": 1, "name": "important"] 75 | 76 | when: 77 | def json = JsonSerializer.serialize(attributes, "tag") 78 | 79 | then: 80 | json == '{"data":{"id":1,"name":"important"},"meta":{"type":"tag"}}' 81 | } 82 | 83 | def "Serialize - serializes entity with type name"() { 84 | given: 85 | def tag = new Tag(1, "important") 86 | 87 | when: 88 | def json = JsonSerializer.serialize(tag, Views.ReadWrite.class, "tag") 89 | 90 | then: 91 | json == '{"data":{"name":"important"},"meta":{"type":"tag"}}' 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/AccountsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Account 4 | import spock.lang.Shared 5 | 6 | class AccountsServiceTest extends BaseSpecification { 7 | 8 | @Shared def account = account ?: client.accounts().self() 9 | 10 | def "Self"() { 11 | when: 12 | def account = client.accounts().self() 13 | 14 | then: 15 | account instanceof Account 16 | account.id > 0 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/AssociatedContactsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.AssociatedContact 4 | import spock.lang.Shared 5 | 6 | class AssociatedContactsServiceTest extends BaseSpecification { 7 | 8 | @Shared def associatedContact = associatedContact ?: createAssociatedContact() 9 | 10 | def "List - with params"() { 11 | when: 12 | def associatedContacts = client.associatedContacts().list(associatedContact.dealId, ["page": 1, "per_page": 1]) 13 | 14 | then: 15 | associatedContacts.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def associatedContacts = client.associatedContacts().list(associatedContact.dealId, new AssociatedContactsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | associatedContacts.size() > 0 24 | } 25 | 26 | def "Create - with attributes"() { 27 | when: 28 | def newAssociatedContact = createAssociatedContact() 29 | 30 | then: 31 | newAssociatedContact instanceof AssociatedContact 32 | } 33 | 34 | def "Delete"() { 35 | given: 36 | def newAssociatedContact = createAssociatedContact() 37 | 38 | when: 39 | def result = client.associatedContacts().delete(newAssociatedContact.dealId, newAssociatedContact.contactId) 40 | 41 | then: 42 | result 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/CallsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Call 4 | import spock.lang.Shared 5 | 6 | class CallsServiceTest extends BaseSpecification { 7 | 8 | @Shared def call = call ?: createCall() 9 | 10 | def "List - with params"() { 11 | when: 12 | def calls = client.calls().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | calls.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def calls = client.calls().list(new CallsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | calls.size() > 0 24 | } 25 | 26 | def "Create and List - by ids"() { 27 | when: 28 | def callOutcome = client.callOutcomes().list(new CallOutcomesService.SearchCriteria()).first() 29 | def call = createCall('outcome_id' : callOutcome.id) 30 | def calls = client.calls().list(new CallsService.SearchCriteria().ids([call.id])) 31 | 32 | then: 33 | calls.size() == 1 34 | calls[0].id == call.id 35 | } 36 | 37 | def "Get"() { 38 | given: 39 | def searched = call 40 | 41 | when: 42 | def found = client.calls().get(searched.id) 43 | 44 | then: 45 | found instanceof Call 46 | found.id == searched.id 47 | } 48 | 49 | 50 | def "Update"() { 51 | when: 52 | def contact = createContact() 53 | def updated = client.calls().update(call.id, [resource_type: "contact", 54 | "resource_id": contact.id]) 55 | 56 | then: 57 | updated instanceof Call 58 | } 59 | 60 | def "Delete"() { 61 | given: 62 | def newCall = createCall() 63 | 64 | when: 65 | def result = client.calls().delete(newCall.id) 66 | 67 | then: 68 | result 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/CollaborationsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Collaboration 4 | import spock.lang.Shared 5 | 6 | class CollaborationsServiceTest extends BaseSpecification { 7 | 8 | @Shared 9 | def collaboration = collaboration ?: createCollaboration() 10 | 11 | def "List - with params"() { 12 | when: 13 | def collaborations = client.collaborations().list(["page": 1, "per_page": 1]) 14 | 15 | then: 16 | collaborations.size() > 0 17 | } 18 | 19 | def "List - with query param builder"() { 20 | when: 21 | def collaborations = client.collaborations().list(new CollaborationsService.SearchCriteria().page(1).perPage(100)) 22 | 23 | then: 24 | collaborations.size() > 0 25 | } 26 | 27 | def "List - by ids"() { 28 | when: 29 | def collaborations = client.collaborations().list(new CollaborationsService.SearchCriteria().ids([collaboration.id])) 30 | 31 | then: 32 | collaborations.size() == 1 33 | collaborations[0].id == collaboration.id 34 | } 35 | 36 | def "Create"() { 37 | when: 38 | def newCollaboration = createCollaboration() 39 | 40 | then: 41 | newCollaboration instanceof Collaboration 42 | } 43 | 44 | def "Get"() { 45 | given: 46 | def searched = collaboration 47 | 48 | when: 49 | def found = client.collaborations().get(collaboration.id) 50 | 51 | then: 52 | found instanceof Collaboration 53 | found.id == searched.id 54 | } 55 | 56 | def "Delete"() { 57 | given: 58 | def newCollaboration = createCollaboration() 59 | 60 | when: 61 | def result = client.collaborations().delete(newCollaboration.id) 62 | 63 | then: 64 | result 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/ContactsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Contact 4 | import spock.lang.Shared 5 | 6 | class ContactsServiceTest extends BaseSpecification { 7 | 8 | @Shared def contact = contact ?: createContact() 9 | 10 | def "List - with params"() { 11 | when: 12 | def contacts = client.contacts().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | contacts.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def contacts = client.contacts().list(new ContactsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | contacts.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | when: 28 | sleep(1000) 29 | def contacts = client.contacts().list(new ContactsService.SearchCriteria().ids([contact.id])) 30 | 31 | then: 32 | contacts.size() == 1 33 | contacts[0].id == contact.id 34 | } 35 | 36 | def "Create - with attributes"() { 37 | when: 38 | def newContact = createContact() 39 | 40 | then: 41 | newContact instanceof Contact 42 | newContact.contactId == null 43 | newContact.parentOrganizationId == null 44 | } 45 | 46 | def "Get"() { 47 | given: 48 | def searched = contact 49 | 50 | when: 51 | def found = client.contacts().get(searched.id) 52 | 53 | then: 54 | found instanceof Contact 55 | found.id == searched.id 56 | } 57 | 58 | 59 | def "Update - with Lead entity"() { 60 | when: 61 | def updated = client.contacts().update(contact) 62 | 63 | then: 64 | updated instanceof Contact 65 | } 66 | 67 | def "Delete"() { 68 | given: 69 | def newContact = createContact() 70 | 71 | when: 72 | def result = client.contacts().delete(newContact.id) 73 | 74 | then: 75 | result 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/DealUnqualifiedReasonsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services 4 | 5 | import com.getbase.models.DealUnqualifiedReason 6 | import spock.lang.Shared 7 | 8 | class DealUnqualifiedReasonsServiceTest extends BaseSpecification { 9 | 10 | @Shared def dealUnqualifiedReason = dealUnqualifiedReason ?: createDealUnqualifiedReason() 11 | 12 | 13 | def "List - with params"() { 14 | when: 15 | def dealUnqualifiedReasons = client.dealUnqualifiedReasons().list(["page": 1, "per_page": 1]) 16 | 17 | then: 18 | dealUnqualifiedReasons.size() > 0 19 | } 20 | 21 | def "List - with query param builder"() { 22 | when: 23 | def dealUnqualifiedReasons = client.dealUnqualifiedReasons().list(new DealUnqualifiedReasonsService.SearchCriteria().page(1).perPage(1)) 24 | 25 | then: 26 | dealUnqualifiedReasons.size() > 0 27 | } 28 | 29 | def "Create - with attributes"() { 30 | when: 31 | def newDealUnqualifiedReason = createDealUnqualifiedReason() 32 | 33 | then: 34 | newDealUnqualifiedReason instanceof DealUnqualifiedReason 35 | } 36 | 37 | 38 | def "Get"() { 39 | given: 40 | def searched = dealUnqualifiedReason 41 | 42 | when: 43 | def found = client.dealUnqualifiedReasons().get(searched.id) 44 | 45 | then: 46 | found instanceof DealUnqualifiedReason 47 | found.id == searched.id 48 | } 49 | 50 | 51 | def "Update - with Lead entity"() { 52 | when: 53 | def updated = client.dealUnqualifiedReasons().update(dealUnqualifiedReason) 54 | 55 | then: 56 | updated instanceof DealUnqualifiedReason 57 | } 58 | 59 | def "Delete"() { 60 | given: 61 | def newDealUnqualifiedReason = createDealUnqualifiedReason() 62 | 63 | when: 64 | def result = client.dealUnqualifiedReasons().delete(newDealUnqualifiedReason.id) 65 | 66 | then: 67 | result 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/DealsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Deal 4 | import spock.lang.Shared 5 | 6 | class DealsServiceTest extends BaseSpecification { 7 | 8 | @Shared 9 | def deal = deal ?: createDeal() 10 | 11 | def "List - with params"() { 12 | when: 13 | def deals = client.deals().list(["page": 1, "per_page": 1]) 14 | 15 | then: 16 | deals.size() > 0 17 | } 18 | 19 | def "List - with query param builder"() { 20 | when: 21 | def deals = client.deals().list(new DealsService.SearchCriteria().page(1).perPage(1)) 22 | 23 | then: 24 | deals.size() > 0 25 | } 26 | 27 | def "List - by ids"() { 28 | when: 29 | sleep(1000) 30 | def deals = client.deals().list(new DealsService.SearchCriteria().ids([deal.id])) 31 | 32 | then: 33 | deals.size() == 1 34 | deals*.id == [deal.id] 35 | } 36 | 37 | def "Create - with attributes"() { 38 | when: 39 | def newDeal = createDeal() 40 | 41 | then: 42 | newDeal instanceof Deal 43 | } 44 | 45 | def "Create - with decimal value attributes"() { 46 | when: 47 | def newDeal = createDecimalDeal() 48 | 49 | then: 50 | newDeal instanceof Deal 51 | } 52 | 53 | def "Get"() { 54 | given: 55 | def searched = deal 56 | 57 | when: 58 | def found = client.deals().get(searched.id) 59 | 60 | then: 61 | found instanceof Deal 62 | found.id == searched.id 63 | } 64 | 65 | def "Update - with Lead entity"() { 66 | when: 67 | def updated = client.deals().update(deal) 68 | 69 | then: 70 | updated instanceof Deal 71 | } 72 | 73 | def "Update - customizedWinLikelihood"() { 74 | when: 75 | deal.setCustomizedWinLikelihood(15) 76 | def updated = client.deals().update(deal) 77 | 78 | then: 79 | updated instanceof Deal 80 | updated.getCustomizedWinLikelihood() == 15 81 | } 82 | 83 | def "Delete"() { 84 | given: 85 | def newDeal = createDeal() 86 | 87 | when: 88 | def result = client.deals().delete(newDeal.id) 89 | 90 | then: 91 | result 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/LeadSourcesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Source 4 | import spock.lang.Shared 5 | 6 | class LeadSourcesServiceTest extends BaseSpecification { 7 | 8 | @Shared def source = source ?: createLeadSource() 9 | 10 | def "List - with params"() { 11 | when: 12 | def sources = client.leadSources().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | sources.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def sources = client.leadSources().list(new LeadSourcesService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | sources.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def sourcesIds = (0..3).collect { createLeadSource() }*.id 29 | 30 | when: 31 | def sources = client.leadSources().list(new LeadSourcesService.SearchCriteria().ids(sourcesIds)) 32 | 33 | then: 34 | sources.size() == 4 35 | sources*.id == sourcesIds 36 | } 37 | 38 | def "Create - with attributes"() { 39 | when: 40 | def newSource = createLeadSource() 41 | 42 | then: 43 | newSource instanceof Source 44 | } 45 | 46 | def "Get"() { 47 | given: 48 | def searched = source 49 | 50 | when: 51 | def found = client.leadSources().get(searched.id) 52 | 53 | then: 54 | found instanceof Source 55 | found.id == searched.id 56 | } 57 | 58 | def "Update - with Source entity"() { 59 | when: 60 | def updated = client.leadSources().update(source) 61 | 62 | then: 63 | updated instanceof Source 64 | } 65 | 66 | def "Delete"() { 67 | given: 68 | def newSource = createLeadSource() 69 | 70 | when: 71 | def result = client.leadSources().delete(newSource.id) 72 | 73 | then: 74 | result 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/LeadUnqualifiedReasonsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services 4 | 5 | class LeadUnqualifiedReasonsServiceTest extends BaseSpecification { 6 | 7 | 8 | def "List - with params"() { 9 | when: 10 | def leadUnqualifiedReasons = client.leadUnqualifiedReasons().list(["page": 1, "per_page": 1]) 11 | 12 | then: 13 | leadUnqualifiedReasons.size() > 0 14 | } 15 | 16 | def "List - with query param builder"() { 17 | when: 18 | def leadUnqualifiedReasons = client.leadUnqualifiedReasons().list(new LeadUnqualifiedReasonsService.SearchCriteria().page(1).perPage(1)) 19 | 20 | then: 21 | leadUnqualifiedReasons.size() > 0 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/LeadsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Lead 4 | import spock.lang.Shared 5 | 6 | class LeadsServiceTest extends BaseSpecification { 7 | 8 | @Shared def lead = lead ?: createLead() 9 | 10 | def "List - with params"() { 11 | when: 12 | def leads = client.leads().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | leads.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def leads = client.leads().list(new LeadsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | leads.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | when: 28 | sleep(1000) 29 | def leads = client.leads().list(new LeadsService.SearchCriteria().ids([lead.id])) 30 | 31 | then: 32 | leads.size() == 1 33 | leads*.id == [lead.id] 34 | } 35 | 36 | def "Create - with attributes"() { 37 | when: 38 | def newLead = createLead() 39 | 40 | then: 41 | newLead instanceof Lead 42 | } 43 | 44 | def "Get"() { 45 | given: 46 | def searched = lead 47 | 48 | when: 49 | def found = client.leads().get(searched.id) 50 | 51 | then: 52 | found instanceof Lead 53 | found.id == searched.id 54 | } 55 | 56 | def "Update - with Lead entity"() { 57 | when: 58 | def updated = client.leads().update(lead) 59 | 60 | then: 61 | updated instanceof Lead 62 | } 63 | 64 | def "Delete"() { 65 | given: 66 | def newLead = createLead() 67 | 68 | when: 69 | def result = client.leads().delete(newLead.id) 70 | 71 | then: 72 | result 73 | } 74 | 75 | def "Lead source setting"() { 76 | given: 77 | def lead = createLead() 78 | def leadSource = createLeadSource() 79 | 80 | when: 81 | lead.sourceId = leadSource.id 82 | client.leads().update(lead) 83 | 84 | then: 85 | client.leads().get(lead.id).sourceId == leadSource.id 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/LineItemsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.LineItem 4 | import spock.lang.Shared 5 | import spock.lang.Unroll 6 | 7 | class LineItemsServiceTest extends BaseSpecification { 8 | 9 | @Shared def order = order ?: createOrder() 10 | @Shared def lineItem = lineItem ?: createLineItem(order) 11 | 12 | def "List - with params"() { 13 | when: 14 | def lineItems = client.lineItems().list(order.id, ["page": 1, "per_page": 1]) 15 | 16 | then: 17 | lineItems.size() > 0 18 | } 19 | 20 | def "List - with query param builder"() { 21 | when: 22 | def lineItems = client.lineItems().list(order.id, new LineItemsService.SearchCriteria().page(1).perPage(1)) 23 | 24 | then: 25 | lineItems.size() > 0 26 | } 27 | 28 | def "List - by ids"() { 29 | given: 30 | def lineItemsIds = (0..3).collect { createLineItem(order) }*.id 31 | 32 | when: 33 | def lineItems = client.lineItems().list(order.id, new LineItemsService.SearchCriteria().ids(lineItemsIds)) 34 | 35 | then: 36 | lineItems.size() == 4 37 | lineItems*.id == lineItemsIds 38 | } 39 | 40 | def "Create - with attributes"() { 41 | given: 42 | def product = createProduct() 43 | 44 | when: 45 | def newLineItem = createLineItem(order, [ 46 | 'product_id' : product.id, 47 | 'currency' : product.prices.first().currency 48 | ]) 49 | 50 | then: 51 | newLineItem instanceof LineItem 52 | newLineItem.price == product.prices.first().amount 53 | } 54 | 55 | @Unroll 56 | def "Create - with #variation"() { 57 | given: 58 | def product = createProduct() 59 | 60 | when: 61 | def newLineItem = createLineItem(order, [ 62 | 'product_id' : product.id, 63 | 'currency' : product.prices.first().currency, 64 | 'variation' : variation_value 65 | ]) 66 | 67 | then: 68 | newLineItem.value == new BigDecimal(expected) 69 | 70 | where: 71 | variation | variation_value | expected 72 | "markup" | 2 | "3671.99" 73 | "discount" | -2 | "3527.99" 74 | } 75 | 76 | def "Get"() { 77 | given: 78 | def searched = lineItem 79 | 80 | when: 81 | def found = client.lineItems().get(order.id, lineItem.id) 82 | 83 | then: 84 | found instanceof LineItem 85 | found.id == searched.id 86 | } 87 | 88 | def "Delete"() { 89 | given: 90 | def newLineItem = createLineItem(order) 91 | 92 | when: 93 | def result = client.lineItems().delete(order.id, newLineItem.id) 94 | 95 | then: 96 | result 97 | } 98 | 99 | def cleanupSpec() { 100 | deleteAllOrders() 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/LossReasonsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.LossReason 4 | import spock.lang.Shared 5 | 6 | class LossReasonsServiceTest extends BaseSpecification { 7 | 8 | @Shared def lossReason = lossReason ?: createLossReason() 9 | 10 | def "List - with params"() { 11 | when: 12 | def lossReasons = client.lossReasons().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | lossReasons.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def lossReasons = client.lossReasons().list(new LossReasonsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | lossReasons.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def lossReasonsIds = (0..3).collect { createLossReason() }*.id 29 | 30 | when: 31 | def lossReasons = client.lossReasons().list(new LossReasonsService.SearchCriteria().ids(lossReasonsIds)) 32 | 33 | then: 34 | lossReasons.size() == 4 35 | lossReasons*.id == lossReasonsIds 36 | } 37 | 38 | def "Create - with attributes"() { 39 | when: 40 | def newLossReason = createLossReason() 41 | 42 | then: 43 | newLossReason instanceof LossReason 44 | } 45 | 46 | def "Get"() { 47 | given: 48 | def searched = lossReason 49 | 50 | when: 51 | def found = client.lossReasons().get(searched.id) 52 | 53 | then: 54 | found instanceof LossReason 55 | found.id == searched.id 56 | } 57 | 58 | def "Update - with Lead entity"() { 59 | when: 60 | def updated = client.lossReasons().update(lossReason) 61 | 62 | then: 63 | updated instanceof LossReason 64 | } 65 | 66 | def "Delete"() { 67 | given: 68 | def newLossReason = createLossReason() 69 | 70 | when: 71 | def result = client.lossReasons().delete(newLossReason.id) 72 | 73 | then: 74 | result 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/NotesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Note 4 | import spock.lang.Shared 5 | 6 | class NotesServiceTest extends BaseSpecification { 7 | 8 | @Shared def note = note ?: createNote() 9 | 10 | def "List - with params"() { 11 | when: 12 | def notes = client.notes().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | notes.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def notes = client.notes().list(new NotesService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | notes.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def notesIds = (0..3).collect { createNote() }*.id 29 | 30 | when: 31 | sleep(1000) 32 | def notes = client.notes().list(new NotesService.SearchCriteria().ids(notesIds)) 33 | 34 | then: 35 | notes.size() == 4 36 | notes*.id == notesIds 37 | } 38 | 39 | def "Create - with attributes"() { 40 | when: 41 | def newNote = createNote() 42 | 43 | then: 44 | newNote instanceof Note 45 | } 46 | 47 | def "Get"() { 48 | given: 49 | def searched = note 50 | 51 | when: 52 | def found = client.notes().get(searched.id) 53 | 54 | then: 55 | found instanceof Note 56 | found.id == searched.id 57 | } 58 | 59 | def "Update - with Lead entity"() { 60 | when: 61 | def updated = client.notes().update(note) 62 | 63 | then: 64 | updated instanceof Note 65 | } 66 | 67 | def "Delete"() { 68 | given: 69 | def newNote = createNote() 70 | 71 | when: 72 | def result = client.notes().delete(newNote.id) 73 | 74 | then: 75 | result 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/OrdersServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Order 4 | import spock.lang.Shared 5 | 6 | class OrdersServiceTest extends BaseSpecification { 7 | 8 | @Shared 9 | def order = order ?: createOrder() 10 | 11 | def "List - with params"() { 12 | when: 13 | def orders = client.orders().list(["page": 1, "per_page": 1]) 14 | 15 | then: 16 | orders.size() > 0 17 | } 18 | 19 | def "List - with query param builder"() { 20 | when: 21 | def orders = client.orders().list(new OrdersService.SearchCriteria().page(1).perPage(100)) 22 | 23 | then: 24 | orders.size() > 0 25 | } 26 | 27 | def "List - by ids"() { 28 | when: 29 | def orders = client.orders().list(new OrdersService.SearchCriteria().ids([order.id])) 30 | 31 | then: 32 | orders.size() == 1 33 | orders[0].id == order.id 34 | } 35 | 36 | def "Create - with attributes"() { 37 | when: 38 | def newOrder = createOrder() 39 | 40 | then: 41 | newOrder instanceof Order 42 | } 43 | 44 | def "Get"() { 45 | given: 46 | def searched = order 47 | 48 | when: 49 | def found = client.orders().get(order.id) 50 | 51 | then: 52 | found instanceof Order 53 | found.id == searched.id 54 | } 55 | 56 | def "Update"() { 57 | when: 58 | order.discount = 15 59 | def updated = client.orders().update(order) 60 | 61 | then: 62 | updated instanceof Order 63 | } 64 | 65 | def "Delete"() { 66 | given: 67 | def newOrder = createOrder() 68 | 69 | when: 70 | def result = client.orders().delete(newOrder.id) 71 | 72 | then: 73 | result 74 | } 75 | 76 | def cleanupSpec() { 77 | deleteAllOrders() 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/PipelinesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | class PipelinesServiceTest extends BaseSpecification { 4 | 5 | def "List - with params"() { 6 | when: 7 | def pipelines = client.pipelines().list(["page": 1, "per_page": 1]) 8 | 9 | then: 10 | pipelines.size() > 0 11 | } 12 | 13 | def "List - with query param builder"() { 14 | when: 15 | def pipelines = client.pipelines().list(new PipelinesService.SearchCriteria().page(1).perPage(1)) 16 | 17 | then: 18 | pipelines.size() > 0 19 | } 20 | 21 | def "List - by ids"() { 22 | given: 23 | def pipelinesIds = client.pipelines().list(["page": 1])*.id 24 | 25 | when: 26 | def pipelines = client.pipelines().list(new PipelinesService.SearchCriteria().ids(pipelinesIds)) 27 | 28 | then: 29 | pipelines.size() == pipelinesIds.size() 30 | pipelines*.id == pipelinesIds 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/ProductsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Product 4 | import spock.lang.Shared 5 | 6 | class ProductsServiceTest extends BaseSpecification { 7 | 8 | @Shared def product = product ?: createProduct() 9 | 10 | def "List - with params"() { 11 | when: 12 | def products = client.products().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | products.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def products = client.products().list(new ProductsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | products.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def productsIds = (0..3).collect { createProduct() }*.id 29 | 30 | when: 31 | def products = client.products().list(new ProductsService.SearchCriteria().ids(productsIds)) 32 | 33 | then: 34 | products.size() == 4 35 | products*.id == productsIds 36 | } 37 | 38 | def "Create - with attributes"() { 39 | when: 40 | def newProduct = createProduct() 41 | 42 | then: 43 | newProduct instanceof Product 44 | } 45 | 46 | def "Get"() { 47 | given: 48 | def searched = product 49 | 50 | when: 51 | def found = client.products().get(searched.id) 52 | 53 | then: 54 | found instanceof Product 55 | found.id == searched.id 56 | } 57 | 58 | def "Update - with Lead entity"() { 59 | when: 60 | def updated = client.products().update(product) 61 | 62 | then: 63 | updated instanceof Product 64 | } 65 | 66 | def "Delete"() { 67 | given: 68 | def newProduct = createProduct() 69 | 70 | when: 71 | def result = client.products().delete(newProduct.id) 72 | 73 | then: 74 | result 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/SourcesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Source 4 | import spock.lang.Shared 5 | 6 | class SourcesServiceTest extends BaseSpecification { 7 | 8 | @Shared def source = source ?: createSource() 9 | 10 | def "List - with params"() { 11 | when: 12 | def sources = client.sources().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | sources.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def sources = client.sources().list(new SourcesService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | sources.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def sourcesIds = (0..3).collect { createSource() }*.id 29 | 30 | when: 31 | def sources = client.sources().list(new SourcesService.SearchCriteria().ids(sourcesIds)) 32 | 33 | then: 34 | sources.size() == 4 35 | sources*.id == sourcesIds 36 | } 37 | 38 | def "Create - with attributes"() { 39 | when: 40 | def newSource = createSource() 41 | 42 | then: 43 | newSource instanceof Source 44 | } 45 | 46 | def "Get"() { 47 | given: 48 | def searched = source 49 | 50 | when: 51 | def found = client.sources().get(searched.id) 52 | 53 | then: 54 | found instanceof Source 55 | found.id == searched.id 56 | } 57 | 58 | def "Update - with Lead entity"() { 59 | when: 60 | def updated = client.sources().update(source) 61 | 62 | then: 63 | updated instanceof Source 64 | } 65 | 66 | def "Delete"() { 67 | given: 68 | def newSource = createSource() 69 | 70 | when: 71 | def result = client.sources().delete(newSource.id) 72 | 73 | then: 74 | result 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/StagesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | class StagesServiceTest extends BaseSpecification { 4 | 5 | def "List - with params"() { 6 | when: 7 | def stages = client.stages().list(["page": 1, "per_page": 1]) 8 | 9 | then: 10 | stages.size() > 0 11 | } 12 | 13 | def "List - with query param builder"() { 14 | when: 15 | def stages = client.stages().list(new StagesService.SearchCriteria().page(1).perPage(1)) 16 | 17 | then: 18 | stages.size() > 0 19 | } 20 | 21 | def "List - by ids"() { 22 | given: 23 | def stagesIds = client.stages().list(["page": 1])*.id 24 | 25 | when: 26 | def stages = client.stages().list(new StagesService.SearchCriteria().ids(stagesIds)) 27 | 28 | then: 29 | stages.size() == stagesIds.size() 30 | stages*.id == stagesIds 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/TagsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Tag 4 | import spock.lang.Shared 5 | 6 | class TagsServiceTest extends BaseSpecification { 7 | 8 | @Shared def tag = tag ?: createTag() 9 | 10 | def "List - with params"() { 11 | when: 12 | def tags = client.tags().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | tags.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def tags = client.tags().list(new TagsService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | tags.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def tagsIds = (0..3).collect { createTag() }*.id 29 | 30 | when: 31 | def tags = client.tags().list(new TagsService.SearchCriteria().ids(tagsIds)) 32 | 33 | then: 34 | tags.size() == 4 35 | tags*.id == tagsIds 36 | } 37 | 38 | def "Create - with attributes"() { 39 | when: 40 | def newTag = createTag() 41 | 42 | then: 43 | newTag instanceof Tag 44 | } 45 | 46 | def "Get"() { 47 | given: 48 | def searched = tag 49 | 50 | when: 51 | def found = client.tags().get(searched.id) 52 | 53 | then: 54 | found instanceof Tag 55 | found.id == searched.id 56 | } 57 | 58 | def "Update - with Lead entity"() { 59 | when: 60 | def updated = client.tags().update(tag) 61 | 62 | then: 63 | updated instanceof Tag 64 | } 65 | 66 | def "Delete"() { 67 | given: 68 | def newTag = createTag() 69 | 70 | when: 71 | def result = client.tags().delete(newTag.id) 72 | 73 | then: 74 | result 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/TasksServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.Task 4 | import spock.lang.Shared 5 | 6 | class TasksServiceTest extends BaseSpecification { 7 | 8 | @Shared def task = task ?: createTask() 9 | 10 | def "List - with params"() { 11 | when: 12 | def tasks = client.tasks().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | tasks.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def tasks = client.tasks().list(new TasksService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | tasks.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | given: 28 | def tasksIds = (0..3).collect { createTask() }*.id 29 | 30 | when: 31 | sleep(1000) 32 | def tasks = client.tasks().list(new TasksService.SearchCriteria().ids(tasksIds)) 33 | 34 | then: 35 | tasks.size() == 4 36 | tasks*.id == tasksIds 37 | } 38 | 39 | def "Create - with attributes"() { 40 | when: 41 | def newTask = createTask() 42 | 43 | then: 44 | newTask instanceof Task 45 | } 46 | 47 | def "Get"() { 48 | given: 49 | def searched = task 50 | 51 | when: 52 | def found = client.tasks().get(searched.id) 53 | 54 | then: 55 | found instanceof Task 56 | found.id == searched.id 57 | } 58 | 59 | def "Update - with Lead entity"() { 60 | when: 61 | def updated = client.tasks().update(task) 62 | 63 | then: 64 | updated instanceof Task 65 | } 66 | 67 | def "Delete"() { 68 | given: 69 | def newTask = createTask() 70 | 71 | when: 72 | def result = client.tasks().delete(newTask.id) 73 | 74 | then: 75 | result 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/TextMessagesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services 4 | 5 | import spock.lang.Shared 6 | 7 | import com.getbase.models.TextMessage 8 | 9 | class TextMessagesServiceTest extends BaseSpecification { 10 | 11 | def "List - with params"() { 12 | when: 13 | def textMessages = client.textMessages().list(["page": 1, "per_page": 1]) 14 | 15 | then: 16 | assert textMessages instanceof List 17 | } 18 | 19 | def "List - with query param builder"() { 20 | when: 21 | def textMessages = client.textMessages().list(new TextMessagesService.SearchCriteria().page(1).perPage(1)) 22 | 23 | then: 24 | assert textMessages instanceof List 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/UsersServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.services 2 | 3 | import com.getbase.models.User 4 | import spock.lang.Shared 5 | 6 | class UsersServiceTest extends BaseSpecification { 7 | 8 | @Shared def user = user ?: client.users().self() 9 | 10 | def "List - with params"() { 11 | when: 12 | def users = client.users().list(["page": 1, "per_page": 1]) 13 | 14 | then: 15 | users.size() > 0 16 | } 17 | 18 | def "List - with query param builder"() { 19 | when: 20 | def users = client.users().list(new UsersService.SearchCriteria().page(1).perPage(1)) 21 | 22 | then: 23 | users.size() > 0 24 | } 25 | 26 | def "List - by ids"() { 27 | when: 28 | def users = client.users().list(new UsersService.SearchCriteria().ids([user.id])) 29 | 30 | then: 31 | users.size() == 1 32 | users*.id == [user.id] 33 | } 34 | 35 | def "Get"() { 36 | given: 37 | def searched = user 38 | 39 | when: 40 | def found = client.users().get(searched.id) 41 | 42 | then: 43 | found instanceof User 44 | found.id == searched.id 45 | } 46 | 47 | def "Self"() { 48 | when: 49 | def user = client.users().self() 50 | 51 | then: 52 | user instanceof User 53 | user.id > 0 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/VisitOutcomesServiceTest.groovy: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services 4 | 5 | import spock.lang.Shared 6 | 7 | import com.getbase.models.VisitOutcome 8 | 9 | class VisitOutcomesServiceTest extends BaseSpecification { 10 | 11 | def "List - with params"() { 12 | when: 13 | def visitOutcomes = client.visitOutcomes().list(["page": 1, "per_page": 1]) 14 | 15 | then: 16 | assert visitOutcomes instanceof List 17 | } 18 | 19 | def "List - with query param builder"() { 20 | when: 21 | def visitOutcomes = client.visitOutcomes().list(new VisitOutcomesService.SearchCriteria().page(1).perPage(1)) 22 | 23 | then: 24 | assert visitOutcomes instanceof List 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/services/VisitsServiceTest.groovy: -------------------------------------------------------------------------------- 1 | // WARNING: This code is auto-generated from the BaseCRM API Discovery JSON Schema 2 | 3 | package com.getbase.services 4 | 5 | import spock.lang.Shared 6 | 7 | import com.getbase.models.Visit 8 | 9 | class VisitsServiceTest extends BaseSpecification { 10 | 11 | def "List - with params"() { 12 | when: 13 | def visits = client.visits().list(["page": 1, "per_page": 1]) 14 | 15 | then: 16 | assert visits instanceof List 17 | } 18 | 19 | def "List - with query param builder"() { 20 | when: 21 | def visits = client.visits().list(new VisitsService.SearchCriteria().page(1).perPage(1)) 22 | 23 | then: 24 | assert visits instanceof List 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/sync/SyncProcessTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.sync 2 | 3 | import com.getbase.Client 4 | import com.getbase.Configuration 5 | import com.getbase.http.HttpClient 6 | import spock.lang.Specification 7 | import spock.lang.Subject 8 | 9 | class SyncProcessTest extends Specification { 10 | 11 | @Subject 12 | SyncProcess syncProcess 13 | 14 | def client = new Client(Configuration.getDefault(), Mock(HttpClient)) 15 | def sessionManager = Mock(SessionManager) 16 | def syncService = Mock(SyncService) 17 | 18 | def deviceUUID = 'device-123' 19 | def sessionId = 'session-id' 20 | def session = new Session(sessionId, []) 21 | 22 | def setup() { 23 | syncProcess = new SyncProcess(client, deviceUUID, sessionManager, { x, y -> true }, Long.MAX_VALUE) 24 | client.syncService = syncService 25 | } 26 | 27 | def 'get session from session manager before create new'() { 28 | when: 29 | syncProcess.run() 30 | 31 | then: 32 | 1 * sessionManager.getSession(deviceUUID) >> session 33 | } 34 | 35 | def 'create new session when no session in session manager'() { 36 | given: 37 | sessionManager.getSession(deviceUUID) >> null 38 | 39 | when: 40 | syncProcess.run() 41 | 42 | then: 43 | 1 * syncService.start(deviceUUID) >> session 44 | } 45 | 46 | def 'saves valid session in session manager'() { 47 | when: 48 | syncService.start(deviceUUID) >> session 49 | syncProcess.run() 50 | 51 | then: 52 | 1 * sessionManager.setSession(deviceUUID, session) 53 | 54 | when: 55 | sessionManager.getSession(deviceUUID) >> session 56 | syncProcess.run() 57 | 58 | then: 59 | 1 * sessionManager.setSession(deviceUUID, session) 60 | } 61 | 62 | def 'clear session when all data processed'() { 63 | given: 64 | syncService.start(deviceUUID) >> session 65 | 66 | when: 67 | syncProcess.run() 68 | 69 | then: 70 | 1 * sessionManager.clearSession(deviceUUID) 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/sync/SyncServiceTest.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.sync 2 | 3 | import com.getbase.http.HttpClient 4 | import com.getbase.http.HttpMethod 5 | import com.getbase.http.Response 6 | import spock.lang.Shared 7 | import spock.lang.Specification 8 | 9 | class SyncServiceTest extends Specification { 10 | @Shared def deviceUUID = "6dadcec8-6e61-4691-b318-1aab27b8fecf" 11 | @Shared def sessionId = "29f2aeeb-8d68-4ea7-95c3-a2c8e151f5a" 12 | 13 | def "Start - nothing new to synchronize"() { 14 | given: 15 | def httpResponse = new Response(204) 16 | 17 | def httpClient = Mock(HttpClient) 18 | 1 * httpClient.request(HttpMethod.POST, 19 | "/v2/sync/start", 20 | null, 21 | ['X-Basecrm-Device-UUID': deviceUUID], 22 | null) >> httpResponse 23 | 24 | def sync = new SyncService(httpClient) 25 | 26 | when: 27 | def session = sync.start(deviceUUID) 28 | 29 | then: 30 | session == null 31 | } 32 | 33 | def "Start - got session"() { 34 | given: 35 | def json = '{"data":{"id":"29f2aeeb-8d68-4ea7-95c3-a2c8e151f5a","queues":[{"data":{"name":"main","pages":1,"total_count":2},"meta":{"type":"sync_session"}}]}}' 36 | def httpResponse = new Response(201, json) 37 | 38 | def httpClient = Mock(HttpClient) 39 | 1 * httpClient.request(HttpMethod.POST, 40 | "/v2/sync/start", 41 | null, 42 | ['X-Basecrm-Device-UUID': deviceUUID], 43 | null) >> httpResponse 44 | 45 | def sync = new SyncService(httpClient) 46 | 47 | when: 48 | def session = sync.start(deviceUUID) 49 | 50 | then: 51 | session != null 52 | session instanceof Session 53 | session.id == sessionId 54 | session.queues.size() == 1 55 | } 56 | 57 | def "Fetch - no more data to synchronize"() { 58 | given: 59 | def httpResponse = new Response(204) 60 | 61 | def httpClient = Mock(HttpClient) 62 | 1 * httpClient.request(HttpMethod.GET, 63 | "/v2/sync/${sessionId}/queues/main", 64 | null, 65 | ['X-Basecrm-Device-UUID': deviceUUID], 66 | null) >> httpResponse 67 | 68 | def sync = new SyncService(httpClient) 69 | 70 | when: 71 | def items = sync.fetch(deviceUUID, sessionId) 72 | 73 | then: 74 | items == null 75 | } 76 | 77 | def "Fetch - got queue items"() { 78 | given: 79 | def json = '{"items":[{"data":{"id":1},"meta":{"type":"user","sync":{"event_type":"created","ack_key":"User-1234-1","revision":1}}}]}' 80 | def httpResponse = new Response(200, json) 81 | 82 | def httpClient = Mock(HttpClient) 83 | 1 * httpClient.request(HttpMethod.GET, 84 | "/v2/sync/${sessionId}/queues/main", 85 | null, 86 | ['X-Basecrm-Device-UUID': deviceUUID], 87 | null) >> httpResponse 88 | 89 | def sync = new SyncService(httpClient) 90 | 91 | when: 92 | def items = sync.fetch(deviceUUID, sessionId) 93 | 94 | then: 95 | items == [[ 96 | "data": ["id":1], 97 | "meta":[ 98 | "type":"user", 99 | "sync": 100 | [ 101 | "event_type":"created", 102 | "ack_key":"User-1234-1", 103 | "revision":1 104 | ] 105 | ] 106 | ]] 107 | } 108 | 109 | def "Ack - with an empty list"() { 110 | given: 111 | def httpClient = Mock(HttpClient) 112 | def sync = new SyncService(httpClient) 113 | 114 | when: 115 | def status = sync.ack(deviceUUID, []) 116 | 117 | then: 118 | status 119 | 0 * httpClient._ 120 | } 121 | 122 | def "Ack"() { 123 | given: 124 | def ackKeys = ["User-1234-1"] 125 | def httpResponse = new Response(202) 126 | 127 | def httpClient = Mock(HttpClient) 128 | 1 * httpClient.request(HttpMethod.POST, 129 | "/v2/sync/ack", 130 | null, 131 | ['X-Basecrm-Device-UUID': deviceUUID], 132 | '{"data":{"ack_keys":["User-1234-1"]}}') >> httpResponse 133 | 134 | def sync = new SyncService(httpClient) 135 | 136 | when: 137 | def status = sync.ack(deviceUUID, ackKeys) 138 | 139 | then: 140 | status 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/test/groovy/com/getbase/utils/JoinerSpec.groovy: -------------------------------------------------------------------------------- 1 | package com.getbase.utils 2 | 3 | import spock.lang.Specification 4 | import spock.lang.Unroll 5 | 6 | 7 | @Unroll 8 | class JoinerSpec extends Specification { 9 | 10 | def "handles null/empty values"() { 11 | expect: 12 | Joiner.join(on, data) == joinedString 13 | 14 | where: 15 | on | data | joinedString 16 | ";" | null | "" 17 | ";" | [] | "" 18 | ";" | [null] | "null" 19 | ";" | [null, "E1"] | "null;E1" 20 | ";" | [null, null, "E1"] | "null;null;E1" 21 | null | null | "" 22 | null | [] | "" 23 | null | [null] | "null" 24 | null | [null, "E1"] | "nullE1" 25 | null | [null, null, "E1"] | "nullnullE1" 26 | } 27 | 28 | } 29 | --------------------------------------------------------------------------------