Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update examples to use latest release and other small updates #124

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
container: swift:5.8
env:
TEST_API_KEY: ${{ secrets.auth-token }}
MOMENTO_API_KEY: ${{ secrets.auth-token }}
steps:
# - uses: swift-actions/setup-swift@65540b95f51493d65f5e59e97dcef9629ddf11bf
# with:
Expand All @@ -38,13 +39,11 @@ jobs:
run: cd Examples/topics && swift build

- name: Build cache example
run: cd Examples/cache && swift build
run: cd Examples/cache && swift run

- name: Build quickstart example
run: cd Examples/quickstart && swift build

- name: Run dev doc examples
env:
MOMENTO_API_KEY: ${{ secrets.auth-token }}
run: cd Examples/doc-example-apis && swift run

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Happy coding :dancer:
## Requirements :coffee:

- Swift version [5.4 or higher](https://www.swift.org/install/) is required
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com)
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com/api-keys)

<br/>

Expand Down
2 changes: 1 addition & 1 deletion Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerequisites

- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com)
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com/api-keys)

## Running the examples

Expand Down
4 changes: 2 additions & 2 deletions Examples/cache/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/momentohq/client-sdk-swift",
"state" : {
"revision" : "4ba910e0874c3dff48419684be5e9cf24be43150",
"version" : "0.3.2"
"revision" : "19087b69bc283727a72f552e28df5743de7584f8",
"version" : "0.4.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/cache/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/momentohq/client-sdk-swift", exact: "0.3.2")
.package(url: "https://github.com/momentohq/client-sdk-swift", exact: "0.4.0")
],
targets: [
.executableTarget(
Expand Down
2 changes: 1 addition & 1 deletion Examples/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerequisites

- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com)
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com/api-keys)

## Running the example

Expand Down
8 changes: 7 additions & 1 deletion Examples/cache/Sources/main.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Momento
import Foundation

func main() async {
print("Running Momento Cache example!")
Expand All @@ -9,7 +10,7 @@ func main() async {
creds = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
} catch {
print("Error establishing credential provider: \(error)")
return
exit(1)
}

let cacheClient = CacheClient(
Expand All @@ -26,6 +27,7 @@ func main() async {
print("Successfully created the cache!")
case .error(let err):
print("Unable to create the cache: \(err)")
exit(1)
}

let listResult = await cacheClient.listCaches()
Expand All @@ -34,6 +36,7 @@ func main() async {
print("Successfully created fetched list of caches: \(success.caches.map { $0.name })")
case .error(let err):
print("Unable to fetch list of caches: \(err)")
exit(1)
}

let setResult = await cacheClient.set(
Expand All @@ -46,6 +49,7 @@ func main() async {
print("Successfully set item in the cache")
case .error(let err):
print("Unable to set item in the cache: \(err)")
exit(1)
}

let getResult = await cacheClient.get(
Expand All @@ -59,6 +63,7 @@ func main() async {
print("Cache miss")
case .error(let err):
print("Unable to get item in the cache: \(err)")
exit(1)
}

let deleteResult = await cacheClient.deleteCache(cacheName: cacheName)
Expand All @@ -67,6 +72,7 @@ func main() async {
print("Successfully deleted the cache!")
case .error(let err):
print("Unable to delete the cache: \(err)")
exit(1)
}
}

Expand Down
7 changes: 2 additions & 5 deletions Examples/demo-chat-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

## Prerequisites

- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com).
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com/api-keys).
- A Momento Cache. You can create a cache in the [Momento Console](https://console.gomomento.com) as well.

## Running the example

1. Open this directory as an Xcode project.
2. Paste your Momento API key in the `demo-chat-app/MomentoDemoChatApp.swift` file where the `momentoApiKey` variable is expecting it.
```
private let momentoApiKey: String = "<your Momento API key>"
```
2. Provide your Momento API key as an [environment variable](https://developer.apple.com/documentation/xcode/customizing-the-build-schemes-for-a-project#Specify-launch-arguments-and-environment-variables) with the name `MOMENTO_API_KEY`.
3. Click Run (in the Product menu).
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@
repositoryURL = "https://github.com/momentohq/client-sdk-swift";
requirement = {
kind = exactVersion;
version = 0.3.2;
version = 0.4.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/momentohq/client-sdk-swift",
"state" : {
"revision" : "4ba910e0874c3dff48419684be5e9cf24be43150",
"version" : "0.3.2"
"revision" : "19087b69bc283727a72f552e28df5743de7584f8",
"version" : "0.4.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0809ED4D2B0E9CDF00EF52B2"
BuildableName = "demo-chat-app.app"
BlueprintName = "demo-chat-app"
ReferencedContainer = "container:demo-chat-app.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0809ED4D2B0E9CDF00EF52B2"
BuildableName = "demo-chat-app.app"
BlueprintName = "demo-chat-app"
ReferencedContainer = "container:demo-chat-app.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "MOMENTO_API_KEY"
value = "eyJlbmRwb2ludCI6ImNlbGwtYWxwaGEtZGV2LnByZXByb2QuYS5tb21lbnRvaHEuY29tIiwiYXBpX2tleSI6ImV5SmhiR2NpT2lKSVV6STFOaUo5LmV5SnpkV0lpT2lKaGJtbDBZVUJ0YjIxbGJuUnZhSEV1WTI5dElpd2lkbVZ5SWpveExDSndJam9pUTBGQlBTSXNJbVY0Y0NJNk1UY3dOVGcyTXpRNE0zMC5rellHNHNScFNxQVNEUV9hNWpTb2Z0ZmQyaGFmcnZtLWM2czdHckg3cE40In0="
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0809ED4D2B0E9CDF00EF52B2"
BuildableName = "demo-chat-app.app"
BlueprintName = "demo-chat-app"
ReferencedContainer = "container:demo-chat-app.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
48 changes: 25 additions & 23 deletions Examples/demo-chat-app/demo-chat-app/MessageStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,35 @@ public class MessageStore: ObservableObject {
cacheName: momentoClient.cacheName,
topicName: momentoClient.topicName
)
switch subResp {
case .subscription(let subscription):
self.subscription = subscription
print("Successful subscription")
case .error(let err):
fatalError("Unable to establish Topics subscription: \(err)")
#if swift(>=5.9)
self.subscription = switch subResp {
case .subscription(let sub): sub
case .error(let err): fatalError("Unable to establish Topics subscription: \(err)")
anitarua marked this conversation as resolved.
Show resolved Hide resolved
}
#else
switch subscribeResponse {
case .error(let err):
fatalError("Unable to establish Topics subscription: \(err)")
case .subscription(let sub):
self.subscription = sub
}
#endif
}

do {
for try await item in self.subscription!.stream {
var value: String = ""
switch item {
case .itemText(let textItem):
value = textItem.value
print("Subscriber recieved text message: \(value)")
messages.append(ReceivedMessage(text: value))
case .itemBinary(let binaryItem):
value = String(decoding: binaryItem.value, as: UTF8.self)
print("Subscriber recieved binary message: \(value)")
messages.append(ReceivedMessage(text: value))
case .error(let err):
print("Subscriber received error: \(err)")
}
for try await item in self.subscription!.stream {
var value: String = ""
switch item {
case .itemText(let textItem):
value = textItem.value
print("Subscriber recieved text message: \(value)")
messages.append(ReceivedMessage(text: value))
case .itemBinary(let binaryItem):
value = String(decoding: binaryItem.value, as: UTF8.self)
print("Subscriber recieved binary message: \(value)")
messages.append(ReceivedMessage(text: value))
case .error(let err):
print("Subscriber received error: \(err)")
}
} catch {
print("Error while awaiting subscription item: \(error)")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import SwiftUI
import Momento

class Momento: ObservableObject {
private let momentoApiKey: String = ""

public var topicClient: TopicClientProtocol
public let cacheName: String = "cache"
public let topicName: String = "demo"

init() {
if momentoApiKey.isEmpty {
fatalError("Missing Momento API key in app initiation")
}
do {
let credProvider = try CredentialProvider.fromString(apiKey: self.momentoApiKey)
let credProvider = try CredentialProvider.fromEnvironmentVariable(envVariableName: "MOMENTO_API_KEY")
self.topicClient = TopicClient(
configuration: TopicClientConfigurations.iOS.latest().withClientTimeout(timeout: 600),
credentialProvider: credProvider
Expand Down
4 changes: 2 additions & 2 deletions Examples/doc-example-apis/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/momentohq/client-sdk-swift",
"state" : {
"revision" : "4ba910e0874c3dff48419684be5e9cf24be43150",
"version" : "0.3.2"
"revision" : "19087b69bc283727a72f552e28df5743de7584f8",
"version" : "0.4.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/doc-example-apis/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "doc-example-apis",
dependencies: [
.package(url: "https://github.com/momentohq/client-sdk-swift", exact: "0.3.2")
.package(url: "https://github.com/momentohq/client-sdk-swift", exact: "0.4.0")
],
targets: [
.executableTarget(
Expand Down
Loading
Loading