├── .buildscript └── deploy_snapshot.sh ├── .github └── workflows │ └── gradle.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle ├── checkstyle.xml ├── gradle.properties ├── gradle ├── dependencies.gradle ├── github-release.gradle ├── gradle-mvn-push.gradle ├── verification.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── releasenotes.gtpl ├── samples ├── cmdline-sample │ ├── README.md │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── uber │ │ │ └── sdk │ │ │ └── rides │ │ │ └── samples │ │ │ └── cmdline │ │ │ └── GetUserProfile.java │ │ └── resources │ │ └── secrets.properties └── servlet-sample │ ├── README.md │ ├── build.gradle │ ├── gradle.properties │ └── src │ └── main │ ├── java │ └── com │ │ └── uber │ │ └── sdk │ │ └── rides │ │ └── samples │ │ └── servlet │ │ ├── OAuth2CallbackServlet.java │ │ ├── SampleServlet.java │ │ └── Server.java │ └── resources │ └── secrets.properties ├── settings.gradle ├── uber-core-oauth-client-adapter ├── build.gradle ├── gradle.properties └── src │ ├── main │ └── java │ │ └── com │ │ └── uber │ │ └── sdk │ │ └── core │ │ ├── auth │ │ ├── CredentialsAuthenticator.java │ │ └── OAuth2Credentials.java │ │ └── client │ │ └── CredentialsSession.java │ └── test │ └── java │ └── com │ └── uber │ └── sdk │ └── core │ └── auth │ └── OAuth2CredentialsTest.java ├── uber-core ├── build.gradle ├── gradle.properties └── src │ ├── main │ └── java │ │ └── com │ │ └── uber │ │ └── sdk │ │ └── core │ │ ├── auth │ │ ├── AccessToken.java │ │ ├── AccessTokenAuthenticator.java │ │ ├── AccessTokenStorage.java │ │ ├── AuthException.java │ │ ├── Authenticator.java │ │ ├── AuthorizationCodeGrantFlow.java │ │ ├── BaseRefreshableAuthenticator.java │ │ ├── ProfileHint.java │ │ ├── Scope.java │ │ ├── ServerTokenAuthenticator.java │ │ └── internal │ │ │ ├── LoginPARResponse.java │ │ │ ├── OAuth2Service.java │ │ │ ├── OAuthScopes.java │ │ │ ├── OAuthScopesAdapter.java │ │ │ └── TokenRequestFlow.java │ │ └── client │ │ ├── AccessTokenSession.java │ │ ├── ServerTokenSession.java │ │ ├── Session.java │ │ ├── SessionConfiguration.java │ │ ├── internal │ │ ├── ApiInterceptor.java │ │ ├── BigDecimalAdapter.java │ │ ├── LoginPARRequestException.java │ │ ├── LoginPushedAuthorizationRequest.java │ │ └── RefreshAuthenticator.java │ │ └── utils │ │ └── Preconditions.java │ └── test │ ├── java │ └── com │ │ └── uber │ │ └── sdk │ │ └── core │ │ ├── WireMockTest.java │ │ ├── auth │ │ ├── AccessTokenAuthenticatorTest.java │ │ ├── AuthorizationCodeGrantFlowTest.java │ │ ├── BaseRefreshableAuthenticatorTest.java │ │ ├── ScopeTest.java │ │ └── internal │ │ │ ├── OAuth2ServiceTest.java │ │ │ └── OAuthScopesAdapterTest.java │ │ └── client │ │ ├── SessionConfigurationTest.java │ │ ├── SessionTest.java │ │ └── internal │ │ ├── ApiInterceptorTest.java │ │ ├── BigDecimalAdapterTest.java │ │ ├── LoginPushedAuthorizationRequestTest.java │ │ └── RefreshAuthenticatorTest.java │ └── resources │ └── __files │ └── token_token.json └── uber-rides ├── build.gradle ├── gradle.properties └── src ├── main └── java │ └── com │ └── uber │ └── sdk │ └── rides │ └── client │ ├── UberRidesApi.java │ ├── error │ ├── ApiError.java │ ├── ClientError.java │ ├── CompatibilityApiError.java │ ├── ErrorParser.java │ ├── Meta.java │ └── SurgeConfirmation.java │ ├── model │ ├── Driver.java │ ├── Location.java │ ├── PaymentMethod.java │ ├── PaymentMethodsResponse.java │ ├── Place.java │ ├── PlaceParameters.java │ ├── PriceEstimate.java │ ├── PriceEstimatesResponse.java │ ├── Product.java │ ├── ProductsResponse.java │ ├── Promotion.java │ ├── Ride.java │ ├── RideEstimate.java │ ├── RideMap.java │ ├── RideReceipt.java │ ├── RideRequestParameters.java │ ├── RideUpdateParameters.java │ ├── SandboxProductRequestParameters.java │ ├── SandboxRideRequestParameters.java │ ├── TimeEstimate.java │ ├── TimeEstimatesResponse.java │ ├── UserActivity.java │ ├── UserActivityPage.java │ ├── UserProfile.java │ └── Vehicle.java │ └── services │ └── RidesService.java └── test ├── java └── com │ └── uber │ └── sdk │ └── rides │ ├── WireMockTest.java │ └── client │ ├── UberRidesApiTest.java │ ├── error │ └── ErrorParserTest.java │ ├── model │ ├── RideRequestParametersTest.java │ └── RideUpdateParametersTest.java │ └── services │ └── RidesServiceTest.java └── resources ├── __files ├── products.json ├── requests_current.json ├── requests_current_UberPool.json ├── token_token.json ├── v1.2_request_estimate_UberPool.json ├── v1_request_estimate_UberPool.json └── v1_requests_estimate.json └── mockresponses ├── estimate_ride_redirect ├── estimate_ride_redirected ├── get_localized_products_response ├── get_product_error ├── get_products_response ├── get_user_profile_response ├── post_refresh_token_response ├── post_ride_error ├── post_ride_request ├── put_sandbox_params_no_product_id_response ├── simple_error_body └── surge_error_body /.buildscript/deploy_snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Deploy a jar, source jar, and javadoc jar to Sonatype's snapshot repo. 4 | # 5 | # Adapted from https://coderwall.com/p/9b_lfq and 6 | # http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ 7 | 8 | SLUG="uber/rides-java-sdk" 9 | JDK="oraclejdk8" 10 | BRANCH="master" 11 | 12 | set -e 13 | 14 | if [ "$TRAVIS_REPO_SLUG" != "$SLUG" ]; then 15 | echo "Skipping snapshot deployment: wrong repository. Expected '$SLUG' but was '$TRAVIS_REPO_SLUG'." 16 | elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then 17 | echo "Skipping snapshot deployment: wrong JDK. Expected '$JDK' but was '$TRAVIS_JDK_VERSION'." 18 | elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 19 | echo "Skipping snapshot deployment: was pull request." 20 | elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then 21 | echo "Skipping snapshot deployment: wrong branch. Expected '$BRANCH' but was '$TRAVIS_BRANCH'." 22 | else 23 | echo "Deploying snapshot..." 24 | ./gradlew clean uploadArchives 25 | echo "Snapshot deployed!" 26 | fi -------------------------------------------------------------------------------- /.github/workflows/gradle.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time 6 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle 7 | 8 | name: Java CI with Gradle 9 | 10 | on: [push, pull_request] 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up JDK 8 23 | uses: actions/setup-java@v3 24 | with: 25 | java-version: '8' 26 | distribution: 'adopt' 27 | - name: Configure Gradle 28 | run: ./gradlew help 29 | - name: Build Project 30 | run: ./gradlew assemble --stacktrace 31 | - name : Testing 32 | run: ./gradlew test --stacktrace 33 | - name: Final Checks 34 | run: ./gradlew check --stacktrace 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | eclipsebin 5 | .gradletasknamecache 6 | 7 | bin 8 | gen 9 | build 10 | out 11 | lib 12 | 13 | target 14 | pom.xml.* 15 | release.properties 16 | local.properties 17 | .gradle 18 | 19 | .idea 20 | *.iml 21 | classes 22 | 23 | obj 24 | 25 | .DS_Store 26 | 27 | *my_secrets.properties 28 | log.txt 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | install: "./gradlew clean assemble --stacktrace" 5 | script: 6 | - "./gradlew check --stacktrace" 7 | after_success: 8 | - ".buildscript/deploy_snapshot.sh" 9 | env: 10 | global: 11 | - secure: lBIR27eM1Ko6KoCabW5+3OjACHeqTItF+nmxTrJ1jKm2SR1HdKuwEc1UgGkZK1Ykbzk/OKApf6NYNMXr+J4Znwh8g516rUiaoXXHmWHMYQbEan9QKCnQgTRmRcVWTBrt7ZJDi8GADUE0D98thN0D/AVlggyTdLqcXRptAd1TmqrccOaaqlLsQ61VyqGAQY6KcVM7gR9fbsVAp+FaOoS7shHMiWAVR4SsE+btOdXvVW/l60a7qYFQMHqkJvHaXz7aVhnqZMI3tG6Uhqy2Mpd/HfdU9/HhrpCJU1Mf846ESN/DY3Qvk3IC+C41hSKbcnusoSiNJO/Jl2iZnsg2iohcF89IOyiMsTl18rsHiqrUl8kJdu8GtlAn/BsEeQfN628i3MmZgFrS1Ta1iz3PtDGcb5tHI2B1Qsl3IWU8GF6TxdDcF5hjFguDZS/xqaFowOf/i9p+IbUMaZPvn7UHoNrnZf5uBEkWqRuDgAZHJdzjPYDST0hYAHJ74FE8svVesC4nOaWRxoE5/ynbvmBKV/LYzEbTbi5I/n5YY4nLcJWotKMBTYUa3VRlZPBcCzy/QRG9N6qVlqljENKVfaGCkhWhHY8Ze8bguIGNhtYroDwBdRKbjPBqxj0ju5nCVkKuyaxj2F0fvJPVpL2hm1yWxr8p93TL8q3O99hz0fDJsqN5KSw= 12 | - secure: MC7IpBcgIqfvs1Drh8yufG3AECrNcfzJUbqSWc4dGyW4cMggfefUvBsxjvTyB385jJnzywTIb1hTePXv5EFo1j4VTgnKiK0tG8eGhddLfyLLIk9/CdTe15wTmdjZFBZXk5jlxGGYajjuxcCBPoOYqyYNv6Fq/WGmXdP40pfr1eFC0AlNUW/0JLNNSMZgvW6PZR11ZyrTQj1PhryS28tnVy67VKz3GZi/7HN5+GO/xh4QJztOVog95N547PaTBN4zdKlvCYIK1fRAJYOGeYFjxRkk/H5BymipqQm84WTuEw85rszAsVeg0wc1jWMqqEY0fIZyXuIg0FapbEG8y52GXp+JI6/xwSxmixaYDQy5j236LovSQYaiZFYQnAocAOk/5ctIAKHw7Swp2BQtIxzjzHm37reiO1VW5pn+2BriTT228W2GYtAs9ICWwYSPLh+KtMfSeCguR9nLHUcLAkKzhLaS40FBxN6aT8PT2Wf1oi1euH+BAV6BmXy5SmdgvwzxM5dRPWDj2F8rcTuPYB0x5iVd+nzWu27FYAtTreGtFzOdfhCJ25ods47s7giM78sZCsZQ6L1FASGhg/LL7BkQVWjiA+w3p/QWLkXkM0k3YoMGPfxF/2Gmpb5SJwazDkCOsdXoIXLm1YzOwB2UexVu/ww5G0/iChCByNIREZeAa6c= 13 | branches: 14 | except: 15 | - gh-pages 16 | notifications: 17 | email: false 18 | cache: 19 | directories: 20 | - "$HOME/.gradle" 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Uber Technologies, Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017. Uber Technologies 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | apply from: 'gradle/dependencies.gradle' 19 | 20 | repositories { 21 | mavenCentral() 22 | maven { url deps.build.repositories.plugins } 23 | } 24 | dependencies { 25 | classpath deps.build.gradlePlugins.github 26 | classpath deps.build.gradlePlugins.release 27 | } 28 | } 29 | 30 | task wrapper(type: Wrapper) { 31 | gradleVersion = deps.build.gradleVersion 32 | distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" 33 | } 34 | 35 | apply from: 'gradle/github-release.gradle' 36 | apply from: 'gradle/verification.gradle' -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | #Tue, 19 Sep 2023 11:23:22 -0700 2 | # 3 | # Copyright (c) 2016 Uber Technologies, Inc. 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | GROUP=com.uber.sdk 24 | #Managed by Github Release plugin 25 | VERSION_NAME=0.8.6-SNAPSHOT 26 | version=0.8.6-SNAPSHOT 27 | POM_URL=https\://developer.uber.com 28 | 29 | POM_SCM_URL=https\://github.com/uber/rides-java-sdk/ 30 | POM_SCM_CONNECTION=scm\:git\:git\://github.com/uber/rides-java-sdk.git 31 | POM_SCM_DEV_CONNECTION=scm\:git\:ssh\://git@github.com/uber/rides-java-sdk.git 32 | 33 | POM_LICENCE_NAME=MIT License 34 | POM_LICENCE_URL=http\://www.opensource.org/licenses/mit-license.php 35 | POM_LICENCE_DIST=repo 36 | 37 | POM_DEVELOPER_ID=uber 38 | POM_DEVELOPER_NAME=Uber Technologies 39 | 40 | GITHUB_OWNER=uber 41 | GITHUB_REPO=rides-java-sdk 42 | GITHUB_DOWNLOAD_PREFIX=https\://github.com/uber/rides-java-sdk/releases/download/ 43 | GITHUB_BRANCH=master 44 | -------------------------------------------------------------------------------- /gradle/dependencies.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017. Uber Technologies 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | def build = [ 18 | gradleVersion: '4.3.1', 19 | ci: 'true' == System.getenv('CI'), 20 | 21 | repositories: [ 22 | plugins: 'https://plugins.gradle.org/m2/' 23 | ], 24 | 25 | gradlePlugins: [ 26 | release: 'net.researchgate:gradle-release:2.1.2', 27 | github: 'co.riiid:gradle-github-plugin:0.4.2', 28 | cobertura: 'net.saliman:gradle-cobertura-plugin:2.3.1', 29 | buildConfig: 'gradle.plugin.de.fuerstenau:BuildConfigPlugin:1.1.8' 30 | ] 31 | ] 32 | 33 | def misc = [ 34 | jsr305: 'com.google.code.findbugs:jsr305:3.0.2', 35 | ] 36 | 37 | def network = [ 38 | retrofit: 'com.squareup.retrofit2:retrofit:2.0.2', 39 | retrofitMoshiConverter: 'com.squareup.retrofit2:converter-moshi:2.0.2', 40 | moshi: 'com.squareup.moshi:moshi:1.2.0', 41 | okhttp: 'com.squareup.okhttp3:okhttp:3.2.0', 42 | okhttpLoggingInterceptor: 'com.squareup.okhttp3:logging-interceptor:3.2.0', 43 | httpClientJackson: 'com.google.http-client:google-http-client-jackson2:1.19.0', 44 | oauthClient: 'com.google.oauth-client:google-oauth-client:1.19.0', 45 | oauthClientJetty: 'com.google.oauth-client:google-oauth-client-jetty:1.19.0', 46 | oauthClientServlet: 'com.google.oauth-client:google-oauth-client-servlet:1.19.0', 47 | jettyServer: 'org.eclipse.jetty:jetty-server:9.2.10.v20150310', 48 | jettyServlet: 'org.eclipse.jetty:jetty-servlet:9.2.10.v20150310' 49 | ] 50 | 51 | def test = [ 52 | junit: 'junit:junit:4.12', 53 | assertj: 'org.assertj:assertj-core:1.7.1', 54 | mockito: 'org.mockito:mockito-core:1.10.19', 55 | wiremock: 'com.github.tomakehurst:wiremock:2.10.1', 56 | hamcrest: 'org.hamcrest:hamcrest-library:1.3' 57 | ] 58 | 59 | ext.deps = [ 60 | "build": build, 61 | "misc": misc, 62 | "network": network, 63 | "test": test, 64 | ] 65 | -------------------------------------------------------------------------------- /gradle/github-release.gradle: -------------------------------------------------------------------------------- 1 | import groovy.text.GStringTemplateEngine 2 | import org.codehaus.groovy.runtime.DateGroovyMethods 3 | 4 | apply plugin: 'net.researchgate.release' 5 | apply plugin: 'co.riiid.gradle' 6 | 7 | ext.set("oldVersion", VERSION_NAME.replaceAll("-SNAPSHOT", "")) 8 | ext.set("samples", project(":samples").subprojects.collect { it.path }) 9 | 10 | ["GITHUB_TOKEN"].each { 11 | checkAndDefaultProperty(it) 12 | } 13 | 14 | def checkAndDefaultProperty(prop) { 15 | if (!project.hasProperty(prop)) { 16 | checkProperty(prop) 17 | rootProject.ext.set(prop, prop) 18 | } 19 | } 20 | 21 | def checkProperty(prop) { 22 | if (!project.hasProperty(prop)) { 23 | logger.warn("Add " + prop + " to your ~/.gradle/gradle.properties file.") 24 | } 25 | } 26 | 27 | def isReleaseBuild() { 28 | return VERSION_NAME.contains("SNAPSHOT") == false 29 | } 30 | 31 | def generateReleaseNotes() { 32 | def changelogSnippet = generateChangelogSnippet() 33 | def releaseVersion = rootProject.version.replaceAll('-SNAPSHOT', '') 34 | def model = [title : "Uber Rides API Java SDK (Beta) v${releaseVersion}", 35 | date : DateGroovyMethods.format(new Date(), 'MM/dd/yyyy'), 36 | snippet: changelogSnippet, 37 | assets : project.samples.collect { 38 | [ 39 | title : project(it).name, 40 | download : GITHUB_DOWNLOAD_PREFIX + "v${releaseVersion}/${project(it).name}-${releaseVersion}.jar", 41 | description: project(it).description, 42 | ] 43 | }] 44 | def engine = new GStringTemplateEngine() 45 | def template = engine.createTemplate(rootProject.file('releasenotes.gtpl')).make(model) 46 | return template.toString() 47 | } 48 | 49 | def generateChangelogSnippet() { 50 | def changelog = rootProject.file('CHANGELOG.md').text 51 | def snippet = "" 52 | def stop = false 53 | changelog.eachLine { line, count -> 54 | if (count >= 2) { 55 | stop = stop || line.startsWith("v"); 56 | if (!stop) { 57 | snippet += line + "\n"; 58 | } 59 | } 60 | } 61 | return " " + snippet.trim() 62 | } 63 | 64 | task updateReleaseVersionChangelog() << { 65 | def newVersion = rootProject.version.replaceAll('-SNAPSHOT', '') 66 | def changelog = rootProject.file('CHANGELOG.md') 67 | def changelogText = changelog.text 68 | def date = new Date().format('MM/dd/yyyy') 69 | 70 | if (changelogText.startsWith("v${oldVersion} - TBD")) { 71 | def updatedChangelog = changelogText.replace("v${oldVersion} - TBD", 72 | "v${newVersion} - ${date}") 73 | changelog.write(updatedChangelog) 74 | 75 | } 76 | } 77 | 78 | task updateNewVersionChangelog() << { 79 | def newVersion = rootProject.version.replaceAll('-SNAPSHOT', '') 80 | def changelog = rootProject.file('CHANGELOG.md') 81 | def changelogText = changelog.text 82 | 83 | if (!changelogText.startsWith("v${newVersion} - TBD")) { 84 | def updatedChangelog = "v${newVersion} - TBD\n" 85 | def dashesCount = updatedChangelog.length()-1 86 | updatedChangelog += "-"*dashesCount + "\n\n" + changelogText 87 | changelog.write(updatedChangelog) 88 | } 89 | } 90 | 91 | task configureGithub() << { 92 | github { 93 | owner = GITHUB_OWNER 94 | repo = GITHUB_REPO 95 | token = "${GITHUB_TOKEN}" 96 | tagName = "v${rootProject.version}" 97 | targetCommitish = GITHUB_BRANCH 98 | name = "v${rootProject.version}" 99 | body = generateReleaseNotes() 100 | assets = project.samples.collect { 101 | "${project(it).buildDir.absolutePath}/libs/${project(it).name}-${rootProject.version}.jar" 102 | } 103 | } 104 | } 105 | 106 | githubRelease.dependsOn ":configureGithub" 107 | configureGithub.mustRunAfter ":createReleaseTag" 108 | 109 | updateVersion.dependsOn ":githubRelease" 110 | githubRelease.mustRunAfter ":configureGithub" 111 | 112 | afterReleaseBuild.dependsOn ( ':uber-core:uploadArchives', 113 | ':uber-core-oauth-client-adapter:uploadArchives', 114 | ':uber-rides:uploadArchives') 115 | 116 | updateReleaseVersionChangelog.mustRunAfter ":afterReleaseBuild" 117 | preTagCommit.dependsOn ':updateReleaseVersionChangelog' 118 | updateNewVersionChangelog.mustRunAfter ":updateVersion" 119 | commitNewVersion.dependsOn ':updateNewVersionChangelog' 120 | 121 | release { 122 | failOnCommitNeeded = false 123 | failOnPublishNeeded = false 124 | failOnSnapshotDependencies = false 125 | revertOnFail = true 126 | tagTemplate = 'v$version' 127 | versionProperties = ['VERSION_NAME'] 128 | } 129 | 130 | -------------------------------------------------------------------------------- /gradle/verification.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017. Uber Technologies 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | subprojects { 18 | buildscript { 19 | repositories { 20 | mavenCentral() 21 | } 22 | } 23 | 24 | repositories { 25 | mavenCentral() 26 | maven { 27 | url 'https://maven.google.com' 28 | } 29 | } 30 | 31 | apply plugin: 'checkstyle' 32 | 33 | afterEvaluate { 34 | if (project.getPlugins().hasPlugin('com.android.application') || 35 | project.getPlugins().hasPlugin('com.android.library')) { 36 | 37 | task checkstyleMain(type: Checkstyle) { 38 | ignoreFailures = true 39 | showViolations = true 40 | source 'src/main', 'src/release' 41 | include '**/*.java' 42 | exclude '**/gen/**' 43 | exclude '**/R.java' 44 | exclude '**/BuildConfig.java' 45 | reports { 46 | xml.destination "$project.buildDir/reports/checkstyle/main.xml" 47 | } 48 | classpath = files() 49 | configFile = rootProject.file('checkstyle.xml') 50 | } 51 | 52 | task checkstyleTest(type: Checkstyle){ 53 | ignoreFailures = true 54 | showViolations = true 55 | source 'src/test', 'src/androidTest' 56 | include '**/*.java' 57 | exclude '**/gen/**' 58 | exclude '**/R.java' 59 | exclude '**/BuildConfig.java' 60 | reports { 61 | xml.destination "$project.buildDir/reports/checkstyle/test.xml" 62 | } 63 | classpath = files() 64 | configFile = rootProject.file('checkstyle.xml') 65 | } 66 | 67 | task checkstyle(dependsOn:['checkstyleMain', 'checkstyleTest']){ 68 | description 'Runs Checkstyle inspection against Android sourcesets.' 69 | group = 'Code Quality' 70 | } 71 | 72 | project.tasks.getByName("check").dependsOn "checkstyle" 73 | } else { 74 | checkstyle { 75 | ignoreFailures = true 76 | showViolations = true 77 | configFile rootProject.file('checkstyle.xml') 78 | } 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uber/rides-java-sdk/1c0b7d4ca6864b8cef01ed45164fe641efda1c12/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-4.8-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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /releasenotes.gtpl: -------------------------------------------------------------------------------- 1 | ${title} - ${date} 2 | ${snippet} 3 | 4 | | Download | Description | 5 | | ------------- |-------------| 6 | <% assets.each{ asset -> %>| <%= "[" + asset.title + "](" + asset.download + ")" %> | <%= asset.description %> |\n<%}%> -------------------------------------------------------------------------------- /samples/cmdline-sample/README.md: -------------------------------------------------------------------------------- 1 | # Uber Rides Java SDK (beta) 2 | 3 | Official Java SDK (beta) to support the Uber Rides API. 4 | 5 | ## Before you begin 6 | 7 | This is a beta Java SDK not intended to be run on Android. An official Android SDK will be released soon. 8 | 9 | ## Running the sample 10 | 11 | First, add your client ID and secret retrieved from developer.uber.com to `src/main/resources/secrets.properties`. 12 | 13 | To run the command line sample, run `$ ./gradlew clean :samples:cmdline-sample:build :samples:cmdline-sample:run`. You 14 | may need to add the redirect URL to your application (at developer.uber.com) for OAuth2 to succeed. 15 | 16 | Running the sample will store user credentials in your home directory under `.uber_credentials` for future executions. 17 | 18 | For full documentation, visit our [Developer Site](https://developer.uber.com/v1/endpoints/). 19 | 20 | ## Getting help 21 | 22 | Uber developers actively monitor the [uber tag](http://stackoverflow.com/questions/tagged/uber-api) on StackOverflow. If you need help installing or using the library, you can ask a question there. Make sure to tag your question with `uber-api` and `java`! 23 | 24 | ## Contributing 25 | 26 | We :heart: contributions. If you've found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo. Write a test to show your bug was fixed or the feature works as expected. -------------------------------------------------------------------------------- /samples/cmdline-sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | apply plugin: 'application' 24 | 25 | targetCompatibility = JavaVersion.VERSION_1_7 26 | sourceCompatibility = JavaVersion.VERSION_1_7 27 | 28 | mainClassName = 'com.uber.sdk.rides.samples.cmdline.GetUserProfile' 29 | 30 | dependencies { 31 | compile project(':uber-core-oauth-client-adapter') 32 | compile project(':uber-rides') 33 | compile deps.network.oauthClientJetty 34 | compile deps.network.oauthClientServlet 35 | } 36 | 37 | run.standardInput = System.in -------------------------------------------------------------------------------- /samples/cmdline-sample/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Uber Technologies, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | # 22 | 23 | description=Command line sample -------------------------------------------------------------------------------- /samples/cmdline-sample/src/main/resources/secrets.properties: -------------------------------------------------------------------------------- 1 | clientId=INSERT_CLIENT_ID_HERE 2 | clientSecret=INSERT_CLIENT_SECRET_HERE -------------------------------------------------------------------------------- /samples/servlet-sample/README.md: -------------------------------------------------------------------------------- 1 | # Uber Rides Java SDK (beta) 2 | 3 | Official Java SDK (beta) to support the Uber Rides API. 4 | 5 | ## Before you begin 6 | 7 | This is a beta Java SDK not intended to be run on Android. An official Android SDK will be released soon. 8 | 9 | ## Running the sample 10 | 11 | First, add your client ID and secret retrieved from developer.uber.com to `src/main/resources/secrets.properties`. 12 | 13 | To run the servlet sample, run `$ ./gradlew clean :samples:servlet-sample:build :samples:servlet-sample:run`. You may 14 | need to add the redirect URL (http://localhost:8181/Callback) to your application (at developer.uber.com) 15 | for OAuth2 to succeed. 16 | 17 | For full documentation, visit our [Developer Site](https://developer.uber.com/v1/endpoints/). 18 | 19 | ## Getting help 20 | 21 | Uber developers actively monitor the [uber tag](http://stackoverflow.com/questions/tagged/uber-api) on StackOverflow. 22 | If you need help installing or using the library, you can ask a question there. Make sure to tag your question 23 | with `uber-api` and `java`! 24 | 25 | ## Contributing 26 | 27 | We :heart: contributions. If you've found a bug in the library or would like new features added, go ahead and open 28 | issues or pull requests against this repo. Write a test to show your bug was fixed or the feature works as expected. -------------------------------------------------------------------------------- /samples/servlet-sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | apply plugin: 'application' 24 | 25 | targetCompatibility = JavaVersion.VERSION_1_7 26 | sourceCompatibility = JavaVersion.VERSION_1_7 27 | 28 | mainClassName = 'com.uber.sdk.rides.samples.servlet.Server' 29 | 30 | repositories { 31 | mavenCentral() 32 | } 33 | 34 | dependencies { 35 | compile project(':uber-core-oauth-client-adapter') 36 | compile project(':uber-rides') 37 | compile deps.network.oauthClientJetty 38 | compile deps.network.oauthClientServlet 39 | compile deps.network.jettyServer 40 | compile deps.network.jettyServlet 41 | } 42 | -------------------------------------------------------------------------------- /samples/servlet-sample/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Uber Technologies, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | # 22 | 23 | description=Servlet sample -------------------------------------------------------------------------------- /samples/servlet-sample/src/main/java/com/uber/sdk/rides/samples/servlet/OAuth2CallbackServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.samples.servlet; 24 | 25 | import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl; 26 | import com.uber.sdk.core.auth.OAuth2Credentials; 27 | import com.uber.sdk.core.client.SessionConfiguration; 28 | 29 | import java.io.IOException; 30 | import java.util.Random; 31 | 32 | import javax.servlet.ServletException; 33 | import javax.servlet.http.HttpServlet; 34 | import javax.servlet.http.HttpServletRequest; 35 | import javax.servlet.http.HttpServletResponse; 36 | import javax.servlet.http.HttpSession; 37 | 38 | /** 39 | * Demonstrates how to make oauth callbacks via a servlet. 40 | */ 41 | public class OAuth2CallbackServlet extends HttpServlet { 42 | 43 | private OAuth2Credentials oAuth2Credentials; 44 | 45 | @Override 46 | protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 47 | if (oAuth2Credentials == null) { 48 | SessionConfiguration config = Server.createSessionConfiguration(); 49 | oAuth2Credentials = Server.createOAuth2Credentials(config); 50 | } 51 | 52 | HttpSession httpSession = req.getSession(true); 53 | if (httpSession.getAttribute(Server.USER_SESSION_ID) == null) { 54 | httpSession.setAttribute(Server.USER_SESSION_ID, new Random().nextLong()); 55 | } 56 | super.service(req, resp); 57 | } 58 | 59 | @Override 60 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 61 | String requestUrl = req.getRequestURL().append('?').append(req.getQueryString()).toString(); 62 | AuthorizationCodeResponseUrl authorizationCodeResponseUrl = 63 | new AuthorizationCodeResponseUrl(requestUrl); 64 | 65 | if (authorizationCodeResponseUrl.getError() != null) { 66 | throw new IOException("Received error: " + authorizationCodeResponseUrl.getError()); 67 | } else { 68 | // Authenticate the user and store their credential with their user ID (derived from 69 | // the request). 70 | HttpSession httpSession = req.getSession(true); 71 | if (httpSession.getAttribute(Server.USER_SESSION_ID) == null) { 72 | httpSession.setAttribute(Server.USER_SESSION_ID, new Random().nextLong()); 73 | } 74 | String authorizationCode = authorizationCodeResponseUrl.getCode(); 75 | oAuth2Credentials.authenticate(authorizationCode, httpSession.getAttribute(Server.USER_SESSION_ID).toString()); 76 | } 77 | resp.sendRedirect("/"); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /samples/servlet-sample/src/main/java/com/uber/sdk/rides/samples/servlet/SampleServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.samples.servlet; 24 | 25 | import com.google.api.client.auth.oauth2.Credential; 26 | import com.uber.sdk.core.auth.OAuth2Credentials; 27 | import com.uber.sdk.core.client.CredentialsSession; 28 | import com.uber.sdk.core.client.SessionConfiguration; 29 | import com.uber.sdk.rides.client.services.RidesService; 30 | import com.uber.sdk.rides.client.UberRidesApi; 31 | import com.uber.sdk.rides.client.model.UserProfile; 32 | 33 | import java.io.IOException; 34 | import java.util.Random; 35 | 36 | import javax.servlet.ServletException; 37 | import javax.servlet.http.HttpServlet; 38 | import javax.servlet.http.HttpServletRequest; 39 | import javax.servlet.http.HttpServletResponse; 40 | import javax.servlet.http.HttpSession; 41 | 42 | /** 43 | * Demonstrates how to authenticate the user and load their profile via a servlet. 44 | */ 45 | public class SampleServlet extends HttpServlet { 46 | 47 | private OAuth2Credentials oAuth2Credentials; 48 | private Credential credential; 49 | private RidesService uberRidesService; 50 | 51 | /** 52 | * Clear the in memory credential and Uber API service once a call has ended. 53 | */ 54 | @Override 55 | public void destroy() { 56 | uberRidesService = null; 57 | credential = null; 58 | 59 | super.destroy(); 60 | } 61 | 62 | /** 63 | * Before each request, fetch an OAuth2 credential for the user or redirect them to the 64 | * OAuth2 login page instead. 65 | */ 66 | @Override 67 | protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { 68 | SessionConfiguration config = Server.createSessionConfiguration(); 69 | if (oAuth2Credentials == null) { 70 | oAuth2Credentials = Server.createOAuth2Credentials(config); 71 | } 72 | 73 | // Load the user from their user ID (derived from the request). 74 | HttpSession httpSession = req.getSession(true); 75 | if (httpSession.getAttribute(Server.USER_SESSION_ID) == null) { 76 | httpSession.setAttribute(Server.USER_SESSION_ID, new Random().nextLong()); 77 | } 78 | credential = oAuth2Credentials.loadCredential(httpSession.getAttribute(Server.USER_SESSION_ID).toString()); 79 | 80 | if (credential != null && credential.getAccessToken() != null) { 81 | 82 | if (uberRidesService == null) { 83 | 84 | CredentialsSession session = new CredentialsSession(config, credential); 85 | 86 | // Set up the Uber API Service once the user is authenticated. 87 | UberRidesApi api = UberRidesApi.with(session).build(); 88 | uberRidesService = api.createService(); 89 | } 90 | 91 | super.service(req, resp); 92 | } else { 93 | resp.sendRedirect(oAuth2Credentials.getAuthorizationUrl()); 94 | } 95 | } 96 | 97 | @Override 98 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 99 | // Fetch the user's profile. 100 | UserProfile userProfile = uberRidesService.getUserProfile().execute().body(); 101 | 102 | response.setContentType("text/html"); 103 | response.setStatus(HttpServletResponse.SC_OK); 104 | response.getWriter().printf("Logged in as %s%n", userProfile.getEmail()); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /samples/servlet-sample/src/main/resources/secrets.properties: -------------------------------------------------------------------------------- 1 | clientId=INSERT_CLIENT_ID_HERE 2 | clientSecret=INSERT_CLIENT_SECRET_HERE -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | include ':uber-core' 24 | include ':uber-core-oauth-client-adapter' 25 | include ':uber-rides' 26 | include ':samples:cmdline-sample' 27 | include ':samples:servlet-sample' 28 | 29 | -------------------------------------------------------------------------------- /uber-core-oauth-client-adapter/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | apply plugin: 'java' 24 | 25 | targetCompatibility = JavaVersion.VERSION_1_7 26 | sourceCompatibility = JavaVersion.VERSION_1_7 27 | 28 | dependencies { 29 | compile project(':uber-core') 30 | compile deps.network.httpClientJackson 31 | compile deps.network.oauthClient 32 | 33 | testCompile deps.test.junit 34 | testCompile deps.test.assertj 35 | testCompile deps.test.hamcrest 36 | testCompile deps.test.mockito 37 | testCompile deps.test.wiremock 38 | } 39 | 40 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 41 | -------------------------------------------------------------------------------- /uber-core-oauth-client-adapter/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Uber Technologies, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | # 22 | 23 | POM_NAME=Uber Java Core Oauth-Client Adapter SDK 24 | POM_ARTIFACT_ID=uber-core-oauth-client-adapter 25 | POM_DESCRIPTION=The Oauth Client Adapter for the Uber SDK 26 | POM_PACKAGING=jar -------------------------------------------------------------------------------- /uber-core-oauth-client-adapter/src/main/java/com/uber/sdk/core/auth/CredentialsAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth; 24 | 25 | import com.google.api.client.auth.oauth2.Credential; 26 | import com.uber.sdk.core.client.SessionConfiguration; 27 | import com.uber.sdk.core.client.internal.ApiInterceptor; 28 | 29 | import java.io.IOException; 30 | 31 | import okhttp3.Request; 32 | import okhttp3.Response; 33 | 34 | public class CredentialsAuthenticator extends BaseRefreshableAuthenticator implements 35 | Authenticator { 36 | static final String HEADER_BEARER_ACCESS_VALUE = "Bearer %s"; 37 | 38 | private final Credential credential; 39 | private final SessionConfiguration sessionConfiguration; 40 | 41 | public CredentialsAuthenticator(SessionConfiguration sessionConfiguration, Credential credential) { 42 | this.credential = credential; 43 | this.sessionConfiguration = sessionConfiguration; 44 | } 45 | 46 | @Override 47 | public void signRequest(Request.Builder builder) { 48 | setBearerToken(builder, credential); 49 | } 50 | 51 | @Override 52 | public boolean isRefreshable() { 53 | return true; 54 | } 55 | 56 | 57 | @Override 58 | protected Request doRefresh(Response response) throws IOException { 59 | if (signedByOldToken(response, credential)) { 60 | return resign(response, credential); 61 | } else { 62 | return refreshAndSign(response, credential); 63 | } 64 | } 65 | 66 | @Override 67 | public SessionConfiguration getSessionConfiguration() { 68 | return sessionConfiguration; 69 | } 70 | 71 | /** 72 | * Get {@link Credential} used for authentication 73 | */ 74 | public Credential getCredential() { 75 | return credential; 76 | } 77 | 78 | private static void setBearerToken(Request.Builder builder, Credential credential) { 79 | ApiInterceptor.setAuthorizationHeader(builder, createBearerToken(credential)); 80 | } 81 | 82 | private static String createBearerToken(Credential credential) { 83 | return String.format(HEADER_BEARER_ACCESS_VALUE, credential.getAccessToken()); 84 | } 85 | 86 | private Request resign(Response response, Credential credential) { 87 | Request.Builder builder = response.request().newBuilder(); 88 | setBearerToken(builder, credential); 89 | 90 | return builder.build(); 91 | } 92 | 93 | private Request refreshAndSign(Response response, Credential credential) throws IOException { 94 | credential.refreshToken(); 95 | return resign(response, credential); 96 | } 97 | 98 | private boolean signedByOldToken(Response response, Credential credential) { 99 | String value = ApiInterceptor.getAuthorizationHeader(response.request()); 100 | 101 | String accessToken = createBearerToken(credential); 102 | 103 | return value != null && !value.equals(accessToken); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /uber-core-oauth-client-adapter/src/main/java/com/uber/sdk/core/client/CredentialsSession.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.client; 2 | 3 | import com.google.api.client.auth.oauth2.Credential; 4 | import com.uber.sdk.core.auth.CredentialsAuthenticator; 5 | 6 | import javax.annotation.Nonnull; 7 | 8 | /** 9 | * A session containing the details of how an Uber authenticated service will interact with the API. 10 | * Does authentication through either a server token or OAuth 2.0 credential, exactly one of which must exist. 11 | * Uses {@link Credential} for connection 12 | */ 13 | public class CredentialsSession extends Session { 14 | /** 15 | * @param config config to define connection parameters 16 | * @param credential to access and refresh token 17 | */ 18 | public CredentialsSession(@Nonnull SessionConfiguration config, @Nonnull Credential credential) { 19 | super(new CredentialsAuthenticator(config, credential)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /uber-core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | buildscript { 23 | repositories { 24 | mavenCentral() 25 | maven { url deps.build.repositories.plugins } 26 | } 27 | dependencies { 28 | classpath deps.build.gradlePlugins.buildConfig 29 | } 30 | } 31 | 32 | apply plugin: 'java' 33 | apply plugin: 'de.fuerstenau.buildconfig' 34 | apply plugin: 'idea' 35 | 36 | targetCompatibility = JavaVersion.VERSION_1_8 37 | sourceCompatibility = JavaVersion.VERSION_1_8 38 | 39 | buildConfig { 40 | appName = POM_ARTIFACT_ID 41 | version = VERSION_NAME 42 | packageName = GROUP 43 | } 44 | 45 | dependencies { 46 | compile deps.network.retrofit 47 | compile deps.network.retrofitMoshiConverter 48 | compile deps.network.moshi 49 | compile deps.network.okhttp 50 | compile deps.network.okhttpLoggingInterceptor 51 | compile deps.misc.jsr305 52 | 53 | testCompile deps.test.junit 54 | testCompile deps.test.assertj 55 | testCompile deps.test.mockito 56 | testCompile deps.test.hamcrest 57 | testCompile deps.test.wiremock 58 | testCompile deps.network.retrofit 59 | testCompile deps.network.okhttp 60 | } 61 | 62 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') -------------------------------------------------------------------------------- /uber-core/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017. Uber Technologies 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | POM_NAME=Uber Java Core SDK 18 | POM_ARTIFACT_ID=uber-core 19 | POM_DESCRIPTION=The Java Core SDK for Uber. 20 | POM_PACKAGING=jar 21 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/AccessTokenStorage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth; 24 | 25 | import javax.annotation.Nonnull; 26 | import javax.annotation.Nullable; 27 | 28 | /** 29 | * Common interface for storing and getting AccessToken 30 | */ 31 | public interface AccessTokenStorage { 32 | /** 33 | * Returned currently stored token. 34 | * 35 | * @return 36 | */ 37 | @Nullable 38 | AccessToken getAccessToken(); 39 | 40 | /** 41 | * Replace token with new one. 42 | * 43 | * @param token 44 | */ 45 | void setAccessToken(@Nonnull AccessToken token); 46 | 47 | /** 48 | * Remove current token. 49 | */ 50 | void removeAccessToken(); 51 | } 52 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/AuthException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth; 24 | 25 | /** 26 | * Exception indicating there was an issue authenticating the user. 27 | */ 28 | public class AuthException extends RuntimeException { 29 | 30 | public AuthException(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | public AuthException(String message) { 35 | super(message); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth; 24 | 25 | import com.uber.sdk.core.client.SessionConfiguration; 26 | 27 | import java.io.IOException; 28 | 29 | import okhttp3.Request; 30 | import okhttp3.Response; 31 | 32 | public interface Authenticator { 33 | 34 | /** 35 | * Indicates whether this authenticator can be refreshed. 36 | * 37 | * @return 38 | */ 39 | boolean isRefreshable(); 40 | 41 | /** 42 | * Add authentication header required to the request. 43 | * 44 | * @param builder 45 | */ 46 | void signRequest(Request.Builder builder); 47 | 48 | /** 49 | * Refresh authentication token that is used to {@link #signRequest(Request.Builder)} 50 | * 51 | * @param response 52 | * @throws IOException 53 | */ 54 | Request refresh(Response response) throws IOException; 55 | 56 | /** 57 | * Get {@link SessionConfiguration} used for providing signining information for requests 58 | */ 59 | SessionConfiguration getSessionConfiguration(); 60 | } 61 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/AuthorizationCodeGrantFlow.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.auth; 2 | 3 | import com.squareup.moshi.Moshi; 4 | import com.uber.sdk.core.auth.internal.OAuth2Service; 5 | import com.uber.sdk.core.auth.internal.OAuthScopesAdapter; 6 | import com.uber.sdk.core.auth.internal.TokenRequestFlow; 7 | import com.uber.sdk.core.client.SessionConfiguration; 8 | 9 | import retrofit2.Call; 10 | import retrofit2.Callback; 11 | import retrofit2.Response; 12 | import retrofit2.Retrofit; 13 | import retrofit2.converter.moshi.MoshiConverterFactory; 14 | 15 | /** 16 | * Provides implementation for {@link TokenRequestFlow} where authorization code is used along with 17 | * proof key code exchange mechanism to fetch oauth tokens 18 | */ 19 | public class AuthorizationCodeGrantFlow implements TokenRequestFlow { 20 | 21 | private final static String GRANT_TYPE = "authorization_code"; 22 | 23 | private final OAuth2Service oAuth2Service; 24 | private final SessionConfiguration sessionConfiguration; 25 | private final String authCode; 26 | private final String codeVerifier; 27 | 28 | public AuthorizationCodeGrantFlow( 29 | SessionConfiguration sessionConfiguration, 30 | String authCode, 31 | String codeVerifier 32 | ) { 33 | this(createOAuthService(sessionConfiguration.getLoginHost()), 34 | sessionConfiguration, 35 | authCode, 36 | codeVerifier 37 | ); 38 | } 39 | 40 | /** 41 | * This contructor is used for testing only 42 | * @param ooAuth2Service 43 | * @param sessionConfiguration 44 | * @param authCode 45 | * @param codeVerifier 46 | */ 47 | AuthorizationCodeGrantFlow( 48 | OAuth2Service ooAuth2Service, 49 | SessionConfiguration sessionConfiguration, 50 | String authCode, 51 | String codeVerifier 52 | ) { 53 | this.oAuth2Service = ooAuth2Service; 54 | this.sessionConfiguration = sessionConfiguration; 55 | this.authCode = authCode; 56 | this.codeVerifier = codeVerifier; 57 | } 58 | 59 | 60 | 61 | @Override 62 | public void execute(TokenRequestFlowCallback callback) { 63 | oAuth2Service.token( 64 | sessionConfiguration.getClientId(), 65 | codeVerifier, 66 | GRANT_TYPE, 67 | sessionConfiguration.getRedirectUri(), 68 | authCode 69 | ).enqueue( 70 | new Callback() { 71 | @Override 72 | public void onResponse(Call call, Response response) { 73 | if (response.isSuccessful()) { 74 | callback.onSuccess(response.body()); 75 | } else { 76 | onFailure(call, new AuthException("Token request failed with code " + response.code())); 77 | } 78 | } 79 | 80 | @Override 81 | public void onFailure(Call call, Throwable t) { 82 | callback.onFailure(t); 83 | } 84 | } 85 | ); 86 | } 87 | 88 | private static OAuth2Service createOAuthService(String baseUrl) { 89 | final Moshi moshi = new Moshi.Builder().add(new OAuthScopesAdapter()).build(); 90 | return new Retrofit.Builder() 91 | .baseUrl(baseUrl) 92 | .addConverterFactory(MoshiConverterFactory.create(moshi)) 93 | .build() 94 | .create(OAuth2Service.class); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/BaseRefreshableAuthenticator.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.auth; 2 | 3 | import java.io.IOException; 4 | 5 | import okhttp3.Request; 6 | import okhttp3.Response; 7 | 8 | public abstract class BaseRefreshableAuthenticator implements Authenticator { 9 | 10 | static final String HEADER_INVALID_SCOPES = "X-Uber-Missing-Scopes"; 11 | static final int MAX_RETRIES = 3; 12 | 13 | @Override 14 | public final Request refresh(Response response) throws IOException { 15 | if (isRefreshable() && canRefresh(response) && canRetry(response)) { 16 | return doRefresh(response); 17 | } 18 | return null; 19 | } 20 | 21 | protected abstract Request doRefresh(Response response) throws IOException; 22 | 23 | /** 24 | * The Uber API returns invalid scopes as 401's and will migrate to 403's in the future. 25 | * This is a temporary measure and will be updated in the future. 26 | * 27 | * @param response to check for {@link BaseRefreshableAuthenticator#HEADER_INVALID_SCOPES} header. 28 | * @return true if a true 401 and can refresh, otherwise false 29 | */ 30 | protected boolean canRefresh(Response response) { 31 | return response.header(HEADER_INVALID_SCOPES) == null; 32 | } 33 | 34 | 35 | protected boolean canRetry(Response response) { 36 | int responseCount = 1; 37 | while ((response = response.priorResponse()) != null) { 38 | responseCount++; 39 | } 40 | 41 | return responseCount < MAX_RETRIES; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/ProfileHint.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.auth; 2 | 3 | import com.squareup.moshi.Json; 4 | 5 | import java.io.Serializable; 6 | 7 | import javax.annotation.Nonnull; 8 | 9 | /** 10 | * {@Link #ProfileHint} is builder to setup user's personal information like phone number, email 11 | * firstName and lastName 12 | */ 13 | final public class ProfileHint implements Serializable { 14 | /** 15 | * Builder class for {@link ProfileHint} 16 | */ 17 | public static class Builder { 18 | private String firstName; 19 | private String lastName; 20 | private String email; 21 | private String phone; 22 | 23 | /** 24 | * Set first name 25 | * 26 | * @param firstName first name of the user 27 | */ 28 | public Builder firstName(@Nonnull String firstName) { 29 | this.firstName = firstName; 30 | return this; 31 | } 32 | 33 | /** 34 | * Set last name 35 | * 36 | * @param lastName last name of the user 37 | */ 38 | public Builder lastName(@Nonnull String lastName) { 39 | this.lastName = lastName; 40 | return this; 41 | } 42 | 43 | /** 44 | * Set email address 45 | * 46 | * @param email email address of the user 47 | */ 48 | public Builder email(@Nonnull String email) { 49 | this.email = email; 50 | return this; 51 | } 52 | 53 | /** 54 | * Set phone number as a string including country code 55 | * 56 | * @param phone phone number of the user 57 | */ 58 | public Builder phone(@Nonnull String phone) { 59 | this.phone = phone; 60 | return this; 61 | } 62 | 63 | public ProfileHint build() { 64 | return new ProfileHint( 65 | firstName, 66 | lastName, 67 | email, 68 | phone 69 | ); 70 | } 71 | } 72 | 73 | /** 74 | * Gets the first name of the user 75 | * 76 | * @return The first name of the user if set, null otherwise 77 | */ 78 | public String getFirstName() { 79 | return firstName; 80 | } 81 | 82 | /** 83 | * Gets the last name of the user 84 | * 85 | * @return The last name of the user if set, null otherwise 86 | */ 87 | public String getLastName() { 88 | return lastName; 89 | } 90 | 91 | /** 92 | * Gets the email address of the user 93 | * 94 | * @return The email address of the user if set, null otherwise 95 | */ 96 | public String getEmail() { 97 | return email; 98 | } 99 | 100 | /** 101 | * Gets the phone number of the user as a string including country code 102 | * 103 | * @return The phone number of the user if set, null otherwise 104 | */ 105 | public String getPhone() { 106 | return phone; 107 | } 108 | 109 | /** 110 | * Returns new Builder with the current instance's properties as default values 111 | * 112 | * @return a new Builder object 113 | */ 114 | public Builder newBuilder() { 115 | return new Builder() 116 | .firstName(firstName) 117 | .lastName(lastName) 118 | .email(email) 119 | .phone(phone); 120 | } 121 | 122 | @Json(name = "first_name") 123 | private final String firstName; 124 | @Json(name = "last_name") 125 | private final String lastName; 126 | @Json(name = "email") 127 | private final String email; 128 | @Json(name = "phone") 129 | private final String phone; 130 | 131 | private ProfileHint( 132 | String firstName, 133 | String lastName, 134 | String email, 135 | String phone) { 136 | this.firstName = firstName; 137 | this.lastName = lastName; 138 | this.email = email; 139 | this.phone = phone; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/ServerTokenAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth; 24 | 25 | import com.uber.sdk.core.client.SessionConfiguration; 26 | import com.uber.sdk.core.client.internal.ApiInterceptor; 27 | 28 | import okhttp3.Request; 29 | import okhttp3.Response; 30 | 31 | public class ServerTokenAuthenticator implements Authenticator { 32 | static final String HEADER_TOKEN_ACCESS_VALUE = "Token %s"; 33 | 34 | private final SessionConfiguration sessionConfiguration; 35 | 36 | public ServerTokenAuthenticator(SessionConfiguration sessionConfiguration) { 37 | this.sessionConfiguration = sessionConfiguration; 38 | } 39 | 40 | @Override 41 | public void signRequest(Request.Builder builder) { 42 | ApiInterceptor.setAuthorizationHeader(builder, 43 | String.format(HEADER_TOKEN_ACCESS_VALUE, sessionConfiguration.getServerToken())); 44 | } 45 | 46 | @Override 47 | public Request refresh(Response response) { 48 | return null; 49 | //Do nothing, server token is not refreshable 50 | } 51 | 52 | @Override 53 | public boolean isRefreshable() { 54 | return false; 55 | } 56 | 57 | /** 58 | * Get {@link SessionConfiguration} used for authentication 59 | */ 60 | @Override 61 | public SessionConfiguration getSessionConfiguration() { 62 | return sessionConfiguration; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/internal/LoginPARResponse.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.auth.internal; 2 | 3 | import com.squareup.moshi.Json; 4 | 5 | public class LoginPARResponse { 6 | @Json(name = "request_uri") 7 | public String requestUri; 8 | @Json(name = "expires_in") 9 | public String expiresIn; 10 | } -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/internal/OAuth2Service.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth.internal; 24 | 25 | import com.uber.sdk.core.auth.AccessToken; 26 | 27 | import retrofit2.Call; 28 | import retrofit2.http.Field; 29 | import retrofit2.http.FormUrlEncoded; 30 | import retrofit2.http.POST; 31 | 32 | public interface OAuth2Service { 33 | @FormUrlEncoded 34 | @POST("token") 35 | Call refresh(@Field("refresh_token") String refreshToken, 36 | @Field("client_id") String clientId); 37 | 38 | @FormUrlEncoded 39 | @POST("/oauth/v2/token") 40 | Call token(@Field("client_id") String clientId, 41 | @Field("code_verifier") String codeVerifier, 42 | @Field("grant_type") String grantType, 43 | @Field("redirect_uri") String redirectUri, 44 | @Field("code") String authCode); 45 | 46 | @FormUrlEncoded 47 | @POST("/oauth/v2/par") 48 | Call loginParRequest( 49 | @Field("client_id") String clientId, 50 | @Field("response_type") String responseType, 51 | @Field("login_hint") String loginHint 52 | ); 53 | } 54 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/internal/OAuthScopes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth.internal; 24 | 25 | import com.squareup.moshi.JsonQualifier; 26 | 27 | import java.lang.annotation.Retention; 28 | 29 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 30 | 31 | @Retention(RUNTIME) 32 | @JsonQualifier 33 | public @interface OAuthScopes { 34 | } 35 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/internal/OAuthScopesAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth.internal; 24 | 25 | import com.squareup.moshi.FromJson; 26 | import com.squareup.moshi.ToJson; 27 | import com.uber.sdk.core.auth.Scope; 28 | 29 | import java.util.Set; 30 | 31 | public class OAuthScopesAdapter { 32 | @FromJson 33 | @OAuthScopes 34 | Set fromJson(String scopes) { 35 | return Scope.parseScopes(scopes); 36 | } 37 | 38 | @ToJson 39 | String toJson(@OAuthScopes Set scopes) { 40 | return Scope.toStandardString(scopes); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/auth/internal/TokenRequestFlow.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.auth.internal; 2 | 3 | import com.uber.sdk.core.auth.AccessToken; 4 | 5 | /** 6 | * Interface to request tokens from the backend 7 | */ 8 | public interface TokenRequestFlow { 9 | /** 10 | * Executes the token request 11 | * @param callback Callback will be invoked when the request succeeds or errors out. 12 | */ 13 | void execute(TokenRequestFlowCallback callback); 14 | 15 | /** 16 | * Interface to provide callback for token request result 17 | */ 18 | interface TokenRequestFlowCallback { 19 | /** 20 | * Called when token request finishes successfully 21 | * @param accessToken {@link AccessToken} object containing oauth tokens 22 | */ 23 | void onSuccess(AccessToken accessToken); 24 | 25 | /** 26 | * Called when token request finishes with a failure 27 | * @param error 28 | */ 29 | void onFailure(Throwable error); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/AccessTokenSession.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.client; 2 | 3 | import com.uber.sdk.core.auth.AccessTokenAuthenticator; 4 | import com.uber.sdk.core.auth.AccessTokenStorage; 5 | 6 | import javax.annotation.Nonnull; 7 | 8 | /** 9 | * A session containing the details of how an Authenticated Uber Service will interact with the API. 10 | * Does authentication through either a server token or OAuth 2.0 credential, exactly one of which must exist. 11 | * Uses {@link AccessTokenStorage} for connection 12 | */ 13 | public class AccessTokenSession extends Session { 14 | /** 15 | * @param config config to define connection parameters 16 | * @param accessTokenStorage to access and refresh tokens 17 | */ 18 | public AccessTokenSession(@Nonnull SessionConfiguration config, @Nonnull AccessTokenStorage accessTokenStorage) { 19 | super(new AccessTokenAuthenticator(config, accessTokenStorage)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/ServerTokenSession.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.client; 2 | 3 | import com.uber.sdk.core.auth.ServerTokenAuthenticator; 4 | 5 | import javax.annotation.Nonnull; 6 | 7 | /** 8 | * A session containing the details of how an Authenticated Uber Service will interact with the API. 9 | * Does authentication through either a server token or OAuth 2.0 credential, exactly one of which must exist. 10 | * Uses server token for connection 11 | */ 12 | public class ServerTokenSession extends Session { 13 | /** 14 | * @param config to define connection parameters 15 | */ 16 | public ServerTokenSession(@Nonnull SessionConfiguration config) { 17 | super(new ServerTokenAuthenticator(config)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/Session.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client; 24 | 25 | import com.uber.sdk.core.auth.Authenticator; 26 | 27 | import javax.annotation.Nonnull; 28 | 29 | /** 30 | * A session containing the details of how an Authenticated Uber Service will interact with the API. 31 | * Does authentication through either a server token or OAuth 2.0 credential, exactly one of which must exist. 32 | */ 33 | public abstract class Session { 34 | 35 | private final T authenticator; 36 | 37 | /** 38 | * @param authenticator used to sign outgoing requests 39 | */ 40 | public Session(@Nonnull T authenticator) { 41 | this.authenticator = authenticator; 42 | } 43 | 44 | /** 45 | * Gets the {@link Authenticator} provided after authentication is completed. 46 | * This is used to sign outgoing requests. 47 | */ 48 | public T getAuthenticator() { 49 | return authenticator; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/internal/ApiInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client.internal; 24 | 25 | import com.uber.sdk.BuildConfig; 26 | import com.uber.sdk.core.auth.Authenticator; 27 | 28 | import java.io.IOException; 29 | 30 | import okhttp3.Interceptor; 31 | import okhttp3.Request; 32 | import okhttp3.Response; 33 | 34 | public class ApiInterceptor implements Interceptor { 35 | static final String HEADER_ACCESS_TOKEN = "Authorization"; 36 | 37 | static final String LIB_VERSION = BuildConfig.VERSION; 38 | static final String HEADER_ACCEPT_LANGUAGE = "Accept-Language"; 39 | static final String HEADER_USER_AGENT = "X-Uber-User-Agent"; 40 | 41 | public final Authenticator authenticator; 42 | 43 | public ApiInterceptor(Authenticator authenticator) { 44 | this.authenticator = authenticator; 45 | } 46 | 47 | @Override 48 | public Response intercept(Chain chain) throws IOException { 49 | Request.Builder requestBuilder = chain.request().newBuilder(); 50 | 51 | requestBuilder.addHeader(HEADER_ACCEPT_LANGUAGE, 52 | authenticator.getSessionConfiguration().getLocale().getLanguage()); 53 | 54 | requestBuilder.addHeader(HEADER_USER_AGENT, "Java Rides SDK v" + LIB_VERSION); 55 | 56 | authenticator.signRequest(requestBuilder); 57 | return chain.proceed(requestBuilder.build()); 58 | } 59 | 60 | public static void setAuthorizationHeader(Request.Builder builder, String authorizationHeader) { 61 | builder.removeHeader(HEADER_ACCESS_TOKEN); 62 | builder.addHeader(HEADER_ACCESS_TOKEN, authorizationHeader); 63 | } 64 | 65 | public static String getAuthorizationHeader(Request request) { 66 | return request.header(HEADER_ACCESS_TOKEN); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/internal/BigDecimalAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client.internal; 24 | 25 | import com.squareup.moshi.FromJson; 26 | import com.squareup.moshi.ToJson; 27 | 28 | import java.math.BigDecimal; 29 | 30 | import javax.annotation.Nullable; 31 | 32 | 33 | /** 34 | * Adapter used to adapt floats to {@link java.math.BigDecimal}. 35 | */ 36 | public class BigDecimalAdapter { 37 | 38 | @ToJson 39 | public float toJson(BigDecimal bigDecimal) { 40 | return bigDecimal.floatValue(); 41 | } 42 | 43 | @FromJson 44 | public BigDecimal bigDecimalFromString(@Nullable Float value) { 45 | return value != null ? new BigDecimal(value.toString()) : null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/internal/LoginPARRequestException.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.client.internal; 2 | 3 | public class LoginPARRequestException extends RuntimeException { 4 | LoginPARRequestException(Throwable cause) { 5 | super(cause); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/internal/LoginPushedAuthorizationRequest.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.client.internal; 2 | 3 | import static java.nio.charset.StandardCharsets.UTF_8; 4 | 5 | import com.squareup.moshi.JsonAdapter; 6 | import com.squareup.moshi.Moshi; 7 | import com.uber.sdk.core.auth.internal.LoginPARResponse; 8 | import com.uber.sdk.core.auth.internal.OAuth2Service; 9 | import com.uber.sdk.core.auth.ProfileHint; 10 | import com.uber.sdk.core.client.SessionConfiguration; 11 | 12 | import java.util.Base64; 13 | import java.util.Locale; 14 | 15 | import retrofit2.Call; 16 | import retrofit2.Response; 17 | import retrofit2.Retrofit; 18 | import retrofit2.converter.moshi.MoshiConverterFactory; 19 | 20 | public class LoginPushedAuthorizationRequest { 21 | 22 | private final OAuth2Service oAuth2Service; 23 | 24 | private final Callback callback; 25 | private final ProfileHint profileHint; 26 | private final String clientId; 27 | private final String responseType; 28 | private final Moshi moshi; 29 | 30 | public LoginPushedAuthorizationRequest( 31 | SessionConfiguration sessionConfiguration, 32 | String responseType, 33 | Callback callback 34 | ) { 35 | this( 36 | createOAuthService(sessionConfiguration.getLoginHost()), 37 | sessionConfiguration.getProfileHint(), 38 | sessionConfiguration.getClientId(), 39 | responseType, 40 | callback 41 | ); 42 | } 43 | 44 | public LoginPushedAuthorizationRequest( 45 | OAuth2Service oAuth2Service, 46 | ProfileHint profileHint, 47 | String clientId, 48 | String responseType, 49 | Callback callback 50 | ) { 51 | this.oAuth2Service = oAuth2Service; 52 | this.profileHint = profileHint; 53 | this.clientId = clientId; 54 | this.responseType = responseType.toLowerCase(Locale.US); 55 | this.callback = callback; 56 | this.moshi = new Moshi.Builder().build(); 57 | } 58 | 59 | public void execute() { 60 | if (profileHint == null) { 61 | callback.onSuccess(""); 62 | return; 63 | } 64 | JsonAdapter profileHintJsonAdapter = moshi.adapter(ProfileHint.class); 65 | String profileHintString = new String( 66 | Base64.getEncoder().encode( 67 | profileHintJsonAdapter.toJson(profileHint).getBytes(UTF_8) 68 | ) 69 | ); 70 | oAuth2Service 71 | .loginParRequest(clientId, responseType, profileHintString) 72 | .enqueue(new retrofit2.Callback() { 73 | @Override 74 | public void onResponse(Call call, Response response) { 75 | if (response.isSuccessful() && response.body() != null) { 76 | callback.onSuccess(response.body().requestUri); 77 | } else { 78 | onFailure(call, new RuntimeException("bad response")); 79 | } 80 | } 81 | 82 | @Override 83 | public void onFailure(Call call, Throwable t) { 84 | callback.onError(new LoginPARRequestException(t)); 85 | } 86 | }); 87 | } 88 | 89 | static OAuth2Service createOAuthService(String baseUrl) { 90 | return new Retrofit.Builder() 91 | .baseUrl(baseUrl) 92 | .addConverterFactory(MoshiConverterFactory.create()) 93 | .build() 94 | .create(OAuth2Service.class); 95 | } 96 | 97 | public static interface Callback { 98 | void onSuccess(String requestUri); 99 | 100 | void onError(LoginPARRequestException e); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/internal/RefreshAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client.internal; 24 | 25 | import com.uber.sdk.core.auth.Authenticator; 26 | 27 | import java.io.IOException; 28 | 29 | import okhttp3.Request; 30 | import okhttp3.Response; 31 | import okhttp3.Route; 32 | 33 | public class RefreshAuthenticator implements okhttp3.Authenticator { 34 | 35 | 36 | public final Authenticator authenticator; 37 | 38 | public RefreshAuthenticator(Authenticator authenticator) { 39 | this.authenticator = authenticator; 40 | } 41 | 42 | @Override 43 | public Request authenticate(Route route, Response response) throws IOException { 44 | return authenticator.refresh(response); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /uber-core/src/main/java/com/uber/sdk/core/client/utils/Preconditions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client.utils;/* 24 | * Copyright (c) 2016 Uber Technologies, Inc. 25 | * 26 | * Permission is hereby granted, free of charge, to any person obtaining a copy 27 | * of this software and associated documentation files (the "Software"), to deal 28 | * in the Software without restriction, including without limitation the rights 29 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 30 | * copies of the Software, and to permit persons to whom the Software is 31 | * furnished to do so, subject to the following conditions: 32 | * 33 | * The above copyright notice and this permission notice shall be included in 34 | * all copies or substantial portions of the Software. 35 | * 36 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 37 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 38 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 39 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 40 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 41 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 42 | * THE SOFTWARE. 43 | */ 44 | 45 | 46 | import java.util.Collection; 47 | 48 | import javax.annotation.Nonnull; 49 | 50 | /** 51 | * Simple static methods to be called at the start of your own methods to verify 52 | * correct arguments and state. 53 | */ 54 | public class Preconditions { 55 | 56 | /** 57 | * Ensures the truth of an expression involving the state of the calling 58 | * instance, but not involving any parameters to the calling method. 59 | * 60 | * @param expression a boolean expression 61 | * @param errorMessage error message thrown if expression is false. 62 | * @throws IllegalStateException if {@code expression} is false 63 | */ 64 | public static void checkState(final boolean expression, @Nonnull String errorMessage) { 65 | if (!expression) { 66 | throw new IllegalStateException(errorMessage); 67 | } 68 | } 69 | 70 | 71 | /** 72 | * Ensures the value is not null. 73 | * 74 | * @param value value to be validated. 75 | * @param errorMessage error message thrown if value is null. 76 | * @param type of value. 77 | * @return value passed in if not null. 78 | */ 79 | @Nonnull 80 | public static T checkNotNull(T value, @Nonnull String errorMessage) { 81 | if (value == null) { 82 | throw new NullPointerException(errorMessage); 83 | } 84 | return value; 85 | } 86 | 87 | /** 88 | * Ensures a collection is neither null nor empty. 89 | * 90 | * @param collection collection to be validated. 91 | * @param errorMessage error message to be thrown if collection is null or empty. 92 | * @param type of the collection item. 93 | * @return collection passed in. 94 | */ 95 | @Nonnull 96 | public static Collection checkNotEmpty(Collection collection, @Nonnull String errorMessage) { 97 | checkState(collection != null && !collection.isEmpty(), errorMessage); 98 | return collection; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/WireMockTest.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core; 2 | 3 | import com.github.tomakehurst.wiremock.common.ConsoleNotifier; 4 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 5 | import com.github.tomakehurst.wiremock.junit.WireMockRule; 6 | 7 | import org.junit.Rule; 8 | 9 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; 10 | 11 | public class WireMockTest { 12 | 13 | protected static WireMockConfiguration WIRE_MOCK_CONFIG = wireMockConfig() 14 | .notifier(new ConsoleNotifier(true)) 15 | .dynamicPort(); 16 | 17 | @Rule 18 | public WireMockRule wireMockRule = new WireMockRule(WIRE_MOCK_CONFIG); 19 | } 20 | -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/auth/ScopeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth; 24 | 25 | import org.junit.Test; 26 | 27 | import java.util.Arrays; 28 | import java.util.Collection; 29 | import java.util.Set; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | public class ScopeTest { 34 | 35 | @Test 36 | public void testParseScopesWithZero_shouldReturnNothing() throws Exception { 37 | Set scopes = Scope.parseScopes(0); 38 | 39 | assertThat(scopes).isEmpty(); 40 | } 41 | 42 | @Test 43 | public void testParseScopesWithNegativeValue_shouldReturnNothing() throws Exception { 44 | Set scopes = Scope.parseScopes(-32); 45 | 46 | assertThat(scopes).isEmpty(); 47 | } 48 | 49 | @Test 50 | public void testParseScopesWithOneScope_shouldReturn() throws Exception { 51 | Set scopes = Scope.parseScopes(Scope.HISTORY.getBitValue()); 52 | 53 | assertThat(scopes).contains(Scope.HISTORY); 54 | } 55 | 56 | @Test 57 | public void testParseScopesWithMultipleGeneralScopes_shouldReturn() throws Exception { 58 | Set scopes = Scope.parseScopes(Scope.HISTORY.getBitValue() | Scope.PROFILE.getBitValue()); 59 | 60 | assertThat(scopes).contains(Scope.HISTORY, Scope.PROFILE); 61 | } 62 | 63 | @Test 64 | public void testParseScopesWithMixLevelScopes_shouldReturn() throws Exception { 65 | Set scopes = Scope.parseScopes( 66 | Scope.HISTORY.getBitValue() | Scope.REQUEST.getBitValue() | Scope.PROFILE.getBitValue()); 67 | 68 | assertThat(scopes).contains(Scope.HISTORY, Scope.REQUEST, Scope.PROFILE); 69 | } 70 | 71 | @Test 72 | public void testCustomScopes_shouldIgnore() throws Exception { 73 | String scopeString = "history profile test"; 74 | Set scopes = Scope.parseScopes(scopeString); 75 | assertThat(scopes).contains(Scope.HISTORY, Scope.PROFILE); 76 | assertThat(scopes.size()).isEqualTo(2); 77 | } 78 | 79 | @Test 80 | public void testToStandardStringOneScope_noSpace() { 81 | Collection scopes = Arrays.asList(Scope.HISTORY); 82 | 83 | assertThat(Scope.toStandardString(scopes)).isEqualTo("history"); 84 | } 85 | 86 | @Test 87 | public void testToStandardStringMultiScopes_spaceDelimited() { 88 | Collection scopes = Arrays.asList(Scope.HISTORY, Scope.ALL_TRIPS); 89 | 90 | assertThat(Scope.toStandardString(scopes)).isEqualTo("history all_trips"); 91 | } 92 | 93 | @Test 94 | public void testParseOneScope_shouldCreateCollection() { 95 | assertThat(Scope.parseScopes("all_trips")).contains(Scope.ALL_TRIPS); 96 | } 97 | 98 | @Test 99 | public void testParseMultiScopes_shouldCreateCollection() { 100 | assertThat(Scope.parseScopes("history all_trips")).contains(Scope.HISTORY, Scope.ALL_TRIPS); 101 | } 102 | } -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/auth/internal/OAuth2ServiceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth.internal; 24 | 25 | import com.squareup.moshi.Moshi; 26 | import com.uber.sdk.core.WireMockTest; 27 | import com.uber.sdk.core.auth.AccessToken; 28 | 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | 32 | import okhttp3.OkHttpClient; 33 | import okhttp3.logging.HttpLoggingInterceptor; 34 | import retrofit2.Retrofit; 35 | import retrofit2.converter.moshi.MoshiConverterFactory; 36 | 37 | import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 38 | import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; 39 | import static com.github.tomakehurst.wiremock.client.WireMock.post; 40 | import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; 41 | import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 42 | import static org.assertj.core.api.Assertions.assertThat; 43 | 44 | 45 | public class OAuth2ServiceTest extends WireMockTest { 46 | 47 | private static final String REFRESH_TOKEN = "RANDOM1234REFRESHTOKEN"; 48 | private static final String CLIENT_ID = "MYCLIENTID123"; 49 | private static final String REQUEST_BODY = "refresh_token=" + REFRESH_TOKEN + "&client_id=" + CLIENT_ID; 50 | 51 | private OAuth2Service oAuth2Service; 52 | 53 | @Before 54 | public void setUp() throws Exception { 55 | final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); 56 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); 57 | 58 | final OkHttpClient okHttpClient = new OkHttpClient.Builder() 59 | .addInterceptor(loggingInterceptor) 60 | .build(); 61 | 62 | final Moshi moshi = new Moshi.Builder().add(new OAuthScopesAdapter()).build(); 63 | 64 | oAuth2Service = new Retrofit.Builder().baseUrl("http://localhost:" + wireMockRule.port()) 65 | .client(okHttpClient) 66 | .addConverterFactory(MoshiConverterFactory.create(moshi)) 67 | .build() 68 | .create(OAuth2Service.class); 69 | } 70 | 71 | @Test 72 | public void testRefresh_whenSuccessful() throws Exception { 73 | stubFor(post(urlEqualTo("/token")) 74 | .withRequestBody(equalTo(REQUEST_BODY)) 75 | .willReturn(aResponse() 76 | .withBodyFile("token_token.json"))); 77 | 78 | AccessToken accessToken = oAuth2Service.refresh(REFRESH_TOKEN, CLIENT_ID).execute().body(); 79 | 80 | assertThat(accessToken.getExpiresIn()).isEqualTo(2592000); 81 | assertThat(accessToken.getToken()).isEqualTo("Access999Token"); 82 | assertThat(accessToken.getRefreshToken()).isEqualTo("888RefreshToken"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/auth/internal/OAuthScopesAdapterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.auth.internal; 24 | 25 | import com.squareup.moshi.JsonAdapter; 26 | import com.squareup.moshi.Moshi; 27 | import com.uber.sdk.core.auth.AccessToken; 28 | import com.uber.sdk.core.auth.Scope; 29 | 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | 33 | import java.util.Arrays; 34 | import java.util.Collection; 35 | 36 | import static org.assertj.core.api.Assertions.assertThat; 37 | 38 | public class OAuthScopesAdapterTest { 39 | private static final String ACCESS_TOKEN = "{" + 40 | "\"last_authenticated\":1464137596," + 41 | "\"access_token\":\"Access999Token\"," + 42 | "\"expires_in\":2592000," + 43 | "\"token_type\":\"Bearer\"," + 44 | "\"scope\":\"request all_trips profile\"," + 45 | "\"refresh_token\":\"888RefreshToken\"" + 46 | "}"; 47 | 48 | private JsonAdapter jsonAdapter; 49 | 50 | @Before 51 | public void setUp() { 52 | Moshi moshi = new Moshi.Builder().add(new OAuthScopesAdapter()).build(); 53 | 54 | jsonAdapter = moshi.adapter(AccessToken.class); 55 | } 56 | 57 | @Test 58 | public void fromJson() throws Exception { 59 | AccessToken accessToken = jsonAdapter.fromJson(ACCESS_TOKEN); 60 | assertThat(accessToken.getToken()).isEqualTo("Access999Token"); 61 | assertThat(accessToken.getExpiresIn()).isEqualTo(2592000); 62 | assertThat(accessToken.getRefreshToken()).isEqualTo("888RefreshToken"); 63 | assertThat(accessToken.getScopes()).contains(Scope.REQUEST, Scope.ALL_TRIPS, Scope.PROFILE); 64 | } 65 | 66 | @Test 67 | public void toJson() throws Exception { 68 | AccessToken accessToken = new AccessToken(2592000, 69 | Arrays.asList(Scope.REQUEST, Scope.ALL_TRIPS, Scope.PROFILE), 70 | "Access999Token", "888RefreshToken", "Bearer"); 71 | 72 | Collection scopes = accessToken.getScopes(); 73 | String json = jsonAdapter.toJson(accessToken); 74 | assertThat(json).containsOnlyOnce("\"scope\":\"" + Scope.toStandardString(scopes) + "\""); 75 | } 76 | } -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/client/SessionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client; 24 | 25 | import com.uber.sdk.core.auth.Authenticator; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.assertEquals; 30 | import static org.mockito.Mockito.mock; 31 | 32 | public class SessionTest { 33 | 34 | @Test 35 | public void buildSession_containsMembersFromConstructor() throws Exception { 36 | Authenticator authenticator = mock(Authenticator.class); 37 | SessionConfiguration configuration = mock(SessionConfiguration.class); 38 | Session session = new Session(authenticator) { }; 39 | assertEquals(authenticator, session.getAuthenticator()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/client/internal/ApiInterceptorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client.internal; 24 | 25 | import com.uber.sdk.core.auth.Authenticator; 26 | import com.uber.sdk.core.client.SessionConfiguration; 27 | 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | import org.mockito.ArgumentCaptor; 31 | import org.mockito.Mock; 32 | import org.mockito.MockitoAnnotations; 33 | 34 | import java.util.Locale; 35 | 36 | import okhttp3.Interceptor; 37 | import okhttp3.Request; 38 | 39 | import static com.uber.sdk.core.client.internal.ApiInterceptor.HEADER_ACCESS_TOKEN; 40 | import static com.uber.sdk.core.client.internal.ApiInterceptor.LIB_VERSION; 41 | import static org.junit.Assert.assertEquals; 42 | import static org.mockito.Matchers.any; 43 | import static org.mockito.Mockito.mock; 44 | import static org.mockito.Mockito.verify; 45 | import static org.mockito.Mockito.when; 46 | 47 | public class ApiInterceptorTest { 48 | 49 | @Mock 50 | Authenticator authenticator; 51 | 52 | @Mock 53 | Interceptor.Chain chain; 54 | 55 | 56 | @Before 57 | public void setup() { 58 | MockitoAnnotations.initMocks(this); 59 | 60 | } 61 | 62 | @Test 63 | public void testIntercept() throws Exception { 64 | ArgumentCaptor captor = ArgumentCaptor.forClass(Request.class); 65 | ApiInterceptor interceptor = new ApiInterceptor(authenticator); 66 | when(chain.request()).thenReturn(new Request.Builder().url("http://test").build()); 67 | when(chain.proceed(captor.capture())).thenReturn(null); 68 | SessionConfiguration config = mock(SessionConfiguration.class); 69 | when(config.getLocale()).thenReturn(Locale.US); 70 | when(authenticator.getSessionConfiguration()).thenReturn(config); 71 | 72 | interceptor.intercept(chain); 73 | 74 | verify(authenticator).signRequest(any(Request.Builder.class)); 75 | Request request = captor.getValue(); 76 | assertEquals(Locale.US.getLanguage(), request.headers().get(ApiInterceptor.HEADER_ACCEPT_LANGUAGE)); 77 | assertEquals("Java Rides SDK v" + LIB_VERSION, request.headers().get(ApiInterceptor.HEADER_USER_AGENT)); 78 | } 79 | 80 | @Test 81 | public void testSetAuthorizationHeader_withExistingToken() { 82 | Request.Builder builder = new Request.Builder().url("http://test"); 83 | builder.header(HEADER_ACCESS_TOKEN, "accessToken"); 84 | ApiInterceptor.setAuthorizationHeader(builder, "accessToken2"); 85 | Request request = builder.build(); 86 | assertEquals("accessToken2", request.header(HEADER_ACCESS_TOKEN)); 87 | } 88 | 89 | @Test 90 | public void testSetAuthorizationHeader_withoutExistingToken() { 91 | Request.Builder builder = new Request.Builder().url("http://test"); 92 | ApiInterceptor.setAuthorizationHeader(builder, "accessToken"); 93 | Request request = builder.build(); 94 | assertEquals("accessToken", request.header(HEADER_ACCESS_TOKEN)); 95 | } 96 | 97 | @Test 98 | public void testGetAuthorizationHeader() { 99 | Request request = new Request.Builder() 100 | .url("http://test") 101 | .header(HEADER_ACCESS_TOKEN, "accessToken") 102 | .build(); 103 | 104 | assertEquals("accessToken", ApiInterceptor.getAuthorizationHeader(request)); 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/client/internal/BigDecimalAdapterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.core.client.internal; 24 | 25 | import com.squareup.moshi.JsonAdapter; 26 | import com.squareup.moshi.Moshi; 27 | 28 | import org.junit.Test; 29 | 30 | import java.io.IOException; 31 | import java.math.BigDecimal; 32 | 33 | import static org.assertj.core.api.Assertions.assertThat; 34 | 35 | public class BigDecimalAdapterTest { 36 | 37 | @Test 38 | public void toJson_shouldWork() { 39 | Moshi moshi = new Moshi.Builder().add(new BigDecimalAdapter()).build(); 40 | JsonAdapter adapter = moshi.adapter(BigDecimalModel.class); 41 | BigDecimalModel bigDecimalModel = new BigDecimalModel(); 42 | bigDecimalModel.presentDecimal = new BigDecimal("1.23"); 43 | String json = adapter.toJson(bigDecimalModel); 44 | assertThat(json).isEqualTo("{\"presentDecimal\":1.23}"); 45 | } 46 | 47 | @Test 48 | public void fromJson_shouldHandleAbsent_andNull_andNonNullValues() throws IOException { 49 | Moshi moshi = new Moshi.Builder().add(new BigDecimalAdapter()).build(); 50 | 51 | JsonAdapter adapter = moshi.adapter(BigDecimalModel.class); 52 | BigDecimalModel model = adapter.fromJson("{\"nullDecimal\":null,\"presentDecimal\":1.23}"); 53 | assertThat(model.absentDecimal).isNull(); 54 | assertThat(model.nullDecimal).isNull(); 55 | assertThat(model.presentDecimal).isEqualTo(new BigDecimal("1.23")); 56 | } 57 | 58 | private static class BigDecimalModel { 59 | 60 | private BigDecimal absentDecimal; 61 | private BigDecimal nullDecimal; 62 | private BigDecimal presentDecimal; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /uber-core/src/test/java/com/uber/sdk/core/client/internal/RefreshAuthenticatorTest.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.core.client.internal; 2 | 3 | import com.uber.sdk.core.auth.Authenticator; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.mockito.Mock; 8 | import org.mockito.MockitoAnnotations; 9 | 10 | import okhttp3.Protocol; 11 | import okhttp3.Request; 12 | import okhttp3.Response; 13 | 14 | import static org.junit.Assert.assertFalse; 15 | import static org.junit.Assert.assertNotNull; 16 | import static org.junit.Assert.assertNull; 17 | import static org.junit.Assert.assertTrue; 18 | import static org.mockito.Matchers.eq; 19 | import static org.mockito.Mockito.doReturn; 20 | import static org.mockito.Mockito.never; 21 | import static org.mockito.Mockito.spy; 22 | import static org.mockito.Mockito.verify; 23 | 24 | public class RefreshAuthenticatorTest { 25 | 26 | @Mock 27 | Authenticator authenticator; 28 | 29 | Request request; 30 | 31 | Response response; 32 | 33 | RefreshAuthenticator refreshAuthenticator; 34 | 35 | @Before 36 | public void setup() { 37 | MockitoAnnotations.initMocks(this); 38 | 39 | request = new Request.Builder().url("http://test").build(); 40 | response = new Response.Builder() 41 | .request(request) 42 | .code(200) 43 | .protocol(Protocol.HTTP_1_1) 44 | .build(); 45 | 46 | refreshAuthenticator = spy(new RefreshAuthenticator(authenticator)); 47 | } 48 | 49 | @Test 50 | public void testAuthenticate_callsAuthenticatorRefresh() throws Exception { 51 | refreshAuthenticator.authenticate(null, response); 52 | verify(authenticator).refresh(eq(response)); 53 | } 54 | } -------------------------------------------------------------------------------- /uber-core/src/test/resources/__files/token_token.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_authenticated": 1464137596, 3 | "access_token": "Access999Token", 4 | "expires_in": 2592000, 5 | "token_type": "Bearer", 6 | "scope": "request all_trips profile ride_widgets history places history_lite", 7 | "refresh_token": "888RefreshToken" 8 | } 9 | -------------------------------------------------------------------------------- /uber-rides/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | apply plugin: 'java' 24 | 25 | targetCompatibility = JavaVersion.VERSION_1_7 26 | sourceCompatibility = JavaVersion.VERSION_1_7 27 | 28 | dependencies { 29 | compile project(':uber-core') 30 | 31 | testCompile deps.test.junit 32 | testCompile deps.test.assertj 33 | testCompile deps.test.hamcrest 34 | testCompile deps.test.mockito 35 | testCompile deps.test.wiremock 36 | } 37 | 38 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') -------------------------------------------------------------------------------- /uber-rides/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2016 Uber Technologies, Inc. 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in 12 | # all copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | # THE SOFTWARE. 21 | # 22 | 23 | POM_NAME=Uber Java Rides SDK 24 | POM_ARTIFACT_ID=uber-rides 25 | POM_DESCRIPTION=The Uber Rides API SDK 26 | POM_PACKAGING=jar -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/error/ApiError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | import javax.annotation.Nonnull; 29 | import javax.annotation.Nullable; 30 | 31 | /** 32 | * Represents an error response from the Uber API. 33 | */ 34 | public final class ApiError { 35 | 36 | @Nullable 37 | private final Meta meta; 38 | @Nonnull 39 | private final List errors; 40 | 41 | public ApiError(@Nullable Meta meta, @Nonnull List clientErrors) { 42 | this.meta = meta; 43 | this.errors = clientErrors; 44 | } 45 | 46 | ApiError(@Nonnull CompatibilityApiError oldApiError, int statusCode) { 47 | this(oldApiError.code, statusCode, oldApiError.message); 48 | } 49 | 50 | ApiError(@Nullable String code, int statusCode, @Nullable String message) { 51 | this(null, Collections.singletonList(new ClientError(code, statusCode, message))); 52 | } 53 | 54 | /** 55 | * @return the {@link Meta} information about the error. 56 | */ 57 | @Nullable 58 | public Meta getMeta() { 59 | return meta; 60 | } 61 | 62 | /** 63 | * @return a list of {@link ClientError}s that occurred. 64 | */ 65 | @Nonnull 66 | public List getClientErrors() { 67 | return errors; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/error/ClientError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * A specific error describing what went wrong. 29 | */ 30 | public final class ClientError { 31 | 32 | @Nullable 33 | private final String code; 34 | private final int status; 35 | @Nullable 36 | private final String title; 37 | 38 | public ClientError(@Nullable String code, int status, @Nullable String title) { 39 | this.code = code; 40 | this.status = status; 41 | this.title = title; 42 | } 43 | 44 | /** 45 | * @return the code for a specific endpoint error. 46 | * See endpoint documentation 47 | * for possible values and possible resolutions. 48 | */ 49 | @Nullable 50 | public String getCode() { 51 | return code; 52 | } 53 | 54 | /** 55 | * @return the HTTP status code. 56 | */ 57 | public int getStatus() { 58 | return status; 59 | } 60 | 61 | /** 62 | * @return the description of the error. 63 | */ 64 | @Nullable 65 | public String getTitle() { 66 | return title; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/error/CompatibilityApiError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | /** 28 | * An error type no longer supported by the API. Used to convert to an {@link ApiError}. 29 | */ 30 | final class CompatibilityApiError { 31 | 32 | @Nonnull 33 | final String message; 34 | @Nonnull 35 | final String code; 36 | 37 | public CompatibilityApiError(@Nonnull String message, @Nonnull String code) { 38 | this.message = message; 39 | this.code = code; 40 | } 41 | 42 | public String getMessage() { 43 | return message; 44 | } 45 | 46 | public String getCode() { 47 | return code; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/error/ErrorParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import com.squareup.moshi.JsonAdapter; 26 | import com.squareup.moshi.JsonDataException; 27 | import com.squareup.moshi.Moshi; 28 | 29 | import java.io.IOException; 30 | 31 | import javax.annotation.Nonnull; 32 | import javax.annotation.Nullable; 33 | 34 | import retrofit2.Response; 35 | 36 | /** 37 | * Used to parse a {@link Response} to an {@link ApiError}. 38 | */ 39 | public final class ErrorParser { 40 | 41 | /** 42 | * Parses a {@link Response} into an {@link ApiError}. 43 | * 44 | * @param response the {@link Response} to parse. 45 | * @return an {@link ApiError} if parsable, or {@code null} if the response is not in error. 46 | */ 47 | @Nullable 48 | public static ApiError parseError(@Nonnull Response response) { 49 | if (response.isSuccessful()) { 50 | return null; 51 | } 52 | 53 | try { 54 | return parseError(response.errorBody().string(), response.code(), response.message()); 55 | } catch (IOException e) { 56 | return new ApiError(null, response.code(), "Unknown Error"); 57 | } 58 | } 59 | 60 | /** 61 | * Parses an error body and code into an {@link ApiError}. 62 | * 63 | * @param errorBody the error body from the response. 64 | * @param statusCode the status code from the response. 65 | * @param message the message from the response. 66 | * @return the parsed {@link ApiError}. 67 | */ 68 | @Nonnull 69 | public static ApiError parseError(@Nullable String errorBody, int statusCode, @Nullable String message) { 70 | if (errorBody == null) { 71 | return new ApiError(null, statusCode, message); 72 | } 73 | 74 | Moshi moshi = new Moshi.Builder().build(); 75 | JsonAdapter oldApiErrorJsonAdapter = moshi.adapter(CompatibilityApiError.class).failOnUnknown(); 76 | try { 77 | return new ApiError(oldApiErrorJsonAdapter.fromJson(errorBody), statusCode); 78 | } catch (IOException | JsonDataException exception) { 79 | // Not old type of error, move on 80 | } 81 | 82 | JsonAdapter apiErrorJsonAdapter = moshi.adapter(ApiError.class).failOnUnknown(); 83 | try { 84 | return apiErrorJsonAdapter.fromJson(errorBody); 85 | } catch (IOException | JsonDataException exception) { 86 | return new ApiError(null, statusCode, "Unknown Error"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/error/Meta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * Meta information about an {@link ApiError}. See specific endpoint 29 | * documentation for what can be contained here. 30 | */ 31 | public class Meta { 32 | 33 | @Nullable 34 | private final SurgeConfirmation surge_confirmation; 35 | 36 | public Meta(@Nullable SurgeConfirmation surgeConfirmation) { 37 | this.surge_confirmation = surgeConfirmation; 38 | } 39 | 40 | /** 41 | * @return The {@link SurgeConfirmation} from the meta data if it was present. 42 | */ 43 | @Nullable 44 | public SurgeConfirmation getSurgeConfirmation() { 45 | return surge_confirmation; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/error/SurgeConfirmation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import com.uber.sdk.rides.client.model.RideRequestParameters; 26 | import com.uber.sdk.rides.client.services.RidesService; 27 | 28 | import javax.annotation.Nonnull; 29 | 30 | /** 31 | * Used to confirm surge pricing when {@link RidesService#requestRide(RideRequestParameters)} has failed. See ride 32 | * request documentation for more 33 | * info. 34 | */ 35 | public final class SurgeConfirmation { 36 | 37 | @Nonnull 38 | public final String href; 39 | @Nonnull 40 | public final String surge_confirmation_id; 41 | public final float multiplier; 42 | public final long expires_at; 43 | 44 | public SurgeConfirmation( 45 | @Nonnull String href, 46 | @Nonnull String surgeConfirmationId, 47 | float multiplier, 48 | long expiresAt) { 49 | this.href = href; 50 | this.surge_confirmation_id = surgeConfirmationId; 51 | this.multiplier = multiplier; 52 | this.expires_at = expiresAt; 53 | } 54 | 55 | /** 56 | * @return the href to be presented to the user for surge confirmation. 57 | */ 58 | @Nonnull 59 | public String getHref() { 60 | return href; 61 | } 62 | 63 | /** 64 | * @return the unique identifier of this surge confirmation. 65 | */ 66 | @Nonnull 67 | public String getSurgeConfirmationId() { 68 | return surge_confirmation_id; 69 | } 70 | 71 | /** 72 | * @return the surge multiplier. 73 | */ 74 | public float getMultiplier() { 75 | return multiplier; 76 | } 77 | 78 | /** 79 | * @return the UTC expiration time for this surge confirmation. 80 | */ 81 | public long getExpiresAt() { 82 | return expires_at; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Driver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * The vehicle's driver. 29 | */ 30 | public class Driver { 31 | 32 | private String phone_number; 33 | @Nullable 34 | private String sms_number; 35 | @Nullable 36 | private Float rating; 37 | @Nullable 38 | private String picture_url; 39 | private String name; 40 | 41 | /** 42 | * The formatted phone number for contacting the driver. 43 | */ 44 | public String getPhoneNumber() { 45 | return phone_number; 46 | } 47 | 48 | /** 49 | * The formatted sms number for contacting the driver. 50 | */ 51 | @Nullable 52 | public String getSmsNumber() { 53 | return sms_number; 54 | } 55 | 56 | /** 57 | * The driver's star rating out of 5 stars. 58 | */ 59 | @Nullable 60 | public Float getRating() { 61 | return rating; 62 | } 63 | 64 | /** 65 | * The URL to the photo of the driver. 66 | */ 67 | @Nullable 68 | public String getPictureUrl() { 69 | return picture_url; 70 | } 71 | 72 | /** 73 | * The first name of the driver. 74 | */ 75 | public String getName() { 76 | return name; 77 | } 78 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Location.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * Location in latitude and longitude in decimal notation. 29 | */ 30 | public class Location { 31 | 32 | private float latitude; 33 | private float longitude; 34 | @Nullable 35 | private Integer bearing; 36 | @Nullable 37 | private Integer eta; 38 | 39 | /** 40 | * Location must be created with a non-null latitude and longitude. 41 | */ 42 | private Location() {} 43 | 44 | /** 45 | * Constructor. 46 | * @param latitude The latitude in decimal notation. 47 | * @param longitude The longitude in decimal notation. 48 | */ 49 | public Location(float latitude, float longitude) { 50 | this.latitude = latitude; 51 | this.longitude = longitude; 52 | } 53 | 54 | /** 55 | * The latitude in decimal notation. 56 | */ 57 | public float getLatitude() { 58 | return latitude; 59 | } 60 | 61 | /** 62 | * The longitude in decimal notation. 63 | */ 64 | public float getLongitude() { 65 | return longitude; 66 | } 67 | 68 | /** 69 | * The current bearing of the vehicle in degrees (0-359). {@code null} if the bearing is 70 | * unknown or no associated bearing. 71 | */ 72 | @Nullable 73 | public Integer getBearing() { 74 | return bearing; 75 | } 76 | 77 | /** 78 | * If present, the ETA in minutes until this location is reached. 79 | */ 80 | @Nullable 81 | public Integer getEta() { 82 | return eta; 83 | } 84 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/PaymentMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * A user's Payment Method. See 29 | * Payment Methods 30 | * for more information. 31 | */ 32 | public class PaymentMethod { 33 | 34 | private String payment_method_id; 35 | private String type; 36 | @Nullable 37 | private String description; 38 | 39 | /** 40 | * Gets the unique identifier of a Payment Method 41 | */ 42 | public String getPaymentMethodId() { 43 | return payment_method_id; 44 | } 45 | 46 | /** 47 | * Gets the type of Payment Method. See 48 | * Payment Method Details 49 | * for more information. 50 | */ 51 | public String getType() { 52 | return type; 53 | } 54 | 55 | /** 56 | * Gets the description of a Payment Method. 57 | */ 58 | @Nullable 59 | public String getDescription() { 60 | return description; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/PaymentMethodsResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Response object containing a user's Payment Methods. See 29 | * Payment Methods 30 | * for more information. 31 | */ 32 | public class PaymentMethodsResponse { 33 | 34 | private List payment_methods; 35 | private String last_used; 36 | 37 | /** 38 | * Gets a list of {@link PaymentMethod}s for a user. 39 | */ 40 | public List getPaymentMethods() { 41 | return payment_methods; 42 | } 43 | 44 | /** 45 | * Gets the identifier of the last used {@link PaymentMethod}. 46 | */ 47 | public String getLastUsedPaymentMethodId() { 48 | return last_used; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Place.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | /** 26 | * A user's Place. See 27 | * Places 28 | * for more information. 29 | */ 30 | public class Place { 31 | 32 | /** 33 | * Represents the defined Places for a user. 34 | */ 35 | public enum Places { 36 | HOME("home"), 37 | WORK("work"); 38 | 39 | private String placeId; 40 | 41 | Places(String placeId) { 42 | this.placeId = placeId; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return this.placeId; 48 | } 49 | } 50 | 51 | private String address; 52 | 53 | /** 54 | * Gets the address of the Place 55 | */ 56 | public String getAddress() { 57 | return address; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/PlaceParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nonnull; 26 | 27 | /** 28 | * Parameters that define a Place 29 | */ 30 | public class PlaceParameters { 31 | 32 | private String address; 33 | 34 | private PlaceParameters(@Nonnull String address) { 35 | this.address = address; 36 | } 37 | 38 | /** 39 | * Builder for place parameters 40 | */ 41 | public static class Builder { 42 | 43 | private String address; 44 | 45 | public Builder setAddress(@Nonnull String address) { 46 | this.address = address; 47 | return this; 48 | } 49 | 50 | public PlaceParameters build() { 51 | return new PlaceParameters(address); 52 | } 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/PriceEstimate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import java.math.BigDecimal; 26 | 27 | import javax.annotation.Nullable; 28 | 29 | /** 30 | * An estimated price for a product on the Uber platform. See 31 | * Price Estimates 32 | * for more information. 33 | */ 34 | public class PriceEstimate { 35 | 36 | private String product_id; 37 | @Nullable 38 | private String currency_code; 39 | private String display_name; 40 | private String estimate; 41 | @Nullable 42 | private BigDecimal low_estimate; 43 | @Nullable 44 | private BigDecimal high_estimate; 45 | @Nullable 46 | private Float surge_multiplier; 47 | @Nullable 48 | private Integer duration; 49 | @Nullable 50 | private Float distance; 51 | 52 | /** 53 | * Unique identifier representing a specific product for a given latitude & longitude. For 54 | * example, uberX in San Francisco will have a different product_id than uberX in Los Angeles. 55 | */ 56 | public String getProductId() { 57 | return product_id; 58 | } 59 | 60 | /** 61 | * ISO 4217 currency code. 62 | */ 63 | @Nullable 64 | public String getCurrencyCode() { 65 | return currency_code; 66 | } 67 | 68 | /** 69 | * Display name of product. 70 | */ 71 | public String getDisplayName() { 72 | return display_name; 73 | } 74 | 75 | /** 76 | * Formatted string of estimate in local currency of the start location. Estimate could be a 77 | * range, a single number (flat rate) or "Metered" for TAXI. 78 | */ 79 | public String getEstimate() { 80 | return estimate; 81 | } 82 | 83 | /** 84 | * Lower bound of the estimated price. 85 | */ 86 | @Nullable 87 | public BigDecimal getLowEstimate() { 88 | return low_estimate; 89 | } 90 | 91 | /** 92 | * Upper bound of the estimated price. 93 | */ 94 | @Nullable 95 | public BigDecimal getHighEstimate() { 96 | return high_estimate; 97 | } 98 | 99 | /** 100 | * Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price 101 | * estimate already factors in the surge multiplier. 102 | */ 103 | @Nullable 104 | public Float getSurgeMultiplier() { 105 | return surge_multiplier; 106 | } 107 | 108 | /** 109 | * Expected activity duration (in seconds). Always show duration in minutes. 110 | */ 111 | @Nullable 112 | public Integer getDuration() { 113 | return duration; 114 | } 115 | 116 | /** 117 | * Expected activity distance (in miles). 118 | */ 119 | @Nullable 120 | public Float getDistance() { 121 | return distance; 122 | } 123 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/PriceEstimatesResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Response object containing available price estimates. 29 | */ 30 | public class PriceEstimatesResponse { 31 | 32 | private List prices; 33 | 34 | /** 35 | * The price estimates. 36 | */ 37 | public List getPrices() { 38 | return prices; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | /** 26 | * A product representing a type of ride on the Uber platform. See 27 | * Products 28 | * for more information. 29 | */ 30 | public class Product { 31 | 32 | private String product_id; 33 | private String display_name; 34 | private String description; 35 | private int capacity; 36 | private String image; 37 | private boolean shared; 38 | private boolean upfront_fare_enabled; 39 | 40 | /** 41 | * A unique identifier representing a specific product for a given latitude & longitude. For 42 | * example, uberX in San Francisco will have a different product_id than uberX in Los Angeles. 43 | */ 44 | public String getProductId() { 45 | return product_id; 46 | } 47 | 48 | /** 49 | * Display name of product. 50 | */ 51 | public String getDisplayName() { 52 | return display_name; 53 | } 54 | 55 | /** 56 | * Description of product. 57 | */ 58 | public String getDescription() { 59 | return description; 60 | } 61 | 62 | /** 63 | * Capacity of product. For samples, 4 people. 64 | */ 65 | public int getCapacity() { 66 | return capacity; 67 | } 68 | 69 | /** 70 | * Image URL representing the product. 71 | */ 72 | public String getImage() { 73 | return image; 74 | } 75 | 76 | /** 77 | * @return {@code true} if the ride may be shared with others. 78 | */ 79 | public boolean isShared() { 80 | return shared; 81 | } 82 | 83 | /** 84 | * @return {code true} if this product is configured to work with upfront fares. 85 | */ 86 | public boolean isUpfrontFareEnabled(){ 87 | return upfront_fare_enabled; 88 | } 89 | } 90 | 91 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/ProductsResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Response object containing available products. 29 | */ 30 | public class ProductsResponse { 31 | 32 | private List products; 33 | 34 | /** 35 | * The products. 36 | */ 37 | public List getProducts() { 38 | return products; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Promotion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | /** 26 | * A promotion for a new user. See 27 | * Promotions for more 28 | * information. 29 | */ 30 | public class Promotion { 31 | 32 | private String display_text; 33 | private String localized_value; 34 | private String type; 35 | 36 | /** 37 | * A localized string we recommend to use when offering the promotion to users. 38 | */ 39 | public String getDisplayText() { 40 | return display_text; 41 | } 42 | 43 | /** 44 | * The value of the promotion that is available to a user in this location in the local 45 | * currency. 46 | */ 47 | public String getLocalizedValue() { 48 | return localized_value; 49 | } 50 | 51 | /** 52 | * The type of the promo which is either "trip_credit" or "account_credit". 53 | */ 54 | public String getType() { 55 | return type; 56 | } 57 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Ride.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import com.squareup.moshi.Json; 26 | 27 | import javax.annotation.Nullable; 28 | 29 | /** 30 | * An ongoing or completed ride. See 31 | * Requests 32 | * for more information. 33 | */ 34 | public class Ride { 35 | 36 | private String request_id; 37 | private Status status; 38 | @Nullable 39 | private Driver driver; 40 | @Nullable 41 | private Float surge_multiplier; 42 | @Nullable 43 | private Location location; 44 | @Nullable 45 | private Vehicle vehicle; 46 | private String product_id; 47 | private boolean shared; 48 | @Nullable 49 | private Location pickup; 50 | @Nullable 51 | private Location destination; 52 | 53 | /** 54 | * The unique ID of the ride. 55 | */ 56 | public String getRideId() { 57 | return request_id; 58 | } 59 | 60 | /** 61 | * The status of the ride indicating state. 62 | */ 63 | public Status getStatus() { 64 | return status; 65 | } 66 | 67 | /** 68 | * The object that contains driver details. 69 | */ 70 | @Nullable 71 | public Driver getDriver() { 72 | return driver; 73 | } 74 | 75 | /** 76 | * The object that contains the location information of the vehicle and driver. 77 | */ 78 | @Nullable 79 | public Location getLocation() { 80 | return location; 81 | } 82 | 83 | /** 84 | * The object that contains vehicle details. 85 | */ 86 | @Nullable 87 | public Vehicle getVehicle() { 88 | return vehicle; 89 | } 90 | 91 | /** 92 | * The surge pricing multiplier used to calculate the increased price of a Request. A multiplier 93 | * of 1.0 means surge pricing is not in effect. 94 | */ 95 | @Nullable 96 | public Float getSurgeMultiplier() { 97 | return surge_multiplier; 98 | } 99 | 100 | /** 101 | * The product ID associated to the Ride. 102 | */ 103 | public String getProductId() { 104 | return product_id; 105 | } 106 | 107 | /** 108 | * Indicates whether the ride is a shared ride or not. UberPool is an example of a shared ride. 109 | */ 110 | public boolean isShared() { 111 | return shared; 112 | } 113 | 114 | @Nullable 115 | public Location getPickup() { 116 | return pickup; 117 | } 118 | 119 | @Nullable 120 | public Location getDestination() { 121 | return destination; 122 | } 123 | 124 | /** 125 | * Represents all possible Ride statuses 126 | */ 127 | public enum Status { 128 | @Json(name = "processing") PROCESSING("processing"), 129 | @Json(name = "no_drivers_available") NO_DRIVERS_AVAILABLE("no_drivers_available"), 130 | @Json(name = "accepted") ACCEPTED("accepted"), 131 | @Json(name = "arriving") ARRIVING("arriving"), 132 | @Json(name = "in_progress") IN_PROGRESS("in_progress"), 133 | @Json(name = "driver_canceled") DRIVER_CANCELED("driver_canceled"), 134 | @Json(name = "rider_canceled") RIDER_CANCELED("rider_canceled"), 135 | @Json(name = "completed") COMPLETED("completed"); 136 | 137 | private String value; 138 | 139 | Status(String value) { 140 | this.value = value; 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/RideMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | /** 26 | * Contains a link to an updating webview for tracking the ride. See 27 | * Request Maps for more 28 | * information. 29 | */ 30 | public class RideMap { 31 | 32 | private String href; 33 | private String request_id; 34 | 35 | /** 36 | * The unique ID of the ride request. 37 | */ 38 | public String getRideId() { 39 | return request_id; 40 | } 41 | 42 | /** 43 | * The URL to the tracking map. 44 | */ 45 | public String getHref() { 46 | return href; 47 | } 48 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/RideReceipt.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | import java.util.List; 27 | 28 | /** 29 | * A receipt for a completed request. 30 | * See 31 | * Ride Request Receipt 32 | * for more information. 33 | */ 34 | public class RideReceipt { 35 | private String request_id; 36 | @Nullable 37 | private List charge_adjustments; 38 | private String subtotal; 39 | private String total_charged; 40 | @Nullable 41 | private Float total_owed; 42 | @Nullable 43 | private String currency_code; 44 | private String duration; 45 | private String distance; 46 | private String distance_label; 47 | 48 | /** 49 | * Gets the unique ID of the ride. 50 | */ 51 | public String getRideId() { 52 | return request_id; 53 | } 54 | 55 | /** 56 | * Gets the adjustments made to the charges such as promotions, and fees. 57 | */ 58 | public List getChargeAdjustments() { 59 | return charge_adjustments; 60 | } 61 | 62 | /** 63 | * Gets the summation of the normal_fare and surge_charge. 64 | */ 65 | public String getSubTotal() { 66 | return subtotal; 67 | } 68 | 69 | /** 70 | * Gets the total amount charged to the users payment method. 71 | * This is the the subtotal (split if applicable) with taxes included. 72 | */ 73 | public String getTotalCharged() { 74 | return total_charged; 75 | } 76 | 77 | /** 78 | * Gets the total amount still owed after attempting to charge the user. 79 | * May be {@code null} if amount was paid in full. 80 | */ 81 | @Nullable 82 | public Float getTotalOwed() { 83 | return total_owed; 84 | } 85 | 86 | /** 87 | * Gets the ISO 4217 currency code. 88 | */ 89 | @Nullable 90 | public String getCurrencyCode() { 91 | return currency_code; 92 | } 93 | 94 | /** 95 | * Gets the time duration of the trip in ISO 8601 HH:MM:SS format. 96 | */ 97 | public String getDuration() { 98 | return duration; 99 | } 100 | 101 | /** 102 | * Gets the distance of the trip charged. 103 | */ 104 | public String getDistance() { 105 | return distance; 106 | } 107 | 108 | /** 109 | * Gets the localized unit of distance. 110 | */ 111 | public String getDistanceLabel() { 112 | return distance_label; 113 | } 114 | 115 | public static class Charge { 116 | private String name; 117 | private float amount; 118 | private String type; 119 | 120 | /** 121 | * Gets the name of the charge. 122 | */ 123 | public String getName() { 124 | return name; 125 | } 126 | 127 | /** 128 | * Gets the amount of the charge. 129 | */ 130 | public float getAmount() { 131 | return amount; 132 | } 133 | 134 | /** 135 | * Gets the type of the charge. 136 | */ 137 | public String getType() { 138 | return type; 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/SandboxProductRequestParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * Parameters to update a sandbox product. 29 | */ 30 | public class SandboxProductRequestParameters { 31 | 32 | @Nullable private Float surge_multiplier; 33 | @Nullable private Boolean drivers_available; 34 | 35 | /** 36 | * Builder for product request parameters. 37 | */ 38 | public static class Builder { 39 | 40 | @Nullable private Float surgeMultiplier; 41 | @Nullable private Boolean driversAvailable; 42 | 43 | /** 44 | * Sets the surge multiplier to a Product should have when making a Request in the Sandbox. 45 | * A multiplier greater than or equal to 2.0 will require the two stage confirmation screen. 46 | * If {@link #driversAvailable} is false, it will override any multiplier set here (i.e. 47 | * there are no drivers to apply surge pricing to). 48 | */ 49 | public Builder setSurgeMultiplier(float surgeMultiplier) { 50 | this.surgeMultiplier = surgeMultiplier; 51 | return this; 52 | } 53 | 54 | /** 55 | * Sets the availability of drivers to simulate. If false, attempts to make a Request in the 56 | * Sandbox will return a no_drivers_available error 57 | */ 58 | public Builder setDriversAvailable(boolean driversAvailable) { 59 | this.driversAvailable = driversAvailable; 60 | return this; 61 | } 62 | 63 | /** 64 | * Builds a {@link SandboxProductRequestParameters}. 65 | */ 66 | public SandboxProductRequestParameters build() { 67 | SandboxProductRequestParameters sandboxProductRequestParameters = new SandboxProductRequestParameters(); 68 | 69 | sandboxProductRequestParameters.surge_multiplier = surgeMultiplier; 70 | sandboxProductRequestParameters.drivers_available = driversAvailable; 71 | 72 | return sandboxProductRequestParameters; 73 | } 74 | } 75 | 76 | private SandboxProductRequestParameters() {} 77 | 78 | @Nullable 79 | public Float getSurgeMultiplier() { 80 | return surge_multiplier; 81 | } 82 | 83 | @Nullable 84 | public Boolean getDriversAvailable() { 85 | return drivers_available; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/SandboxRideRequestParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | /** 26 | * Parameters to update a sandbox ride. 27 | */ 28 | public class SandboxRideRequestParameters { 29 | 30 | private String status; 31 | 32 | /** 33 | * Builder for ride request parameters. 34 | */ 35 | public static class Builder { 36 | 37 | private String status; 38 | 39 | /** 40 | * Sets the value to change a Request's status to. 41 | */ 42 | public Builder setStatus(String status) { 43 | this.status = status; 44 | return this; 45 | } 46 | 47 | private void validate() { 48 | if (status == null) { 49 | throw new IllegalArgumentException("Status must be set."); 50 | } 51 | } 52 | 53 | /** 54 | * Builds a {@link SandboxRideRequestParameters}. 55 | */ 56 | public SandboxRideRequestParameters build() { 57 | validate(); 58 | 59 | SandboxRideRequestParameters sandboxRideRequestParameters = new SandboxRideRequestParameters(); 60 | sandboxRideRequestParameters.status = status; 61 | 62 | return sandboxRideRequestParameters; 63 | } 64 | } 65 | 66 | private SandboxRideRequestParameters() {} 67 | 68 | /** 69 | * The sandbox status to set. 70 | */ 71 | public String getStatus() { 72 | return status; 73 | } 74 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/TimeEstimate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * An estimated time for a product on the Uber platform. See 29 | * Time Estimates 30 | * for more information. 31 | */ 32 | public class TimeEstimate { 33 | 34 | private String product_id; 35 | private String display_name; 36 | @Nullable 37 | private Integer estimate; 38 | 39 | /** 40 | * Unique identifier representing a specific product for a given latitude & longitude. For 41 | * example, uberX in San Francisco will have a different product_id than uberX in Los Angeles. 42 | */ 43 | public String getProductId() { 44 | return product_id; 45 | } 46 | 47 | /** 48 | * Display name of product. 49 | */ 50 | public String getDisplayName() { 51 | return display_name; 52 | } 53 | 54 | /** 55 | * ETA for the product (in seconds). Always show estimate in minutes. 56 | */ 57 | @Nullable 58 | public Integer getEstimate() { 59 | return estimate; 60 | } 61 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/TimeEstimatesResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Response object containing time estimates. 29 | */ 30 | public class TimeEstimatesResponse { 31 | 32 | private List times; 33 | 34 | /** 35 | * The time estimates. 36 | */ 37 | public List getTimes() { 38 | return times; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/UserActivityPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Represents a page of user activities. 29 | */ 30 | public class UserActivityPage { 31 | 32 | private int offset; 33 | private int limit; 34 | private int count; 35 | private List history; 36 | 37 | /** 38 | * The user activities. 39 | */ 40 | public List getUserActivities() { 41 | return history; 42 | } 43 | 44 | /** 45 | * Position in pagination. 46 | */ 47 | public int getOffset() { 48 | return offset; 49 | } 50 | 51 | /** 52 | * Number of items to retrieve (50 max). 53 | */ 54 | public int getLimit() { 55 | return limit; 56 | } 57 | 58 | /** 59 | * Total number of items available. 60 | */ 61 | public int getCount() { 62 | return count; 63 | } 64 | } -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/UserProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | /** 26 | * A user's profile. See 27 | * User Profile for more information. 28 | */ 29 | public class UserProfile { 30 | 31 | private String first_name; 32 | private String last_name; 33 | private String email; 34 | private String picture; 35 | private String promo_code; 36 | private String uuid; 37 | 38 | /** 39 | * First name of the Uber user. 40 | */ 41 | public String getFirstName() { 42 | return first_name; 43 | } 44 | 45 | /** 46 | * Last name of the Uber user. 47 | */ 48 | public String getLastName() { 49 | return last_name; 50 | } 51 | 52 | /** 53 | * Email address of the Uber user. 54 | */ 55 | public String getEmail() { 56 | return email; 57 | } 58 | 59 | /** 60 | * Image URL of the Uber user. 61 | */ 62 | public String getPicture() { 63 | return picture; 64 | } 65 | 66 | /** 67 | * Promo code of the Uber user. 68 | */ 69 | public String getPromoCode() { 70 | return promo_code; 71 | } 72 | 73 | /** 74 | * Unique identifier of the Uber user. 75 | */ 76 | public String getUuid() { 77 | return uuid; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /uber-rides/src/main/java/com/uber/sdk/rides/client/model/Vehicle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.model; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | /** 28 | * An Uber vehicle. 29 | */ 30 | public class Vehicle { 31 | 32 | private String make; 33 | private String model; 34 | @Nullable 35 | private String license_plate; 36 | @Nullable 37 | private String picture_url; 38 | 39 | /** 40 | * The vehicle make or brand. 41 | */ 42 | public String getMake() { 43 | return make; 44 | } 45 | 46 | /** 47 | * The vehicle model or type. 48 | */ 49 | public String getModel() { 50 | return model; 51 | } 52 | 53 | /** 54 | * The license plate number of the vehicle. 55 | */ 56 | @Nullable 57 | public String getLicensePlate() { 58 | return license_plate; 59 | } 60 | 61 | /** 62 | * The URL to the photo of the vehicle. 63 | */ 64 | @Nullable 65 | public String getPictureUrl() { 66 | return picture_url; 67 | } 68 | } -------------------------------------------------------------------------------- /uber-rides/src/test/java/com/uber/sdk/rides/WireMockTest.java: -------------------------------------------------------------------------------- 1 | package com.uber.sdk.rides; 2 | 3 | import com.github.tomakehurst.wiremock.common.ConsoleNotifier; 4 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 5 | import com.github.tomakehurst.wiremock.junit.WireMockRule; 6 | 7 | import org.junit.Rule; 8 | 9 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; 10 | 11 | public class WireMockTest { 12 | 13 | protected static WireMockConfiguration WIRE_MOCK_CONFIG = wireMockConfig() 14 | .notifier(new ConsoleNotifier(true)) 15 | .dynamicPort(); 16 | 17 | @Rule 18 | public WireMockRule wireMockRule = new WireMockRule(WIRE_MOCK_CONFIG); 19 | } 20 | -------------------------------------------------------------------------------- /uber-rides/src/test/java/com/uber/sdk/rides/client/error/ErrorParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Uber Technologies, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | package com.uber.sdk.rides.client.error; 24 | 25 | import org.junit.Test; 26 | 27 | import java.util.List; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | import static org.mockito.Mockito.mock; 31 | 32 | public class ErrorParserTest { 33 | 34 | @Test 35 | public void parseError_whenSuccessfulResponse_shouldReturnNull() { 36 | ApiError apiError = ErrorParser.parseError(null, 404, "Not Found"); 37 | assertThat(apiError.getMeta()).isNull(); 38 | 39 | assertError(apiError.getClientErrors(), null, 404, "Not Found"); 40 | } 41 | 42 | @Test 43 | public void parseError_whenOldError_shouldReturnProperApiError() { 44 | String body = "{\"message\":\"Unable to find product thisIsNotAProductId\",\"code\":\"not_found\"}"; 45 | ApiError apiError = ErrorParser.parseError(body, 404, "Not Found"); 46 | assertThat(apiError.getMeta()).isNull(); 47 | assertError(apiError.getClientErrors(), "not_found", 404, "Unable to find product thisIsNotAProductId"); 48 | } 49 | 50 | @Test 51 | public void parseError_whenErrorWithEmptyMeta_shouldReturnErrorWithMetaButNoCofirmation() { 52 | String body = "{\"meta\":{},\"errors\":[{\"status\":404,\"code\":\"unknown_place_id\",\"title\":\"Only " 53 | + "\\\"home\\\" and \\\"work\\\" are allowed.\"}]}"; 54 | ApiError apiError = ErrorParser.parseError(body, 404, "Not Found"); 55 | assertThat(apiError.getMeta().getSurgeConfirmation()).isNull(); 56 | assertError(apiError.getClientErrors(), "unknown_place_id", 404, "Only \"home\" and \"work\" are allowed."); 57 | } 58 | 59 | @Test 60 | public void parseError_whenErrorWithSurge_shouldReturnFullError() { 61 | String body = "{\"meta\":{\"surge_confirmation\":{\"href\":\"https:\\/\\/api.uber.com\\/v1\\/surge-confirmations\\/a9ca7bf4-315c-4a8d-86a4-1697b7b94de4\",\"expires_at\":1464118311,\"multiplier\":2.1,\"surge_confirmation_id\":\"a9ca7bf4-315c-4a8d-86a4-1697b7b94de4\"}},\"errors\":[{\"status\":409,\"code\":\"surge\",\"title\":\"Surge pricing is currently in effect for this product.\"}]}"; 62 | ApiError apiError = ErrorParser.parseError(body, 409, "Unavailable"); 63 | 64 | SurgeConfirmation surgeConfirmation = apiError.getMeta().getSurgeConfirmation(); 65 | assertThat(surgeConfirmation.getHref()).isEqualTo("https://api.uber.com/v1/surge-confirmations/a9ca7bf4-315c-4a8d-86a4-1697b7b94de4"); 66 | assertThat(surgeConfirmation.getMultiplier()).isEqualTo(2.1f); 67 | assertThat(surgeConfirmation.getExpiresAt()).isEqualTo(1464118311); 68 | assertThat(surgeConfirmation.getSurgeConfirmationId()).isEqualTo("a9ca7bf4-315c-4a8d-86a4-1697b7b94de4"); 69 | 70 | assertError(apiError.getClientErrors(), "surge", 409, "Surge pricing is currently in effect for this product."); 71 | } 72 | 73 | @Test 74 | public void parseError_whenUnknownError_shouldReturnKnownError() { 75 | String body = "{\"error\":\"This is not a supported Error\",\"random\":\"random field\"}"; 76 | ApiError apiError = ErrorParser.parseError(body, 416, "ThisWasTheHttpMessage"); 77 | 78 | assertError(apiError.getClientErrors(), null, 416, "Unknown Error"); 79 | } 80 | 81 | private void assertError(List clientErrors, String code, int status, String title) { 82 | assertThat(clientErrors).hasSize(1); 83 | ClientError clientError = clientErrors.get(0); 84 | assertThat(clientError.getCode()).isEqualTo(code); 85 | assertThat(clientError.getStatus()).isEqualTo(status); 86 | assertThat(clientError.getTitle()).isEqualTo(title); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/products.json: -------------------------------------------------------------------------------- 1 | { 2 | "products": [ 3 | { 4 | "capacity": 2, 5 | "product_id": "26546650-e557-4a7b-86e7-6a3942445247", 6 | "price_details": null, 7 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-uberpool.png", 8 | "shared": true, 9 | "short_description": "POOL", 10 | "display_name": "uberPOOL", 11 | "description": "Share the ride, split the cost.", 12 | "upfront_fare_enabled": true 13 | }, 14 | { 15 | "capacity": 4, 16 | "product_id": "a1111c8c-c720-46c3-8534-2fcdd730040d", 17 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-uberx.png", 18 | "shared": false, 19 | "short_description": "uberX", 20 | "display_name": "uberX", 21 | "description": "The low-cost Uber", 22 | "upfront_fare_enabled": true 23 | }, 24 | { 25 | "capacity": 6, 26 | "product_id": "821415d8-3bd5-4e27-9604-194e4359a449", 27 | "image": "https://uber-static.s3.amazonaws.com/car-types/mono/mono-uberxl2-2.png", 28 | "shared": false, 29 | "short_description": "uberXL", 30 | "display_name": "uberXL", 31 | "description": "Low-cost rides for large groups", 32 | "upfront_fare_enabled": true 33 | }, 34 | { 35 | "capacity": 4, 36 | "product_id": "57c0ff4e-1493-4ef9-a4df-6b961525cf92", 37 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-uberselect.png", 38 | "shared": false, 39 | "short_description": "SELECT", 40 | "display_name": "UberSELECT", 41 | "description": "A step above the every day", 42 | "upfront_fare_enabled": true 43 | }, 44 | { 45 | "capacity": 4, 46 | "product_id": "d4abaae7-f4d6-4152-91cc-77523e8165a4", 47 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-black.png", 48 | "shared": false, 49 | "short_description": "BLACK CAR", 50 | "display_name": "UberBLACK", 51 | "description": "The original Uber", 52 | "upfront_fare_enabled": true 53 | }, 54 | { 55 | "capacity": 6, 56 | "product_id": "8920cb5e-51a4-4fa4-acdf-dd86c5e18ae0", 57 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-suv.png", 58 | "shared": false, 59 | "short_description": "SUV", 60 | "display_name": "UberSUV", 61 | "description": "Room for everyone", 62 | "upfront_fare_enabled": true 63 | }, 64 | { 65 | "capacity": 4, 66 | "product_id": "ff5ed8fe-6585-4803-be13-3ca541235de3", 67 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-wheelchair.png", 68 | "shared": false, 69 | "short_description": "ASSIST", 70 | "display_name": "ASSIST", 71 | "description": "ASSIST", 72 | "upfront_fare_enabled": true 73 | }, 74 | { 75 | "capacity": 4, 76 | "product_id": "2832a1f5-cfc0-48bb-ab76-7ea7a62060e7", 77 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-wheelchair.png", 78 | "shared": false, 79 | "short_description": "WAV", 80 | "display_name": "uberWAV", 81 | "description": "Wheelchair Accessible Vehicles", 82 | "upfront_fare_enabled": true 83 | }, 84 | { 85 | "capacity": 4, 86 | "product_id": "3ab64887-4842-4c8e-9780-ccecd3a0391d", 87 | "price_details": null, 88 | "image": "http://d1a3f4spazzrp4.cloudfront.net/car-types/mono/mono-taxi.png", 89 | "shared": false, 90 | "short_description": "TAXI", 91 | "display_name": "uberTAXI", 92 | "description": "Taxi without the hassle", 93 | "upfront_fare_enabled": true 94 | } 95 | ] 96 | } -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/requests_current.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": "processing", 3 | "product_id": "a1111c8c-c720-46c3-8534-2fcdd730040d", 4 | "request_id": "6a964a88-5ed9-49a0-9be9-dd09ed8c9d7a", 5 | "driver": null, 6 | "location": null, 7 | "vehicle": null, 8 | "pickup":{ 9 | "latitude":37.7872486012, 10 | "longitude":-122.4026315287, 11 | "eta":5 12 | }, 13 | "destination":{ 14 | "latitude":37.7766874, 15 | "longitude":-122.394857, 16 | "eta":19 17 | }, 18 | "surge_multiplier": 1.0, 19 | "shared": false 20 | } -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/requests_current_UberPool.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": "processing", 3 | "product_id": "26546650-e557-4a7b-86e7-6a3942445247", 4 | "request_id": "7c658aac-3bbb-4d37-9520-9ad95f13deea", 5 | "driver": null, 6 | "location": null, 7 | "pickup":{ 8 | "latitude":37.7872486012, 9 | "longitude":-122.4026315287, 10 | "eta":5 11 | }, 12 | "destination":{ 13 | "latitude":37.7766874, 14 | "longitude":-122.394857, 15 | "eta":19 16 | }, 17 | "vehicle": null, 18 | "surge_multiplier": 1.0, 19 | "shared": true 20 | } -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/token_token.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_authenticated": 1464137596, 3 | "access_token": "Access999Token", 4 | "expires_in": 2592000, 5 | "token_type": "Bearer", 6 | "scope": "request all_trips profile ride_widgets history places history_lite", 7 | "refresh_token": "888RefreshToken" 8 | } 9 | -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/v1.2_request_estimate_UberPool.json: -------------------------------------------------------------------------------- 1 | { 2 | "fare": { 3 | "value": 9.99, 4 | "fare_id": "9b071e64ec5001d50afaa4f28ed7040450c10edc73fdc477844dfb6dd194263c", 5 | "expires_at": 1474919953, 6 | "display": "$9.99", 7 | "currency_code": "USD" 8 | }, 9 | "trip": { 10 | "distance_unit": "mile", 11 | "duration_estimate": 720, 12 | "distance_estimate": 1.88 13 | }, 14 | "pickup_estimate": 4 15 | } -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/v1_request_estimate_UberPool.json: -------------------------------------------------------------------------------- 1 | { 2 | "estimate": { 3 | "surge_confirmation_href": null, 4 | "high_estimate": 5, 5 | "fare_id": "2455e0e040da58e77babe4e32e4c771f89faf87778a95bc5aec2be406865ad30", 6 | "surge_confirmation_id": null, 7 | "minimum": null, 8 | "expires_at": 1466106805, 9 | "low_estimate": 4, 10 | "fare_breakdown": [], 11 | "surge_multiplier": 1.0, 12 | "display": "$4.87", 13 | "currency_code": "USD" 14 | }, 15 | "trip": { 16 | "distance_unit": "mile", 17 | "duration_estimate": 720, 18 | "distance_estimate": 1.88 19 | }, 20 | "pickup_estimate": 4 21 | } -------------------------------------------------------------------------------- /uber-rides/src/test/resources/__files/v1_requests_estimate.json: -------------------------------------------------------------------------------- 1 | { 2 | "estimate": { 3 | "surge_confirmation_href": null, 4 | "high_estimate": 10, 5 | "surge_confirmation_id": null, 6 | "minimum": 7, 7 | "low_estimate": 7, 8 | "fare_breakdown": [ 9 | { 10 | "high_amount": 2.0, 11 | "display_amount": "2.00", 12 | "display_name": "Base Fare", 13 | "low_amount": 2.0 14 | }, 15 | { 16 | "high_amount": 2.59, 17 | "display_amount": "1.94-2.59", 18 | "display_name": "Distance", 19 | "low_amount": 1.94 20 | }, 21 | { 22 | "high_amount": 1.55, 23 | "display_amount": "1.55", 24 | "display_name": "Booking Fee", 25 | "low_amount": 1.55 26 | }, 27 | { 28 | "high_amount": 3.08, 29 | "display_amount": "2.31-3.08", 30 | "display_name": "Time", 31 | "low_amount": 2.31 32 | } 33 | ], 34 | "surge_multiplier": 1.0, 35 | "display": "$7-10", 36 | "currency_code": "USD" 37 | }, 38 | "trip": { 39 | "distance_unit": "mile", 40 | "duration_estimate": 720, 41 | "distance_estimate": 1.88 42 | }, 43 | "pickup_estimate": 2 44 | } -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/estimate_ride_redirect: -------------------------------------------------------------------------------- 1 | {"token":"thisiseriouslynotarealtokeniswearhah.thisiseriouslynotarealtokeniswearhahcnkiLCJoaXN0b3J5X2xpdGUiXSwic3ViIjoiNzJjMWI5ODgtZDZlMC00MGMxLWEyODItZjRhZTdkZGFkNTZjIiwiaXNzIjoidWJlci1jbjEiLCJqdGkiOiIzNDRjNjBlZS03MWIyLTRjNTQtOWMyMi00Zjg1ZjI0NDY5MTUiLCJleHAiOjE0NTgyNTkyODEsImlhdCI6MTQ1NTY2NzI4MCwidWFjdCI6IlpFVzBIRWhvNHRJQ1kwN1ZTY2l5MDA2d3RjTXJteSIsIm5iZiI6MTQ1NTY2NzE5MCwiYXVkIjoiOHNENEU5WjA5UVpmdmVIcDUzellhMVFUYjdmLUFSeTAifQ.oxDnLd1urlbyeOI3P9lx9giw5MeVZqNEK2qgUYkJa4jd6lSMUC1NrvT_ybSfR6ZUPCmKHj6vtNb4pxMBLjJsF_vpW_4tW9sBHnvmrK7m9sObU4qhlBK1aHVTWWbeD5WjifSlPKbWjtsMHNH2vR2Yh6ZzpZS8UWwprYiwYT0BpY9lNwepbFE4ni8TSEvMnyG1jtMmMOp7T_H2ByBeQDqQgHrX-dQ3ecmyxpOTUvvTmSBLqNrZ0urbvAzISCz2aR6Xk9KmogE7qp85WhA04qjC1GNxVgsDjCNfwwAfDEAvEnJt1EkX-Vthisiseriouslynotarealtokeniswearhah","meta":{},"errors":[{"status":302,"code":"retry_request_on_uri","title":"Retry request on given redirect URI."}]} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/estimate_ride_redirected: -------------------------------------------------------------------------------- 1 | {"price":{"surge_confirmation_href":null,"high_estimate":6,"surge_confirmation_id":null,"minimum":5,"low_estimate":5,"surge_multiplier":1.0,"display":"$5-6","currency_code":"USD"},"trip":{"distance_unit":"mile","duration_estimate":60,"distance_estimate":0.01},"pickup_estimate":7} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/get_localized_products_response: -------------------------------------------------------------------------------- 1 | {"products":[{"capacity":4,"product_id":"a1111c8c-c720-46c3-8534-2fcdd730040d","price_details":{"service_fees":[{"fee":1.35,"name":"Avgift f\u00f6r s\u00e4kra resor"}],"cost_per_minute":0.22,"distance_unit":"mile","minimum":5.35,"cost_per_distance":1.15,"base":2.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-uberx.png","display_name":"uberX","description":"Den billigare Ubern"},{"capacity":6,"product_id":"821415d8-3bd5-4e27-9604-194e4359a449","price_details":{"service_fees":[{"fee":1.35,"name":"Avgift f\u00f6r s\u00e4kra resor"}],"cost_per_minute":0.3,"distance_unit":"mile","minimum":7.35,"cost_per_distance":2.0,"base":3.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"https:\/\/uber-static.s3.amazonaws.com\/car-types\/mono\/mono-uberxl2-2.png","display_name":"uberXL","description":"Billiga resor f\u00f6r stora grupper"},{"capacity":4,"product_id":"57c0ff4e-1493-4ef9-a4df-6b961525cf92","price_details":{"service_fees":[{"fee":1.35,"name":"Avgift f\u00f6r s\u00e4kra resor"}],"cost_per_minute":0.5,"distance_unit":"mile","minimum":10.35,"cost_per_distance":2.75,"base":5.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-uberselect.png","display_name":"uberSELECT","description":"N\u00e5got ut\u00f6ver det vanliga"},{"capacity":4,"product_id":"d4abaae7-f4d6-4152-91cc-77523e8165a4","price_details":{"service_fees":[],"cost_per_minute":0.65,"distance_unit":"mile","minimum":15.0,"cost_per_distance":3.75,"base":8.0,"cancellation_fee":10.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-black.png","display_name":"UberBLACK","description":"Uber-originalet"},{"capacity":6,"product_id":"8920cb5e-51a4-4fa4-acdf-dd86c5e18ae0","price_details":{"service_fees":[],"cost_per_minute":0.9,"distance_unit":"mile","minimum":25.0,"cost_per_distance":3.75,"base":15.0,"cancellation_fee":10.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-suv.png","display_name":"UberSUV","description":"Plats f\u00f6r alla"},{"capacity":4,"product_id":"ff5ed8fe-6585-4803-be13-3ca541235de3","price_details":{"service_fees":[{"fee":1.35,"name":"Avgift f\u00f6r s\u00e4kra resor"}],"cost_per_minute":0.22,"distance_unit":"mile","minimum":5.35,"cost_per_distance":1.15,"base":2.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-wheelchair.png","display_name":"ASSIST","description":"ASSIST"},{"capacity":4,"product_id":"2832a1f5-cfc0-48bb-ab76-7ea7a62060e7","price_details":{"service_fees":[{"fee":1.35,"name":"Avgift f\u00f6r s\u00e4kra resor"}],"cost_per_minute":0.45,"distance_unit":"mile","minimum":8.35,"cost_per_distance":2.15,"base":5.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-wheelchair.png","display_name":"uberWAV","description":"Rullstolsanpassade fordon"},{"capacity":4,"product_id":"3ab64887-4842-4c8e-9780-ccecd3a0391d","price_details":null,"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-taxi.png","display_name":"uberTAXI","description":"Taxi utan besv\u00e4r"}]} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/get_product_error: -------------------------------------------------------------------------------- 1 | {"message":"Unable to find product thisIsNotAProductId","code":"not_found"} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/get_products_response: -------------------------------------------------------------------------------- 1 | {"products":[{"capacity":4,"product_id":"04a497f5-380d-47f2-bf1b-ad4cfdcb51f2","price_details":{"service_fees":[{"fee":1.0,"name":"Safe rides fee"}],"cost_per_minute":0.2,"distance_unit":"mile","minimum":5.0,"cost_per_distance":1.1,"base":1.95,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-uberx.png","display_name":"uberX","description":"uberX"},{"capacity":6,"product_id":"b5e6755e-05dd-44cc-903d-94bdaa7ffc78","price_details":{"service_fees":[{"fee":1.0,"name":"Safe rides fee"}],"cost_per_minute":0.45,"distance_unit":"mile","minimum":8.0,"cost_per_distance":2.15,"base":5.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"https:\/\/uber-static.s3.amazonaws.com\/car-types\/mono\/mono-uberxl2-2.png","display_name":"uberXL","description":"Low-cost rides for large groups"},{"capacity":4,"product_id":"d4abaae7-f4d6-4152-91cc-77523e8165a4","price_details":{"service_fees":[],"cost_per_minute":0.65,"distance_unit":"mile","minimum":15.0,"cost_per_distance":3.75,"base":8.0,"cancellation_fee":10.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-black.png","display_name":"UberBLACK","description":"The original Uber"},{"capacity":6,"product_id":"8920cb5e-51a4-4fa4-acdf-dd86c5e18ae0","price_details":{"service_fees":[],"cost_per_minute":0.9,"distance_unit":"mile","minimum":25.0,"cost_per_distance":3.75,"base":15.0,"cancellation_fee":10.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-suv.png","display_name":"UberSUV","description":"Room for everyone"},{"capacity":4,"product_id":"4057d8cc-f0f5-43fa-b448-1cd891b0fc66","price_details":{"service_fees":[{"fee":1.0,"name":"Safe rides fee"}],"cost_per_minute":0.2,"distance_unit":"mile","minimum":5.0,"cost_per_distance":1.1,"base":1.95,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-wheelchair.png","display_name":"ASSIST","description":"ASSIST"},{"capacity":4,"product_id":"2832a1f5-cfc0-48bb-ab76-7ea7a62060e7","price_details":{"service_fees":[{"fee":1.0,"name":"Safe rides fee"}],"cost_per_minute":0.45,"distance_unit":"mile","minimum":8.0,"cost_per_distance":2.15,"base":5.0,"cancellation_fee":5.0,"currency_code":"USD"},"image":"http:\/\/d1a3f4spazzrp4.cloudfront.net\/car-types\/mono\/mono-wheelchair.png","display_name":"uberWAV","description":"Wheelchair Accessible Vehicles"}]} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/get_user_profile_response: -------------------------------------------------------------------------------- 1 | {"picture":"userprofile.jpeg","first_name":"User","last_name":"Profile","promo_code":"user-profile","email":"user@profile.com","uuid":"userprofileuuid"} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/post_refresh_token_response: -------------------------------------------------------------------------------- 1 | {"last_authenticated":1440111331,"access_token":"accessToken2","expires_in":2592000,"token_type":"Bearer","scope":"request profile","refresh_token":"refreshToken2"} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/post_ride_error: -------------------------------------------------------------------------------- 1 | {"message":"Invalid product \"thisIsNotAProductId\". Available: d4abaae7-f4d6-4152-91cc-77523e8165a4, 8920cb5e-51a4-4fa4-acdf-dd86c5e18ae0, 04a497f5-380d-47f2-bf1b-ad4cfdcb51f2, 2832a1f5-cfc0-48bb-ab76-7ea7a62060e7, 4057d8cc-f0f5-43fa-b448-1cd891b0fc66, b5e6755e-05dd-44cc-903d-94bdaa7ffc78","code":"not_found"} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/post_ride_request: -------------------------------------------------------------------------------- 1 | {"status":"processing","request_id":"1033c525-746e-48ab-8eee-ab983e039e78","driver":null,"eta":13,"location":null,"vehicle":null,"surge_multiplier":1.0} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/put_sandbox_params_no_product_id_response: -------------------------------------------------------------------------------- 1 | {"message":"Unable to find product thisIsNotAProductId","code":"not_found"} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/simple_error_body: -------------------------------------------------------------------------------- 1 | {"message":"Unable to find product notAProductId","code":"not_found"} -------------------------------------------------------------------------------- /uber-rides/src/test/resources/mockresponses/surge_error_body: -------------------------------------------------------------------------------- 1 | {"meta":{"surge_confirmation":{"href":"https:\/\/api.uber.com\/v1\/surge-confirmations\/e100a670","surge_confirmation_id":"e100a670"}},"errors":[{"status": 409,"code": "surge","title": "Surge pricing is currently in effect for this product."}]} --------------------------------------------------------------------------------