Skip to content

Commit

Permalink
Merge pull request #198 from intercom/james/release_4_0_0
Browse files Browse the repository at this point in the history
Release 4.0.0
  • Loading branch information
Br1an-Boyle committed Aug 30, 2017
2 parents 650d352 + 32901e6 commit b4f77ab
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 51 deletions.
12 changes: 8 additions & 4 deletions .travis.yml
@@ -1,17 +1,21 @@
language: objective-c

node_js:
- 5.10
node_js: '6.11.2'

sudo: false

cache:
directories:
- node_modules

install:
- npm install -g npm@5.3.0
- npm install -g cordova

before_script:
- cd Example
- cordova platform add ios
- cordova plugin add ..
- cordova platform add ios
- cordova plugin add ../intercom-plugin

script:
- cordova build ios
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# Intercom for Cordova/PhoneGap

## 4.0.0 (2017-08-29)

* Updated Intercom for Android to 4.0.1
* Updated Intercom for iOS to 4.0.1
* Removed deprecated method `intercom.setSecureMode(hmac, data)`.
* Added support for iOS 11.
* Added support for Android Oreo.
* Updated GCM & FCM to version 11.

## 3.2.2 (2017-05-17)

* Prevent unsafe versions of the Support Library being used to fix [#182](https://github.com/intercom/intercom-cordova/issues/182).
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -4,7 +4,7 @@

This is a plugin that allows your Cordova or PhoneGap app to use [Intercom for iOS](https://github.com/intercom/intercom-ios) and/or [Intercom for Android](https://github.com/intercom/intercom-android).

* Intercom for iOS supports iOS 8, 9 & 10.
* Intercom for iOS supports iOS 8, 9, 10 & 11.
* Intercom for Android supports API 15 and above.

## Installation
Expand All @@ -19,7 +19,7 @@ cordova plugin add cordova-plugin-intercom

To add the plugin to your PhoneGap app, add the following to your `config.xml`:
```xml
<plugin name="cordova-plugin-intercom" version="~3.2.2" />
<plugin name="cordova-plugin-intercom" version="~4.0.0" />
```
### Ionic

Expand Down
29 changes: 16 additions & 13 deletions circle.yml
Expand Up @@ -2,35 +2,38 @@ general:
build_dir: Example

machine:
environment:
ORG_GRADLE_PROJECT_cdvCompileSdkVersion: android-26
ORG_GRADLE_PROJECT_cdvBuildToolsVersion: 26.0.1
node:
version: 6.1.0
version: 6.11.2
java:
version: openjdk8

dependencies:
override:
- npm install -g cordova
- if [ ! -e $ANDROID_HOME/platforms/android-25 ]; then echo y | android update sdk --no-ui --all --filter android-25; fi
- if [ ! -e $ANDROID_HOME/extras/android/m2repository/com/android/support/design/25.3.1 ]; then echo y | android update sdk --no-ui --all --filter extra-android-m2repository; fi
- if [ ! -e $ANDROID_HOME/extras/google/m2repository/com/google/firebase/firebase-messaging/10.2.1 ]; then echo y | android update sdk --no-ui --all --filter extra-google-m2repository; fi
# Need to always update these 2 to accept licenses
- echo y | android update sdk --no-ui --all --filter android-25
- echo y | android update sdk --no-ui --all --filter android-26
- if [ ! -e $ANDROID_HOME/build-tools/26.0.1 ]; then echo y | android update sdk --no-ui --all --filter build-tools-26.0.1; fi
- if [ ! -e $ANDROID_HOME/extras/google/m2repository/com/google/firebase/firebase-messaging/11.0.4 ]; then echo y | android update sdk --no-ui --all --filter extra-google-m2repository; fi

cache_directories:
# Android SDK
- "/usr/local/android-sdk-linux/platforms/android-24"
- "/usr/local/android-sdk-linux/extras/android/m2repository"
- "/usr/local/android-sdk-linux/build-tools/26.0.1"
- "/usr/local/android-sdk-linux/extras/google/m2repository"

test:
pre:
- cordova platform add android
- cordova plugin add ..
override:
- cordova build android
- cordova platform add android
- cordova plugin add ../intercom-plugin
- cordova build android --verbose -- --gradleArg=--stacktrace

deployment:
master:
tag: /3(\.[0-9]+)+/
tag: /[0-9](\.[0-9]+)+/
owner: intercom
commands:
- echo -e "$NPM_USER\n$NPM_PASSWORD\n$NPM_EMAIL" | npm login
- cd .. && npm publish
- cd ../intercom-plugin && npm publish
2 changes: 1 addition & 1 deletion package.json → intercom-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-intercom",
"version": "3.2.2",
"version": "4.0.0",
"description": "Official Cordova/PhoneGap plugin for Intercom",
"cordova": {
"id": "cordova-plugin-intercom",
Expand Down
4 changes: 2 additions & 2 deletions plugin.xml → intercom-plugin/plugin.xml
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-intercom" version="3.2.2" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="cordova-plugin-intercom" version="4.0.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>Intercom</name>
<author>Intercom</author>
<license>MIT License</license>
Expand Down Expand Up @@ -47,7 +47,7 @@
</array>
</config-file>

<framework src="Intercom" type="podspec" spec="~> 3.2.2" />
<framework src="Intercom" type="podspec" spec="~> 4.0.0" />
</platform>

<platform name="android">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -34,6 +34,8 @@

public class IntercomBridge extends CordovaPlugin {

private static final String CUSTOM_ATTRIBUTES = "custom_attributes";

@Override protected void pluginInitialize() {
cordova.getActivity().runOnUiThread(new Runnable() {
@Override public void run() {
Expand Down Expand Up @@ -66,7 +68,7 @@ private void setUpIntercom() {
try {
Context context = IntercomBridge.this.cordova.getActivity().getApplicationContext();

CordovaHeaderInterceptor.setCordovaVersion(context, "3.2.2");
CordovaHeaderInterceptor.setCordovaVersion(context, "4.0.0");

switch (IntercomPushManager.getInstalledModuleType()) {
case GCM: {
Expand Down Expand Up @@ -121,14 +123,6 @@ private enum Action {
callbackContext.success();
}
},
setSecureMode {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String hmac = args.optString(0);
String data = args.optString(1);
Intercom.client().setSecureMode(hmac, data);
callbackContext.success();
}
},
setUserHash {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
String hmac = args.optString(0);
Expand Down Expand Up @@ -212,7 +206,15 @@ private enum Action {
updateUser {
@Override void performAction(JSONArray args, CallbackContext callbackContext, CordovaInterface cordova) {
Map<String, Object> attributes = IntercomBridge.mapFromJSON(args.optJSONObject(0));
Intercom.client().updateUser(attributes);
UserAttributes.Builder builder = new UserAttributes.Builder();
Object customAttributes = attributes.get(CUSTOM_ATTRIBUTES);
if (customAttributes instanceof Map) {
//noinspection unchecked
builder.customAttributes.putAll((Map<? extends String, ?>) customAttributes);
}
attributes.remove(CUSTOM_ATTRIBUTES);
builder.attributes.putAll(attributes);
Intercom.client().updateUser(builder.build());
callbackContext.success();
}
},
Expand Down
File renamed without changes.
Expand Up @@ -9,7 +9,7 @@ android.defaultConfig.applicationId manifest.@package.text()
// some libraries depend on higher versions of our dependencies than we support
// we keep track of these dependencies here and override the version to a safe one
def safeVersions = [
"com.android.support:support-v4": "25.+"
"com.android.support:support-v4": "26.+"
]

def badVersionIndicators = [
Expand Down
Expand Up @@ -10,9 +10,10 @@ buildscript {
repositories {
jcenter()
mavenLocal()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.android.tools.build:gradle:2.3.+'
if (pushType == 'fcm') {
classpath 'com.google.gms:google-services:3.0.0'
}
Expand All @@ -21,14 +22,15 @@ buildscript {

repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
compile 'io.intercom.android:intercom-sdk-base:3.2.+'
compile 'io.intercom.android:intercom-sdk-base:4.0.+'
if (pushType == 'gcm') {
compile 'io.intercom.android:intercom-sdk-gcm:3.2.+'
compile 'io.intercom.android:intercom-sdk-gcm:4.0.+'
} else if (pushType == 'fcm') {
compile 'com.google.firebase:firebase-messaging:10.+'
compile 'io.intercom.android:intercom-sdk-fcm:3.2.+'
compile 'com.google.firebase:firebase-messaging:11.+'
compile 'io.intercom.android:intercom-sdk-fcm:4.0.+'
}
}

Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -8,7 +8,7 @@
- (void)registerUnidentifiedUser:(CDVInvokedUrlCommand*)command;
- (void)reset:(CDVInvokedUrlCommand*)command;

- (void)setSecureMode:(CDVInvokedUrlCommand*)command;
- (void)setUserHash:(CDVInvokedUrlCommand*)command;

- (void)updateUser:(CDVInvokedUrlCommand*)command;
- (void)logEvent:(CDVInvokedUrlCommand*)command;
Expand Down
113 changes: 101 additions & 12 deletions src/ios/IntercomBridge.m → intercom-plugin/src/ios/IntercomBridge.m
Expand Up @@ -9,7 +9,7 @@ + (void)setCordovaVersion:(NSString *)v;
@implementation IntercomBridge : CDVPlugin

- (void)pluginInitialize {
[Intercom setCordovaVersion:@"3.2.2"];
[Intercom setCordovaVersion:@"4.0.0"];
#ifdef DEBUG
[Intercom enableLogging];
#endif
Expand Down Expand Up @@ -56,14 +56,6 @@ - (void)reset:(CDVInvokedUrlCommand*)command {
[self sendSuccess:command];
}

- (void)setSecureMode:(CDVInvokedUrlCommand*)command {
NSString *hmac = command.arguments[0];
NSString *data = command.arguments[1];

[Intercom setHMAC:hmac data:data];
[self sendSuccess:command];
}

- (void)setUserHash:(CDVInvokedUrlCommand*)command {
NSString *hmac = command.arguments[0];

Expand All @@ -72,9 +64,8 @@ - (void)setUserHash:(CDVInvokedUrlCommand*)command {
}

- (void)updateUser:(CDVInvokedUrlCommand*)command {
NSDictionary* attributes = command.arguments[0];
[Intercom updateUserWithAttributes:attributes];

NSDictionary* attributesDict = command.arguments[0];
[Intercom updateUser:[self userAttributesForDictionary:attributesDict]];
[self sendSuccess:command];
}

Expand Down Expand Up @@ -153,6 +144,104 @@ - (void)registerForPush:(CDVInvokedUrlCommand*)command {
[self sendSuccess:command];
}

#pragma mark - User attributes

- (ICMUserAttributes *)userAttributesForDictionary:(NSDictionary *)attributesDict {
ICMUserAttributes *attributes = [ICMUserAttributes new];
if ([self stringValueForKey:@"email" inDictionary:attributesDict]) {
attributes.email = [self stringValueForKey:@"email" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"user_id" inDictionary:attributesDict]) {
attributes.userId = [self stringValueForKey:@"user_id" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"name" inDictionary:attributesDict]) {
attributes.name = [self stringValueForKey:@"name" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"phone" inDictionary:attributesDict]) {
attributes.phone = [self stringValueForKey:@"phone" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"language_override" inDictionary:attributesDict]) {
attributes.languageOverride = [self stringValueForKey:@"language_override" inDictionary:attributesDict];
}
if ([self dateValueForKey:@"signed_up_at" inDictionary:attributesDict]) {
attributes.signedUpAt = [self dateValueForKey:@"signed_up_at" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"unsubscribed_from_emails" inDictionary:attributesDict]) {
attributes.unsubscribedFromEmails = [self stringValueForKey:@"unsubscribed_from_emails" inDictionary:attributesDict];
}
if (attributesDict[@"custom_attributes"]) {
attributes.customAttributes = attributesDict[@"custom_attributes"];
}
if (attributesDict[@"companies"]) {
NSMutableArray<ICMCompany *> *companies = [NSMutableArray new];
for (NSDictionary *companyDict in attributesDict[@"companies"]) {
[companies addObject:[self companyForDictionary:companyDict]];
}
attributes.companies = companies;
}
return attributes;
}

- (ICMCompany *)companyForDictionary:(NSDictionary *)attributesDict {
ICMCompany *company = [ICMCompany new];
if ([self stringValueForKey:@"company_id" inDictionary:attributesDict]) {
company.companyId = [self stringValueForKey:@"company_id" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"name" inDictionary:attributesDict]) {
company.name = [self stringValueForKey:@"name" inDictionary:attributesDict];
}
if ([self dateValueForKey:@"created_at" inDictionary:attributesDict]) {
company.createdAt = [self dateValueForKey:@"created_at" inDictionary:attributesDict];
}
if ([self numberValueForKey:@"monthly_spend" inDictionary:attributesDict]) {
company.monthlySpend = [self numberValueForKey:@"monthly_spend" inDictionary:attributesDict];
}
if ([self stringValueForKey:@"plan" inDictionary:attributesDict]) {
company.plan = [self stringValueForKey:@"plan" inDictionary:attributesDict];
}
if (attributesDict[@"custom_attributes"]) {
company.customAttributes = attributesDict[@"custom_attributes"];
}
return company;
}

- (NSString *)stringValueForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary {
NSString *value = dictionary[key];
if ([value isKindOfClass:[NSString class]]) {
return value;
}
if ([value isKindOfClass:[NSNumber class]]) {
return [NSString stringWithFormat:@"%@", value];
}
if ([value isKindOfClass:[NSNull class]]) {
return [ICMUserAttributes nullStringAttribute];
}
return nil;
}

- (NSNumber *)numberValueForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary {
NSNumber *value = dictionary[key];
if ([value isKindOfClass:[NSNumber class]]) {
return value;
}
if ([value isKindOfClass:[NSNull class]]) {
return [ICMUserAttributes nullNumberAttribute];
}
return nil;
}

- (NSDate *)dateValueForKey:(NSString *)key inDictionary:(NSDictionary *)dictionary {
NSNumber *value = dictionary[key];
if ([value isKindOfClass:[NSNumber class]]) {
return [NSDate dateWithTimeIntervalSince1970:[value doubleValue]];
}
if ([value isKindOfClass:[NSNull class]]) {
return [ICMUserAttributes nullDateAttribute];
}
return nil;
}


#pragma mark - Private methods

- (void)sendSuccess:(CDVInvokedUrlCommand*)command {
Expand Down
File renamed without changes.

0 comments on commit b4f77ab

Please sign in to comment.