Skip to content

Commit 323f87c

Browse files
committed
Update readme file
1 parent ec2a0ba commit 323f87c

File tree

1 file changed

+26
-89
lines changed

1 file changed

+26
-89
lines changed

README.md

Lines changed: 26 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
```swift
1313
import SwiftJSONRPC
14+
import PromiseKit
1415

1516
class UserService: JSONRPCService {
16-
func vote(rating: Int) -> ResultProvider<Int> {
17+
func vote(rating: Int) -> Promise<Int> {
1718
return invoke("vote", params: ["rating": rating])
1819
}
1920

20-
func create(name: String) -> ResultProvider<UserModel> {
21+
func create(name: String) -> Promise<UserModel> {
2122
return invoke("create", params: ["name": name])
2223
}
2324

@@ -43,99 +44,18 @@ service.vote(rating: 5)
4344

4445
### Result Handling
4546

46-
```swift
47-
service.vote(rating: 5).result { newRating in
48-
// Handle result
49-
}
50-
```
51-
52-
SwiftJSONRPC contains five different invocation callback types.
53-
54-
###### Result
55-
56-
```swift
57-
func result(queue: ResultQueue = .background, block: @escaping (Result) -> Void) -> Self
58-
```
59-
60-
Called on success result. Include generic response data type that you defined in `RPCService` subclass.
61-
62-
###### Error
63-
64-
```swift
65-
func error(queue: ResultQueue = .background, block: @escaping (RPCError) -> Void) -> Self
66-
```
67-
68-
Called on error result. Include instance of `RPCError` type.
69-
70-
###### Cancel
71-
72-
```swift
73-
func cancel(queue: ResultQueue = .background, block: @escaping () -> Void) -> Self
74-
```
75-
76-
Called if invocation was cancelled by calling `cancel()` method.
77-
78-
###### Start
79-
80-
```swift
81-
func start(queue: ResultQueue = .background, block: @escaping () -> Void) -> Self
82-
```
83-
84-
Called before performing invocation. Can be used for starting loading animation.
85-
86-
###### Finish
87-
88-
```swift
89-
func finish(queue: ResultQueue = .background, block: @escaping () -> Void) -> Self
90-
```
91-
92-
Called after performing invocation. In all cases including canceling. Can be used for stopping loading animation.
93-
94-
#### Chained Invocation Callbacks
95-
96-
Invocation callbacks can be chained:
97-
98-
```swift
99-
service.vote(rating: 5)
100-
.result { newRating in
101-
// Handle result
102-
}
103-
.error { error in
104-
// Handle error
105-
}
106-
.start {
107-
// Setup activity indicator
108-
}
109-
.finish {
110-
// Remove activity indicator
111-
}
112-
```
113-
114-
#### Invocation Callbacks Queue
115-
116-
By default invocation callback called on background queue. But you can specify custom queue for each callback:
47+
SwiftJSONRPC uses [PromiseKit](https://github.com/mxcl/PromiseKit) to return result.
11748

11849
```swift
11950
service.vote(rating: 5)
120-
.result(queue: .background) { newRating in
51+
.done { newRating in
12152
// Handle result
12253
}
123-
.error(queue: .main) { error in
54+
.catch { error in
12455
// Handle error
12556
}
12657
```
12758

128-
Use one of available queue types:
129-
130-
```swift
131-
enum ResultQueue
132-
{
133-
case main
134-
case background
135-
case custom(queue: DispatchQueue)
136-
}
137-
```
138-
13959
#### Result Serialization
14060

14161
SwiftJSONRPC provides built-in result serialization for `Int`, `String`, `Bool` types.
@@ -170,13 +90,13 @@ After that use this struct as `RPCService.Result` generic parameter:
17090

17191
```swift
17292
class UserService: JSONRPCService {
173-
func create(name: String) -> ResultProvider<UserModel> {
93+
func create(name: String) -> Promise<UserModel> {
17494
return invoke("create", params: ["name": name])
17595
}
17696
}
17797
```
17898
```swift
179-
service.create(name: "testuser").result { user in
99+
service.create(name: "testuser").done { user in
180100
print("User created with ID = \(user.id)")
181101
}
182102
```
@@ -185,7 +105,7 @@ Using array of `Parcelable` objects is also supported:
185105

186106
```swift
187107
extension UserService {
188-
func allUsers() -> ResultProvider<[UserModel]> {
108+
func allUsers() -> Promise<[UserModel]> {
189109
return invoke("all_users")
190110
}
191111
}
@@ -200,16 +120,33 @@ extension UserService {
200120

201121
## Installation
202122

123+
### CocoaPods
124+
203125
SwiftJSONRPC is available through [CocoaPods](http://cocoapods.org). To install
204126
it, simply add the following line to your Podfile:
205127

206128
```ruby
207129
pod "SwiftJSONRPC"
208130
```
209131

132+
### Carthage
133+
134+
```ruby
135+
github "kolyasev/SwiftJSONRPC"
136+
```
137+
138+
### Swift Package Manager
139+
140+
```swift
141+
dependencies: [
142+
.package(url: "https://github.com/kolyasev/SwiftJSONRPC.git", .upToNextMajor(from: "0.7.0"))
143+
]
144+
```
145+
210146
## ToDo
211147

212148
- [ ] Add support for notification request object without an "id" member.
149+
- [ ] Remove `Parcelable` protocol and use `Decodable`.
213150

214151
## Author
215152

0 commit comments

Comments
 (0)