Skip to content

Instantly share code, notes, and snippets.

@michaeldmueller
Last active October 14, 2020 20:10
Show Gist options
  • Save michaeldmueller/f7596bbe9c0106e386469e2a2624157b to your computer and use it in GitHub Desktop.
Save michaeldmueller/f7596bbe9c0106e386469e2a2624157b to your computer and use it in GitHub Desktop.
Response Objects

/auth

struct AuthResponse: Decodable {
    var data: UserDataResponse
    
    struct UserDataResponse: Decodable {
        var id: Int
        var email: String
        var apiToken: String
        var customer: CustomerResponse
        
        enum CodingKeys: String, CodingKey {
            case id = "id"
            case email = "email"
            case apiToken = "api_token"
            case customer = "customer"
        }
    }
    
    struct CustomerResponse: Decodable {
        var id: Int
        var firstName: String
        var lastName: String
        var emailAddress: String
        var mobilePhone: String?
        var smsAccepted: Int
        var shippingName: String?
        var shippingAddress1: String?
        var shippingAddress2: String?
        var shippingCity: String?
        var shippingState: String?
        var shippingZipCode: String?
        
        enum CodingKeys: String, CodingKey {
            case id = "id"
            case firstName = "first_name"
            case lastName = "last_name"
            case emailAddress = "email_address"
            case mobilePhone = "mobile_phone"
            case smsAccepted = "sms_accepted"
            case shippingName = "shipping_name"
            case shippingAddress1 = "shipping_address1"
            case shippingAddress2 = "shipping_address2"
            case shippingCity = "shipping_city"
            case shippingState = "shipping_state"
            case shippingZipCode = "shipping_zip_code"
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment