|
| 1 | +// |
| 2 | +/**************************************************************************** |
| 3 | +* Copyright 2019, Optimizely, Inc. and contributors * |
| 4 | +* * |
| 5 | +* Licensed under the Apache License, Version 2.0 (the "License"); * |
| 6 | +* you may not use this file except in compliance with the License. * |
| 7 | +* You may obtain a copy of the License at * |
| 8 | +* * |
| 9 | +* http://www.apache.org/licenses/LICENSE-2.0 * |
| 10 | +* * |
| 11 | +* Unless required by applicable law or agreed to in writing, software * |
| 12 | +* distributed under the License is distributed on an "AS IS" BASIS, * |
| 13 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * |
| 14 | +* See the License for the specific language governing permissions and * |
| 15 | +* limitations under the License. * |
| 16 | +***************************************************************************/ |
| 17 | + |
| 18 | + |
| 19 | +import Foundation |
| 20 | + |
| 21 | +extension AppDelegate { |
| 22 | + |
| 23 | + func samplesForAPI() { |
| 24 | + |
| 25 | + let attributes = ["country": "us"] |
| 26 | + let eventTags = ["price": "100"] |
| 27 | + |
| 28 | + if let variationKey = try? optimizely.activate(experimentKey: "experimentKey", |
| 29 | + userId: "userId", |
| 30 | + attributes: attributes) { |
| 31 | + print("[activate] \(variationKey)") |
| 32 | + } |
| 33 | + |
| 34 | + if let variationKey = try? optimizely.getVariationKey(experimentKey: "experimentKey", |
| 35 | + userId: "userId", |
| 36 | + attributes: attributes) { |
| 37 | + print("[getVariationKey] \(variationKey)") |
| 38 | + } |
| 39 | + |
| 40 | + if let variationKey = optimizely.getForcedVariation(experimentKey: "experimentKey", userId: "userId") { |
| 41 | + print("[getForcedVariation] \(variationKey)") |
| 42 | + } |
| 43 | + |
| 44 | + if optimizely.setForcedVariation(experimentKey: "experimentKey", |
| 45 | + userId: "userId", |
| 46 | + variationKey: "variationKey") { |
| 47 | + print("[setForcedVariation]") |
| 48 | + } |
| 49 | + |
| 50 | + do { |
| 51 | + let result = try optimizely.isFeatureEnabled(featureKey: "featureKey", |
| 52 | + userId: "userId", |
| 53 | + attributes: attributes) |
| 54 | + print("[isFeatureEnabled] \(result)") |
| 55 | + } catch { |
| 56 | + // error |
| 57 | + } |
| 58 | + |
| 59 | + if let value = try? optimizely.getFeatureVariableBoolean(featureKey: "featureKey", |
| 60 | + variableKey: "kBoolean", |
| 61 | + userId: "userId", |
| 62 | + attributes: attributes) { |
| 63 | + print("[getFeatureVariableBoolean] \(value)") |
| 64 | + } |
| 65 | + |
| 66 | + if let value = try? optimizely.getFeatureVariableDouble(featureKey: "featureKey", |
| 67 | + variableKey: "kDouble", |
| 68 | + userId: "userId", |
| 69 | + attributes: attributes) { |
| 70 | + print("[getFeatureVariableDouble] \(value)") |
| 71 | + } |
| 72 | + |
| 73 | + if let value = try? optimizely.getFeatureVariableInteger(featureKey: "featureKey", |
| 74 | + variableKey: "kInteger", |
| 75 | + userId: "userId", |
| 76 | + attributes: attributes) { |
| 77 | + print("[getFeatureVariableInteger] \(value)") |
| 78 | + } |
| 79 | + |
| 80 | + if let value = try? optimizely.getFeatureVariableString(featureKey: "featureKey", |
| 81 | + variableKey: "kString", |
| 82 | + userId: "userId", |
| 83 | + attributes: attributes) { |
| 84 | + print("[getFeatureVariableString] \(value)") |
| 85 | + } |
| 86 | + |
| 87 | + if let features = try? optimizely.getEnabledFeatures(userId: "userId", attributes: attributes) { |
| 88 | + print("[getEnabledFeatures] \(features)") |
| 89 | + } |
| 90 | + |
| 91 | + try? optimizely.track(eventKey: "eventKey", userId: "userId", attributes: attributes, eventTags: eventTags) |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | +} |
0 commit comments