Skip to content

Commit 2a58140

Browse files
author
Travis CI User
committed
Version 0.4
1 parent 820fbc9 commit 2a58140

File tree

4 files changed

+131
-138
lines changed

4 files changed

+131
-138
lines changed

doc/customer.md

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
# Customers
22

3-
Customers are managed via a `CustomerOperation`
4-
5-
A customer operation can be retrieved using the following.
6-
7-
```
8-
val customerOperation = FlyBuy.customer.getCustomerOperation()
9-
```
10-
11-
## Observe the customer
12-
13-
Returns a `LiveData` stream of the current customer to observe. The customer received will either be the logged in user or `null`
14-
15-
```
16-
val customer: Customer = customerOperation.customers
17-
```
18-
193
## Create a Customer
204

21-
Create a customer account using information from the user. Consent should be collected from the user (e.g. checkboxes)
5+
Create a customer account using information from the user. Consent should be collected from the user (e.g. checkboxes).
226

23-
```
7+
```kotlin
8+
fun createCustomer() {
249
val customerInfo = CustomerInfo (
2510
name = "Marty McFly",
2611
carType = "DeLorean",
@@ -32,20 +17,22 @@ Create a customer account using information from the user. Consent should be col
3217
ageVerification = true
3318
)
3419

35-
fun createProfile(): LiveData<WorkStatus> {
36-
return customerOperation.create(customerInfo, customerConsent)
20+
FlyBuy.customer.create(customerInfo, customerConsent) { customer, sdkError ->
21+
// Handle customer or deal with error
3722
}
23+
}
3824
```
3925

40-
## Sign Up a Customer
26+
## Create a Customer with Login
4127

42-
Create a customer account with email and password using information from the user. Consent should be collected from the user (e.g. checkboxes)
28+
Create a customer account with email and password using information from the user. Consent should be collected from the user (e.g. checkboxes).
4329

44-
```
30+
```kotlin
31+
fun createCustomerWithLogin() {
4532
val loginInfo = LoginInfo (
4633
email = "[email protected]",
4734
password = "password"
48-
}
35+
)
4936
val customerInfo = CustomerInfo (
5037
name = "Marty McFly",
5138
carType = "DeLorean",
@@ -57,66 +44,83 @@ Create a customer account with email and password using information from the use
5744
ageVerification = true
5845
)
5946

60-
fun signUp(): LiveData<WorkStatus> {
61-
return customerOperation.signUp(customerInfo, loginInfo, customerConsent)
47+
FlyBuy.customer.createWithLogin(customerInfo, loginInfo, customerConsent) { customer , sdkError ->
48+
// Handle customer or deal with error
6249
}
50+
}
6351
```
6452

65-
## "Upgrade" a Customer
53+
## Sign Up a Customer
6654

67-
Link an email and password with the current anonymous logged in user
55+
Link an email and password with the current anonymous logged in user.
6856

69-
```
57+
```kotlin
58+
fun signUp() {
7059
val loginInfo = LoginInfo (
7160
email = "[email protected]",
7261
password = "password"
7362
)
7463

75-
fun upgrade(): LiveData<WorkStatus> {
76-
return customerOperation.upgrade(customerInfo)
64+
FlyBuy.customer.signUp(loginInfo) { customer, sdkError ->
65+
// Handle customer or deal with error
7766
}
67+
}
7868
```
7969

8070
## Sign In
8171

8272
Sign the user in using existing credentials
8373

84-
```
74+
```kotlin
75+
fun login() {
8576
val loginInfo = LoginInfo(
8677
email = "[email protected]",
8778
password = "password"
8879
)
8980

90-
fun login(loginInfo: LoginInfo): LiveData<WorkStatus> {
91-
return customerOperation.login(loginInfo)
81+
FlyBuy.customer.login(loginInfo) { customer, sdkError ->
82+
// Handle customer or deal with error
9283
}
84+
}
9385
```
9486

9587
## Sign out the current Customer
9688

9789
Signs out the current customer.
9890

99-
```
100-
fun signOut(): LiveData<WorkStatus> {
101-
return customerOperation.logout()
91+
```kotlin
92+
fun signOut() {
93+
FlyBuy.customer.signOut { sdkError ->
94+
// Handle error
10295
}
96+
}
10397
```
10498

10599
## Update a Customer
106100

107101
Update customer info for the logged in user
108102

109-
```
103+
```kotlin
104+
fun updateCustomer() {
110105
val customerInfo = CustomerInfo (
111106
name = "Marty McFly",
112107
carType = "DeLorean",
113108
carColor = "Silver",
114109
licensePlate = "OUTATIME"
115110
)
116111

117-
fun update(customerInfo: CustomerInfo): LiveData<WorkStatus> {
118-
return customerOperation.updateCustomer(customerInfo)
112+
FlyBuy.customer.update(customerInfo) { customer, sdkError ->
113+
// Handle customer or deal with error
119114
}
115+
}
116+
```
117+
118+
## Get the current Customer
119+
120+
Returns an instance of the current customer. This may not be accessed directly from the main thread.
121+
122+
```kotlin
123+
FlyBuy.customer.current
120124
```
121125

122126

doc/notifications.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,42 @@ FlyBuy can leverage Google's Firebase Cloud Messaging (FCM) to get updates about
44

55
To pass the message to FlyBuy, override the `FirebaseMessagingService.onMessageReceived` method as follows.
66

7-
```
7+
```kotlin
88
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
9-
// result is a LiveData<WorkStatus> object that can be observed
10-
val result = FlyBuy.onMessageReceived(remoteMessage)
9+
FlyBuy.onMessageReceived(remoteMessage) { sdkError ->
10+
// Handle error
11+
}
1112
}
1213
```
1314

1415
You do not need to filter or check the body of the `remoteMessage` data, FlyBuy will inspect it and only process the notification if it is relevant to the SDK.
1516

1617
Since a device's push token can change, the FlyBuy SDK needs to be informed when that occurs. To do so, override the `FirebaseMessagingingService.onNewToken()` method as follows.
1718

18-
```
19-
override fun onNewToken(token: String?) {
20-
FlyBuy.onNewPushToken(token)
21-
}
19+
```kotlin
20+
override fun onNewToken(token: String?) {
21+
FlyBuy.onNewPushToken(token)
22+
}
2223
```
2324

2425
The SDK should also be updated with the push token when the app starts. The following code snippet provides an example function that can be called from `onCreate()` in your activity.
2526

26-
```
27-
private fun updatePushToken() {
28-
FirebaseInstanceId.getInstance().instanceId
29-
.addOnCompleteListener(OnCompleteListener { task ->
30-
if (!task.isSuccessful) {
31-
Timber.w(task.exception, "getInstanceId failed")
32-
return@OnCompleteListener
33-
}
34-
35-
// Get new Instance ID token
36-
task.result?.token?.let {
37-
FlyBuy.getInstance(this).onNewPushToken(it)
38-
}
39-
40-
})
41-
}
27+
```kotlin
28+
private fun updatePushToken() {
29+
FirebaseInstanceId.getInstance().instanceId
30+
.addOnCompleteListener(OnCompleteListener { task ->
31+
if (!task.isSuccessful) {
32+
Timber.w(task.exception, "getInstanceId failed")
33+
return@OnCompleteListener
34+
}
35+
36+
// Get new Instance ID token
37+
task.result?.token?.let {
38+
FlyBuy.getInstance(this).onNewPushToken(it)
39+
}
40+
41+
})
42+
}
4243
```
4344

4445
## Setting the Service Notification Title and Content

doc/orders.md

Lines changed: 49 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,60 @@
11
# Orders
22

3-
Orders are managed via a `OrdersOperation`
3+
## Fetch Orders
44

5-
Each operation can be retrieved using the following:
5+
Fetch the latest orders with the server
66

77
```
8-
val ordersOperation = FlyBuy.orders.getOrdersOperation()
9-
```
10-
11-
## Observe the orders
12-
13-
Returns a `LiveData` stream of orders
14-
15-
```
16-
openOrders = getOrdersOperation.orders.open()
17-
closedOrders = getOrdersOperation.orders.closed()
18-
```
19-
20-
## Syncing Orders
21-
22-
Syncs the latest orders with the server and returns a `LiveData<WorkStatus>` stream for observing status
23-
24-
```
25-
fun sync(): LiveData<WorkStatus>? {
26-
return ordersOperation.sync()
8+
fun fetchOrders() {
9+
FlyBuy.orders.fetch { orders, sdkError ->
10+
// Handle orders or deal with error
2711
}
12+
}
2813
```
2914

30-
## Redeem Order
15+
## Claim Order
3116

32-
First, check that an order exists for a given redeem code
17+
An order which is created in the FlyBuy service can be "claimed" by the SDK in order to associate it with the current customer.
3318

34-
```
35-
fun checkCode(): LiveData<WorkStatus>? {
36-
return redeemCode.value?.let {
37-
ordersOperation.findOrder(it)
38-
}
39-
}
40-
```
19+
To get information about an unclaimed order, the app can call `fetch(redemptionCode, callback)`
4120

42-
Claim the order for the customer for the given redeem code
4321

44-
```
45-
fun redeemOrder(): LiveData<WorkStatus>? {
46-
return listOf(redeemCode.value, customerInfo.value).any {it == null}.let {
47-
null
48-
} ?: run {
49-
ordersOperation.claimOrder(redeemCode.value!!, customerInfo.value!!)
50-
}
22+
```kotlin
23+
fun fetchOrder() {
24+
FlyBuy.orders.fetch(redemptionCode) { order, sdkError ->
25+
// update order claim view with order details here
5126
}
27+
}
5228
```
5329

54-
## Create Order
55-
56-
Create an order by passing order identifiers to the `create` method. There are numerous attributes available, but the only mandatory ones are the `siteID` and `partnerIdentifier`. Returns a `LiveData<WorkStatus>` stream for observing status
57-
58-
```
59-
val info = CreateOrderInfo(
60-
siteID = 101,
61-
partnerIdentifier = "1234123",
62-
customerCarColor = "#FF9900",
63-
customerCarType = "Silver Sedan",
64-
customerLicensePlate = "XYZ-456",
65-
customerName = customerName
66-
)
67-
68-
fun create(): LiveData<WorkStatus> {
69-
return ordersOperation.findOrder(info)
30+
To claim the order for the current customer, the app should call the `claim` method:
31+
32+
```kotlin
33+
fun claimOrder() {
34+
val customerInfo = CustomerInfo (
35+
name = "Marty McFly",
36+
carType = "DeLorean",
37+
carColor = "Silver",
38+
licensePlate = "OUTATIME"
39+
)
40+
FlyBuy.orders.claim(redemptionCode, customerInfo) { order, sdkError ->
41+
// if sdkError == null, order has been claimed
7042
}
43+
}
7144
```
7245

73-
#### Order Info attributes
74-
75-
| Attribute | Description |
76-
| ---------------------- | ----------------------------------------------- |
77-
| `siteID` | The FlyBuy Site Identifier |
78-
| `partnerIdentifier` | Internal customer or order identifier. |
79-
| `customerCarColor` | Color of the customer's vehicle |
80-
| `customerCarType` | Make and model of the customer's vehicle |
81-
| `customerLicensePlate` | License plate of the customer's vehicle |
82-
| `customerName` | Customer's name |
83-
| `pushToken` | The token used for push messages (or sent to the webhook) |
46+
After an order is claimed, the app may want to call `FlyBuy.orders.fetch()` to update the list of orders. The newly claimed order should now appear in the list of open orders which is available via `FlyBuy.orders.open`.
8447

8548
## Updating Orders
8649

87-
Orders are always updated with an Order Event. Returns a `LiveData<WorkStatus>` stream for observing status
50+
Orders are always updated with an Order Event.
8851

89-
```
90-
fun create(): LiveData<WorkStatus> {
91-
return ordersOperation.event(order, CustomerState.waiting)
52+
```kotlin
53+
fun updateOrder() {
54+
FlyBuy.orders.event(order, CustomerState.WAITING) { order, sdkError ->
55+
// if sdkError == null, order has been updated
9256
}
57+
}
9358
```
9459

9560
#### Order Event attributes
@@ -103,10 +68,19 @@ Orders are always updated with an Order Event. Returns a `LiveData<WorkStatus>`
10368

10469
| Value | Description |
10570
| ----------- | ------------------------------------------------------------------- |
106-
| `created` | Order has been created |
107-
| `enRoute` | Order tracking is started the customer is on their way |
108-
| `nearby` | The customer is close to the site |
109-
| `arrived` | The customer has arrived on premises |
110-
| `waiting` | The customer is in a pickup area or manually said they were waiting |
111-
| `completed` | The order is complete |
71+
| `CREATED` | Order has been created |
72+
| `EN_ROUTE` | Order tracking is started the customer is on their way |
73+
| `NEARBY` | The customer is close to the site |
74+
| `ARRIVED` | The customer has arrived on premises |
75+
| `WAITING` | The customer is in a pickup area or manually said they were waiting |
76+
| `COMPLETED` | The order is complete |
77+
78+
## Observe the orders
79+
80+
If you are using Android Jetpack, you can observe orders using `LiveData` streams of orders
81+
82+
```kotlin
83+
val openOrders = FlyBuy.orders.open
84+
val closedOrders = FlyBuy.orders.closed
85+
```
11286

0 commit comments

Comments
 (0)