├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CISCO_API_LICENSE.pdf ├── IntegrationTesting.sh ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── sdk ├── .gitignore ├── build.gradle ├── libs │ └── utils-1.0.jar ├── proguard-rules.pro └── src │ ├── androidTest │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── ciscospark │ │ └── androidsdk │ │ ├── PhoneImplTest.java │ │ ├── SparkTest.java │ │ ├── SparkTestRunner.java │ │ ├── auth │ │ └── JWTAuthenticatorTest.java │ │ ├── membership │ │ └── MembershipClientTest.java │ │ ├── message │ │ └── MessageClientTest.java │ │ ├── people │ │ └── PeopleClientTest.java │ │ ├── room │ │ └── RoomClientTest.java │ │ ├── team │ │ └── TeamClientTest.java │ │ └── webhook │ │ └── WebhookClientTest.java │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── ciscospark │ │ └── androidsdk │ │ ├── CompletionHandler.java │ │ ├── Result.java │ │ ├── Spark.java │ │ ├── SparkError.java │ │ ├── auth │ │ ├── Authenticator.java │ │ ├── JWTAuthenticator.java │ │ ├── OAuthAuthenticator.java │ │ ├── OAuthTestUserAuthenticator.java │ │ ├── OAuthWebViewAuthenticator.java │ │ ├── SSOAuthenticator.java │ │ └── internal │ │ │ └── OAuthLauncher.java │ │ ├── internal │ │ ├── AcquirePermissionActivity.java │ │ ├── MetricsClient.java │ │ └── ResultImpl.java │ │ ├── membership │ │ ├── Membership.java │ │ ├── MembershipClient.java │ │ └── internal │ │ │ └── MembershipClientImpl.java │ │ ├── message │ │ ├── LocalFile.java │ │ ├── Mention.java │ │ ├── Message.java │ │ ├── MessageClient.java │ │ ├── MessageObserver.java │ │ ├── RemoteFile.java │ │ └── internal │ │ │ └── MessageClientImpl.java │ │ ├── people │ │ ├── Person.java │ │ ├── PersonClient.java │ │ └── internal │ │ │ └── PersonClientImpl.java │ │ ├── phone │ │ ├── Call.java │ │ ├── CallMembership.java │ │ ├── CallObserver.java │ │ ├── MediaOption.java │ │ ├── MediaRenderView.java │ │ ├── Phone.java │ │ └── internal │ │ │ ├── CallImpl.java │ │ │ ├── CallMembershipImpl.java │ │ │ ├── H264LicensePrompter.java │ │ │ ├── PhoneImpl.java │ │ │ └── RotationHandler.java │ │ ├── room │ │ ├── Room.java │ │ ├── RoomClient.java │ │ └── internal │ │ │ └── RoomClientImpl.java │ │ ├── team │ │ ├── Team.java │ │ ├── TeamClient.java │ │ ├── TeamMembership.java │ │ ├── TeamMembershipClient.java │ │ └── internal │ │ │ ├── TeamClientImpl.java │ │ │ └── TeamMembershipClientImpl.java │ │ ├── utils │ │ ├── Utils.java │ │ ├── http │ │ │ ├── DefaultHeadersInterceptor.java │ │ │ ├── ErrorHandlingAdapter.java │ │ │ ├── ListBody.java │ │ │ ├── ListCallback.java │ │ │ ├── ListenerCallback.java │ │ │ ├── ObjectCallback.java │ │ │ ├── RetryCallAdapterFactory.java │ │ │ └── ServiceBuilder.java │ │ └── log │ │ │ ├── DebugLn.java │ │ │ ├── LogCaptureUtil.java │ │ │ ├── MediaLog.java │ │ │ ├── NoLn.java │ │ │ └── WarningLn.java │ │ └── webhook │ │ ├── Webhook.java │ │ ├── WebhookClient.java │ │ └── internal │ │ └── WebhookClientImpl.java │ └── test │ └── java │ └── com │ └── ciscospark │ └── androidsdk │ ├── auth │ └── OAuthAuthenticatorTest.java │ ├── membership │ └── MembershipTest.java │ ├── people │ ├── PersonClientTest.java │ └── PersonTest.java │ └── utils │ └── ErrorHandlingAdapterTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | .idea/* 40 | 41 | # Keystore files 42 | *.jks 43 | 44 | # External native build folder generated in Android Studio 2.2 and later 45 | .externalNativeBuild 46 | 47 | # Google Services (e.g. APIs or Firebase) 48 | google-services.json 49 | 50 | # Freeline 51 | freeline.py 52 | freeline/ 53 | freeline_project_description.json 54 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | android: 3 | components: 4 | # Uncomment the lines below if you want to 5 | # use the latest revision of Android SDK Tools 6 | # - tools 7 | # - platform-tools 8 | 9 | # The BuildTools version used by your project 10 | - build-tools-27.0.2 11 | 12 | # The SDK version used to compile your project 13 | - android-27 14 | before_install: 15 | - sudo apt-get -qq update 16 | - sudo apt-get install -y sendemail libnet-ssleay-perl libcrypt-ssleay-perl libnet-https-any-perl libio-socket-ssl-perl 17 | script: 18 | - ./gradlew clean sdk:testDebugUnitTest 19 | - travis_wait 50 bash IntegrationTesting.sh 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | #### 1.4.0 Releases 5 | - `1.4.0` Releases - [1.4.0](#140) 6 | 7 | #### 1.3.0 Releases 8 | - `1.3.0` Releases - [1.3.0](#130) 9 | 10 | #### 0.2.0 Releases 11 | 12 | - `0.2.0` Releases - [0.2.0](#020) 13 | 14 | --- 15 | ## [1.4.0](https://github.com/ciscospark/spark-android-sdk/releases/tag/1.4.0) 16 | Released on 2018-08-23. 17 | 18 | #### Added 19 | - Support screen sharing for both sending and receiving. 20 | - A new API to refresh token for authentication. 21 | - Two properties in Membership: personDisplayName, personOrgId. 22 | - Support real time message receiving. 23 | - Support message end to end encription. 24 | - A few new APIs to do message/file end to end encryption, Mention in message, upload and download encrypted files. 25 | - Five properties in Person: nickName, firstName, lastName, orgId, type. 26 | - Three functions to create/update/delete a person for organization's administrator. 27 | - Support room list ordered by either room ID, lastactivity time or creation time. 28 | - A new property in TeamMembership: personOrgId. 29 | - Two new parameters to update webhook : status and secret. 30 | 31 | #### Updated 32 | - Fixed sometimes cannot receive callback when hangup a call. 33 | - Fixed video call has bad video quality with Vuzix M300 smart glasses. 34 | - Fixed the order of redirectUri and scope are reversed in OAuthWebViewAuthenticator. 35 | 36 | ## [1.3.0](https://github.com/ciscospark/spark-android-sdk/releases/tag/1.3.0) 37 | Released on 2018-01-12. 38 | 39 | #### Added 40 | - Receive and display content-sharing stream 41 | - Support room calling/multi-party calling 42 | - Support Single-Sign-On authentication 43 | - Set the maximum bandwidth for Audio/Video/Content Sharing 44 | 45 | #### Updated 46 | - Fixed always receiving incoming room call even if there is nobody in the meeting room 47 | - Fixed unstable call state caused by race condition in call control events 48 | - Fixed random crash when logout 49 | - Updated the license by adding a term for H264 codec, and adding a new license file for "Cisco API" used in the project. 50 | 51 | #### Removed 52 | The following exclude is no longer needed in the packagingOptions (unless RxJava2 or its related library is involved in developers's app): 53 | 54 | packagingOptions { 55 | exclude 'META-INF/rxjava.properties' 56 | } 57 | 58 | ## [0.2.0](https://github.com/ciscospark/spark-android-sdk/releases/tag/0.2.0) 59 | Released on 2017-11-30. 60 | 61 | #### Added 62 | - Initial release of Cisco Spark SDK for Android. 63 | -------------------------------------------------------------------------------- /CISCO_API_LICENSE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webex/spark-android-sdk/1bf40b272d63a07aa4ee778b4ad7e43e943a59af/CISCO_API_LICENSE.pdf -------------------------------------------------------------------------------- /IntegrationTesting.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ "$Email" == "" ]; then 3 | echo "lost email address!" 4 | exit 0 5 | fi 6 | 7 | if $IsIntegrationTestingTask -eq "true" ; then 8 | echo "start Integration testing..." 9 | sendemail -f "$Email" -t "$Email" -u "Jenkins build by Travis" -m "BranchName=$TRAVIS_BRANCH\nTravisNumber=$TRAVIS_JOB_ID\nPullRequestNumber=$TRAVIS_PULL_REQUEST" -s smtp.gmail.com:587 -o tls=yes -xu "$Email" -xp "$EmailPWD" 10 | else 11 | echo "not the integration test task return normal..." 12 | exit 0 13 | fi 14 | 15 | sleep 60 16 | 17 | for ((i=0; i<=25; i++)); do 18 | buildEmailTitle=`curl -u $Email:$EmailPWD --silent "https://mail.google.com/mail/feed/atom" | awk -F '' '{for (i=3; i<=NF; i++) {print $i"\n"}}' | awk -F '' '{for (i=1; i<=NF; i=i+2) {print $i"\n"}}' | awk -F: '/^TravisNumber:'"$TRAVIS_JOB_ID"'/'` 19 | 20 | if [ $i -eq "24" ] ; then 21 | echo "Integration testing : TIMEOUT!" 22 | exit 0 23 | fi 24 | 25 | echo "$buildEmailTitle" 26 | if [ "$buildEmailTitle" == "" ]; then 27 | #wait 28 | echo "wait 60 sec" 29 | sleep 60 30 | else 31 | buildResult=`echo | awk '{print test}' test="$buildEmailTitle" | awk -F: '/Fixed/||/Successful/'` 32 | #echo "$buildResult" 33 | if [ "$buildResult" == "" ]; then 34 | #build failed 35 | echo "$buildEmailTitle" 36 | exit 1 37 | else 38 | echo "Jenkins build Successful!" 39 | exit 0 40 | fi 41 | fi 42 | done 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | - Except the "Wme.framework" licensed under Cisco API license (see CISCO_API_LICENSE.pdf), 2 | - And except the H264 codec license under the following license https://developer.ciscospark.com/docs/sdk-widgets/ios/h264-license-information.html 3 | Everything else is licensed under MIT License below. 4 | 5 | MIT License 6 | 7 | Copyright (c) 2016-2018 Cisco Systems, Inc. 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.ben-manes.versions' 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | google() 7 | maven { 8 | url 'https://maven.fabric.io/public' 9 | } 10 | } 11 | ext.kotlin_version = "1.1.51" 12 | ext.gradleVersion = System.env.GRADLE_VERSION == null ? '3.0.1' : System.env.GRADLE_VERSION 13 | 14 | dependencies { 15 | classpath 'com.github.ben-manes:gradle-versions-plugin:0.12.0' 16 | classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+' 17 | classpath "com.android.tools.build:gradle:$gradleVersion" 18 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | mavenLocal() 25 | jcenter() 26 | google() 27 | maven { 28 | url 'https://devhub.cisco.com/artifactory/sparksdk-SNAPSHOT' 29 | } 30 | maven { 31 | url 'https://devhub.cisco.com/artifactory/sparksdk/' 32 | } 33 | } 34 | } 35 | 36 | subprojects { 37 | afterEvaluate { project -> 38 | if (!(project.plugins.hasPlugin('com.android.application') || project.plugins.hasPlugin('com.android.library'))) { 39 | return 40 | } 41 | android { 42 | lintOptions { 43 | lintConfig file('lint.xml') 44 | abortOnError true 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 13 | 14 | org.gradle.parallel=true 15 | org.gradle.daemon=true 16 | 17 | android.enableAapt2=false 18 | 19 | MULTIDEX_VERSION = 1.0.1 20 | 21 | JODA_VERSION = 2.9.9 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webex/spark-android-sdk/1bf40b272d63a07aa4ee778b4ad7e43e943a59af/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 13 17:43:56 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /sdk/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sdk/libs/utils-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webex/spark-android-sdk/1bf40b272d63a07aa4ee778b4ad7e43e943a59af/sdk/libs/utils-1.0.jar -------------------------------------------------------------------------------- /sdk/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/jooreill/Library/Android/sdk_2.2/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sdk/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/PhoneImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk; 24 | 25 | import java.lang.reflect.Field; 26 | 27 | import com.cisco.spark.android.authenticator.OAuth2Tokens; 28 | import com.ciscospark.androidsdk.auth.JWTAuthenticator; 29 | 30 | import me.helloworld.utils.reflect.Fields; 31 | 32 | import org.junit.Test; 33 | 34 | /** 35 | * Created on 10/06/2017. 36 | */ 37 | public class PhoneImplTest { 38 | 39 | private String auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhbmRyb2lkX3Rlc3R1c2VyXzEiLCJuYW1lIjoiQW5kcm9pZFRlc3RVc2VyMSIsImlzcyI6ImNkNWM5YWY3LThlZDMtNGUxNS05NzA1LTAyNWVmMzBiMWI2YSJ9.eJ99AY9iNDhG4HjDJsY36wgqOnNQSes_PIu0DKBHBzs"; 40 | 41 | @Test 42 | public void test() throws InterruptedException { 43 | JWTAuthenticator authenticator = new JWTAuthenticator(); 44 | authenticator.authorize(auth_token); 45 | authenticator.getToken(new CompletionHandler() { 46 | @Override 47 | public void onComplete(Result result) { 48 | System.out.println(result.getData()); 49 | System.out.println(result.getError()); 50 | } 51 | }); 52 | Thread.sleep(10 * 1000); 53 | } 54 | 55 | @Test 56 | public void hello() { 57 | OAuth2Tokens tokens = new OAuth2Tokens(); 58 | Field f = Fields.findDeclaredField(OAuth2Tokens.class, "refreshToken"); 59 | System.out.println(f); 60 | System.out.println(f.getDeclaringClass()); 61 | try { 62 | f.set(tokens, "123344"); 63 | } catch (IllegalAccessException e) { 64 | e.printStackTrace(); 65 | } 66 | 67 | System.out.println(tokens.getAccessToken()); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/SparkTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk; 24 | 25 | import java.io.UnsupportedEncodingException; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | 29 | import android.support.annotation.Nullable; 30 | import android.util.Base64; 31 | 32 | import com.ciscospark.androidsdk.auth.JWTAuthenticator; 33 | import com.google.gson.Gson; 34 | 35 | import org.junit.Test; 36 | 37 | /** 38 | * Created on 12/06/2017. 39 | */ 40 | public class SparkTest { 41 | private String auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMiIsIm5hbWUiOiJ1c2VyICMyIiwiaXNzIjoiWTJselkyOXpjR0Z5YXpvdkwzVnpMMDlTUjBGT1NWcEJWRWxQVGk5aU5tSmtNemRtTUMwNU56RXhMVFEzWldVdE9UUTFOUzAxWWpZNE1tUTNNRFV6TURZIn0.5VvjLtuD-jn9hXtLthnGDdhxlIHaoKZbI80y1vK2-bY"; 42 | private static final String TAG = "SparkTest"; 43 | 44 | @Test 45 | public void version() throws Exception { 46 | JWTAuthenticator authenticator = new JWTAuthenticator(); 47 | authenticator.authorize(auth_token); 48 | Spark spark = new Spark(SparkTestRunner.application, authenticator); 49 | System.out.println(spark.getVersion()); 50 | System.out.println(spark._mediaEngine); 51 | authenticator.getToken(System.out::println); 52 | Thread.sleep(1000000 * 1000); 53 | // assertEquals(spark.version(), "0.1"); 54 | } 55 | 56 | @Test 57 | public void authorize() throws Exception { 58 | // Spark spark = new Spark(); 59 | // JWTAuthenticator strategy = new JWTAuthenticator(); 60 | // spark.setAuthenticator(strategy); 61 | // spark.authorize(new CompletionHandler() { 62 | // @Override 63 | // public void onComplete(String code) { 64 | // assertTrue(spark.isAuthorized()); 65 | // Log.i(TAG, "get token: " + code); 66 | // } 67 | // 68 | // @Override 69 | // public void onError(SparkError E) { 70 | // assertFalse(true); 71 | // } 72 | // }); 73 | // Thread.sleep(10 * 1000); 74 | } 75 | 76 | private @Nullable 77 | Map parseJWT(String jwt) { 78 | String[] split = jwt.split("\\."); 79 | if (split.length != 3) { 80 | return null; 81 | } 82 | try { 83 | String json = new String(Base64.decode(split[1], Base64.URL_SAFE), "UTF-8"); 84 | Gson gson = new Gson(); 85 | Map map = new HashMap(); 86 | return gson.fromJson(json, map.getClass()); 87 | } catch (UnsupportedEncodingException e) { 88 | return null; 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/auth/JWTAuthenticatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.auth; 24 | 25 | import org.junit.FixMethodOrder; 26 | import org.junit.Test; 27 | import org.junit.runners.MethodSorters; 28 | 29 | /** 30 | * @author Allen Xiao 31 | * @version 0.1 32 | */ 33 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 34 | public class JWTAuthenticatorTest { 35 | private String auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhbmRyb2lkX3Rlc3R1c2VyXzEiLCJuYW1lIjoiQW5kcm9pZFRlc3RVc2VyMSIsImlzcyI6ImNkNWM5YWY3LThlZDMtNGUxNS05NzA1LTAyNWVmMzBiMWI2YSJ9.eJ99AY9iNDhG4HjDJsY36wgqOnNQSes_PIu0DKBHBzs"; 36 | 37 | @Test 38 | public void test() { 39 | JWTAuthenticator authenticator = new JWTAuthenticator(); 40 | authenticator.authorize(auth_token); 41 | authenticator.getToken(System.out::println); 42 | } 43 | 44 | 45 | } -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/membership/MembershipClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.membership; 24 | 25 | import java.util.List; 26 | 27 | import com.ciscospark.androidsdk.CompletionHandler; 28 | import com.ciscospark.androidsdk.Result; 29 | import com.ciscospark.androidsdk.Spark; 30 | import com.ciscospark.androidsdk.SparkTestRunner; 31 | import com.ciscospark.androidsdk.auth.JWTAuthenticator; 32 | import com.ciscospark.androidsdk.membership.internal.MembershipClientImpl; 33 | 34 | import org.junit.BeforeClass; 35 | import org.junit.Test; 36 | 37 | /** 38 | * Created by zhiyuliu on 31/08/2017. 39 | */ 40 | 41 | public class MembershipClientTest { 42 | 43 | private static final String SPARK_ROOM_CALL_ROOM_ID = "Y2lzY29zcGFyazovL3VzL1JPT00vOWM2ZjQyZDAtMGFmNi0xMWU4LTg2ODQtZmQ0MTFjYTUzOWZl"; 44 | private static String sparkUserEmail = "sparksdktestuser15@tropo.com"; 45 | private static MembershipClient mClient; 46 | private static Membership mMembership, mModerator; 47 | 48 | @BeforeClass 49 | public static void setUp() throws Exception { 50 | Thread.sleep(10*1000); 51 | System.out.println("setup test case"); 52 | Spark spark = SparkTestRunner.getSpark(); 53 | mClient = spark.memberships(); 54 | } 55 | 56 | @Test 57 | public void testcase1() throws Exception{ 58 | System.out.println("create membership"); 59 | mClient.create(SPARK_ROOM_CALL_ROOM_ID, null, sparkUserEmail, false, new CompletionHandler() { 60 | @Override 61 | public void onComplete(Result result) { 62 | System.out.println(result.getData()); 63 | mMembership = result.getData(); 64 | } 65 | }); 66 | Thread.sleep(10*1000); 67 | } 68 | 69 | @Test 70 | public void testcase2() throws Exception { 71 | System.out.println("lsit membership"); 72 | mClient.list(SPARK_ROOM_CALL_ROOM_ID, null, null, 0, new CompletionHandler>() { 73 | @Override 74 | public void onComplete(Result> result) { 75 | for (Membership membership : result.getData()) { 76 | System.out.println(membership); 77 | if (membership.getPersonEmail().equals("qimdeng@cisco.com")) 78 | mModerator = membership; 79 | } 80 | } 81 | }); 82 | Thread.sleep(10 * 1000); 83 | } 84 | 85 | @Test 86 | public void testcase3() throws Exception { 87 | System.out.println("update membership"); 88 | mClient.update(mModerator.getId(), !mModerator.isModerator(), new CompletionHandler() { 89 | @Override 90 | public void onComplete(Result result) { 91 | System.out.println(result.getData()); 92 | } 93 | }); 94 | Thread.sleep(10*1000); 95 | } 96 | 97 | @Test 98 | public void testcase4() throws Exception { 99 | System.out.println("get membership"); 100 | mClient.get(mMembership.getId(), new CompletionHandler() { 101 | @Override 102 | public void onComplete(Result result) { 103 | System.out.println(result.getData()); 104 | } 105 | }); 106 | Thread.sleep(10*1000); 107 | } 108 | 109 | @Test 110 | public void testcase5() throws Exception { 111 | System.out.println("delete membership"); 112 | mClient.delete(mMembership.getId(), new CompletionHandler() { 113 | @Override 114 | public void onComplete(Result result) { 115 | System.out.println(result); 116 | } 117 | }); 118 | 119 | Thread.sleep(10 * 1000); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/message/MessageClientTest.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.message; 2 | 3 | import com.ciscospark.androidsdk.Spark; 4 | import com.ciscospark.androidsdk.room.Room; 5 | import com.ciscospark.androidsdk.room.RoomClient; 6 | 7 | import org.junit.AfterClass; 8 | import org.junit.BeforeClass; 9 | import org.junit.FixMethodOrder; 10 | import org.junit.Test; 11 | import org.junit.runners.MethodSorters; 12 | 13 | import java.util.concurrent.CountDownLatch; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | import static com.ciscospark.androidsdk.SparkTestRunner.getSpark; 17 | import static junit.framework.Assert.assertNotNull; 18 | import static junit.framework.Assert.assertTrue; 19 | import static org.hamcrest.CoreMatchers.equalTo; 20 | import static org.hamcrest.CoreMatchers.instanceOf; 21 | import static org.hamcrest.CoreMatchers.is; 22 | import static org.hamcrest.MatcherAssert.assertThat; 23 | 24 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 25 | public class MessageClientTest { 26 | 27 | private static Spark spark; 28 | private static MessageClient messageClient; 29 | private static Room room; 30 | private static Message msg; 31 | 32 | @BeforeClass 33 | public static void setUpBeforeClass() throws Exception { 34 | spark = getSpark(); 35 | messageClient = getSpark().messages(); 36 | createRoom(); 37 | } 38 | 39 | @AfterClass 40 | public static void tearDownAfterClass() throws Exception { 41 | removeRoom(); 42 | } 43 | 44 | private static void createRoom() throws InterruptedException { 45 | final CountDownLatch signal = new CountDownLatch(1); 46 | RoomClient roomClient = spark.rooms(); 47 | roomClient.create("message test room", null, result -> { 48 | if (result.isSuccessful()) { 49 | System.out.println(result.getData()); 50 | room = result.getData(); 51 | } else { 52 | System.out.println(result.getError()); 53 | } 54 | signal.countDown(); 55 | }); 56 | signal.await(); 57 | } 58 | 59 | private static void removeRoom() throws InterruptedException { 60 | System.out.println(":::: remove room"); 61 | final CountDownLatch signal = new CountDownLatch(1); 62 | RoomClient roomClient = spark.rooms(); 63 | roomClient.delete(room.getId(), result -> signal.countDown()); 64 | signal.await(); 65 | } 66 | 67 | private void waitForMessage(CountDownLatch signal, String text) { 68 | messageClient.setMessageObserver(event -> { 69 | assertThat(event, instanceOf(MessageObserver.MessageArrived.class)); 70 | msg = ((MessageObserver.MessageArrived) event).getMessage(); 71 | assertNotNull(msg); 72 | assertThat(msg.getText(), is(equalTo(text))); 73 | messageClient.setMessageObserver(null); 74 | signal.countDown(); 75 | }); 76 | } 77 | 78 | @Test 79 | public void testA1_post() throws InterruptedException { 80 | System.out.println("::::post 1"); 81 | assertNotNull(room); 82 | final String text = "test post 1"; 83 | final CountDownLatch signal = new CountDownLatch(1); 84 | 85 | messageClient.post(room.getId(), null, null, text, null, null, result -> { 86 | assertTrue(result.isSuccessful()); 87 | }); 88 | waitForMessage(signal, text); 89 | signal.await(30, TimeUnit.SECONDS); 90 | } 91 | 92 | @Test 93 | public void testA2_post() throws InterruptedException { 94 | System.out.println("::::post 2"); 95 | assertNotNull(room); 96 | final String text = "test post 2"; 97 | 98 | final CountDownLatch signal = new CountDownLatch(1); 99 | messageClient.post(room.getId(), text, null, null, result -> { 100 | assertTrue(result.isSuccessful()); 101 | }); 102 | waitForMessage(signal, text); 103 | signal.await(30, TimeUnit.SECONDS); 104 | } 105 | 106 | 107 | @Test 108 | public void testB_list() throws InterruptedException { 109 | System.out.println("::::list"); 110 | final CountDownLatch signal = new CountDownLatch(1); 111 | messageClient.list(room.getId(), null, null, null, 10, result -> { 112 | assertTrue(result.isSuccessful()); 113 | signal.countDown(); 114 | }); 115 | signal.await(); 116 | } 117 | 118 | 119 | @Test 120 | public void testC_get() throws InterruptedException { 121 | System.out.println("::::get"); 122 | assertNotNull(msg); 123 | final CountDownLatch signal = new CountDownLatch(1); 124 | messageClient.get(msg.getId(), result -> { 125 | assertTrue(result.isSuccessful()); 126 | signal.countDown(); 127 | }); 128 | signal.await(); 129 | } 130 | 131 | @Test 132 | public void testD_delete() throws InterruptedException { 133 | System.out.println("::::delete"); 134 | assertNotNull(msg); 135 | final CountDownLatch signal = new CountDownLatch(1); 136 | messageClient.delete(msg.getId(), result -> { 137 | assertTrue(result.isSuccessful()); 138 | signal.countDown(); 139 | }); 140 | signal.await(); 141 | } 142 | } -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/people/PeopleClientTest.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.people; 2 | 3 | import com.ciscospark.androidsdk.CompletionHandler; 4 | import com.ciscospark.androidsdk.Result; 5 | import com.ciscospark.androidsdk.Spark; 6 | import com.ciscospark.androidsdk.SparkTestRunner; 7 | import com.ciscospark.androidsdk.room.Room; 8 | import com.ciscospark.androidsdk.room.RoomClient; 9 | 10 | import org.junit.BeforeClass; 11 | import org.junit.Test; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by qimdeng on 7/26/18. 17 | */ 18 | 19 | public class PeopleClientTest { 20 | private static PersonClient mClient; 21 | private static Person mPerson; 22 | 23 | @BeforeClass 24 | public static void setUp() throws Exception { 25 | Thread.sleep(10*1000); 26 | System.out.println("setup test case"); 27 | Spark spark = SparkTestRunner.getSpark(); 28 | mClient = spark.people(); 29 | } 30 | 31 | @Test 32 | public void testcase1() throws Exception { 33 | System.out.println("list person"); 34 | mClient.list("qimdeng@cisco.com", null, 3, new CompletionHandler>() { 35 | @Override 36 | public void onComplete(Result> result) { 37 | for (Person person : result.getData()) 38 | System.out.println(person); 39 | mPerson = result.getData().get(0); 40 | } 41 | }); 42 | Thread.sleep(10*1000); 43 | } 44 | 45 | @Test 46 | public void testcase2() throws Exception { 47 | System.out.println("get person"); 48 | mClient.get(mPerson.getId(), new CompletionHandler() { 49 | @Override 50 | public void onComplete(Result result) { 51 | System.out.println(result.getData()); 52 | } 53 | }); 54 | Thread.sleep(10*1000); 55 | } 56 | 57 | @Test 58 | public void testcase3() throws Exception { 59 | System.out.println("getMe"); 60 | mClient.getMe(new CompletionHandler() { 61 | @Override 62 | public void onComplete(Result result) { 63 | System.out.println(result); 64 | } 65 | }); 66 | Thread.sleep(10*1000); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/room/RoomClientTest.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.room; 2 | 3 | import com.ciscospark.androidsdk.CompletionHandler; 4 | import com.ciscospark.androidsdk.Result; 5 | import com.ciscospark.androidsdk.Spark; 6 | import com.ciscospark.androidsdk.SparkTestRunner; 7 | 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by qimdeng on 7/25/18. 15 | */ 16 | 17 | public class RoomClientTest{ 18 | private static RoomClient mClient; 19 | private static Room mRoom; 20 | 21 | @BeforeClass 22 | public static void setUp() throws Exception { 23 | Thread.sleep(10*1000); 24 | System.out.println("setup test case"); 25 | Spark spark = SparkTestRunner.getSpark(); 26 | mClient = spark.rooms(); 27 | } 28 | 29 | @Test 30 | public void testcase1() throws Exception{ 31 | System.out.println("create room"); 32 | mClient.create("TestRoom", null, new CompletionHandler() { 33 | @Override 34 | public void onComplete(Result result) { 35 | System.out.println(result.getData()); 36 | mRoom = result.getData(); 37 | } 38 | }); 39 | Thread.sleep(10*1000); 40 | } 41 | 42 | @Test 43 | public void testcase2() throws Exception { 44 | System.out.println("list room"); 45 | mClient.list(null, 3, null, null, new CompletionHandler>() { 46 | @Override 47 | public void onComplete(Result> result) { 48 | for (Room room : result.getData()) 49 | System.out.println(room); 50 | } 51 | }); 52 | Thread.sleep(10*1000); 53 | } 54 | 55 | @Test 56 | public void testcase3() throws Exception { 57 | System.out.println("update room"); 58 | mClient.update(mRoom.getId(),"UpdateTestRoom", new CompletionHandler() { 59 | @Override 60 | public void onComplete(Result result) { 61 | System.out.println(result.getData()); 62 | } 63 | }); 64 | Thread.sleep(10*1000); 65 | } 66 | 67 | @Test 68 | public void testcase4() throws Exception { 69 | System.out.println("get room"); 70 | mClient.get(mRoom.getId(), new CompletionHandler() { 71 | @Override 72 | public void onComplete(Result result) { 73 | System.out.println(result.getData()); 74 | } 75 | }); 76 | Thread.sleep(10*1000); 77 | } 78 | 79 | @Test 80 | public void testcase5() throws Exception { 81 | System.out.println("delete room"); 82 | mClient.delete(mRoom.getId(), new CompletionHandler() { 83 | @Override 84 | public void onComplete(Result result) { 85 | System.out.println(result); 86 | } 87 | }); 88 | Thread.sleep(10*1000); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/team/TeamClientTest.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.team; 2 | 3 | import com.ciscospark.androidsdk.CompletionHandler; 4 | import com.ciscospark.androidsdk.Result; 5 | import com.ciscospark.androidsdk.Spark; 6 | import com.ciscospark.androidsdk.SparkTestRunner; 7 | 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by qimdeng on 7/27/18. 16 | */ 17 | 18 | public class TeamClientTest { 19 | public static String jwtUserID1 = "dce2861a-debb-4834-802b-6f08515c0bf2"; 20 | public static String jwtUserID2 = "11bc13ac-5a84-4a1f-a1be-4b0910e8d10d"; 21 | private static TeamClient mClient; 22 | private static Team mTeam; 23 | private static List teamMemberShipList = new ArrayList<>(); 24 | 25 | @BeforeClass 26 | public static void setUp() throws Exception { 27 | Thread.sleep(10*1000); 28 | System.out.println("setup test case"); 29 | Spark spark = SparkTestRunner.getSpark(); 30 | mClient = spark.teams(); 31 | } 32 | 33 | @Test 34 | public void testcase1() throws Exception{ 35 | System.out.println("create team"); 36 | mClient.create("TestTeam", new CompletionHandler() { 37 | @Override 38 | public void onComplete(Result result) { 39 | System.out.println(result.getData()); 40 | mTeam = result.getData(); 41 | } 42 | }); 43 | Thread.sleep(10*1000); 44 | } 45 | 46 | @Test 47 | public void testcase2() throws Exception { 48 | System.out.println("add MembershipToTeam"); 49 | SparkTestRunner.getSpark().teamMembershipClient().create(mTeam.getId(), jwtUserID1, 50 | null, false, new CompletionHandler() { 51 | @Override 52 | public void onComplete(Result result) { 53 | System.out.println(result.getData()); 54 | teamMemberShipList.add(result.getData()); 55 | } 56 | }); 57 | SparkTestRunner.getSpark().teamMembershipClient().create(mTeam.getId(), jwtUserID2, 58 | null, false, new CompletionHandler() { 59 | @Override 60 | public void onComplete(Result result) { 61 | System.out.println(result.getData()); 62 | teamMemberShipList.add(result.getData()); 63 | } 64 | }); 65 | Thread.sleep(10 * 1000); 66 | } 67 | 68 | @Test 69 | public void testcase3() throws Exception { 70 | System.out.println("list TeamMemberShips"); 71 | SparkTestRunner.getSpark().teamMembershipClient().list(mTeam.getId(), 0, new CompletionHandler>() { 72 | @Override 73 | public void onComplete(Result> result) { 74 | for (TeamMembership teamMembership : result.getData()) { 75 | System.out.println(teamMembership); 76 | } 77 | } 78 | }); 79 | Thread.sleep(10 * 1000); 80 | } 81 | 82 | @Test 83 | public void testcase4() throws Exception { 84 | System.out.println("delete TeamMembership"); 85 | SparkTestRunner.getSpark().teamMembershipClient().delete(teamMemberShipList.get(0).getId(), new CompletionHandler() { 86 | @Override 87 | public void onComplete(Result result) { 88 | System.out.println(result); 89 | } 90 | }); 91 | Thread.sleep(10*1000); 92 | } 93 | 94 | @Test 95 | public void testcase5() throws Exception { 96 | System.out.println("update TeamMembership"); 97 | SparkTestRunner.getSpark().teamMembershipClient().update(teamMemberShipList.get(1).getId(), true, new CompletionHandler() { 98 | @Override 99 | public void onComplete(Result result) { 100 | System.out.println(result.getData()); 101 | } 102 | }); 103 | Thread.sleep(10*1000); 104 | } 105 | 106 | @Test 107 | public void testcase6() throws Exception { 108 | System.out.println("get team"); 109 | mClient.get(mTeam.getId(), new CompletionHandler() { 110 | @Override 111 | public void onComplete(Result result) { 112 | System.out.println(result.getData()); 113 | } 114 | }); 115 | 116 | Thread.sleep(10 * 1000); 117 | } 118 | 119 | @Test 120 | public void testcase7() throws Exception { 121 | System.out.println("update team"); 122 | mClient.update(mTeam.getId(), "TestUpdatedTeam", new CompletionHandler() { 123 | @Override 124 | public void onComplete(Result result) { 125 | System.out.println(result.getData()); 126 | } 127 | }); 128 | 129 | Thread.sleep(10 * 1000); 130 | } 131 | 132 | @Test 133 | public void testcase8() throws Exception { 134 | System.out.println("delete team"); 135 | mClient.delete(mTeam.getId(), new CompletionHandler() { 136 | @Override 137 | public void onComplete(Result result) { 138 | System.out.println(result); 139 | } 140 | }); 141 | 142 | Thread.sleep(10 * 1000); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /sdk/src/androidTest/java/com/ciscospark/androidsdk/webhook/WebhookClientTest.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.webhook; 2 | 3 | import com.ciscospark.androidsdk.CompletionHandler; 4 | import com.ciscospark.androidsdk.Result; 5 | import com.ciscospark.androidsdk.Spark; 6 | import com.ciscospark.androidsdk.SparkTestRunner; 7 | 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by qimdeng on 7/27/18. 15 | */ 16 | 17 | public class WebhookClientTest { 18 | private final static String SparkWebhookTestTargetUrl = "https://ios-demo-pushnoti-server.herokuapp.com/webhook"; 19 | private static WebhookClient mClient; 20 | private static Webhook mWebhook; 21 | 22 | @BeforeClass 23 | public static void setUp() throws Exception { 24 | Thread.sleep(10*1000); 25 | System.out.println("setup test case"); 26 | Spark spark = SparkTestRunner.getSpark(); 27 | mClient = spark.webhooks(); 28 | } 29 | 30 | @Test 31 | public void testcase1() throws Exception{ 32 | System.out.println("create webhook"); 33 | mClient.create("TestWebHook", SparkWebhookTestTargetUrl, 34 | "messages", "all", null, null, new CompletionHandler() { 35 | @Override 36 | public void onComplete(Result result) { 37 | System.out.println(result.getData()); 38 | mWebhook = result.getData(); 39 | } 40 | }); 41 | Thread.sleep(10*1000); 42 | } 43 | 44 | @Test 45 | public void testcase2() throws Exception { 46 | System.out.println("lsit webhook"); 47 | mClient.list(3, new CompletionHandler>() { 48 | @Override 49 | public void onComplete(Result> result) { 50 | for (Webhook webhook : result.getData()) { 51 | System.out.println(webhook); 52 | } 53 | } 54 | }); 55 | Thread.sleep(10 * 1000); 56 | } 57 | 58 | @Test 59 | public void testcase3() throws Exception { 60 | System.out.println("update webhook"); 61 | mClient.update(mWebhook.getId(), "UpdatedWebHook", 62 | SparkWebhookTestTargetUrl + "Updated", "1qa2ws3ed", null, new CompletionHandler() { 63 | @Override 64 | public void onComplete(Result result) { 65 | System.out.println(result.getData()); 66 | } 67 | }); 68 | Thread.sleep(10*1000); 69 | } 70 | 71 | @Test 72 | public void testcase4() throws Exception { 73 | System.out.println("get webhook"); 74 | mClient.get(mWebhook.getId(), new CompletionHandler() { 75 | @Override 76 | public void onComplete(Result result) { 77 | System.out.println(result.getData()); 78 | } 79 | }); 80 | Thread.sleep(10*1000); 81 | } 82 | 83 | @Test 84 | public void testcase5() throws Exception { 85 | System.out.println("delete webhook"); 86 | mClient.delete(mWebhook.getId(), new CompletionHandler() { 87 | @Override 88 | public void onComplete(Result result) { 89 | System.out.println(result); 90 | } 91 | }); 92 | 93 | Thread.sleep(10 * 1000); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /sdk/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/CompletionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk; 24 | 25 | /** 26 | * A callback handler to be executed when a operation is completed. 27 | * 28 | * @since 0.1 29 | */ 30 | public interface CompletionHandler { 31 | 32 | /** 33 | * A callback to be executed when a operation is completed. 34 | * 35 | * @param result result of the operation. 36 | * @since 0.1 37 | */ 38 | void onComplete(Result result); 39 | } -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/Result.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk; 24 | 25 | import android.support.annotation.Nullable; 26 | 27 | /** 28 | * Service request results. 29 | * 30 | * @since 0.1 31 | */ 32 | public interface Result { 33 | 34 | /** 35 | * Returns true if the result is a success, false otherwise 36 | * 37 | * @since 0.1 38 | */ 39 | boolean isSuccessful(); 40 | 41 | /** 42 | * Returns the associated error value if the result is a failure, null otherwise. 43 | * 44 | * @since 0.1 45 | */ 46 | @Nullable 47 | SparkError getError(); 48 | 49 | /** 50 | * Returns the associated data if the result is a success, `null` otherwise. 51 | * 52 | * @since 0.1 53 | */ 54 | @Nullable 55 | T getData(); 56 | } 57 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/SparkError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk; 24 | 25 | import me.helloworld.utils.Objects; 26 | import me.helloworld.utils.annotation.StringPart; 27 | 28 | /** 29 | * The enumeration of error types in Cisco Spark Android SDK. 30 | * 31 | * @since 0.1 32 | */ 33 | public class SparkError { 34 | 35 | public enum ErrorCode { 36 | UNEXPECTED_ERROR, 37 | SERVICE_ERROR, 38 | PERMISSION_ERROR 39 | } 40 | 41 | @StringPart 42 | protected ErrorCode _code = null; 43 | 44 | @StringPart 45 | protected String _message = ""; 46 | 47 | protected T _data = null; 48 | 49 | /** 50 | * The default constructor 51 | */ 52 | public SparkError() { 53 | } 54 | 55 | /** 56 | * The constructor with the error code 57 | * 58 | * @param errorCode the error code 59 | */ 60 | public SparkError(ErrorCode errorCode) { 61 | _code = errorCode; 62 | } 63 | 64 | /** 65 | * The constructor with the error code and error message 66 | * 67 | * @param errorCode the error code 68 | * @param message the error message 69 | */ 70 | public SparkError(ErrorCode errorCode, String message) { 71 | _code = errorCode; 72 | _message = message; 73 | } 74 | 75 | /** 76 | * The constructor with the error code and error message 77 | * 78 | * @param errorCode the error code 79 | * @param message the error message 80 | * @param data the error data 81 | */ 82 | public SparkError(ErrorCode errorCode, String message, T data) { 83 | _code = errorCode; 84 | _message = message; 85 | _data = data; 86 | } 87 | 88 | ErrorCode getErrorCode() { 89 | return _code; 90 | } 91 | 92 | String getErrorMessage() { 93 | return _message; 94 | } 95 | 96 | T getData() { 97 | return _data; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return Objects.toStringByAnnotation(this); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/auth/Authenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.auth; 24 | 25 | import com.ciscospark.androidsdk.CompletionHandler; 26 | 27 | /** 28 | * An interface for generic authentication strategies in Cisco Spark. 29 | * Each authentication strategy is responsible for providing an accessToken used throughout this SDK. 30 | * 31 | * @since 0.1 32 | */ 33 | public interface Authenticator { 34 | 35 | /** 36 | * Returns True if the user is logically authorized. 37 | *

38 | * This may not mean the user has a valid access token yet, 39 | * but the authentication strategy should be able to obtain one without further user interaction. 40 | * 41 | * @return True if the user is logically authorized 42 | * @since 0.1 43 | */ 44 | boolean isAuthorized(); 45 | 46 | /** 47 | * Deauthorizes the current user and clears any persistent state with regards to the current user. 48 | * If the {@link com.ciscospark.androidsdk.phone.Phone} is registered, 49 | * it should be deregistered before calling this method. 50 | * 51 | * @since 0.1 52 | */ 53 | void deauthorize(); 54 | 55 | /** 56 | * Returns an access token of this authenticator. 57 | *

58 | * This may involve long-running operations such as service calls, but may also return immediately. 59 | * The application should not make assumptions about how quickly this completes. 60 | * 61 | * @param handler a callback to be executed when completed, with the access token if successfuly retrieved, otherwise nil. 62 | * @since 0.1 63 | */ 64 | void getToken(CompletionHandler handler); 65 | 66 | /** 67 | * Refresh an access token of this authenticator. 68 | *

69 | * This may involve long-running operations such as service calls, but may also return immediately. 70 | * The application should not make assumptions about how quickly this completes. 71 | * 72 | * @param handler a callback to be executed when completed, with the access token if successfuly retrieved, otherwise nil. 73 | * @since 1.4 74 | */ 75 | void refreshToken(CompletionHandler handler); 76 | } 77 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/internal/MetricsClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.internal; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import com.ciscospark.androidsdk.CompletionHandler; 29 | import com.ciscospark.androidsdk.Result; 30 | import com.ciscospark.androidsdk.auth.Authenticator; 31 | import com.ciscospark.androidsdk.utils.http.ServiceBuilder; 32 | import com.github.benoitdion.ln.Ln; 33 | 34 | import me.helloworld.utils.collection.Maps; 35 | import retrofit2.Call; 36 | import retrofit2.Callback; 37 | import retrofit2.Response; 38 | import retrofit2.http.Body; 39 | import retrofit2.http.Header; 40 | import retrofit2.http.POST; 41 | 42 | public class MetricsClient { 43 | 44 | private Authenticator _authenticator; 45 | 46 | private MetricsService _service; 47 | 48 | public MetricsClient(Authenticator authenticator, String URL) { 49 | _authenticator = authenticator; 50 | _service = new ServiceBuilder().baseURL(URL).build(MetricsService.class); 51 | } 52 | 53 | public void post(List> metrics) { 54 | _authenticator.getToken(new CompletionHandler() { 55 | @Override 56 | public void onComplete(Result result) { 57 | String token = result.getData(); 58 | if (token != null) { 59 | _service.post("Bearer " + token, Maps.makeMap("metrics", metrics)).enqueue(new Callback() { 60 | @Override 61 | public void onResponse(Call call, Response response) { 62 | Ln.d("%s", response); 63 | } 64 | 65 | @Override 66 | public void onFailure(Call call, Throwable t) { 67 | Ln.e(t); 68 | } 69 | }); 70 | } 71 | } 72 | }); 73 | } 74 | 75 | interface MetricsService { 76 | 77 | @POST("metrics") 78 | Call post(@Header("Authorization") String authorization, @Body Map parameters); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/internal/ResultImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.internal; 24 | 25 | import java.io.IOException; 26 | 27 | import com.ciscospark.androidsdk.Result; 28 | import com.ciscospark.androidsdk.SparkError; 29 | 30 | import me.helloworld.utils.Objects; 31 | import me.helloworld.utils.annotation.StringPart; 32 | import retrofit2.Response; 33 | 34 | public class ResultImpl implements Result { 35 | 36 | public static Result success(T data) { 37 | return new ResultImpl(data, null); 38 | } 39 | 40 | public static Result error(String message) { 41 | return new ResultImpl(null, new SparkError(SparkError.ErrorCode.UNEXPECTED_ERROR, message)); 42 | } 43 | 44 | public static Result error(Throwable t) { 45 | return new ResultImpl(null, makeError(t)); 46 | } 47 | 48 | public static Result error(SparkError error) { 49 | return new ResultImpl(null, error); 50 | } 51 | 52 | public static Result error(Response response) { 53 | return new ResultImpl(null, makeError(response)); 54 | } 55 | 56 | @StringPart 57 | private T _data; 58 | 59 | @StringPart 60 | private SparkError _error; 61 | 62 | public ResultImpl(T data, SparkError error) { 63 | _data = data; 64 | _error = error; 65 | } 66 | 67 | public boolean isSuccessful() { 68 | return _error == null; 69 | } 70 | 71 | public SparkError getError() { 72 | return _error; 73 | } 74 | 75 | public T getData() { 76 | return _data; 77 | } 78 | 79 | public String toString() { 80 | return Objects.toStringByAnnotation(this); 81 | } 82 | 83 | private static SparkError makeError(Throwable t) { 84 | return new SparkError(SparkError.ErrorCode.UNEXPECTED_ERROR, t.toString()); 85 | } 86 | 87 | private static SparkError makeError(Response res) { 88 | StringBuilder message = new StringBuilder().append(res.code()).append("/").append(res.message()); 89 | try { 90 | String body = res.errorBody().string(); 91 | message.append("/").append(body); 92 | } catch (IOException e) { 93 | e.printStackTrace(); 94 | } 95 | return new SparkError(SparkError.ErrorCode.SERVICE_ERROR, message.toString()); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/membership/Membership.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.membership; 24 | 25 | import java.util.Date; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.annotations.SerializedName; 29 | 30 | /** 31 | * Membership contents. 32 | * 33 | * @since 0.1 34 | */ 35 | public class Membership { 36 | 37 | @SerializedName("id") 38 | private String _id; 39 | 40 | @SerializedName("personId") 41 | private String _personId; 42 | 43 | @SerializedName("personEmail") 44 | private String _personEmail; 45 | 46 | @SerializedName("personDisplayName") 47 | private String _personDisplayName; 48 | 49 | @SerializedName("personOrgId") 50 | private String _personOrgId; 51 | 52 | @SerializedName("roomId") 53 | private String _roomId; 54 | 55 | @SerializedName("isModerator") 56 | private boolean _isModerator; 57 | 58 | @SerializedName("isMonitor") 59 | private boolean _isMonitor; 60 | 61 | @SerializedName("created") 62 | private Date _created; 63 | 64 | /** 65 | * @return The id of this membership. 66 | * @since 0.1 67 | */ 68 | public String getId() { 69 | return _id; 70 | } 71 | 72 | /** 73 | * @return The id of the person. 74 | * @since 0.1 75 | */ 76 | public String getPersonId() { 77 | return _personId; 78 | } 79 | 80 | /** 81 | * @return The email address of the person. 82 | * @since 0.1 83 | */ 84 | public String getPersonEmail() { 85 | return _personEmail; 86 | } 87 | 88 | /** 89 | * @return The display name of the person. 90 | * @since 0.1 91 | */ 92 | public String getPersonDisplayName() { 93 | return _personDisplayName; 94 | } 95 | 96 | /** 97 | * @return The id of the room. 98 | * @since 0.1 99 | */ 100 | public String getRoomId() { 101 | return _roomId; 102 | } 103 | 104 | /** 105 | * @return True if this member is a moderator of the room in this membership. Otherwise false. 106 | * @since 0.1 107 | */ 108 | public boolean isModerator() { 109 | return _isModerator; 110 | } 111 | 112 | /** 113 | * @return True if this member is a monitor of the room in this membership. Otherwise false. 114 | * @since 0.1 115 | */ 116 | public boolean isMonitor() { 117 | return _isMonitor; 118 | } 119 | 120 | /** 121 | * @return The timestamp that the membership being created. 122 | * @since 0.1 123 | */ 124 | public Date getCreated() { 125 | return _created; 126 | } 127 | 128 | /** 129 | * @return The personOrgId name of the person 130 | * @since 1.4 131 | */ 132 | public String getPersonOrgId() { 133 | return _personOrgId; 134 | } 135 | 136 | @Override 137 | public String toString() { 138 | Gson gson = new Gson(); 139 | return gson.toJson(this); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/membership/MembershipClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.membership; 24 | 25 | import java.util.List; 26 | 27 | import android.support.annotation.NonNull; 28 | import android.support.annotation.Nullable; 29 | 30 | import com.ciscospark.androidsdk.CompletionHandler; 31 | 32 | /** 33 | * A client wrapper of the Cisco Spark Room Memberships REST API 34 | * 35 | * @since 0.1 36 | */ 37 | public interface MembershipClient { 38 | 39 | /** 40 | * Lists all room memberships where the authenticated user belongs. 41 | * 42 | * @param roomId The identifier of the room where the membership belongs. 43 | * @param personId The identifier of the person who has the memberships. 44 | * @param personEmail The email address of the person who has the memberships. 45 | * @param max The maximum number of items in the response. 46 | * @param handler A closure to be executed once the request has finished. 47 | * @since 0.1 48 | */ 49 | void list(@Nullable String roomId, @Nullable String personId, @Nullable String personEmail, int max, @NonNull CompletionHandler> handler); 50 | 51 | /** 52 | * Adds a person to a room by person id; optionally making the person a moderator. 53 | * 54 | * @param roomId The identifier of the room where the person is to be added. 55 | * @param personId The identifier of the person to be added. 56 | * @param personEmail The email address of the person to be added. 57 | * @param isModerator If true, make the person a moderator of the room. The default is false. 58 | * @param handler A closure to be executed once the request has finished. 59 | * @since 0.1 60 | */ 61 | void create(@NonNull String roomId, @Nullable String personId, @Nullable String personEmail, boolean isModerator, @NonNull CompletionHandler handler); 62 | 63 | /** 64 | * Retrieves the details for a membership by membership id. 65 | * 66 | * @param membershipId The identifier of the membership. 67 | * @param handler A closure to be executed once the request has finished. 68 | * @since 0.1 69 | */ 70 | void get(@NonNull String membershipId, @NonNull CompletionHandler handler); 71 | 72 | /** 73 | * Updates the properties of a membership by membership id. 74 | * 75 | * @param membershipId The identifier of the membership. 76 | * @param isModerator If true, make the person a moderator of the room in this membership. The default is false. 77 | * @param handler A closure to be executed once the request has finished. 78 | * @since 0.1 79 | */ 80 | void update(@NonNull String membershipId, boolean isModerator, @NonNull CompletionHandler handler); 81 | 82 | /** 83 | * Deletes a membership by membership id. It removes the person from the room where the membership belongs. 84 | * 85 | * @param membershipId The identifier of the membership. 86 | * @param handler A closure to be executed once the request has finished. 87 | * @since 0.1 88 | */ 89 | void delete(@NonNull String membershipId, @NonNull CompletionHandler handler); 90 | 91 | } 92 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/membership/internal/MembershipClientImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.membership.internal; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import android.support.annotation.NonNull; 29 | import android.support.annotation.Nullable; 30 | 31 | import com.ciscospark.androidsdk.CompletionHandler; 32 | import com.ciscospark.androidsdk.auth.Authenticator; 33 | import com.ciscospark.androidsdk.membership.Membership; 34 | import com.ciscospark.androidsdk.membership.MembershipClient; 35 | import com.ciscospark.androidsdk.utils.http.ListBody; 36 | import com.ciscospark.androidsdk.utils.http.ListCallback; 37 | import com.ciscospark.androidsdk.utils.http.ObjectCallback; 38 | import com.ciscospark.androidsdk.utils.http.ServiceBuilder; 39 | 40 | import me.helloworld.utils.collection.Maps; 41 | import retrofit2.Call; 42 | import retrofit2.http.Body; 43 | import retrofit2.http.DELETE; 44 | import retrofit2.http.GET; 45 | import retrofit2.http.Header; 46 | import retrofit2.http.POST; 47 | import retrofit2.http.PUT; 48 | import retrofit2.http.Path; 49 | import retrofit2.http.Query; 50 | 51 | public class MembershipClientImpl implements MembershipClient { 52 | 53 | private Authenticator _authenticator; 54 | 55 | private MembershipService _service; 56 | 57 | 58 | public MembershipClientImpl(Authenticator authenticator) { 59 | _authenticator = authenticator; 60 | _service = new ServiceBuilder().build(MembershipService.class); 61 | } 62 | 63 | public void list(@Nullable String roomId, @Nullable String personId, @Nullable String personEmail, int max, @NonNull CompletionHandler> handler) { 64 | ServiceBuilder.async(_authenticator, handler, s -> 65 | _service.list(s, roomId, personId, personEmail, max <= 0 ? null : max), new ListCallback<>(handler)); 66 | } 67 | 68 | public void create(@NonNull String roomId, @Nullable String personId, @Nullable String personEmail, boolean isModerator, @NonNull CompletionHandler handler) { 69 | ServiceBuilder.async(_authenticator, handler, s -> 70 | _service.create(s, Maps.makeMap("roomId", roomId, "personId", personId, "personEmail", personEmail, "isModerator", isModerator)), new ObjectCallback<>(handler)); 71 | } 72 | 73 | public void get(@NonNull String membershipId, @NonNull CompletionHandler handler) { 74 | ServiceBuilder.async(_authenticator, handler, s -> 75 | _service.get(s, membershipId), new ObjectCallback<>(handler)); 76 | } 77 | 78 | public void update(@NonNull String membershipId, boolean isModerator, @NonNull CompletionHandler handler) { 79 | ServiceBuilder.async(_authenticator, handler, s -> 80 | _service.update(s, membershipId, Maps.makeMap("isModerator", isModerator)), new ObjectCallback<>(handler)); 81 | } 82 | 83 | public void delete(@NonNull String membershipId, @NonNull CompletionHandler handler) { 84 | ServiceBuilder.async(_authenticator, handler, s -> 85 | _service.delete(s, membershipId), new ObjectCallback<>(handler)); 86 | } 87 | 88 | private interface MembershipService { 89 | @GET("memberships") 90 | Call> list(@Header("Authorization") String authorization, 91 | @Query("roomId") String roomId, 92 | @Query("personId") String personId, 93 | @Query("personEmail") String personEmail, 94 | @Query("max") Integer max); 95 | 96 | @POST("memberships") 97 | Call create(@Header("Authorization") String authorization, @Body Map parameters); 98 | 99 | @GET("memberships/{membershipId}") 100 | Call get(@Header("Authorization") String authorization, @Path("membershipId") String membershipId); 101 | 102 | @PUT("memberships/{membershipId}") 103 | Call update(@Header("Authorization") String authorization, @Path("membershipId") String membershipId, @Body Map parameters); 104 | 105 | @DELETE("memberships/{membershipId}") 106 | Call delete(@Header("Authorization") String authorization, @Path("membershipId") String membershipId); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/message/LocalFile.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.message; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * A data type represents a local file. 7 | * 8 | * @since 1.4.0 9 | */ 10 | public class LocalFile { 11 | 12 | /** 13 | * A data type represents a local file thumbnail. 14 | * 15 | * @since 1.4.0 16 | */ 17 | public static class Thumbnail { 18 | public String path; 19 | public int width; 20 | public int height; 21 | public long size; 22 | public String mimeType; 23 | } 24 | 25 | public String path; 26 | public String name; 27 | public long size; 28 | public String mimeType; 29 | public MessageClient.ProgressHandler progressHandler; 30 | public Thumbnail thumbnail; 31 | 32 | public LocalFile(File file) { 33 | this._file = file; 34 | if (_file.exists() && _file.isFile()) { 35 | this.name = file.getName(); 36 | this.size = file.length(); 37 | this.path = file.getPath(); 38 | } 39 | } 40 | 41 | public File getFile() { 42 | return _file; 43 | } 44 | 45 | private File _file; 46 | } 47 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/message/Mention.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.message; 2 | 3 | /** 4 | * A data type represents mention. 5 | * @since 1.4.0 6 | */ 7 | public abstract class Mention { 8 | 9 | /** 10 | * Mention one particular person by person Id. 11 | * @since 1.4.0 12 | */ 13 | public static class MentionPerson extends Mention { 14 | public String personId; 15 | 16 | public MentionPerson(String personId) { 17 | this.personId = personId; 18 | } 19 | } 20 | 21 | /** 22 | * Mention all people in a room. 23 | * @since 1.4.0 24 | */ 25 | public static class MentionAll extends Mention { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/message/MessageObserver.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.message; 2 | 3 | /** 4 | * The struct of a message event 5 | * @since 1.4.0 6 | */ 7 | public interface MessageObserver { 8 | 9 | /** 10 | * 11 | */ 12 | abstract class MessageEvent { 13 | } 14 | 15 | /** 16 | * The struct of a new message received event 17 | * @since 1.4.0 18 | */ 19 | class MessageArrived extends MessageEvent { 20 | private Message message; 21 | 22 | public MessageArrived(Message message) { 23 | this.message = message; 24 | } 25 | public Message getMessage() { 26 | return message; 27 | } 28 | 29 | public void setMessage(Message message) { 30 | this.message = message; 31 | } 32 | } 33 | 34 | /** 35 | * The struct of a message delete event 36 | * @since 1.4.0 37 | */ 38 | class MessageDeleted extends MessageEvent { 39 | private String messageId; 40 | 41 | public MessageDeleted(String messageId) { 42 | this.messageId = messageId; 43 | } 44 | 45 | public String getMessageId() { 46 | return messageId; 47 | } 48 | } 49 | 50 | /** 51 | * Call back when message arrived. 52 | * @param event Message event 53 | */ 54 | void onEvent(MessageEvent event); 55 | } 56 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/message/RemoteFile.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.message; 2 | 3 | /** 4 | * Data struct for a remote file. 5 | * @since 1.4.0 6 | */ 7 | public class RemoteFile { 8 | 9 | /** 10 | * A data type represents a thumbnail file. 11 | * @since 1.4.0 12 | */ 13 | public class Thumbnail { 14 | public int width; 15 | public int height; 16 | public String mimeType; 17 | public String url; 18 | } 19 | 20 | public String displayName; 21 | public String mimeType; 22 | public Long size; 23 | public String url; 24 | public Thumbnail thumbnail; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/people/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.people; 24 | 25 | import java.util.Date; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.annotations.SerializedName; 29 | 30 | /** 31 | * Person contents. 32 | * 33 | * @since 0.1 34 | */ 35 | public class Person { 36 | 37 | @SerializedName("id") 38 | private String _id; 39 | 40 | @SerializedName("emails") 41 | private String[] _emails; 42 | 43 | @SerializedName("displayName") 44 | private String _displayName; 45 | 46 | @SerializedName("nickName") 47 | private String _nickName; 48 | 49 | @SerializedName("firstName") 50 | private String _firstName; 51 | 52 | @SerializedName("lastName") 53 | private String _lastName; 54 | 55 | @SerializedName("avatar") 56 | private String _avatar; 57 | 58 | @SerializedName("orgId") 59 | private String _orgId; 60 | 61 | @SerializedName("created") 62 | private Date _created; 63 | 64 | @SerializedName("lastActivity") 65 | private String _lastActivity; // may not exist 66 | 67 | @SerializedName("status") 68 | private String _status; // may not exist 69 | 70 | @SerializedName("type") 71 | private String _type; // bot/person 72 | 73 | /** 74 | * @return The id of this person. 75 | * @since 0.1 76 | */ 77 | public String getId() { 78 | return _id; 79 | } 80 | 81 | /** 82 | * @return The emails of this person. 83 | * @since 0.1 84 | */ 85 | public String[] getEmails() { 86 | return _emails; 87 | } 88 | 89 | /** 90 | * @return The display name of this person. 91 | * @since 0.1 92 | */ 93 | public String getDisplayName() { 94 | return _displayName; 95 | } 96 | 97 | /** 98 | * @return The URL of this person's avatar. 99 | * @since 0.1 100 | */ 101 | public String getAvatar() { 102 | return _avatar; 103 | } 104 | 105 | /** 106 | * @return The timestamp that this person being created. 107 | * @since 0.1 108 | */ 109 | public Date getCreated() { 110 | return _created; 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | Gson gson = new Gson(); 116 | return gson.toJson(this); 117 | } 118 | 119 | /** 120 | * @return The nick name of person 121 | * @since 1.4 122 | */ 123 | public String getNickName() { 124 | return _nickName; 125 | } 126 | 127 | /** 128 | * @return The nick first name of person 129 | * @since 1.4 130 | */ 131 | public String getFirstName() { 132 | return _firstName; 133 | } 134 | 135 | /** 136 | * @return The nick last name of person 137 | * @since 1.4 138 | */ 139 | public String getLastName() { 140 | return _lastName; 141 | } 142 | 143 | /** 144 | * @return The nick org Id of person 145 | * @since 1.4 146 | */ 147 | public String getOrgId() { 148 | return _orgId; 149 | } 150 | 151 | /** 152 | * @return The nick type of person, default is "person" 153 | * @since 1.4 154 | */ 155 | public String getType() { 156 | return _type; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/people/PersonClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.people; 24 | 25 | import java.util.List; 26 | 27 | import android.support.annotation.NonNull; 28 | import android.support.annotation.Nullable; 29 | 30 | import com.ciscospark.androidsdk.CompletionHandler; 31 | 32 | /** 33 | * A client wrapper of the Cisco Spark People REST API 34 | * 35 | * @since 0.1 36 | */ 37 | public interface PersonClient { 38 | 39 | /** 40 | * Lists people in the authenticated user's organization. 41 | * 42 | * @param email If not nil, only list people with this email address. 43 | * @param displayName If not nil, only list people whose name starts with this string. 44 | * @param max The maximum number of people in the response. 45 | * @param handler A closure to be executed once the request has finished. 46 | * @since 0.1 47 | */ 48 | void list(@NonNull String email, @Nullable String displayName, int max, @NonNull CompletionHandler> handler); 49 | 50 | /** 51 | * Retrieves the details for a person by person id. 52 | * 53 | * @param personId The identifier of the person. 54 | * @param handler A closure to be executed once the request has finished. 55 | * @since 0.1 56 | */ 57 | void get(@NonNull String personId, @NonNull CompletionHandler handler); 58 | 59 | /** 60 | * Retrieves the details for the authenticated user. 61 | * 62 | * @param handler A closure to be executed once the request has finished. 63 | * @since 0.1 64 | */ 65 | void getMe(@NonNull CompletionHandler handler); 66 | 67 | /** Create people in the authenticated user's organization. 68 | * Only admins are able to use this function 69 | * 70 | * @param email Email address of the person. 71 | * @param displayName Full name of the person. 72 | * @param firstName firstName name of the person. 73 | * @param lastName lastName firstName name of the person. 74 | * @param avatar URL to the person's avatar in PNG format. 75 | * @param orgId ID of the organization to which this person belongs. 76 | * @param roles Roles of the person. 77 | * @param licenses Licenses allocated to the person. 78 | * @param handler A closure to be executed once the request has finished. 79 | * @since 1.4 80 | */ 81 | void create(@NonNull String email, @Nullable String displayName, @Nullable String firstName, @Nullable String lastName, 82 | @Nullable String avatar, @Nullable String orgId, @Nullable String roles, @Nullable String licenses, @NonNull CompletionHandler handler); 83 | 84 | /** Update people in the authenticated user's organization. 85 | * Only admins are able to use this function 86 | * 87 | * @param personId The identifier of the person. 88 | * @param email Email address of the person. 89 | * @param displayName Full name of the person. 90 | * @param firstName firstName name of the person. 91 | * @param lastName lastName firstName name of the person. 92 | * @param avatar URL to the person's avatar in PNG format. 93 | * @param orgId ID of the organization to which this person belongs. 94 | * @param roles Roles of the person. 95 | * @param licenses Licenses allocated to the person. 96 | * @param handler A closure to be executed once the request has finished. 97 | * @since 1.4 98 | */ 99 | void update(@NonNull String personId, @Nullable String email, @Nullable String displayName, @Nullable String firstName, @Nullable String lastName, 100 | @Nullable String avatar, @Nullable String orgId, @Nullable String roles, @Nullable String licenses, @NonNull CompletionHandler handler); 101 | 102 | /** Delete the details of person by person id. 103 | * Only admins are able to use this function 104 | * 105 | * @param personId The identifier of the person. 106 | * @param handler A closure to be executed once the request has finished. 107 | * @since 1.4 108 | */ 109 | void delete(@NonNull String personId, @NonNull CompletionHandler handler); 110 | 111 | } 112 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/phone/CallMembership.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.phone; 24 | 25 | /** 26 | * A data type represents a relationship between *Call* and *Person* at Cisco Spark cloud. 27 | * 28 | * @since 0.1 29 | */ 30 | public interface CallMembership { 31 | 32 | /** 33 | * The enumeration of the status of the person in the membership. 34 | * 35 | * @since 0.1 36 | */ 37 | enum State { 38 | /** 39 | * The person status is unknown. 40 | * 41 | * @since 0.1 42 | */ 43 | UNKNOWN, 44 | /** 45 | * The person is idle w/o any call. 46 | * 47 | * @since 0.1 48 | */ 49 | IDLE, 50 | /** 51 | * The person has been notified about the call. 52 | * 53 | * @since 0.1* 54 | */ 55 | NOTIFIED, 56 | /** 57 | * The person has joined the call. 58 | * 59 | * @since 0.1 60 | */ 61 | JOINED, 62 | /** 63 | * The person has left the call. 64 | * 65 | * @since 0.1 66 | */ 67 | LEFT, 68 | /** 69 | * The person has declined the call. 70 | * 71 | * @since 0.1 72 | */ 73 | DECLINED 74 | } 75 | 76 | /** 77 | * @return True if the person is the initiator of the call. 78 | * @since 0.1 79 | */ 80 | boolean isInitiator(); 81 | 82 | /** 83 | * @return The identifier of the person. 84 | * @since 0.1 85 | */ 86 | String getPersonId(); 87 | 88 | /** 89 | * @return The status of the person in this CallMembership. 90 | * @since 0.1 91 | */ 92 | State getState(); 93 | 94 | /** 95 | * @return The email address of the person in this CallMembership. 96 | * @since 0.1 97 | */ 98 | String getEmail(); 99 | 100 | /** 101 | * @return The SIP address of the person in this CallMembership. 102 | * @since 0.1 103 | */ 104 | String getSipUrl(); 105 | 106 | /** 107 | * @return The phone number of the person in this CallMembership. 108 | * @since 0.1 109 | */ 110 | String getPhoneNumber(); 111 | 112 | /** 113 | * @return True if the CallMembership is sending video. Otherwise, false. 114 | * @since 0.1 115 | */ 116 | boolean isSendingVideo(); 117 | 118 | /** 119 | * @return True if the CallMembership is sending audio. Otherwise, false. 120 | * @since 0.1 121 | */ 122 | boolean isSendingAudio(); 123 | 124 | /** 125 | * @return True if the CallMembership is sending content share. Otherwise, false. 126 | * @since 1.3.0 127 | */ 128 | boolean isSendingSharing(); 129 | } 130 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/phone/MediaOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.phone; 24 | 25 | import android.support.annotation.NonNull; 26 | import android.support.annotation.Nullable; 27 | import android.util.Pair; 28 | import android.view.View; 29 | 30 | /** 31 | * A data type represents the media options of a call. 32 | * 33 | * @since 0.1 34 | */ 35 | public class MediaOption { 36 | 37 | /** 38 | * Constructs an audio only media option. 39 | * 40 | * @since 0.1 41 | */ 42 | public static MediaOption audioOnly() { 43 | return new MediaOption(null, null, null, false, false); 44 | } 45 | 46 | /** 47 | * Constructs an audio and video media option. 48 | * 49 | * @param localView Video view for self. 50 | * @param remoteView Video view for remote 51 | * @since 0.1 52 | */ 53 | public static MediaOption audioVideo(@NonNull View localView, @NonNull View remoteView) { 54 | return new MediaOption(localView, remoteView, null, false, true); 55 | } 56 | 57 | /** 58 | * Constructs an audio and video media option. 59 | * 60 | * @param videoRenderViews Local video view and remote video view. 61 | * @since 1.3.0 62 | */ 63 | public static MediaOption audioVideo(@Nullable Pair videoRenderViews) { 64 | if (videoRenderViews == null || videoRenderViews.first == null || videoRenderViews.second == null) { 65 | return new MediaOption(null, null, null, false, true); 66 | } 67 | return new MediaOption(videoRenderViews.first, videoRenderViews.second, null, false, true); 68 | } 69 | 70 | /** 71 | * Constructs an audio/video and share media option. 72 | * 73 | * @param videoRenderViews Local video view and remote video view. 74 | * @param sharingView share view for remote. 75 | * @since 1.3.0 76 | */ 77 | public static MediaOption audioVideoSharing(@Nullable Pair videoRenderViews, @Nullable View sharingView) { 78 | if (videoRenderViews == null || videoRenderViews.first == null || videoRenderViews.second == null) { 79 | return new MediaOption(null, null, sharingView, true, true); 80 | } 81 | return new MediaOption(videoRenderViews.first, videoRenderViews.second, sharingView, true, true); 82 | } 83 | 84 | private View _remoteView; 85 | 86 | private View _localView; 87 | 88 | private View _sharingView; 89 | 90 | private boolean _hasSharing; 91 | 92 | private boolean _hasVideo; 93 | 94 | private MediaOption(@Nullable View localView, @Nullable View remoteView, @Nullable View sharingView, boolean hasSharing, boolean hasVideo) { 95 | _localView = localView; 96 | _remoteView = remoteView; 97 | _sharingView = sharingView; 98 | _hasSharing = hasSharing; 99 | _hasVideo = hasVideo; 100 | } 101 | 102 | /** 103 | * Whether video is enabled. 104 | * 105 | * @return False if neither local or remote video is enabled. Otherwise, true. 106 | * @since 0.1 107 | */ 108 | public boolean hasVideo() { 109 | return _hasVideo; 110 | } 111 | 112 | /** 113 | * Whether content sharing is enabled. 114 | * 115 | * @return true if content sharing is enabled. Otherwise, false. 116 | * @since 1.3.0 117 | */ 118 | public boolean hasSharing() { 119 | return _hasSharing; 120 | } 121 | 122 | /** 123 | * @return The remote video view 124 | * @since 0.1 125 | */ 126 | public View getRemoteView() { 127 | return _remoteView; 128 | } 129 | 130 | /** 131 | * @return The local video view 132 | * @since 0.1 133 | */ 134 | public View getLocalView() { 135 | return _localView; 136 | } 137 | 138 | /** 139 | * @return The sharing view 140 | * @since 1.3.0 141 | */ 142 | public View getSharingView() { 143 | return _sharingView; 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/phone/MediaRenderView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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 | 24 | package com.ciscospark.androidsdk.phone; 25 | 26 | import android.annotation.TargetApi; 27 | import android.content.Context; 28 | import android.util.AttributeSet; 29 | 30 | import com.webex.wseclient.WseSurfaceView; 31 | 32 | 33 | /** 34 | * Spark media view for local, remote and screen share 35 | *

36 | * This view is use by {@link MediaOption} and should be placed in Android layout xml file. 37 | *

38 | * e.g. 39 | * 40 | * @see MediaOption 41 | * @since 1.4 42 | */ 43 | public class MediaRenderView extends WseSurfaceView { 44 | public MediaRenderView(Context context) { 45 | super(context); 46 | } 47 | 48 | public MediaRenderView(Context var1, AttributeSet var2) { 49 | super(var1, var2); 50 | } 51 | 52 | public MediaRenderView(Context var1, AttributeSet var2, int var3) { 53 | super(var1, var2, var3); 54 | } 55 | 56 | @TargetApi(21) 57 | public MediaRenderView(Context var1, AttributeSet var2, int var3, int var4) { 58 | super(var1, var2, var3, var4); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/phone/internal/CallMembershipImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.phone.internal; 24 | 25 | import com.cisco.spark.android.locus.model.LocusParticipant; 26 | import com.cisco.spark.android.locus.model.LocusParticipantInfo; 27 | import com.cisco.spark.android.locus.model.MediaDirection; 28 | import com.ciscospark.androidsdk.phone.Call; 29 | import com.ciscospark.androidsdk.phone.CallMembership; 30 | 31 | import me.helloworld.utils.Objects; 32 | import me.helloworld.utils.annotation.StringPart; 33 | 34 | /** 35 | * Created on 12/06/2017. 36 | */ 37 | 38 | public class CallMembershipImpl implements CallMembership { 39 | 40 | private static CallMembership.State fromLocusState(LocusParticipant.State state) { 41 | if (state == LocusParticipant.State.IDLE) { 42 | return CallMembership.State.IDLE; 43 | } else if (state == LocusParticipant.State.NOTIFIED) { 44 | return State.NOTIFIED; 45 | } else if (state == LocusParticipant.State.JOINED) { 46 | return State.JOINED; 47 | } else if (state == LocusParticipant.State.LEFT) { 48 | return State.LEFT; 49 | } else if (state == LocusParticipant.State.DECLINED) { 50 | return State.DECLINED; 51 | } else if (state == LocusParticipant.State.LEAVING) { 52 | return State.LEFT; 53 | } else { 54 | return State.UNKNOWN; 55 | } 56 | } 57 | 58 | @StringPart 59 | private boolean _isInitiator = false; 60 | 61 | @StringPart 62 | private String _personId; 63 | 64 | @StringPart 65 | private State _state = State.UNKNOWN; 66 | 67 | @StringPart 68 | private String _email; 69 | 70 | @StringPart 71 | private String _sipUrl; 72 | 73 | @StringPart 74 | private String _phoneNumber; 75 | 76 | @StringPart 77 | private boolean _sendingVideo = false; 78 | 79 | @StringPart 80 | private boolean _sendingAudio = false; 81 | 82 | @StringPart 83 | private boolean _sendingSharing = false; 84 | 85 | CallMembershipImpl(LocusParticipant participant, Call call) { 86 | LocusParticipantInfo person = participant.getPerson(); 87 | _personId = person.getId(); 88 | _email = person.getEmail(); 89 | _phoneNumber = person.getPhoneNumber(); 90 | _sipUrl = person.getPhoneNumber(); 91 | _isInitiator = participant.isCreator(); 92 | _state = fromLocusState(participant.getState()); 93 | _sendingVideo = MediaDirection.SENDRECV.equals(participant.getStatus().getVideoStatus()); 94 | _sendingAudio = MediaDirection.SENDRECV.equals(participant.getStatus().getAudioStatus()); 95 | _sendingSharing = false; 96 | if (call instanceof CallImpl && ((CallImpl) call).getSharingSender() != null) { 97 | _sendingSharing = ((CallImpl) call).getSharingSender().getPerson().getId().equalsIgnoreCase(person.getId()); 98 | } 99 | 100 | } 101 | 102 | public boolean isInitiator() { 103 | return _isInitiator; 104 | } 105 | 106 | public String getPersonId() { 107 | return _personId; 108 | } 109 | 110 | public State getState() { 111 | return _state; 112 | } 113 | 114 | public String getEmail() { 115 | return _email; 116 | } 117 | 118 | public String getSipUrl() { 119 | return _sipUrl; 120 | } 121 | 122 | public String getPhoneNumber() { 123 | return _phoneNumber; 124 | } 125 | 126 | public boolean isSendingVideo() { 127 | return _sendingVideo; 128 | } 129 | 130 | public boolean isSendingAudio() { 131 | return _sendingAudio; 132 | } 133 | 134 | public boolean isSendingSharing() { 135 | return _sendingSharing; 136 | } 137 | 138 | public String toString() { 139 | return Objects.toStringByAnnotation(this); 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/phone/internal/H264LicensePrompter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.phone.internal; 24 | 25 | import android.app.AlertDialog; 26 | import android.content.Context; 27 | import android.content.DialogInterface; 28 | import android.content.Intent; 29 | import android.content.SharedPreferences; 30 | import android.net.Uri; 31 | import android.support.annotation.NonNull; 32 | 33 | import com.github.benoitdion.ln.Ln; 34 | 35 | /** 36 | * Created with IntelliJ IDEA. 37 | * User: zhiyuliu 38 | * Date: 15/09/2017 39 | * Time: 6:42 PM 40 | */ 41 | 42 | public class H264LicensePrompter { 43 | 44 | public interface CompletionHandler { 45 | void onComplete(T result); 46 | } 47 | 48 | private SharedPreferences _preferences; 49 | 50 | H264LicensePrompter(SharedPreferences preferences) { 51 | _preferences = preferences; 52 | } 53 | 54 | String getLicense() { 55 | return "To enable video calls, activate a free video license (H.264 AVC) from Cisco. By selecting 'Activate', you accept the Cisco End User License Agreement and Notices."; 56 | } 57 | 58 | String getLicenseURL() { 59 | return "http://www.openh264.org/BINARY_LICENSE.txt"; 60 | } 61 | 62 | void check(@NonNull AlertDialog.Builder builder, @NonNull CompletionHandler handler) { 63 | if (isVideoLicenseActivated() || isVideoLicenseActivationDisabled()) { 64 | handler.onComplete(true); 65 | } else { 66 | Context context = builder.getContext(); 67 | builder.setTitle("Activate License"); 68 | builder.setMessage(getLicense()); 69 | builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() { 70 | @Override 71 | public void onClick(DialogInterface dialog, int which) { 72 | Ln.i("Video license has been activated"); 73 | setVideoLicenseActivated(true); 74 | handler.onComplete(true); 75 | } 76 | }); 77 | 78 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 79 | @Override 80 | public void onClick(DialogInterface dialog, int which) { 81 | Ln.i("Video license has not been activated"); 82 | dialog.cancel(); 83 | handler.onComplete(false); 84 | } 85 | }); 86 | 87 | builder.setNeutralButton("View License", new DialogInterface.OnClickListener() { 88 | @Override 89 | public void onClick(DialogInterface dialog, int which) { 90 | Ln.i("Video license opened for viewing"); 91 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getLicenseURL())); 92 | context.startActivity(browserIntent); 93 | dialog.cancel(); 94 | handler.onComplete(false); 95 | } 96 | }); 97 | AlertDialog diag = builder.create(); 98 | diag.show(); 99 | } 100 | } 101 | 102 | boolean isVideoLicenseActivationDisabled() { 103 | return _preferences.getBoolean("isVideoLicenseActivationDisabledKey", false); 104 | } 105 | 106 | void setVideoLicenseActivationDisabled(boolean disabled) { 107 | _preferences.edit().putBoolean("isVideoLicenseActivationDisabledKey", disabled).apply(); 108 | } 109 | 110 | void reset() { 111 | setVideoLicenseActivationDisabled(false); 112 | setVideoLicenseActivated(false); 113 | } 114 | 115 | private boolean isVideoLicenseActivated() { 116 | return _preferences.getBoolean("isVideoLicenseActivatedKey", false); 117 | } 118 | 119 | private void setVideoLicenseActivated(boolean activated) { 120 | _preferences.edit().putBoolean("isVideoLicenseActivatedKey", activated).apply(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/phone/internal/RotationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.phone.internal; 24 | 25 | 26 | import android.content.BroadcastReceiver; 27 | import android.content.Context; 28 | import android.content.Intent; 29 | import android.content.IntentFilter; 30 | import android.os.Bundle; 31 | import android.view.WindowManager; 32 | 33 | public class RotationHandler { 34 | private static BroadcastReceiver _receiver; 35 | 36 | static int getRotation(Context context) { 37 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 38 | int rotation = windowManager.getDefaultDisplay().getRotation(); 39 | return rotation; 40 | } 41 | 42 | 43 | static class RotationBroadcastReceiver extends BroadcastReceiver { 44 | PhoneImpl _phoneImpl; 45 | 46 | public RotationBroadcastReceiver(PhoneImpl phoneImpl) { 47 | super(); 48 | _phoneImpl = phoneImpl; 49 | } 50 | 51 | @Override 52 | public void onReceive(Context context, Intent intent) { 53 | _phoneImpl.setDisplayRotation(getRotation(context)); 54 | } 55 | } 56 | 57 | static void registerRotationReceiver(Context context, PhoneImpl phoneImpl) { 58 | if (_receiver == null) { 59 | _receiver = new RotationBroadcastReceiver(phoneImpl); 60 | context.registerReceiver(_receiver, new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED)); 61 | } 62 | } 63 | 64 | static void unregisterRotationReceiver(Context context) { 65 | if (_receiver != null) { 66 | context.unregisterReceiver(_receiver); 67 | _receiver = null; 68 | } 69 | } 70 | 71 | public static void setScreenshotPermission(final Intent permissionIntent) { 72 | if (_receiver != null) { 73 | ((RotationBroadcastReceiver) _receiver)._phoneImpl.setScreenshotPermission(permissionIntent); 74 | } 75 | } 76 | 77 | public static void makeCall(Bundle data, boolean permission) { 78 | if (_receiver != null) { 79 | ((RotationBroadcastReceiver) _receiver)._phoneImpl.makeCall(data, permission); 80 | } 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/room/Room.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.room; 24 | 25 | import java.util.Date; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.annotations.SerializedName; 29 | 30 | /** 31 | * A data type represents a Room at Cisco Spark cloud. 32 | *

33 | * Room has been renamed to Space in Cisco Spark. 34 | * 35 | * @since 0.1 36 | */ 37 | public class Room { 38 | 39 | /** 40 | * The enumeration of the types of a room. 41 | * 42 | * @since 0.1 43 | */ 44 | public enum RoomType { 45 | /** 46 | * Group room among multiple people 47 | * 48 | * @since 0.1 49 | */ 50 | @SerializedName("group") 51 | group, 52 | 53 | /** 54 | * 1-to-1 room between two people 55 | * 56 | * @since 0.1 57 | */ 58 | @SerializedName("direct") 59 | direct 60 | } 61 | 62 | @SerializedName("id") 63 | private String _id; 64 | 65 | @SerializedName("title") 66 | private String _title; 67 | 68 | @SerializedName("type") 69 | private RoomType _type; 70 | 71 | @SerializedName("teamId") 72 | private String _teamId; 73 | 74 | @SerializedName("isLocked") 75 | private boolean _isLocked; 76 | 77 | @SerializedName("lastActivity") 78 | private Date _lastActivity; 79 | 80 | @SerializedName("created") 81 | private Date _created; 82 | 83 | @SerializedName("sipAddress") 84 | private String _sipAddress; 85 | 86 | @Override 87 | public String toString() { 88 | Gson gson = new Gson(); 89 | return gson.toJson(this); 90 | } 91 | 92 | /** 93 | * @return The identifier of this room. 94 | * @since 0.1 95 | */ 96 | public String getId() { 97 | return _id; 98 | } 99 | 100 | /** 101 | * @return The title of this room. 102 | * @since 0.1 103 | */ 104 | public String getTitle() { 105 | return _title; 106 | } 107 | 108 | /** 109 | * @return The type of this room. 110 | * @since 0.1 111 | */ 112 | public RoomType getType() { 113 | return _type; 114 | } 115 | 116 | /** 117 | * @return The team Id that this room associated with. 118 | * @since 0.1 119 | */ 120 | public String getTeamId() { 121 | return _teamId; 122 | } 123 | 124 | /** 125 | * @return Indicate if this room is locked. 126 | * @since 0.1 127 | */ 128 | public boolean isLocked() { 129 | return _isLocked; 130 | } 131 | 132 | /** 133 | * @return Last activity of this room. 134 | * @since 0.1 135 | */ 136 | public Date getLastActivity() { 137 | return _lastActivity; 138 | } 139 | 140 | /** 141 | * @return The timestamp that this room being created. 142 | * @since 0.1 143 | */ 144 | public Date getCreated() { 145 | return _created; 146 | } 147 | 148 | /** 149 | * @return The sipAddress that this room associated with. 150 | * @since 1.4 151 | */ 152 | public String getSipAddress() { 153 | return _sipAddress; 154 | } 155 | } -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/room/RoomClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.room; 24 | 25 | 26 | import java.util.List; 27 | 28 | import android.support.annotation.NonNull; 29 | import android.support.annotation.Nullable; 30 | 31 | import com.ciscospark.androidsdk.CompletionHandler; 32 | 33 | /** 34 | * A client wrapper of the Cisco Spark Rooms REST API 35 | * 36 | * @since 0.1 37 | */ 38 | public interface RoomClient { 39 | 40 | /** 41 | * Sort results by room ID (id), most recent activity (lastactivity), or most recently created (created). 42 | * 43 | * @since 0.1 44 | */ 45 | enum SortBy { 46 | ID, LASTACTIVITY, CREATED 47 | } 48 | 49 | /** 50 | * Lists all rooms where the authenticated user belongs. 51 | * 52 | * @param teamId If not nil, only list the rooms that are associated with the team by team id. 53 | * @param max The maximum number of rooms in the response. 54 | * @param type If not nil, only list the rooms of this type. Otherwise all rooms are listed. 55 | * @param sortBy Sort results by room ID (id), most recent activity (lastactivity), or most recently created (created). 56 | * @param handler A closure to be executed once the request has finished. 57 | * @since 0.1 58 | */ 59 | void list(@Nullable String teamId, int max, @Nullable Room.RoomType type, @Nullable SortBy sortBy, @NonNull CompletionHandler> handler); 60 | 61 | /** 62 | * Creates a room. The authenticated user is automatically added as a member of the room. See the Memberships API to learn how to add more people to the room. 63 | * 64 | * @param title A user-friendly name for the room. 65 | * @param teamId If not nil, this room will be associated with the team by team id. Otherwise, this room is not associated with any team. 66 | * @param handler A closure to be executed once the request has finished. 67 | * @see com.ciscospark.androidsdk.membership.MembershipClient 68 | * @since 0.1 69 | */ 70 | void create(@NonNull String title, @Nullable String teamId, @NonNull CompletionHandler handler); 71 | 72 | /** 73 | * Retrieves the details for a room by id. 74 | * 75 | * @param roomId The identifier of the room. 76 | * @param handler The queue on which the completion handler is dispatched. 77 | * @since 0.1 78 | */ 79 | void get(@NonNull String roomId, @NonNull CompletionHandler handler); 80 | 81 | /** 82 | * Updates the details for a room by id. 83 | * 84 | * @param roomId The identifier of the room. 85 | * @param title A user-friendly name for the room. 86 | * @param handler A closure to be executed once the request has finished. 87 | * @since 0.1 88 | */ 89 | void update(@NonNull String roomId, @NonNull String title, @NonNull CompletionHandler handler); 90 | 91 | /** 92 | * Deletes a room by id. 93 | * 94 | * @param roomId The identifier of the room. 95 | * @param handler A closure to be executed once the request has finished. 96 | * @since 0.1 97 | */ 98 | void delete(@NonNull String roomId, @NonNull CompletionHandler handler); 99 | 100 | } 101 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/room/internal/RoomClientImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.room.internal; 24 | 25 | 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | import android.support.annotation.NonNull; 30 | import android.support.annotation.Nullable; 31 | 32 | import com.ciscospark.androidsdk.CompletionHandler; 33 | import com.ciscospark.androidsdk.auth.Authenticator; 34 | import com.ciscospark.androidsdk.room.Room; 35 | import com.ciscospark.androidsdk.room.RoomClient; 36 | import com.ciscospark.androidsdk.utils.http.ListBody; 37 | import com.ciscospark.androidsdk.utils.http.ListCallback; 38 | import com.ciscospark.androidsdk.utils.http.ObjectCallback; 39 | import com.ciscospark.androidsdk.utils.http.ServiceBuilder; 40 | 41 | import me.helloworld.utils.collection.Maps; 42 | import retrofit2.Call; 43 | import retrofit2.http.Body; 44 | import retrofit2.http.DELETE; 45 | import retrofit2.http.GET; 46 | import retrofit2.http.Header; 47 | import retrofit2.http.POST; 48 | import retrofit2.http.PUT; 49 | import retrofit2.http.Path; 50 | import retrofit2.http.Query; 51 | 52 | public class RoomClientImpl implements RoomClient { 53 | 54 | private Authenticator _authenticator; 55 | 56 | private RoomService _service; 57 | 58 | public RoomClientImpl(Authenticator authenticator) { 59 | _authenticator = authenticator; 60 | _service = new ServiceBuilder().build(RoomService.class); 61 | } 62 | 63 | public void list(@Nullable String teamId, int max, @Nullable Room.RoomType type, @Nullable SortBy sortBy, @NonNull CompletionHandler> handler) { 64 | ServiceBuilder.async(_authenticator, handler, s -> 65 | _service.list(s, teamId, type != null ? type.name() : null, sortBy != null ? sortBy.name().toLowerCase() : null, max <= 0 ? null : max), new ListCallback(handler)); 66 | } 67 | 68 | public void create(@NonNull String title, @Nullable String teamId, @NonNull CompletionHandler handler) { 69 | ServiceBuilder.async(_authenticator, handler, s -> 70 | _service.create(s, Maps.makeMap("title", title, "teamId", teamId)), new ObjectCallback<>(handler)); 71 | } 72 | 73 | public void get(@NonNull String roomId, @NonNull CompletionHandler handler) { 74 | ServiceBuilder.async(_authenticator, handler, s -> 75 | _service.get(s, roomId), new ObjectCallback<>(handler)); 76 | } 77 | 78 | public void update(@NonNull String roomId, @NonNull String title, @NonNull CompletionHandler handler) { 79 | ServiceBuilder.async(_authenticator, handler, s -> 80 | _service.update(s, roomId, Maps.makeMap("title", title)), new ObjectCallback<>(handler)); 81 | } 82 | 83 | public void delete(@NonNull String roomId, @NonNull CompletionHandler handler) { 84 | ServiceBuilder.async(_authenticator, handler, s -> 85 | _service.delete(s, roomId), new ObjectCallback<>(handler)); 86 | } 87 | 88 | private interface RoomService { 89 | @GET("rooms") 90 | Call> list(@Header("Authorization") String authorization, 91 | @Query("teamId") String teamId, 92 | @Query("type") String type, 93 | @Query("sortBy") String sortBy, 94 | @Query("max") Integer max); 95 | 96 | @POST("rooms") 97 | Call create(@Header("Authorization") String authorization, @Body Map parameters); 98 | 99 | @GET("rooms/{roomId}") 100 | Call get(@Header("Authorization") String authorization, @Path("roomId") String roomId); 101 | 102 | @PUT("rooms/{roomId}") 103 | Call update(@Header("Authorization") String authorization, @Path("roomId") String roomId, @Body Map parameters); 104 | 105 | @DELETE("rooms/{roomId}") 106 | Call delete(@Header("Authorization") String authorization, @Path("roomId") String membershipId); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/team/Team.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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 | 24 | package com.ciscospark.androidsdk.team; 25 | 26 | 27 | import java.util.Date; 28 | 29 | import com.google.gson.Gson; 30 | import com.google.gson.annotations.SerializedName; 31 | 32 | /** 33 | * A data type represents a Team at Cisco Spark cloud. 34 | * 35 | * @since 0.1 36 | */ 37 | public class Team { 38 | 39 | @SerializedName("id") 40 | private String _id; 41 | 42 | @SerializedName("name") 43 | private String _name; 44 | 45 | @SerializedName("created") 46 | private Date _created; 47 | 48 | @Override 49 | public String toString() { 50 | Gson gson = new Gson(); 51 | return gson.toJson(this); 52 | } 53 | 54 | /** 55 | * @return The identifier of this team. 56 | * @since 0.1 57 | */ 58 | public String getId() { 59 | return _id; 60 | } 61 | 62 | /** 63 | * @return The name of this team 64 | * @since 0.1 65 | */ 66 | public String getName() { 67 | return _name; 68 | } 69 | 70 | /** 71 | * @return The timestamp that this team being created. 72 | * @since 0.1 73 | */ 74 | public Date getCreated() { 75 | return _created; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/team/TeamClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.team; 24 | 25 | 26 | import java.util.List; 27 | 28 | import android.support.annotation.NonNull; 29 | 30 | import com.ciscospark.androidsdk.CompletionHandler; 31 | 32 | /** 33 | * An client wrapper of the Cisco Spark Teams REST API 34 | * 35 | * @since 0.1 36 | */ 37 | public interface TeamClient { 38 | 39 | /** 40 | * Lists teams to which the authenticated user belongs. 41 | * 42 | * @param max The maximum number of teams in the response. 43 | * @param handler A closure to be executed once the request has finished. 44 | * @since 0.1 45 | */ 46 | void list(int max, @NonNull CompletionHandler> handler); 47 | 48 | /** 49 | * Creates a team. The authenticated user is automatically added as a member of the team. 50 | *

51 | * See the Team Memberships API to learn how to add more people to the team. 52 | * 53 | * @param name A user-friendly name for the team. 54 | * @param handler A closure to be executed once the request has finished. 55 | * @see TeamMembershipClient 56 | * @since 0.1 57 | */ 58 | void create(@NonNull String name, @NonNull CompletionHandler handler); 59 | 60 | /** 61 | * Retrieves the details for a team by id. 62 | * 63 | * @param teamId The identifier of the team. 64 | * @param handler A closure to be executed once the request has finished. 65 | * @since 0.1 66 | */ 67 | void get(@NonNull String teamId, @NonNull CompletionHandler handler); 68 | 69 | /** 70 | * Updates the details for a team by id. 71 | * 72 | * @param teamId The identifier of the team. 73 | * @param name A user-friendly name for the team. 74 | * @param handler A closure to be executed once the request has finished. 75 | * @since 0.1 76 | */ 77 | void update(@NonNull String teamId, String name, @NonNull CompletionHandler handler); 78 | 79 | /** 80 | * @param teamId The identifier of the team. 81 | * @param handler A closure to be executed once the request has finished. 82 | * @since 0.1 83 | */ 84 | void delete(@NonNull String teamId, @NonNull CompletionHandler handler); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/team/TeamMembership.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.team; 24 | 25 | 26 | import java.util.Date; 27 | 28 | import com.google.gson.Gson; 29 | import com.google.gson.annotations.SerializedName; 30 | 31 | /** 32 | * A data type represents a relationship between Team and Person at Cisco Spark cloud. 33 | * 34 | * @since 0.1 35 | */ 36 | public class TeamMembership { 37 | 38 | @SerializedName("id") 39 | private String _id; 40 | 41 | @SerializedName("personId") 42 | private String _personId; 43 | 44 | @SerializedName("personEmail") 45 | private String _personEmail; 46 | 47 | @SerializedName("personDisplayName") 48 | private String _personDisplayName; 49 | 50 | @SerializedName("personOrgId") 51 | private String _personOrgId; 52 | 53 | @SerializedName("teamId") 54 | private String _teamId; 55 | 56 | @SerializedName("isModerator") 57 | private boolean _isModerator; 58 | 59 | @SerializedName("created") 60 | private Date _created; 61 | 62 | @Override 63 | public String toString() { 64 | Gson gson = new Gson(); 65 | return gson.toJson(this); 66 | } 67 | 68 | /** 69 | * @return The identifier of this team membership. 70 | * @since 0.1 71 | */ 72 | public String getId() { 73 | return _id; 74 | } 75 | 76 | /** 77 | * @return The identifier of the person. 78 | * @since 0.1 79 | */ 80 | public String getPersonId() { 81 | return _personId; 82 | } 83 | 84 | /** 85 | * @return The email address of the person. 86 | * @since 0.1 87 | */ 88 | public String getPersonEmail() { 89 | return _personEmail; 90 | } 91 | 92 | /** 93 | * @return The display name of the person. 94 | * @since 0.1 95 | */ 96 | public String getPersonDisplayName() { 97 | return _personDisplayName; 98 | } 99 | 100 | /** 101 | * @return The identifier of the team. 102 | * @since 0.1 103 | */ 104 | public String getTeamId() { 105 | return _teamId; 106 | } 107 | 108 | /** 109 | * @return True if the person in this membership is a moderator of the team. 110 | * @since 0.1 111 | */ 112 | public boolean isModerator() { 113 | return _isModerator; 114 | } 115 | 116 | /** 117 | * @return The timestamp that the team membership being created. 118 | * @since 0.1 119 | */ 120 | public Date getCreated() { 121 | return _created; 122 | } 123 | 124 | /** 125 | * @return The personOrgId name of the person 126 | * @since 1.4 127 | */ 128 | public String getPersonOrgId() { 129 | return _personOrgId; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/team/TeamMembershipClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.team; 24 | 25 | import java.util.List; 26 | 27 | import android.support.annotation.NonNull; 28 | import android.support.annotation.Nullable; 29 | 30 | import com.ciscospark.androidsdk.CompletionHandler; 31 | 32 | /** 33 | * A client wrapper of the Cisco Spark TeamMemberships REST API 34 | * 35 | * @since 0.1 36 | */ 37 | public interface TeamMembershipClient { 38 | 39 | /** 40 | * Lists all team memberships where the authenticated user belongs. 41 | * 42 | * @param teamId Limit results to a specific team, by ID. 43 | * @param max The maximum number of team memberships in the response. 44 | * @param handler A closure to be executed once the request has finished. 45 | * @since 0.1 46 | */ 47 | void list(@Nullable String teamId, int max, @NonNull CompletionHandler> handler); 48 | 49 | /** 50 | * Adds a person to a team by person id; optionally making the person a moderator of the team. 51 | * 52 | * @param teamId The identifier of the team. 53 | * @param personId The identifier of the person. 54 | * @param personEmail The email of the person. 55 | * @param isModerator If true, make the person a moderator of the team. The default is false. 56 | * @param handler A closure to be executed once the request has finished. 57 | * @since 0.1 58 | */ 59 | void create(@NonNull String teamId, @Nullable String personId, @Nullable String personEmail, boolean isModerator, @NonNull CompletionHandler handler); 60 | 61 | /** 62 | * Retrieves the details for a membership by id. 63 | * 64 | * @param membershipId The identifier of the membership. 65 | * @param handler A closure to be executed once the request has finished. 66 | * @since 0.1 67 | */ 68 | void get(@NonNull String membershipId, @NonNull CompletionHandler handler); 69 | 70 | /** 71 | * Updates the details for a membership by id. 72 | * 73 | * @param membershipId The identifier of the membership. 74 | * @param isModerator If true, make the person a moderator of the team. The default is false. 75 | * @param handler A closure to be executed once the request has finished. 76 | * @since 0.1 77 | */ 78 | void update(@NonNull String membershipId, boolean isModerator, @NonNull CompletionHandler handler); 79 | 80 | /** 81 | * Deletes a membership by id. 82 | * 83 | * @param membershipId The identifier of the membership. 84 | * @param handler A closure to be executed once the request has finished. 85 | * @since 0.1 86 | */ 87 | void delete(@NonNull String membershipId, @NonNull CompletionHandler handler); 88 | 89 | } 90 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/team/internal/TeamClientImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.team.internal; 24 | 25 | 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | import android.support.annotation.NonNull; 30 | 31 | import com.ciscospark.androidsdk.CompletionHandler; 32 | import com.ciscospark.androidsdk.auth.Authenticator; 33 | import com.ciscospark.androidsdk.team.Team; 34 | import com.ciscospark.androidsdk.team.TeamClient; 35 | import com.ciscospark.androidsdk.utils.http.ListBody; 36 | import com.ciscospark.androidsdk.utils.http.ListCallback; 37 | import com.ciscospark.androidsdk.utils.http.ObjectCallback; 38 | import com.ciscospark.androidsdk.utils.http.ServiceBuilder; 39 | 40 | import me.helloworld.utils.collection.Maps; 41 | import retrofit2.Call; 42 | import retrofit2.http.Body; 43 | import retrofit2.http.DELETE; 44 | import retrofit2.http.GET; 45 | import retrofit2.http.Header; 46 | import retrofit2.http.POST; 47 | import retrofit2.http.PUT; 48 | import retrofit2.http.Path; 49 | import retrofit2.http.Query; 50 | 51 | public class TeamClientImpl implements TeamClient { 52 | 53 | private Authenticator _authenticator; 54 | 55 | private TeamService _service; 56 | 57 | public TeamClientImpl(Authenticator authenticator) { 58 | _authenticator = authenticator; 59 | _service = new ServiceBuilder().build(TeamService.class); 60 | } 61 | 62 | public void list(int max, @NonNull CompletionHandler> handler) { 63 | ServiceBuilder.async(_authenticator, handler, s -> 64 | _service.list(s, max <= 0 ? null : max), new ListCallback<>(handler)); 65 | } 66 | 67 | public void create(@NonNull String name, @NonNull CompletionHandler handler) { 68 | ServiceBuilder.async(_authenticator, handler, s -> 69 | _service.create(s, Maps.makeMap("name", name)), new ObjectCallback<>(handler)); 70 | } 71 | 72 | public void get(@NonNull String teamId, @NonNull CompletionHandler handler) { 73 | ServiceBuilder.async(_authenticator, handler, s -> 74 | _service.get(s, teamId), new ObjectCallback<>(handler)); 75 | } 76 | 77 | public void update(@NonNull String teamId, String name, @NonNull CompletionHandler handler) { 78 | ServiceBuilder.async(_authenticator, handler, s -> 79 | _service.update(s, teamId, Maps.makeMap("name", name)), new ObjectCallback<>(handler)); 80 | } 81 | 82 | public void delete(@NonNull String teamId, @NonNull CompletionHandler handler) { 83 | ServiceBuilder.async(_authenticator, handler, s -> 84 | _service.delete(s, teamId), new ObjectCallback<>(handler)); 85 | } 86 | 87 | private interface TeamService { 88 | @GET("teams") 89 | Call> list(@Header("Authorization") String authorization, @Query("max") Integer max); 90 | 91 | @POST("teams") 92 | Call create(@Header("Authorization") String authorization, @Body Map parameters); 93 | 94 | @GET("teams/{teamId}") 95 | Call get(@Header("Authorization") String authorization, @Path("teamId") String teamId); 96 | 97 | @PUT("teams/{teamId}") 98 | Call update(@Header("Authorization") String authorization, @Path("teamId") String teamId, @Body Map parameters); 99 | 100 | @DELETE("teams/{teamId}") 101 | Call delete(@Header("Authorization") String authorization, @Path("teamId") String teamId); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/team/internal/TeamMembershipClientImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.team.internal; 24 | 25 | 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | import android.support.annotation.NonNull; 30 | import android.support.annotation.Nullable; 31 | 32 | import com.ciscospark.androidsdk.CompletionHandler; 33 | import com.ciscospark.androidsdk.auth.Authenticator; 34 | import com.ciscospark.androidsdk.team.TeamMembership; 35 | import com.ciscospark.androidsdk.team.TeamMembershipClient; 36 | import com.ciscospark.androidsdk.utils.http.ListBody; 37 | import com.ciscospark.androidsdk.utils.http.ListCallback; 38 | import com.ciscospark.androidsdk.utils.http.ObjectCallback; 39 | import com.ciscospark.androidsdk.utils.http.ServiceBuilder; 40 | 41 | import me.helloworld.utils.collection.Maps; 42 | import retrofit2.Call; 43 | import retrofit2.http.Body; 44 | import retrofit2.http.DELETE; 45 | import retrofit2.http.GET; 46 | import retrofit2.http.Header; 47 | import retrofit2.http.POST; 48 | import retrofit2.http.PUT; 49 | import retrofit2.http.Path; 50 | import retrofit2.http.Query; 51 | 52 | public class TeamMembershipClientImpl implements TeamMembershipClient { 53 | 54 | private Authenticator _authenticator; 55 | 56 | private TeamMembershipService _service; 57 | 58 | public TeamMembershipClientImpl(Authenticator authenticator) { 59 | _authenticator = authenticator; 60 | _service = new ServiceBuilder().build(TeamMembershipService.class); 61 | } 62 | 63 | public void list(@Nullable String teamId, int max, @NonNull CompletionHandler> handler) { 64 | ServiceBuilder.async(_authenticator, handler, s -> 65 | _service.list(s, teamId, max <= 0 ? null : max), new ListCallback<>(handler)); 66 | } 67 | 68 | public void create(@NonNull String teamId, @Nullable String personId, @Nullable String personEmail, boolean isModerator, @NonNull CompletionHandler handler) { 69 | ServiceBuilder.async(_authenticator, handler, s -> 70 | _service.create(s, Maps.makeMap("teamId", teamId, "personId", personId, "personEmail", personEmail, "isModerator", isModerator)), new ObjectCallback<>(handler)); 71 | } 72 | 73 | public void get(@NonNull String membershipId, @NonNull CompletionHandler handler) { 74 | ServiceBuilder.async(_authenticator, handler, s -> 75 | _service.get(s, membershipId), new ObjectCallback<>(handler)); 76 | } 77 | 78 | public void update(@NonNull String membershipId, boolean isModerator, @NonNull CompletionHandler handler) { 79 | ServiceBuilder.async(_authenticator, handler, s -> 80 | _service.update(s, membershipId, Maps.makeMap("isModerator", isModerator)), new ObjectCallback<>(handler)); 81 | } 82 | 83 | public void delete(@NonNull String membershipId, @NonNull CompletionHandler handler) { 84 | ServiceBuilder.async(_authenticator, handler, s -> 85 | _service.delete(s, membershipId), new ObjectCallback<>(handler)); 86 | } 87 | 88 | private interface TeamMembershipService { 89 | @GET("team/memberships") 90 | Call> list(@Header("Authorization") String authorization, @Query("teamId") String roomId, @Query("max") Integer max); 91 | 92 | @POST("team/memberships") 93 | Call create(@Header("Authorization") String authorization, @Body Map parameters); 94 | 95 | @GET("team/memberships/{membershipId}") 96 | Call get(@Header("Authorization") String authorization, @Path("membershipId") String membershipId); 97 | 98 | @PUT("team/memberships/{membershipId}") 99 | Call update(@Header("Authorization") String authorization, @Path("membershipId") String membershipId, @Body Map parameters); 100 | 101 | @DELETE("team/memberships/{membershipId}") 102 | Call delete(@Header("Authorization") String authorization, @Path("membershipId") String membershipId); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils; 24 | 25 | import android.os.Build; 26 | import android.support.annotation.Nullable; 27 | 28 | import com.cisco.spark.android.util.Strings; 29 | import com.ciscospark.androidsdk.Spark; 30 | 31 | import org.joda.time.DateTime; 32 | import org.joda.time.DateTimeZone; 33 | 34 | /** 35 | * An utility class. 36 | * 37 | * @since 0.1 38 | */ 39 | 40 | public class Utils { 41 | public static T checkNotNull(@Nullable T object, String message) { 42 | if (object == null) { 43 | throw new NullPointerException(message); 44 | } 45 | return object; 46 | } 47 | 48 | public static String timestampUTC() { 49 | return DateTime.now(DateTimeZone.UTC).toString(); 50 | } 51 | 52 | public static String versionInfo() { 53 | String tempUserAgent = String.format("%s/%s (Android %s; %s %s / %s %s;)", 54 | Spark.APP_NAME, Spark.APP_VERSION, 55 | Build.VERSION.RELEASE, 56 | Strings.capitalize(Build.MANUFACTURER), 57 | Strings.capitalize(Build.DEVICE), 58 | Strings.capitalize(Build.BRAND), 59 | Strings.capitalize(Build.MODEL) 60 | ); 61 | return Strings.stripInvalidHeaderChars(tempUserAgent); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/http/DefaultHeadersInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.http; 24 | 25 | import java.io.IOException; 26 | 27 | import com.ciscospark.androidsdk.utils.Utils; 28 | 29 | import okhttp3.Interceptor; 30 | import okhttp3.Request; 31 | import okhttp3.Response; 32 | 33 | public class DefaultHeadersInterceptor implements Interceptor { 34 | 35 | protected String _userAgent; 36 | 37 | public DefaultHeadersInterceptor() { 38 | _userAgent = Utils.versionInfo(); 39 | } 40 | 41 | @Override 42 | public Response intercept(Chain chain) throws IOException { 43 | Request original = chain.request(); 44 | Request request = original.newBuilder() 45 | .header("User-Agent", _userAgent) 46 | .header("Spark-User-Agent", _userAgent) 47 | .header("Content-Type", "application/json; charset=utf-8") 48 | .method(original.method(), original.body()) 49 | .build(); 50 | 51 | return chain.proceed(request); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/http/ListBody.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.http; 24 | 25 | import java.util.List; 26 | 27 | import com.google.gson.annotations.SerializedName; 28 | 29 | /** 30 | * Created by zhiyuliu on 02/09/2017. 31 | */ 32 | 33 | public class ListBody { 34 | 35 | @SerializedName("items") 36 | private List _items; 37 | 38 | List getItems() { 39 | return _items; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/http/ListCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.http; 24 | 25 | import java.util.List; 26 | 27 | import com.ciscospark.androidsdk.CompletionHandler; 28 | import com.ciscospark.androidsdk.internal.ResultImpl; 29 | import retrofit2.Call; 30 | import retrofit2.Response; 31 | 32 | /** 33 | * Created by zhiyuliu on 02/09/2017. 34 | */ 35 | 36 | public class ListCallback extends ListenerCallback> { 37 | 38 | private CompletionHandler> _handler; 39 | 40 | public ListCallback(CompletionHandler> handler) { 41 | _handler = handler; 42 | } 43 | 44 | @Override 45 | public void onResponse(Call> call, Response> response) { 46 | if (response.isSuccessful()) { 47 | _handler.onComplete(ResultImpl.success(response.body().getItems())); 48 | } else if (!checkUnauthError(response)) { 49 | _handler.onComplete(ResultImpl.error(response)); 50 | } 51 | } 52 | 53 | @Override 54 | public void onFailure(Call> call, Throwable t) { 55 | _handler.onComplete(ResultImpl.error(t)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/http/ListenerCallback.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.utils.http; 2 | 3 | import retrofit2.Call; 4 | import retrofit2.Callback; 5 | import retrofit2.Response; 6 | 7 | /** 8 | * Created by qimdeng on 4/4/18. 9 | */ 10 | 11 | public class ListenerCallback implements Callback { 12 | 13 | private boolean hasHandleUnauthError = false; // only handle unauth error once 14 | 15 | private ServiceBuilder.UnauthErrorListener _listener; 16 | public void setUnauthErrorListener(ServiceBuilder.UnauthErrorListener listener){ 17 | _listener = listener; 18 | } 19 | 20 | @Override 21 | public void onResponse(Call call, Response response) { 22 | 23 | } 24 | 25 | @Override 26 | public void onFailure(Call call, Throwable t) { 27 | 28 | } 29 | 30 | protected boolean checkUnauthError(Response response){ 31 | if (response.code() == 401 && !hasHandleUnauthError && _listener != null) { 32 | hasHandleUnauthError = true; 33 | _listener.onUnauthError(response); 34 | return true; 35 | } 36 | return false; 37 | } 38 | } -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/http/ObjectCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.http; 24 | 25 | import com.ciscospark.androidsdk.CompletionHandler; 26 | import com.ciscospark.androidsdk.internal.ResultImpl; 27 | import retrofit2.Call; 28 | import retrofit2.Response; 29 | 30 | /** 31 | * Created by zhiyuliu on 02/09/2017. 32 | */ 33 | 34 | public class ObjectCallback extends ListenerCallback { 35 | 36 | private CompletionHandler _handler; 37 | 38 | public ObjectCallback(CompletionHandler handler) { 39 | _handler = handler; 40 | } 41 | 42 | @Override 43 | public void onResponse(Call call, Response response) { 44 | if (response.isSuccessful()) { 45 | _handler.onComplete(ResultImpl.success(response.body())); 46 | } else if (!checkUnauthError(response)) { 47 | _handler.onComplete(ResultImpl.error(response)); 48 | } 49 | } 50 | 51 | @Override 52 | public void onFailure(Call call, Throwable t) { 53 | _handler.onComplete(ResultImpl.error(t)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/http/RetryCallAdapterFactory.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.utils.http; 2 | 3 | import java.io.IOException; 4 | import java.lang.annotation.Annotation; 5 | import java.lang.reflect.Type; 6 | import java.util.concurrent.Executors; 7 | import java.util.concurrent.ScheduledExecutorService; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import com.github.benoitdion.ln.Ln; 11 | import okhttp3.Request; 12 | import retrofit2.Call; 13 | import retrofit2.CallAdapter; 14 | import retrofit2.Callback; 15 | import retrofit2.Response; 16 | import retrofit2.Retrofit; 17 | 18 | /** 19 | * Retries calls for 429 request error. 20 | */ 21 | public class RetryCallAdapterFactory extends CallAdapter.Factory { 22 | private final ScheduledExecutorService mExecutor; 23 | 24 | private RetryCallAdapterFactory() { 25 | mExecutor = Executors.newScheduledThreadPool(1); 26 | } 27 | 28 | public static RetryCallAdapterFactory create() { 29 | return new RetryCallAdapterFactory(); 30 | } 31 | 32 | private static int count = 0; 33 | 34 | @Override 35 | public CallAdapter get(final Type returnType, Annotation[] annotations, Retrofit retrofit) { 36 | final boolean shouldRetryCall = true; 37 | final CallAdapter delegate = retrofit.nextCallAdapter(this, returnType, annotations); 38 | return new CallAdapter() { 39 | @Override 40 | public Type responseType() { 41 | return delegate.responseType(); 42 | } 43 | 44 | @Override 45 | public Object adapt(Call call) { 46 | return delegate.adapt(new RetryingCall<>(call, mExecutor, Integer.MAX_VALUE)); 47 | } 48 | }; 49 | } 50 | 51 | static final class RetryingCall implements Call { 52 | private final Call mDelegate; 53 | private final ScheduledExecutorService mExecutor; 54 | private final int mMaxRetries; 55 | 56 | public RetryingCall(Call delegate, ScheduledExecutorService executor, int maxRetries) { 57 | mDelegate = delegate; 58 | mExecutor = executor; 59 | mMaxRetries = maxRetries; 60 | } 61 | 62 | @Override 63 | public Response execute() throws IOException { 64 | return mDelegate.execute(); 65 | } 66 | 67 | @Override 68 | public void enqueue(Callback callback) { 69 | mDelegate.enqueue(new RetryingCallback<>(mDelegate, callback, mExecutor, mMaxRetries)); 70 | } 71 | 72 | @Override 73 | public boolean isExecuted() { 74 | return false; 75 | } 76 | 77 | @Override 78 | public void cancel() { 79 | mDelegate.cancel(); 80 | } 81 | 82 | @Override 83 | public boolean isCanceled() { 84 | return false; 85 | } 86 | 87 | @SuppressWarnings("CloneDoesntCallSuperClone" /* Performing deep clone */) 88 | @Override 89 | public Call clone() { 90 | return new RetryingCall<>(mDelegate.clone(), mExecutor, mMaxRetries); 91 | } 92 | 93 | @Override 94 | public Request request() { 95 | return null; 96 | } 97 | } 98 | 99 | // Exponential backoff approach from https://developers.google.com/drive/web/handle-errors 100 | static final class RetryingCallback implements Callback { 101 | private static final int DEFAULT_RETRY_AFTER = 60; 102 | private static final int MAX_RETRY_AFTER = 3600; 103 | private final int mMaxRetries; 104 | private final Call mCall; 105 | private final Callback mDelegate; 106 | private final ScheduledExecutorService mExecutor; 107 | private final int mRetries; 108 | 109 | RetryingCallback(Call call, Callback delegate, ScheduledExecutorService executor, int maxRetries) { 110 | this(call, delegate, executor, maxRetries, 0); 111 | } 112 | 113 | RetryingCallback(Call call, Callback delegate, ScheduledExecutorService executor, int maxRetries, int retries) { 114 | mCall = call; 115 | mDelegate = delegate; 116 | mExecutor = executor; 117 | mMaxRetries = maxRetries; 118 | mRetries = retries; 119 | } 120 | 121 | private void retryCall(int interval) { 122 | mExecutor.schedule(new Runnable() { 123 | @Override 124 | public void run() { 125 | Ln.d("retryCall: " + (mRetries + 1)); 126 | final Call call = mCall.clone(); 127 | call.enqueue(new RetryingCallback<>(call, mDelegate, mExecutor, mMaxRetries, mRetries + 1)); 128 | } 129 | }, interval, TimeUnit.SECONDS); 130 | } 131 | 132 | private int get429RetryAfterSeconds(final Response response) { 133 | if (response == null || response.code() != 429) { 134 | return 0; 135 | } 136 | 137 | final String retryAfterHeader = response.headers().get("Retry-After"); 138 | if (retryAfterHeader == null) { 139 | return DEFAULT_RETRY_AFTER; 140 | } 141 | 142 | final int retrySeconds; 143 | try { 144 | retrySeconds = Integer.parseInt(retryAfterHeader); 145 | } catch (final NumberFormatException e) { 146 | Ln.w("Failed parsing Retry-After header"); 147 | return DEFAULT_RETRY_AFTER; 148 | } 149 | 150 | if (retrySeconds <= 0) { 151 | return DEFAULT_RETRY_AFTER; 152 | } 153 | 154 | return Math.min(retrySeconds, MAX_RETRY_AFTER); 155 | } 156 | 157 | @Override 158 | public void onResponse(Call call, Response response) { 159 | // Retry 429 request 160 | int interval = get429RetryAfterSeconds(response); 161 | Ln.d("onResponse: " + response.code() + " retry interval: " + interval + " retries: " + mRetries); 162 | if (interval > 0 && mRetries < mMaxRetries) { 163 | retryCall(interval); 164 | } else { 165 | mDelegate.onResponse(call, response); 166 | } 167 | } 168 | 169 | @Override 170 | public void onFailure(Call call, Throwable t) { 171 | mDelegate.onFailure(call, t); 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/log/DebugLn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.log; 24 | 25 | import android.util.Log; 26 | 27 | import com.github.benoitdion.ln.BaseLn; 28 | 29 | /** 30 | * Created by zhiyuliu on 03/09/2017. 31 | */ 32 | 33 | public class DebugLn extends BaseLn { 34 | @Override 35 | public void v(Throwable throwable) { 36 | clearExtra(); 37 | } 38 | 39 | @Override 40 | public void v(String message, Object... args) { 41 | clearExtra(); 42 | } 43 | 44 | @Override 45 | public void v(Throwable throwable, String message, Object... args) { 46 | clearExtra(); 47 | } 48 | 49 | @Override 50 | public void d(Throwable throwable) { 51 | println(Log.DEBUG, false, throwable, null); 52 | } 53 | 54 | @Override 55 | public void d(String message, Object... args) { 56 | println(Log.DEBUG, false, null, message, args); 57 | } 58 | 59 | @Override 60 | public void d(Throwable throwable, String message, Object... args) { 61 | println(Log.DEBUG, false, throwable, message, args); 62 | } 63 | 64 | @Override 65 | public void i(Throwable throwable) { 66 | println(Log.INFO, false, throwable, null); 67 | } 68 | 69 | @Override 70 | public void i(Throwable throwable, String message, Object... args) { 71 | println(Log.INFO, false, throwable, message, args); 72 | } 73 | 74 | @Override 75 | public void i(String message, Object... args) { 76 | println(Log.INFO, false, null, message, args); 77 | } 78 | 79 | @Override 80 | public void w(Throwable throwable) { 81 | println(Log.WARN, true, throwable, null); 82 | } 83 | 84 | @Override 85 | public void w(Throwable throwable, String message, Object... args) { 86 | println(Log.WARN, true, throwable, message, args); 87 | } 88 | 89 | @Override 90 | public void w(String message, Object... args) { 91 | println(Log.WARN, true, null, message, args); 92 | } 93 | 94 | @Override 95 | public void w(boolean report, Throwable throwable) { 96 | println(Log.WARN, report, throwable, null); 97 | } 98 | 99 | @Override 100 | public void w(boolean report, Throwable throwable, String message, Object... args) { 101 | println(Log.WARN, report, throwable, message, args); 102 | } 103 | 104 | @Override 105 | public void w(boolean report, String message, Object... args) { 106 | println(Log.WARN, report, null, message, args); 107 | } 108 | 109 | @Override 110 | public void e(Throwable throwable) { 111 | println(Log.ERROR, true, throwable, null); 112 | } 113 | 114 | @Override 115 | public void e(Throwable throwable, String message, Object... args) { 116 | println(Log.ERROR, true, throwable, message, args); 117 | } 118 | 119 | @Override 120 | public void e(String message, Object... args) { 121 | println(Log.ERROR, true, null, message, args); 122 | } 123 | 124 | @Override 125 | public void e(boolean report, Throwable t) { 126 | println(Log.ERROR, report, null, null); 127 | } 128 | 129 | @Override 130 | public void e(boolean report, Throwable throwable, String message, Object... args) { 131 | println(Log.ERROR, report, throwable, message, args); 132 | } 133 | 134 | @Override 135 | public void e(boolean report, String message, Object... args) { 136 | println(Log.ERROR, report, null, message, args); 137 | } 138 | 139 | @Override 140 | public boolean isDebugEnabled() { 141 | return true; 142 | } 143 | 144 | @Override 145 | public boolean isVerboseEnabled() { 146 | return true; 147 | } 148 | 149 | @Override 150 | protected String formatMessage(String message) { 151 | message = String.format("%s %s", Thread.currentThread().getName(), message); 152 | return message; 153 | } 154 | } 155 | 156 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/log/MediaLog.java: -------------------------------------------------------------------------------- 1 | package com.ciscospark.androidsdk.utils.log; 2 | 3 | import android.util.Log; 4 | 5 | import com.github.benoitdion.ln.Ln; 6 | 7 | /** 8 | * Created with IntelliJ IDEA. 9 | * User: kt 10 | * Date: 29/11/2017 11 | * Time: 00:47 12 | */ 13 | 14 | public class MediaLog { 15 | 16 | public static int outputLog(int priority, String tag, String msg) { 17 | String message = "<" + tag + ">" + msg; 18 | if (priority == Log.WARN) { 19 | Ln.w(message); 20 | } else if (priority == Log.ERROR) { 21 | Ln.e(message); 22 | } else if (priority == Log.DEBUG) { 23 | Ln.d(message); 24 | } else if (priority == Log.INFO) { 25 | Ln.i(message); 26 | } else if (priority == Log.VERBOSE) { 27 | Ln.v(message); 28 | } else { 29 | Ln.e(message); 30 | } 31 | return 0; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/log/NoLn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.log; 24 | 25 | import com.github.benoitdion.ln.BaseLn; 26 | 27 | /** 28 | * Created by zhiyuliu on 03/09/2017. 29 | */ 30 | 31 | public class NoLn extends BaseLn { 32 | 33 | @Override 34 | public void v(Throwable throwable) { 35 | clearExtra(); 36 | } 37 | 38 | @Override 39 | public void v(String message, Object... args) { 40 | clearExtra(); 41 | } 42 | 43 | @Override 44 | public void v(Throwable throwable, String message, Object... args) { 45 | clearExtra(); 46 | } 47 | 48 | @Override 49 | public void d(Throwable throwable) { 50 | clearExtra(); 51 | } 52 | 53 | @Override 54 | public void d(String message, Object... args) { 55 | clearExtra(); 56 | } 57 | 58 | @Override 59 | public void d(Throwable throwable, String message, Object... args) { 60 | clearExtra(); 61 | } 62 | 63 | @Override 64 | public void i(Throwable throwable) { 65 | clearExtra(); 66 | } 67 | 68 | @Override 69 | public void i(Throwable throwable, String message, Object... args) { 70 | clearExtra(); 71 | } 72 | 73 | @Override 74 | public void i(String message, Object... args) { 75 | clearExtra(); 76 | } 77 | 78 | @Override 79 | public void w(Throwable throwable) { 80 | clearExtra(); 81 | } 82 | 83 | @Override 84 | public void w(Throwable throwable, String message, Object... args) { 85 | clearExtra(); 86 | } 87 | 88 | @Override 89 | public void w(String message, Object... args) { 90 | clearExtra(); 91 | } 92 | 93 | @Override 94 | public void w(boolean report, Throwable throwable) { 95 | clearExtra(); 96 | } 97 | 98 | @Override 99 | public void w(boolean report, Throwable throwable, String message, Object... args) { 100 | clearExtra(); 101 | } 102 | 103 | @Override 104 | public void w(boolean report, String message, Object... args) { 105 | clearExtra(); 106 | } 107 | 108 | @Override 109 | public void e(Throwable t) { 110 | clearExtra(); 111 | } 112 | 113 | @Override 114 | public void e(Throwable throwable, String message, Object... args) { 115 | clearExtra(); 116 | } 117 | 118 | @Override 119 | public void e(String message, Object... args) { 120 | clearExtra(); 121 | } 122 | 123 | @Override 124 | public void e(boolean report, Throwable throwable) { 125 | clearExtra(); 126 | } 127 | 128 | @Override 129 | public void e(boolean report, Throwable throwable, String message, Object... args) { 130 | clearExtra(); 131 | } 132 | 133 | @Override 134 | public void e(boolean report, String message, Object... args) { 135 | clearExtra(); 136 | } 137 | 138 | @Override 139 | public boolean isDebugEnabled() { 140 | return false; 141 | } 142 | 143 | @Override 144 | public boolean isVerboseEnabled() { 145 | return false; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/utils/log/WarningLn.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.utils.log; 24 | 25 | import android.util.Log; 26 | 27 | import com.github.benoitdion.ln.BaseLn; 28 | 29 | /** 30 | * Created by zhiyuliu on 03/09/2017. 31 | */ 32 | 33 | public class WarningLn extends BaseLn { 34 | 35 | @Override 36 | public void v(Throwable throwable) { 37 | clearExtra(); 38 | } 39 | 40 | @Override 41 | public void v(String message, Object... args) { 42 | clearExtra(); 43 | } 44 | 45 | @Override 46 | public void v(Throwable throwable, String message, Object... args) { 47 | clearExtra(); 48 | } 49 | 50 | @Override 51 | public void d(Throwable throwable) { 52 | clearExtra(); 53 | } 54 | 55 | @Override 56 | public void d(String message, Object... args) { 57 | clearExtra(); 58 | } 59 | 60 | @Override 61 | public void d(Throwable throwable, String message, Object... args) { 62 | clearExtra(); 63 | } 64 | 65 | @Override 66 | public void i(Throwable throwable) { 67 | clearExtra(); 68 | } 69 | 70 | @Override 71 | public void i(Throwable throwable, String message, Object... args) { 72 | clearExtra(); 73 | } 74 | 75 | @Override 76 | public void i(String message, Object... args) { 77 | clearExtra(); 78 | } 79 | 80 | @Override 81 | public void w(Throwable throwable) { 82 | println(Log.WARN, true, throwable, null); 83 | } 84 | 85 | @Override 86 | public void w(Throwable throwable, String message, Object... args) { 87 | println(Log.WARN, true, throwable, message, args); 88 | } 89 | 90 | @Override 91 | public void w(String message, Object... args) { 92 | println(Log.WARN, true, null, message, args); 93 | } 94 | 95 | @Override 96 | public void w(boolean report, Throwable throwable) { 97 | println(Log.WARN, report, throwable, null); 98 | } 99 | 100 | @Override 101 | public void w(boolean report, Throwable throwable, String message, Object... args) { 102 | println(Log.WARN, report, throwable, message, args); 103 | } 104 | 105 | @Override 106 | public void w(boolean report, String message, Object... args) { 107 | println(Log.WARN, report, null, message, args); 108 | } 109 | 110 | @Override 111 | public void e(Throwable throwable) { 112 | println(Log.ERROR, true, throwable, null); 113 | } 114 | 115 | @Override 116 | public void e(Throwable throwable, String message, Object... args) { 117 | println(Log.ERROR, true, throwable, message, args); 118 | } 119 | 120 | @Override 121 | public void e(String message, Object... args) { 122 | println(Log.ERROR, true, null, message, args); 123 | } 124 | 125 | @Override 126 | public void e(boolean report, Throwable t) { 127 | println(Log.ERROR, report, null, null); 128 | } 129 | 130 | @Override 131 | public void e(boolean report, Throwable throwable, String message, Object... args) { 132 | println(Log.ERROR, report, throwable, message, args); 133 | } 134 | 135 | @Override 136 | public void e(boolean report, String message, Object... args) { 137 | println(Log.ERROR, report, null, message, args); 138 | } 139 | 140 | @Override 141 | public boolean isDebugEnabled() { 142 | return false; 143 | } 144 | 145 | @Override 146 | public boolean isVerboseEnabled() { 147 | return false; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/webhook/Webhook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.webhook; 24 | 25 | import java.util.Date; 26 | 27 | import com.google.gson.Gson; 28 | import com.google.gson.annotations.SerializedName; 29 | 30 | /** 31 | * A data type presents a Webhook at Cisco Spark for Developer. 32 | * 33 | * @see Webhook Explained 34 | * @since 0.1 35 | */ 36 | public class Webhook { 37 | 38 | @SerializedName("id") 39 | private String _id; 40 | 41 | @SerializedName("name") 42 | private String _name; 43 | 44 | @SerializedName("targetUrl") 45 | private String _targetUrl; 46 | 47 | @SerializedName("resource") 48 | private String _resource; 49 | 50 | @SerializedName("event") 51 | private String _event; 52 | 53 | @SerializedName("filter") 54 | private String _filter; 55 | 56 | @SerializedName("secret") 57 | private String _secret; 58 | 59 | @SerializedName("created") 60 | private Date _created; 61 | 62 | @SerializedName("status") 63 | private String _status; 64 | 65 | @Override 66 | public String toString() { 67 | Gson gson = new Gson(); 68 | return gson.toJson(this); 69 | } 70 | 71 | /** 72 | * @return The identifier of this webhook. 73 | * @since 0.1 74 | */ 75 | public String getId() { 76 | return _id; 77 | } 78 | 79 | /** 80 | * @return A user-friendly name for this webhook. 81 | * @since 0.1 82 | */ 83 | public String getName() { 84 | return _name; 85 | } 86 | 87 | /** 88 | * @return The URL that receives POST requests for each event. 89 | * @since 0.1 90 | */ 91 | public String getTargetUrl() { 92 | return _targetUrl; 93 | } 94 | 95 | /** 96 | * @return The resource type for the webhook. 97 | * @since 0.1 98 | */ 99 | public String getResource() { 100 | return _resource; 101 | } 102 | 103 | /** 104 | * @return The event type for the webhook. 105 | * @since 0.1 106 | */ 107 | public String getEvent() { 108 | return _event; 109 | } 110 | 111 | /** 112 | * @return The filter that defines the webhook scope. 113 | * @since 0.1 114 | */ 115 | public String getFilter() { 116 | return _filter; 117 | } 118 | 119 | /** 120 | * @return The secret for the webhook. 121 | * @since 0.1 122 | */ 123 | public String getSecret() { 124 | return _secret; 125 | } 126 | 127 | /** 128 | * @return The timestamp that the webhook being created. 129 | * @since 0.1 130 | */ 131 | public Date getCreated() { 132 | return _created; 133 | } 134 | 135 | /** 136 | * @return The status of the webhook. Use active to reactivate a disabled webhook. 137 | * @since 1.4 138 | */ 139 | public String getStatus() { 140 | return _status; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/webhook/WebhookClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.webhook; 24 | 25 | import java.util.List; 26 | 27 | import android.support.annotation.NonNull; 28 | import android.support.annotation.Nullable; 29 | 30 | import com.ciscospark.androidsdk.CompletionHandler; 31 | 32 | /** 33 | * A client wrapper of the Cisco Spark Webhooks REST API 34 | * 35 | * @since 0.1 36 | */ 37 | public interface WebhookClient { 38 | 39 | /** 40 | * Lists all webhooks of the authenticated user. 41 | * 42 | * @param max The maximum number of webhooks in the response. 43 | * @param handler A closure to be executed once the request has finished. 44 | * @since 0.1 45 | */ 46 | void list(int max, @NonNull CompletionHandler> handler); 47 | 48 | /** 49 | * Posts a webhook for the authenticated user. 50 | * 51 | * @param name A user-friendly name for this webhook. 52 | * @param targetUrl The URL that receives POST requests for each event. 53 | * @param resource The resource type for the webhook. 54 | * @param event The event type for the webhook. 55 | * @param filter The filter that defines the webhook scope. 56 | * @param secret Secret use to generate payload signiture 57 | * @param handler A closure to be executed once the request has finished. 58 | * @since 0.1 59 | */ 60 | void create(@NonNull String name, @NonNull String targetUrl, @NonNull String resource, @NonNull String event, @Nullable String filter, @Nullable String secret, @NonNull CompletionHandler handler); 61 | 62 | /** 63 | * Retrieves the details for a webhook by id. 64 | * 65 | * @param webhookId The identifier of the webhook. 66 | * @param handler A closure to be executed once the request has finished. 67 | * @since 0.1 68 | */ 69 | void get(@NonNull String webhookId, @NonNull CompletionHandler handler); 70 | 71 | /** 72 | * Updates a webhook by id. 73 | * 74 | * @param webhookId The identifier of the webhook. 75 | * @param name A user-friendly name for this webhook. 76 | * @param targetUrl The URL that receives POST requests for each event. 77 | * @param handler A closure to be executed once the request has finished. 78 | * @since 0.1 79 | */ 80 | void update(@NonNull String webhookId, @NonNull String name, @NonNull String targetUrl, @NonNull CompletionHandler handler); 81 | 82 | /** 83 | * Updates a webhook by id. 84 | * 85 | * @param webhookId The identifier of the webhook. 86 | * @param name A user-friendly name for this webhook. 87 | * @param targetUrl The URL that receives POST requests for each event. 88 | * @param secret The Secret used to generate payload signature. 89 | * @param status The status of the webhook. Use "active" to reactivate a disabled webhook. 90 | * @param handler A closure to be executed once the request has finished. 91 | * @since 1.4 92 | */ 93 | void update(@NonNull String webhookId, @NonNull String name, @NonNull String targetUrl, @Nullable String secret, @Nullable String status, @NonNull CompletionHandler handler); 94 | 95 | 96 | /** 97 | * Deletes a webhook by id. 98 | * 99 | * @param webhookId The identifier of the webhook. 100 | * @param handler A closure to be executed once the request has finished. 101 | * @since 0.1 102 | */ 103 | void delete(@NonNull String webhookId, @NonNull CompletionHandler handler); 104 | 105 | } 106 | -------------------------------------------------------------------------------- /sdk/src/main/java/com/ciscospark/androidsdk/webhook/internal/WebhookClientImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.webhook.internal; 24 | 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import android.support.annotation.NonNull; 29 | import android.support.annotation.Nullable; 30 | 31 | import com.ciscospark.androidsdk.CompletionHandler; 32 | import com.ciscospark.androidsdk.auth.Authenticator; 33 | import com.ciscospark.androidsdk.utils.http.ListBody; 34 | import com.ciscospark.androidsdk.utils.http.ListCallback; 35 | import com.ciscospark.androidsdk.utils.http.ObjectCallback; 36 | import com.ciscospark.androidsdk.utils.http.ServiceBuilder; 37 | import com.ciscospark.androidsdk.webhook.Webhook; 38 | import com.ciscospark.androidsdk.webhook.WebhookClient; 39 | 40 | import me.helloworld.utils.collection.Maps; 41 | import retrofit2.Call; 42 | import retrofit2.http.Body; 43 | import retrofit2.http.DELETE; 44 | import retrofit2.http.GET; 45 | import retrofit2.http.Header; 46 | import retrofit2.http.POST; 47 | import retrofit2.http.PUT; 48 | import retrofit2.http.Path; 49 | import retrofit2.http.Query; 50 | 51 | public class WebhookClientImpl implements WebhookClient { 52 | 53 | private Authenticator _authenticator; 54 | 55 | private WebhookService _service; 56 | 57 | public WebhookClientImpl(Authenticator authenticator) { 58 | _authenticator = authenticator; 59 | _service = new ServiceBuilder().build(WebhookService.class); 60 | } 61 | 62 | public void list(int max, @NonNull CompletionHandler> handler) { 63 | ServiceBuilder.async(_authenticator, handler, s -> 64 | _service.list(s, max <= 0 ? null : max), new ListCallback<>(handler)); 65 | } 66 | 67 | public void create(@NonNull String name, @NonNull String targetUrl, @NonNull String resource, @NonNull String event, @Nullable String filter, @Nullable String secret, @NonNull CompletionHandler handler) { 68 | ServiceBuilder.async(_authenticator, handler, s -> 69 | _service.create(s, Maps.makeMap("name", name, "targetUrl", targetUrl, "filter", filter, "secret", secret, "resource", resource, "event", event)), new ObjectCallback<>(handler)); 70 | } 71 | 72 | public void get(@NonNull String webhookId, @NonNull CompletionHandler handler) { 73 | ServiceBuilder.async(_authenticator, handler, s -> 74 | _service.get(s, webhookId), new ObjectCallback<>(handler)); 75 | } 76 | 77 | public void update(@NonNull String webhookId, @NonNull String name, @NonNull String targetUrl, @NonNull CompletionHandler handler) { 78 | ServiceBuilder.async(_authenticator, handler, s -> 79 | _service.update(s, webhookId, Maps.makeMap("name", name, "targetUrl", targetUrl)), new ObjectCallback<>(handler)); 80 | } 81 | 82 | @Override 83 | public void update(@NonNull String webhookId, @NonNull String name, @NonNull String targetUrl, @Nullable String secret, @Nullable String status, @NonNull CompletionHandler handler) { 84 | ServiceBuilder.async(_authenticator, handler, s -> 85 | _service.update(s, webhookId, Maps.makeMap("name", name, "targetUrl", targetUrl, "secret", secret, "status", status)), new ObjectCallback<>(handler)); 86 | } 87 | 88 | public void delete(@NonNull String webhookId, @NonNull CompletionHandler handler) { 89 | ServiceBuilder.async(_authenticator, handler, s -> 90 | _service.delete(s, webhookId), new ObjectCallback<>(handler)); 91 | } 92 | 93 | private interface WebhookService { 94 | @GET("webhooks") 95 | Call> list(@Header("Authorization") String authorization, @Query("max") Integer max); 96 | 97 | @POST("webhooks") 98 | Call create(@Header("Authorization") String authorization, @Body Map parameters); 99 | 100 | @GET("webhooks/{webhookId}") 101 | Call get(@Header("Authorization") String authorization, @Path("webhookId") String webhookId); 102 | 103 | @PUT("webhooks/{webhookId}") 104 | Call update(@Header("Authorization") String authorization, @Path("webhookId") String webhookId, @Body Map parameters); 105 | 106 | @DELETE("webhooks/{webhookId}") 107 | Call delete(@Header("Authorization") String authorization, @Path("webhookId") String webhookId); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /sdk/src/test/java/com/ciscospark/androidsdk/auth/OAuthAuthenticatorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.auth; 24 | 25 | import org.junit.FixMethodOrder; 26 | import org.junit.runners.MethodSorters; 27 | 28 | /** 29 | * @author Allen Xiao 30 | * @version 0.1 31 | */ 32 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 33 | public class OAuthAuthenticatorTest { 34 | String clientId = "Cc580d5219555f0df8b03d99f3e020381eae4eee0bad1501ad187480db311cce4"; 35 | String clientSec = "c87879c646f82b6d23a7a4c2f6eea1894234a53e013777e90bced91f22225317"; 36 | String redirect = "AndroidDemoApp://response"; 37 | // Every time get the code from browser manually, or test will fail. 38 | // Visit flowing link in browser to get the code: 39 | // "https://api.ciscospark.com/v1/authorize?client_id=Cc580d5219555f0df8b03d99f3e020381eae4eee0bad1501ad187480db311cce4&response_type=code&redirect_uri=AndroidDemoApp%3A%2F%2Fresponse&scope=spark%3Aall%20spark%3Akms" 40 | String code = "Y2Y0ZjliNTYtN2Q1NS00Y2ZjLTk2ZGQtOGY4YzRhNTA1NzE5NTMxMDVhNzYtNTk5"; 41 | String email = "xionxiao@cisco.com"; 42 | String scope = "spark:all spark:kms"; 43 | 44 | OAuthAuthenticator strategy; 45 | 46 | // @Before 47 | // public void init() throws Exception { 48 | // strategy = new OAuthAuthenticator(clientId, clientSec, redirect, scope, email, code); 49 | // } 50 | // 51 | // @Test 52 | // public void a_authorize() throws Exception { 53 | // strategy.authorize(new CompletionHandler() { 54 | // @Override 55 | // public void onComplete(String authCode) { 56 | // assertTrue(strategy.isAuthorized()); 57 | // assertNotNull(authCode); 58 | // assertFalse(authCode.isEmpty()); 59 | // System.out.println(authCode); 60 | // System.out.println("success"); 61 | // } 62 | // 63 | // @Override 64 | // public void onError(SparkError error) { 65 | // assertFalse("Every time get the code from browser manually, or test will fail.", true); 66 | // } 67 | // }); 68 | // Thread.sleep(10 * 1000); 69 | // } 70 | // 71 | // @Test 72 | // public void b_deauthorize() throws Exception { 73 | // strategy.deauthorize(); 74 | // assertFalse(strategy.isAuthorized()); 75 | // } 76 | // 77 | // @Test 78 | // public void c_authorizeFailed() throws Exception { 79 | // strategy.setAuthCode("wrong_code"); 80 | // strategy.authorize(new CompletionHandler() { 81 | // @Override 82 | // public void onComplete(String authCode) { 83 | // // not go here 84 | // assertFalse(true); 85 | // } 86 | // 87 | // @Override 88 | // public void onError(SparkError error) { 89 | // assertTrue(true); 90 | // } 91 | // }); 92 | // Thread.sleep(10 * 1000); 93 | // } 94 | // 95 | // @Test 96 | // public void d_authorizeFailed() throws Exception { 97 | // strategy.setScope("wrong_scope"); 98 | // strategy.authorize(new CompletionHandler() { 99 | // @Override 100 | // public void onComplete(String code) { 101 | // // not go here 102 | // assertFalse(true); 103 | // } 104 | // 105 | // @Override 106 | // public void onError(SparkError error) { 107 | // assertTrue(true); 108 | // } 109 | // }); 110 | // Thread.sleep(10 * 1000); 111 | // } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /sdk/src/test/java/com/ciscospark/androidsdk/membership/MembershipTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.membership; 24 | 25 | import com.google.gson.Gson; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.assertEquals; 30 | import static org.junit.Assert.assertNotNull; 31 | 32 | /** 33 | * Created by zhiyuliu on 31/08/2017. 34 | */ 35 | 36 | public class MembershipTest { 37 | 38 | @Test 39 | public void testConvert() { 40 | String jsonString = "{\n" + 41 | " \"id\" : \"Y2lzY29zcGFyazovL3VzL01FTUJFUlNISVAvMGQwYzkxYjYtY2U2MC00NzI1LWI2ZDAtMzQ1NWQ1ZDExZWYzOmNkZTFkZDQwLTJmMGQtMTFlNS1iYTljLTdiNjU1NmQyMjA3Yg\",\n" + 42 | " \"roomId\" : \"Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0\",\n" + 43 | " \"personId\" : \"Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mNWIzNjE4Ny1jOGRkLTQ3MjctOGIyZi1mOWM0NDdmMjkwNDY\",\n" + 44 | " \"personEmail\" : \"john.andersen@example.com\",\n" + 45 | " \"personDisplayName\" : \"John Andersen\",\n" + 46 | " \"personOrgId\" : \"Y2lzY29zcGFyazovL3VzL09SR0FOSVpBVElPTi85NmFiYzJhYS0zZGNjLTExZTUtYTE1Mi1mZTM0ODE5Y2RjOWE\",\n" + 47 | " \"isModerator\" : true,\n" + 48 | " \"isMonitor\" : true,\n" + 49 | " \"created\" : \"2015-10-18T14:26:16.203Z\"\n" + 50 | "}"; 51 | Gson gson = new Gson(); 52 | Membership membership = gson.fromJson(jsonString, Membership.class); 53 | assertNotNull(membership); 54 | assertEquals(membership.getId(), "Y2lzY29zcGFyazovL3VzL01FTUJFUlNISVAvMGQwYzkxYjYtY2U2MC00NzI1LWI2ZDAtMzQ1NWQ1ZDExZWYzOmNkZTFkZDQwLTJmMGQtMTFlNS1iYTljLTdiNjU1NmQyMjA3Yg"); 55 | assertEquals(membership.getPersonEmail(), "john.andersen@example.com"); 56 | assertEquals(membership.getPersonDisplayName(), "John Andersen"); 57 | assertEquals(membership.getRoomId(), "Y2lzY29zcGFyazovL3VzL1JPT00vYmJjZWIxYWQtNDNmMS0zYjU4LTkxNDctZjE0YmIwYzRkMTU0"); 58 | assertEquals(membership.isModerator(), true); 59 | assertEquals(membership.isMonitor(), true); 60 | assertNotNull(membership.getCreated()); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /sdk/src/test/java/com/ciscospark/androidsdk/people/PersonClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2018 Cisco Systems 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.ciscospark.androidsdk.people; 24 | 25 | import com.ciscospark.androidsdk.Spark; 26 | import com.ciscospark.androidsdk.auth.JWTAuthenticator; 27 | 28 | /** 29 | * Created on 27/08/2017. 30 | */ 31 | public class PersonClientTest { 32 | private static String auth_token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhbmRyb2lkX3Rlc3R1c2VyXzEiLCJuYW1lIjoiQW5kcm9pZFRlc3RVc2VyMSIsImlzcyI6ImNkNWM5YWY3LThlZDMtNGUxNS05NzA1LTAyNWVmMzBiMWI2YSJ9.eJ99AY9iNDhG4HjDJsY36wgqOnNQSes_PIu0DKBHBzs"; 33 | private static String testPersonId = "Y2lzY29zcGFyazovL3VzL1BFT1BMRS84MWM1MzkwOC1jMDIxLTRkOWQtOTk0Ny0xMDJlMzQ3ODMwMDc"; 34 | private static JWTAuthenticator authenticator; 35 | private static PersonClient mClient; 36 | private static Spark mSpark; 37 | private static boolean authCompleted = false; 38 | 39 | // @BeforeClass 40 | // public static void setUp() throws Exception { 41 | // System.out.println("setup test case"); 42 | // authenticator = new JWTAuthenticator(); 43 | // mSpark = new Spark(authenticator); 44 | // mSpark.authorize(new CompletionHandler() { 45 | // @Override 46 | // public void onComplete(String result) { 47 | // System.out.println(result); 48 | // authCompleted = true; 49 | // } 50 | // 51 | // @Override 52 | // public void onError(SparkError error) { 53 | // System.out.println(error.toString()); 54 | // assertFalse(true); 55 | // } 56 | // }); 57 | // 58 | // int time_wait = 0; 59 | // while(!authCompleted && ++time_wait < 10) { 60 | // System.out.println(time_wait + "s"); 61 | // Thread.sleep(1000); 62 | // } 63 | // 64 | // if (authenticator.isAuthorized()) { 65 | // mClient = new PersonClient(mSpark); 66 | // } 67 | // } 68 | // 69 | // @Test 70 | // public void list() throws Exception { 71 | // if (mSpark.isAuthorized()) { 72 | // mClient.list("xionxiao@cisco.com", null, 3, new CompletionHandler>() { 73 | // @Override 74 | // public void onComplete(List result) { 75 | // System.out.println(result.toString()); 76 | // assertTrue(true); 77 | // } 78 | // 79 | // @Override 80 | // public void onError(SparkError error) { 81 | // System.out.println(error.toString()); 82 | // assertFalse(true); 83 | // } 84 | // }); 85 | // } else { 86 | // assertFalse(true); 87 | // } 88 | // Thread.sleep(10 * 1000); 89 | // } 90 | // 91 | // @Test 92 | // public void get() throws Exception { 93 | // if (mSpark.isAuthorized()) { 94 | // mClient.get(testPersonId, new CompletionHandler() { 95 | // @Override 96 | // public void onComplete(Person result) { 97 | // System.out.println(result.toString()); 98 | // assertTrue(true); 99 | // } 100 | // 101 | // @Override 102 | // public void onError(SparkError error) { 103 | // System.out.println(error.toString()); 104 | // assertFalse(true); 105 | // 106 | // } 107 | // }); 108 | // } else { 109 | // assertFalse(true); 110 | // } 111 | // Thread.sleep(10 * 1000); 112 | // } 113 | // 114 | // @Test 115 | // public void getMe() throws Exception { 116 | // if (mSpark.isAuthorized()) { 117 | // mClient.getMe(new CompletionHandler() { 118 | // @Override 119 | // public void onComplete(Person result) { 120 | // System.out.println(result.toString()); 121 | // assertNotNull(result); 122 | // } 123 | // 124 | // @Override 125 | // public void onError(SparkError error) { 126 | // System.out.println(error.toString()); 127 | // assertFalse(true); 128 | // } 129 | // }); 130 | // } else { 131 | // assertFalse(true); 132 | // } 133 | // Thread.sleep(10 * 1000); 134 | // } 135 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sdk' 2 | --------------------------------------------------------------------------------