Skip to content

Commit 090d05b

Browse files
authored
Readme and documentation update (#96)
1 parent 9decb3f commit 090d05b

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

Documentation/REST API.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,39 @@
2424

2525
## Initialization
2626

27+
Create Uploadcare project in the [dashboard](https://app.uploadcare.com/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-swift) and copy its API keys from there.
28+
2729
REST API requires both public and secret keys:
2830

2931
```swift
30-
let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")
32+
final class MyClass {
33+
private var uploadcare: Uploadcare
34+
35+
init() {
36+
self.uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")
37+
}
38+
}
3139
```
3240

41+
You can create more than Uploadcare objects if you need to work with multiple projects on your Uploadcare account:
42+
43+
```swift
44+
final class MyClass {
45+
private let project1: Uploadcare
46+
private let project2: Uploadcare
47+
48+
init() {
49+
// A project to use Upload API only
50+
self.project1 = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY_1", secretKey: "YOUR_SECRET_KEY_1")
51+
52+
// A project to use both REST API and Upload API
53+
self.project2 = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY_2", secretKey: "YOUR_SECRET_KEY_2")
54+
}
55+
}
56+
```
57+
58+
Keep in mind that since Uploadcare is not a singleton. You should store a strong reference (as an instance variable, for example) to your Uploadcare object or it will get deallocated.
59+
3360
## List of files ([API Reference](https://uploadcare.com/api-refs/rest-api/v0.6.0/#operation/filesList)) ##
3461

3562
```swift

Documentation/Upload API.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,43 @@
1414

1515
## Initialization
1616

17+
Create Uploadcare project in the [dashboard](https://app.uploadcare.com/?utm_source=github&utm_medium=referral&utm_campaign=uploadcare-swift) and copy its API keys from there.
18+
1719
Upload API requires only a public key:
1820

1921
```swift
20-
let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY")
22+
final class MyClass {
23+
private var uploadcare: Uploadcare
24+
25+
init() {
26+
self.uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY")
27+
28+
// Secret key is optional for Upload API
29+
// But you still can provide it if you want to use both Upload API and REST API:
30+
self.uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")
31+
}
32+
}
33+
```
34+
35+
You can create more than Uploadcare objects if you need to work with multiple projects on your Uploadcare account:
36+
37+
```swift
38+
final class MyClass {
39+
private let project1: Uploadcare
40+
private let project2: Uploadcare
41+
42+
init() {
43+
// A project to use Upload API only
44+
self.project1 = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY_1")
45+
46+
// A project to use both REST API and Upload API
47+
self.project2 = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY_2", secretKey: "YOUR_SECRET_KEY_2")
48+
}
49+
}
2150
```
2251

52+
Keep in mind that since Uploadcare is not a singleton. You should store a strong reference (as an instance variable, for example) to your Uploadcare object or it will get deallocated.
53+
2354
## File upload ##
2455
Uploadcare provides a simple method that will handle file upload. It decides internally the best way to upload a file (to use direct or multipart upload).
2556

README.md

+30-3
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,38 @@ Create your project in [Uploadcare dashboard](https://uploadcare.com/dashboard/?
7777
Upload API requires only a public key, while REST API requires both public and secret keys:
7878

7979
```swift
80-
let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY")
81-
// Secret key is optional. Initialization with secret key:
82-
let uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")
80+
final class MyClass {
81+
private var uploadcare: Uploadcare
82+
83+
init() {
84+
self.uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY")
85+
86+
// Secret key is optional if you want to use Upload API only.
87+
// REST API requires both public and secret keys:
88+
self.uploadcare = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY", secretKey: "YOUR_SECRET_KEY")
89+
}
90+
}
8391
```
8492

93+
You can create more Uploadcare objects if you need to work with multiple projects in your Uploadcare account:
94+
95+
```swift
96+
final class MyClass {
97+
private let project1: Uploadcare
98+
private let project2: Uploadcare
99+
100+
init() {
101+
// A project to use Upload API only
102+
self.project1 = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY_1")
103+
104+
// A project to use both REST API and Upload API
105+
self.project2 = Uploadcare(withPublicKey: "YOUR_PUBLIC_KEY_2", secretKey: "YOUR_SECRET_KEY_2")
106+
}
107+
}
108+
```
109+
110+
Keep in mind that since Uploadcare is not a singleton. You should store a strong reference (as an instance variable, for example) to your Uploadcare object or it will get deallocated.
111+
85112
## Using Upload API
86113

87114
Check the [Upload API documentation](https://github.com/uploadcare/uploadcare-swift/blob/master/Documentation/Upload%20API.md) to see all available methods.

0 commit comments

Comments
 (0)