Skip to content

Commit

Permalink
Adding endpoint changes. (#5)
Browse files Browse the repository at this point in the history
* Adding endpoint changes.

* Allowing for variable types in flag values.
  • Loading branch information
wicheda authored Jul 1, 2021
1 parent 0a55251 commit 59d04e4
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 252 deletions.
12 changes: 7 additions & 5 deletions BulletTrainClient/Classes/APIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ enum Router {
case .getFlags:
return "flags/"
case .getIdentity(let identity):
return "identities/\(identity)/"
case .postTrait(let trait, let identity):
return "identities/\(identity)/traits/\(trait.key)"
return "identities/?identifier=\(identity)"
case .postTrait(let _, let _):
return "traits/"
}
}

private var body: Result<Data?, Error> {
switch self {
case .getFlags, .getIdentity:
return .success(nil)
case .postTrait(let trait, _):
case .postTrait(let trait, let identifier):
do {
return .success(try JSONEncoder().encode(trait))
let postTraitStruct = PostTrait(key:trait.key, value:trait.value, identifier:identifier)
let json = try JSONEncoder().encode(postTraitStruct)
return .success(json)
} catch {
return .failure(error)
}
Expand Down
2 changes: 1 addition & 1 deletion BulletTrainClient/Classes/BulletTrain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class BulletTrain {
switch result {
case .success(let flags):
let value = flags.first(where: {$0.feature.name == id})?.value
completion(.success(value))
completion(.success(value?.stringValue))
case .failure(let error):
completion(.failure(error))
}
Expand Down
2 changes: 1 addition & 1 deletion BulletTrainClient/Classes/Flag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public struct Flag: Decodable {
}

public let feature: Feature
public let value: String?
let value: UnknownTypeValue?
public let enabled: Bool
}
32 changes: 32 additions & 0 deletions BulletTrainClient/Classes/Trait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,35 @@ public struct Trait: Codable {
self.value = value
}
}

/**
A PostTrait represents a structure to set a new trait, with the Trait fields and the identity.
*/
public struct PostTrait: Codable {
enum CodingKeys: String, CodingKey {
case key = "trait_key"
case value = "trait_value"
case identity = "identity"
}

public let key: String
public var value: String
var identity: IdentityStruct

struct IdentityStruct: Codable {
var identifier: String

enum CodingKeys: String, CodingKey {
case identifier = "identifier"
}
public init(identifier: String) {
self.identifier = identifier
}
}

public init(key: String, value: String, identifier:String) {
self.key = key
self.value = value
self.identity = IdentityStruct(identifier: identifier)
}
}
4 changes: 0 additions & 4 deletions Example/BulletTrainClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,11 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-BulletTrainClient_Example/Pods-BulletTrainClient_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/BulletTrainClient/BulletTrainClient.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/BulletTrainClient.framework",
);
Expand Down
1 change: 1 addition & 0 deletions Example/BulletTrainClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
BulletTrain.shared.hasFeatureFlag(withID: "freeze_delinquent_accounts") { (result) in
print(result)
}
//BulletTrain.shared.setTrait(Trait(key: "<my_key>", value: "<my_value>"), forIdentity: "<my_identity>") { (result) in print(result) }
return true
}

Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- BulletTrainClient (0.1.0)
- BulletTrainClient (1.0.1)

DEPENDENCIES:
- BulletTrainClient (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
BulletTrainClient: 9e55475a502f93657de849220749c7558b879925
BulletTrainClient: c21ea61bd2a7da9292404e5f45903e3a7ad78d2f

PODFILE CHECKSUM: be7a2446bc362d87dab4e909a6d3abf808921b04

COCOAPODS: 1.6.2
COCOAPODS: 1.10.0
18 changes: 10 additions & 8 deletions Example/Pods/Local Podspecs/BulletTrainClient.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 59d04e4

Please sign in to comment.