Commit ed9fc1f8 authored by Jose Blaya's avatar Jose Blaya
Browse files

referralLink and canInvite attributes for invites and account endpoints

parent 1518c9da
......@@ -31,6 +31,9 @@ public struct AccountInfo {
/// The date by when the account is due to expire.
public let expirationDate: Date
/// Returns `true` if the account can refer friends and get extra days
public let canInvite: Bool
/// Returns `true` if the account has expired.
public var isExpired: Bool {
return (expirationDate.timeIntervalSinceNow < 0)
......
......@@ -17,6 +17,8 @@ public struct InvitesInformation {
public let totalFreeDaysGiven: Int
public let uniqueReferralLink: String
public let invites: [Invites]
}
......@@ -16,12 +16,15 @@ class GlossAccountInfo: GlossParser {
let email: String? = "email" <~~ json
let productId: String? = "product_id" <~~ json
let plan: Plan = "plan" <~~ json ?? .other
let canInvite: Bool = "can_invite" <~~ json ?? false
guard let isRenewable: Bool = "renewable" <~~ json else {
return nil
}
guard let isRecurring: Bool = "recurring" <~~ json else {
return nil
}
guard let expirationTime: TimeInterval = "expiration_time" <~~ json else {
return nil
}
......@@ -40,6 +43,7 @@ class GlossAccountInfo: GlossParser {
isRenewable: isRenewable,
isRecurring: isRecurring,
expirationDate: Date(timeIntervalSince1970: expirationTime),
canInvite: canInvite,
shouldPresentExpirationAlert: shouldPresentExpirationAlert,
renewUrl: renewUrl
)
......@@ -54,6 +58,7 @@ extension AccountInfo: JSONEncodable {
"product_id" ~~> productId,
"plan" ~~> plan.rawValue,
"renewable" ~~> isRenewable,
"can_invite" ~~> canInvite,
"recurring" ~~> isRecurring,
"expiration_time" ~~> expirationDate.timeIntervalSince1970,
"expire_alert" ~~> shouldPresentExpirationAlert,
......
......@@ -18,6 +18,11 @@ class GlossInvitesInformation: GlossParser {
let totalInvites: Int = "total_invites_sent" <~~ json ?? 0
let totalRewarded: Int = "total_invites_rewarded" <~~ json ?? 0
let totalDays: Int = "total_free_days_given" <~~ json ?? 0
guard let uniqueReferralLink: String = "unique_referral_link" <~~ json else {
return nil
}
var invites : [Invites] = []
if let inviteJSON = json["invites"] as? [JSON] {
......@@ -48,6 +53,7 @@ class GlossInvitesInformation: GlossParser {
parsed = InvitesInformation(totalInvitesSent: totalInvites,
totalInvitesRewarded: totalRewarded,
totalFreeDaysGiven: totalDays,
uniqueReferralLink: uniqueReferralLink,
invites: invites)
}
......
......@@ -44,6 +44,9 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
/// Fakes authentication outcome.
public var mockIsUnauthorized = false
/// Fakes can invite.
public var mockCanInvite = false
/// Fakes sign-up outcome.
public var mockSignupOutcome: SignupOutcome = .success
......@@ -95,6 +98,7 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
isRenewable: self.mockIsRenewable,
isRecurring: self.mockIsRecurring,
expirationDate: self.mockExpirationDate,
canInvite: self.mockCanInvite,
shouldPresentExpirationAlert: self.mockIsExpiring,
renewUrl: nil
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment