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

docs: Update README with base information about SDK usage #58

Merged
merged 2 commits into from
Jan 5, 2024

Conversation

polok
Copy link
Contributor

@polok polok commented Dec 27, 2023

No description provided.

@polok polok requested a review from a team as a code owner December 27, 2023 22:08
README.md Outdated
The SDK can be initialized in two different ways depending on your needs.

### Synchronous
You can fetch the data file content on your own and just pass it via options.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single word datafile.

```swift
import FeaturevisorSDK

let datafileContent: DatafileContent = ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any handy function for converting JSON string to DatafileContent? something like:

let datafileContent = DatafileContent.fromString("...stringified json here...")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today it can be achieved like below but anyway, such a direct method will be useful. Will handle it under a different PR.

guard let data = datafileJSON.data(using: .utf8) else { return }
let datafileContent = try? JSONDecoder().decode(DatafileContent.self, from: data)

README.md Outdated
var options: InstanceOptions = .default
options.datafile = datafileContent

let featurevisor = try createInstance(options: options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the website, I have tried using f as the instance variable everywhere.

you don't have to change anything, only mentioning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be consistent across our SDKs as much as possible.

README.md Outdated

var options: InstanceOptions = .default
options.handleDatafileFetch = { datafileUrl in
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we supposed to return an object following DatafileContent type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, as handleDatafileFetch is a following type public typealias DatafileFetchHandler = (_ datafileUrl: String) -> Result<DatafileContent, Error>

README.md Outdated
"userId": .string("123")
]

let variation = sdk.getVariation(featureKey: featureKey, context: context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea for future: we may consider using the _ thingy in Swift, so we don't always have to pass the argument names manually.

we could then do:

let variation = sdk.getVariation(featureKey, context)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was fighting with my thoughts about this some time ago trying to find the answer to what will be more obvious for people using it. Will take it as an improvement and handle under different PR.

README.md Outdated
"country": .string("nl")
]

let isEnabled = sdk.isEnabled(featureKey: featureKey, context: context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth clarifying that sdk is the SDK instance here. we may want to use the same instance variable name consistently throughout this whole README.

README.md Outdated

#### JSON object
```swift
sdk.getVariableJSON(featureKey: FeatureKey, variableKey: VariableKey, context: Context)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does Swift support generics? and if yes, should this method accept a type as a generic for the expected returned output?

like:

sdk.getVariableJSON<MyTypeHere>(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we have generics :). Something like below is enough for the compiler to know the type:
let variable: MyAwesomeType = sdk.getVariableJSON(featureKey: "feature_key", variableKey: "variable_key", context: context)
Will update the readme to be more precise.

README.md Outdated
```

### Logging
By default, Featurevisor will log logs to the for `warn` and `error` levels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to the "console"? I don't know what's the console equivalent (from browser and Node.js environments) in Swift.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking about the IDE's console output window. Will update the description

let logger = createLogger(
levels: [.error, .warn, .info, .debug],
handle: { level, message, details in ... })
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth showing how the logger instance is passed to options when creating the SDK instance.

@polok polok merged commit 828e9a7 into main Jan 5, 2024
1 check passed
@polok polok deleted the docs_readme_update_base_information branch January 5, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants