FTLSessionController
Entity handling Customer Session, Registration, login, logout, updating customer info, deleting a customer
Contents
init()
loggedCustomer()
logCustomerOut()
registerCustomerWithUsername(_:password:name:lastName:campaignBonus:completion:)
logCustomerWithUsername(_:password:fullInfomationFetch:completion:)
removeCustomer(_:completion:)
updateLoggedCustomer(_:)
public struct FTLSessionController
init()
public init()
DESIGNATED INITIALIZER
loggedCustomer()
public func loggedCustomer() -> FTLCustomer?
Retrieves current logged customer, if any
logCustomerOut()
public func logCustomerOut()
Locally deletes the logged customer & session
registerCustomerWithUsername(_:password:name:lastName:campaignBonus:completion:)
public func registerCustomerWithUsername(_ username : String, // username is email
password : String,
name: String,
lastName: String,
campaignBonus : FTLCampaignBonus? = nil,
completion : FTLCompletionWithCustomer?)
Registers customer, if campaigns have been fetched for the API user, registers the customer for all campaigns
If succesful, SessionController.loggedCustomer() will contain a reference to the customer
Parameters:
username: credential to use for use login (alphanumeric, email, phone number, etc)
password: password to log the customer for the given username
name: customer’s first name
lastName: customer’s last name
signupBonus: number of points to grant a user on initial signup
completion: optional (_ customer : Customer?, _ success : Bool, _ error : FTPayError?) -> () completion block
Name | Description |
---|---|
username | credential to use for use login (alphanumeric, email, phone number, etc) |
password | password to log the customer for the given username |
name | customer’s first name |
lastName | customer’s last name |
signupBonus | number of points to grant a user on initial signup |
completion | optional (_ customer : Customer?, _ success : Bool, _ error : FTPayError?) -> () completion block |
logCustomerWithUsername(_:password:fullInfomationFetch:completion:)
public func logCustomerWithUsername(_ username : String,
password : String,
fullInfomationFetch full: Bool = true,
completion : FTLCompletionWithCustomer?)
Returns a customer given a username & password, starts a local session with customer if successful, retrievable via SessionController.loggedCustomer()
Parameters:
username: customer username
password: customer password
fullInformationFetch: after login, executed additional calls to obtain additional customer info (campaigns, promotion & rewards), defaults to true
completion: optional CompletionWithCustomer block
Name | Description |
---|---|
username | customer username |
password | customer password |
fullInformationFetch | after login, executed additional calls to obtain additional customer info (campaigns, promotion & rewards), defaults to true |
completion | optional CompletionWithCustomer block |
removeCustomer(_:completion:)
public func removeCustomer(_ customer : FTLCustomer,
completion : FTLCompletionWithSuccess?)
Removes a customer from the User’s account
Parameter customer: customer to remove
Parameter completion: optional CompletionWithCustomer block, executed on calling thread
Note: completion block is executed on calling thread
Name | Description |
---|---|
customer | customer to remove |
completion | optional CompletionWithCustomer block, executed on calling thread |
updateLoggedCustomer(_:)
public func updateLoggedCustomer(_ completion : FTLCompletionWithCustomer?)
Updates currently logged customer with the latest User & self Campaigns, fetches promotions & balances
- Parameter completion:
optional CompletionWithCustomer block
Name | Description |
---|---|
completion | optional CompletionWithCustomer block |
FTLCustomerController
Entity handling customer info (campaigns, balances, rewards, etc) fetching operations
Contents
init()
getCampaignBalancesFor(_:completion:)
getBalanceForCampaignWithIdentifier(_:ofCustomer:completion:)
getBalanceForCampaign(_:ofCustomer:completion:)
public struct FTLCustomerController
init()
public init()
DESIGNATED INITIALIZER
getCampaignBalancesFor(_:completion:)
public func getCampaignBalancesFor(_ customer : FTLCustomer? = nil,
completion : FTLCompletionWithCampaigns?)
Gets balances for each campaign in customer.campaings, customer will contain updated campaigns
CompletionBlock will be excuted on the calling queue
- Parameters:
- customer: Customer to get the campaign balances for, pass nil to use SessionController.loggedCustomer()
- completion: optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error
Name | Description |
---|---|
customer | Customer to get the campaign balances for, pass nil to use SessionController.loggedCustomer() |
completion | optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error |
getBalanceForCampaignWithIdentifier(_:ofCustomer:completion:)
public func getBalanceForCampaignWithIdentifier(_ identifier : String,
ofCustomer customer : FTLCustomer? = nil,
completion : FTLCompletionWithCampaigns?)
Gets balances for a campaign identifier is currently in customer.campaigns
Parameters:
identifier: unique identifier of the campaign to fetch balance for
customer: the customer that has the campaign, pass nil to use SessionController.loggedCustomer(), if available
completion: optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error
Name | Description |
---|---|
identifier | unique identifier of the campaign to fetch balance for |
customer | the customer that has the campaign, pass nil to use SessionController.loggedCustomer(), if available |
completion | optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error |
getBalanceForCampaign(_:ofCustomer:completion:)
public func getBalanceForCampaign(_ campaign : FTLCampaignView,
ofCustomer customer: FTLCustomer? = nil,
completion: FTLCompletionWithCampaigns?)
Gets balances for specific campaign of given customer.
Returns array of [CampaignView] with count = 1 with the updated campaign, also updates the respective campaign inside customer
- Parameters:
- campaign: the campaign to get balances for
- customer: the customer that has the campaign, pass nil to use SessionController.loggedCustomer(), if available
- completion: optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error
Name | Description |
---|---|
campaign | the campaign to get balances for |
customer | the customer that has the campaign, pass nil to use SessionController.loggedCustomer(), if available |
completion | optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error |
FTLCampaignController
Entity handling User & Customer Campaigns
Contents
init()
fetchUserCampaigns(campaignType:fetchPromotions:fetchRewards:usingCache:completion:)
fetchRewardsForCustomer(_:completion:)
fetchRewardsForCachedCampaigns(_:)
fetchRewardsForCampaigns(_:completion:)
fetchRewardsForCampaignWithIdentifier(_:completion:)
fetchRewardsFor(_:completion:)
getPromotionsFor(_:completion:)
fetchPromotionsInfoFor(_:inQueue:completion:)
public struct FTLCampaignController
init()
public init()
DESIGNATED INITIALIZER
fetchUserCampaigns(campaignType:fetchPromotions:fetchRewards:usingCache:completion:)
public func fetchUserCampaigns(campaignType : FTLCampaignType = FTLoyalty.campaignType,
fetchPromotions : Bool = false,
fetchRewards : Bool = false,
usingCache caching : Bool = true,
completion : FTLCompletionWithCampaigns?)
Fetches all campaigns for a user for a given campaign type
Use this call to retrieve User campaigns, and optionally promotions & rewards, defaults to false. Setting these values to true may significantly return time if there are a large number of campaigns available
- Parameters:
campaignType: the type of campaign to fetch, defaults to FTPay.campaignType
fetchPromotions: whether to fetch promotions for each of the campaigns
fetchRewards: wheter to fetch rewards for each of the campaigns
caching: whether to retrieve last fetched values from cache is the are younger than FTPay.Cache.cachedSeconds
completion: optional (_ campaigns : [CampaignView]?, _ success : Bool, _ error : FTPayError?) -> () block
Name | Description |
---|---|
campaignType | the type of campaign to fetch, defaults to FTPay.campaignType |
fetchPromotions | whether to fetch promotions for each of the campaigns |
fetchRewards | wheter to fetch rewards for each of the campaigns |
caching | whether to retrieve last fetched values from cache is the are younger than FTPay.Cache.cachedSeconds |
completion | optional (_ campaigns : [CampaignView]?, _ success : Bool, _ error : FTPayError?) -> () block |
fetchRewardsForCustomer(_:completion:)
public func fetchRewardsForCustomer(_ customer : FTLCustomer? = nil, completion : FTLCompletionWithCampaigns?)
Fetches rewards for customer campaigns
Parameter customer: the customer to obtain rewards for. Reward information for each of Customer.campaigns will be fetched. Pass nil to use the logged customer
Parameter completion: optional (_ campaigns : [CompletionWithCampaigns]?, _ success : Bool, _ error : FTPayError?) -> () block.
Will return array of passed campaigns with updated rewards info. Executed on the calling queue.Remark: if customer == nil, the logged customer, if any, will be used and update in its session.
Name | Description |
---|---|
customer | the customer to obtain rewards for. Reward information for each of Customer.campaigns will be fetched. Pass nil to use the logged customer |
completion | optional (_ campaigns : [CompletionWithCampaigns]?, _ success : Bool, _ error : FTPayError?) -> () block. Will return array of passed campaigns with updated rewards info. Executed on the calling queue. |
fetchRewardsForCachedCampaigns(_:)
public func fetchRewardsForCachedCampaigns(_ completion : FTLCompletionWithCampaigns?)
Fetches rewards for cached campaigns, updates the cache
- Parameter completion: optional (_ campaigns : [CompletionWithCampaigns]?, _ success : Bool, _ error : FTPayError?) -> () block.
Will return array of passed campaigns with updated rewards info. Executed on the calling queue.
Name | Description |
---|---|
completion | optional (_ campaigns : [CompletionWithCampaigns]?, _ success : Bool, _ error : FTPayError?) -> () block. Will return array of passed campaigns with updated rewards info. Executed on the calling queue. |
fetchRewardsForCampaigns(_:completion:)
public func fetchRewardsForCampaigns(_ campaigns : [FTLCampaignView], completion : FTLCompletionWithCampaigns?)
Fetches the rewards available for each of the campaigns in a campaign array
- Parameters:
- campaigns: the campaign array to fetch rewards for.
- completion: optional (_ campaigns : [CompletionWithCampaigns]?, _ success : Bool, _ error : FTPayError?) -> () block. Will return array of passed campaigns with updated rewards info. Executed on the calling queue
Name | Description |
---|---|
campaigns | the campaign array to fetch rewards for. |
completion | optional (_ campaigns : [CompletionWithCampaigns]?, _ success : Bool, _ error : FTPayError?) -> () block. Will return array of passed campaigns with updated rewards info. Executed on the calling queue |
fetchRewardsForCampaignWithIdentifier(_:completion:)
public func fetchRewardsForCampaignWithIdentifier(_ identifier : String, completion : FTLCompletionWithRewards?)
Adds rewards to a campaign given a campaign identifier
- Parameters:
- identifier: the unique campaign identifier to fetch rewards for. Will update campaigns in Cache (User Campaigns) & Customer.campaigns if found
- completion: optional (_ campaigns : [RewardView]?, _ success : Bool, _ error : FTPayError?) -> () block, will contain 1 [RewardView] returning the passed campaign
Name | Description |
---|---|
identifier | the unique campaign identifier to fetch rewards for. Will update campaigns in Cache (User Campaigns) & Customer.campaigns if found |
completion | optional (_ campaigns : [RewardView]?, _ success : Bool, _ error : FTPayError?) -> () block, will contain 1 [RewardView] returning the passed campaign |
fetchRewardsFor(_:completion:)
public func fetchRewardsFor(_ campaign : FTLCampaignView, completion : FTLCompletionWithRewards?)
Adds rewards to an existing campaign
- Parameters:
- campaign: The campaign to retrieve rewards for, will be mutated to contain found rewards
- completion: optional (_ campaigns : [RewardView]?, _ success : Bool, _ error : FTPayError?) -> () block, will contain 1 [CampaignView] returning the passed campaign
Name | Description |
---|---|
campaign | The campaign to retrieve rewards for, will be mutated to contain found rewards |
completion | optional (_ campaigns : [RewardView]?, _ success : Bool, _ error : FTPayError?) -> () block, will contain 1 [CampaignView] returning the passed campaign |
getPromotionsFor(_:completion:)
public func getPromotionsFor(_ campaign : FTLCampaignView, completion : FTLCompletionWithPromotions?)
Adds promotions to an existing campaign
- Parameters:
- campaign: The campaign to retrieve promotions for, will be mutated to contain found promotions
- completion: optional (_ promotions : [PromotionView], _ success : Bool, _ error : FTPayError?) -> () block. Will contain empty array if error found
Name | Description |
---|---|
campaign | The campaign to retrieve promotions for, will be mutated to contain found promotions |
completion | optional (_ promotions : [PromotionView], _ success : Bool, _ error : FTPayError?) -> () block. Will contain empty array if error found |
fetchPromotionsInfoFor(_:inQueue:completion:)
public func fetchPromotionsInfoFor(_ campaigns : [FTLCampaignView],
inQueue queue : OperationQueue? = nil,
completion: FTLCompletionWithCampaigns?)
Fills campaigns with available promotions, if available
- Parameters:
- campaigns: campaign array to find promotions for
- queue: queue to execute completion block on
- completion: Optional (_ campaigns : [FTCampaignView], _ success : Bool, _ error : FTPayError?) -> () block
Name | Description |
---|---|
campaigns | campaign array to find promotions for |
queue | queue to execute completion block on |
completion | Optional (_ campaigns : [FTCampaignView], _ success : Bool, _ error : FTPayError?) -> () block |
FTLTransactionController
Entity handling executing promotions & claiming rewards
Contents
init()
addPoints(_:toCampaignWithId:forCustomer:completion:)
recordPromotionWithId(_:forCustomer:completion:)
redeemRewardWithId(_:ofCampaignWithId:forCustomer:completion:)
public struct FTLTransactionController
init()
public init()
DESIGNATED INITIALIZER
addPoints(_:toCampaignWithId:forCustomer:completion:)
public func addPoints(_ points : Int, toCampaignWithId campaignId : String, forCustomer customer : FTLCustomer? = nil, completion : FTLCompletionWithCustomer?)
Adds points to a campaign
- Parameters:
- points: number of points to grant
- campaignId: the campaign identifier to add points to
- customer: customer to add the points to, defaults to currently logged user
- completion: completion block with updated customer, campaigns and points
Name | Description |
---|---|
points | number of points to grant |
campaignId | the campaign identifier to add points to |
customer | customer to add the points to, defaults to currently logged user |
completion | completion block with updated customer, campaigns and points |
recordPromotionWithId(_:forCustomer:completion:)
public func recordPromotionWithId(_ promotionId : String,
forCustomer customer : FTLCustomer? = nil,
completion : FTLCompletionWithCustomer?)
Records a promotion for a customer in a given points-based campaigns
Returns without action if customer.campaign[campaignId].promotion[promotionId] is not found
Returns on the calling queue
Parameter id: promotion identifier
Parameter customer: customer to record promotion for, pass nil to execute on logged customer
Parameter completion: optional (_ customer : Customer?, _ success : Bool, _ error : FTPayError?) -> () completion block
Name | Description |
---|---|
id | promotion identifier |
customer | customer to record promotion for, pass nil to execute on logged customer |
completion | optional (_ customer : Customer?, _ success : Bool, _ error : FTPayError?) -> () completion block |
redeemRewardWithId(_:ofCampaignWithId:forCustomer:completion:)
public func redeemRewardWithId(_ rewardId : String,
ofCampaignWithId campaignid : String,
forCustomer customer : FTLCustomer? = nil,
completion: FTLCompletionWithCampaigns?)
Redeem a reward of a given campaign for a given customer
Reward.level <= Campaign.balance to succeed
If successful, the reward balance will be updated
- Parameters:
- rewardId: unique identifier of the reward to redeem
- campaignid: unique identifier of the campaign to redeem, must be found of customer.campaigns
- customer: customer to redeem the reward for, pass nil to use SessionController.loggedCustomer(), if available
- completion: optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error. [CampaignView] will contain the updated campaign if succesful or empty on error. Executed on the calling queue.
Name | Description |
---|---|
rewardId | unique identifier of the reward to redeem |
campaignid | unique identifier of the campaign to redeem, must be found of customer.campaigns |
customer | customer to redeem the reward for, pass nil to use SessionController.loggedCustomer(), if available |
completion | optional (_ campaigns : [CampaignView], _ success : Bool, _ error : FTPayError?) -> (), campaign array will be empty on error. [CampaignView] will contain the updated campaign if succesful or empty on error. Executed on the calling queue. |