Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
668 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Activity.swift | ||
// | ||
// Copyright © 2020 Button, Inc. All rights reserved. (https://usebutton.com) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
A protocol through which user activities can be reported. | ||
*/ | ||
@objc public protocol Activity: class { | ||
|
||
/** | ||
Report that the user has viewed a product. | ||
- Parameters: | ||
- product: The product being viewed. | ||
*/ | ||
func productViewed(_ product: ButtonProductCompatible?) | ||
|
||
/** | ||
Report that the user added a product to their cart. | ||
- Parameters: | ||
- product: The product added to the cart. | ||
*/ | ||
func productAddedToCart(_ product: ButtonProductCompatible?) | ||
|
||
/** | ||
Report that the user viewed their cart. | ||
- Parameters: | ||
- products: The list of products in the cart. | ||
*/ | ||
func cartViewed(_ products: [ButtonProductCompatible]?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// ActivityRequestBody.swift | ||
// | ||
// Copyright © 2020 Button, Inc. All rights reserved. (https://usebutton.com) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
|
||
import Foundation | ||
|
||
internal struct ActivityRequestBody { | ||
let ifa: String? | ||
let attributionToken: String? | ||
let name: String | ||
let products: [ButtonProductCompatible]? | ||
|
||
var dictionaryRepresentation: [String: Any] { | ||
var dict: [String: Any?] = [ | ||
"ifa": ifa, | ||
"btn_ref": attributionToken | ||
] | ||
var data: [String: Any?] = ["name": name] | ||
if let products = products { | ||
data["products"] = products.map { product -> [String: Any] in | ||
var productDict: [String: Any?] = [ | ||
"id": product.id, | ||
"upc": product.upc, | ||
"categories": product.categories, | ||
"name": product.name, | ||
"currency": product.currency, | ||
"url": product.url, | ||
"attributes": product.attributes | ||
] | ||
if product.value != 0 { | ||
productDict["value"] = product.value | ||
} | ||
if product.quantity != 0 { | ||
productDict["quantity"] = product.quantity | ||
} | ||
return productDict.compactMapValues { $0 } | ||
} | ||
} | ||
dict["activity_data"] = data | ||
return dict.compactMapValues { $0 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// ButtonProduct.swift | ||
// | ||
// Copyright © 2020 Button, Inc. All rights reserved. (https://usebutton.com) | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
A protocol that defines the product properties that may be provided when reporting user activity. | ||
*/ | ||
@objc public protocol ButtonProductCompatible: class { | ||
|
||
/** | ||
The product identifier. | ||
*/ | ||
var id: String? { get } | ||
|
||
/** | ||
The UPC (Universal Product Code) of the product. | ||
*/ | ||
var upc: String? { get } | ||
|
||
/** | ||
A flat array of the names of the categories to which the product belongs. | ||
*/ | ||
var categories: [String]? { get } | ||
|
||
/** | ||
The name of the product. | ||
*/ | ||
var name: String? { get } | ||
|
||
/** | ||
The ISO-4217 currency code in which the product's value is reported. | ||
*/ | ||
var currency: String? { get } | ||
|
||
/** | ||
The value of the order. Includes any discounts, if applicable. Example: 1234 for $12.34. | ||
*/ | ||
var value: Int { get } | ||
|
||
/** | ||
The quantity of the product. | ||
*/ | ||
var quantity: Int { get } | ||
|
||
/** | ||
The URL of the product. | ||
*/ | ||
var url: String? { get } | ||
|
||
/** | ||
Any additional attributes to be included with the product. | ||
*/ | ||
var attributes: [String: String]? { get } | ||
} | ||
|
||
/** | ||
A concrete implementation of the ButtonProductCompatible protocol. | ||
*/ | ||
final public class ButtonProduct: NSObject, ButtonProductCompatible { | ||
public var id: String? | ||
public var upc: String? | ||
public var categories: [String]? | ||
public var name: String? | ||
public var currency: String? | ||
public var value: Int = 0 | ||
public var quantity: Int = 0 | ||
public var url: String? | ||
public var attributes: [String: String]? | ||
} |
Oops, something went wrong.