Guest User

Untitled

a guest
Sep 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. class CoinbaseUser: Decodable {
  2. var id: String!
  3. var name: String!
  4. var userName: String? = nil
  5. var profileLocation: String? = nil
  6. var profileBio: String? = nil
  7. var profileUrl: String? = nil
  8. var avatarUrl: String!
  9. var resource: String!
  10. var resourcePath: String!
  11.  
  12. enum CoinbaseUserKey: String, CodingKey {
  13. case id = "id"
  14. case name = "name"
  15. case username = "username"
  16. case profileLocation = "profile_location"
  17. case profileBio = "profile_bio"
  18. case profileUrl = "profile_url"
  19. case avatarUrl = "avatar_url"
  20. case resource = "resource"
  21. case resourcePath = "resource_path"
  22. }
  23.  
  24. init(id: String, name: String, userName: String?, profileLocation: String?, profileBio: String?, profileUrl: String?, avatarUrl: String, resource: String, resourcePath: String) {
  25. self.id = id
  26. self.name = name
  27. self.userName = userName
  28. self.profileLocation = profileLocation
  29. self.profileBio = profileBio
  30. self.profileUrl = profileUrl
  31. self.avatarUrl = avatarUrl
  32. self.resource = resource
  33. self.resourcePath = resourcePath
  34. }
  35.  
  36. required convenience init(from decoder: Decoder) throws {
  37. let values = try decoder.container(keyedBy: CoinbaseUserKey.self)
  38. let id: String = try values.decode(String.self, forKey: .id)
  39. let name: String = try values.decode(String.self, forKey: .name)
  40. var userName: String? = nil
  41.  
  42. if let user: String = try values.decodeIfPresent(String.self, forKey: .username) {
  43. userName = user
  44. }
  45. var profileLocation: String? = nil
  46. if let location: String = try values.decodeIfPresent(String.self, forKey: .profileLocation) {
  47. profileLocation = location
  48. }
  49. var profileBio: String?
  50. if let bio: String = try values.decodeIfPresent(String.self, forKey: .profileBio) {
  51. profileBio = bio
  52. }
  53. var profileUrl: String?
  54. if let url: String = try values.decodeIfPresent(String.self, forKey: .profileUrl) {
  55. profileUrl = url
  56. }
  57. let avatarUrl: String = try values.decode(String.self, forKey: .avatarUrl)
  58. let resource: String = try values.decode(String.self, forKey: .resource)
  59. let resourcePath: String = try values.decode(String.self, forKey: .resourcePath)
  60.  
  61. self.init(id: id, name: name, userName: userName, profileLocation: profileLocation, profileBio: profileBio, profileUrl: profileUrl, avatarUrl: avatarUrl, resource: resource, resourcePath: resourcePath)
  62. }
  63. }
Add Comment
Please, Sign In to add comment