Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions Demo/Demo/Gravatar-Demo/DemoFetchProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import UIKit
import Gravatar

class DemoFetchProfileViewController: UIViewController {
@StoredValue(keyName: "QEEmailKey", defaultValue: "")
var savedEmail: String

@StoredValue(keyName: "QETokenKey", defaultValue: "")
var savedToken: String

let rootStackView: UIStackView = {
let stack = UIStackView()
stack.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -19,15 +25,25 @@ class DemoFetchProfileViewController: UIViewController {
control.selectedSegmentIndex = 0
return control
}()

let emailField: UITextField = {

lazy var tokenField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.placeholder = "OAuth Token (Optional)"
textField.isSecureTextEntry = true
textField.text = savedToken
return textField
}()

lazy var emailField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.placeholder = "Email"
textField.keyboardType = .emailAddress
textField.autocapitalizationType = .none
textField.textContentType = .emailAddress
textField.textAlignment = .center
textField.text = savedEmail
return textField
}()

Expand Down Expand Up @@ -64,7 +80,7 @@ class DemoFetchProfileViewController: UIViewController {
title = "Fetch Profile"
view.backgroundColor = .systemBackground

for view in [segmentedControl, emailField, fetchProfileButton, activityIndicator, profileTextView] {
for view in [segmentedControl, tokenField, emailField, fetchProfileButton, activityIndicator, profileTextView] {
rootStackView.addArrangedSubview(view)
}
view.addSubview(rootStackView)
Expand All @@ -83,7 +99,14 @@ class DemoFetchProfileViewController: UIViewController {
var identifier: ProfileIdentifier

guard activityIndicator.isAnimating == false else { return }


if let tokenString = tokenField.text, tokenString.isEmpty == false {
Task {
await fetchOwnProfile(with: tokenString)
}
return
}

if segmentedControl.selectedSegmentIndex == 0 {
guard let email = emailField.text, email.isEmpty == false else { return }
identifier = .email(email)
Expand All @@ -109,11 +132,23 @@ class DemoFetchProfileViewController: UIViewController {
}
}

func fetchOwnProfile(with token: String) async {
let service = ProfileService()
do {
let profile = try await service.fetchOwnProfile(token: token)
setProfile(with: profile)
} catch {
showError(error)
}
}

func setProfile(with profile: Profile) {
activityIndicator.stopAnimating()
profileTextView.text = """
Profile URL: \(profile.profileUrl)
Display name: \(profile.displayName)
User login (authenticated): \(profile.userLogin ?? "nil")
User ID (authenticated): \(String(describing: profile.userId))
Preferred User Name: \(profile.displayName)
Thumbnail URL: \(profile.avatarUrl)
Verified accounts (\(profile.numberVerifiedAccounts ?? 0)): \(profile.verifiedAccounts)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

struct GetVerifiedAccountServices200Response: Codable, Hashable, Sendable {
/// List of supported verified account services.
private(set) var services: [GetVerifiedAccountServices200ResponseServicesInner]

init(services: [GetVerifiedAccountServices200ResponseServicesInner]) {
self.services = services
}

enum CodingKeys: String, CodingKey, CaseIterable {
case services
}

// Encodable protocol methods

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(services, forKey: .services)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation

struct GetVerifiedAccountServices200ResponseServicesInner: Codable, Hashable, Sendable {
/// The identifier for the service.
private(set) var id: String
/// The human-readable label for the service.
private(set) var label: String

init(id: String, label: String) {
self.id = id
self.label = label
}

enum CodingKeys: String, CodingKey, CaseIterable {
case id
case label
}

// Encodable protocol methods

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(label, forKey: .label)
}
}
12 changes: 12 additions & 0 deletions Sources/Gravatar/OpenApi/Generated/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Foundation
/// A user's profile information.
///
public struct Profile: Codable, Hashable, Sendable {
/// The unique user ID. NOTE: This is only provided in OAuth2 authenticated requests.
public private(set) var userId: Int?
/// The user's login name. NOTE: This is only provided in OAuth2 authenticated requests.
public private(set) var userLogin: String?
/// The SHA256 hash of the user's primary email address.
public private(set) var hash: String
/// The user's display name. This is the name that is displayed on their profile.
Expand Down Expand Up @@ -58,6 +62,8 @@ public struct Profile: Codable, Hashable, Sendable {
public private(set) var registrationDate: Date?

init(
userId: Int? = nil,
userLogin: String? = nil,
hash: String,
displayName: String,
profileUrl: String,
Expand Down Expand Up @@ -86,6 +92,8 @@ public struct Profile: Codable, Hashable, Sendable {
lastProfileEdit: Date? = nil,
registrationDate: Date? = nil
) {
self.userId = userId
self.userLogin = userLogin
self.hash = hash
self.displayName = displayName
self.profileUrl = profileUrl
Expand Down Expand Up @@ -116,6 +124,8 @@ public struct Profile: Codable, Hashable, Sendable {
}

enum CodingKeys: String, CodingKey, CaseIterable {
case userId = "user_id"
case userLogin = "user_login"
case hash
case displayName = "display_name"
case profileUrl = "profile_url"
Expand Down Expand Up @@ -149,6 +159,8 @@ public struct Profile: Codable, Hashable, Sendable {

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(userId, forKey: .userId)
try container.encodeIfPresent(userLogin, forKey: .userLogin)
try container.encode(hash, forKey: .hash)
try container.encode(displayName, forKey: .displayName)
try container.encode(profileUrl, forKey: .profileUrl)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Foundation

struct SearchProfilesByVerifiedAccount200Response: Codable, Hashable, Sendable {
private(set) var profiles: [Profile]
/// Total number of pages available.
private(set) var totalPages: Int

init(profiles: [Profile], totalPages: Int) {
self.profiles = profiles
self.totalPages = totalPages
}

enum CodingKeys: String, CodingKey, CaseIterable {
case profiles
case totalPages = "total_pages"
}

// Encodable protocol methods

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(profiles, forKey: .profiles)
try container.encode(totalPages, forKey: .totalPages)
}
}
20 changes: 19 additions & 1 deletion Sources/Gravatar/OpenApi/Generated/UpdateProfileRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public struct UpdateProfileRequest: Codable, Hashable, Sendable {
public private(set) var jobTitle: String?
/// The user's current company's name.
public private(set) var company: String?
/// The user's cell phone number.
public private(set) var cellPhone: String?
/// The user's contact email address.
public private(set) var contactEmail: String?
/// Whether the user's contact information is hidden on their profile.
public private(set) var hiddenContactInfo: Bool?

public init(
firstName: String? = nil,
Expand All @@ -31,7 +37,10 @@ public struct UpdateProfileRequest: Codable, Hashable, Sendable {
pronouns: String? = nil,
location: String? = nil,
jobTitle: String? = nil,
company: String? = nil
company: String? = nil,
cellPhone: String? = nil,
contactEmail: String? = nil,
hiddenContactInfo: Bool? = nil
) {
self.firstName = firstName
self.lastName = lastName
Expand All @@ -42,6 +51,9 @@ public struct UpdateProfileRequest: Codable, Hashable, Sendable {
self.location = location
self.jobTitle = jobTitle
self.company = company
self.cellPhone = cellPhone
self.contactEmail = contactEmail
self.hiddenContactInfo = hiddenContactInfo
}

enum CodingKeys: String, CodingKey, CaseIterable {
Expand All @@ -54,6 +66,9 @@ public struct UpdateProfileRequest: Codable, Hashable, Sendable {
case location
case jobTitle = "job_title"
case company
case cellPhone = "cell_phone"
case contactEmail = "contact_email"
case hiddenContactInfo = "hidden_contact_info"
}

// Encodable protocol methods
Expand All @@ -69,5 +84,8 @@ public struct UpdateProfileRequest: Codable, Hashable, Sendable {
try container.encodeIfPresent(location, forKey: .location)
try container.encodeIfPresent(jobTitle, forKey: .jobTitle)
try container.encodeIfPresent(company, forKey: .company)
try container.encodeIfPresent(cellPhone, forKey: .cellPhone)
try container.encodeIfPresent(contactEmail, forKey: .contactEmail)
try container.encodeIfPresent(hiddenContactInfo, forKey: .hiddenContactInfo)
}
}
5 changes: 4 additions & 1 deletion access-control-modifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ let internalTypes: [String] = [
"AssociatedResponse",
"Avatar",
"AvatarRating",
"UpdateAvatarRequest"
"UpdateAvatarRequest",
"GetVerifiedAccountServices200Response",
"GetVerifiedAccountServices200ResponseServicesInner",
"SearchProfilesByVerifiedAccount200Response"
]

let packageTypes: [String] = [
Expand Down
3 changes: 3 additions & 0 deletions openapi/GravatarOpenAPIClient/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ Sources/GravatarOpenAPIClient/Models/Avatar.swift
Sources/GravatarOpenAPIClient/Models/AvatarRating.swift
Sources/GravatarOpenAPIClient/Models/CryptoWalletAddress.swift
Sources/GravatarOpenAPIClient/Models/GalleryImage.swift
Sources/GravatarOpenAPIClient/Models/GetVerifiedAccountServices200Response.swift
Sources/GravatarOpenAPIClient/Models/GetVerifiedAccountServices200ResponseServicesInner.swift
Sources/GravatarOpenAPIClient/Models/Interest.swift
Sources/GravatarOpenAPIClient/Models/Language.swift
Sources/GravatarOpenAPIClient/Models/Link.swift
Sources/GravatarOpenAPIClient/Models/ModelError.swift
Sources/GravatarOpenAPIClient/Models/Profile.swift
Sources/GravatarOpenAPIClient/Models/ProfileContactInfo.swift
Sources/GravatarOpenAPIClient/Models/ProfilePayments.swift
Sources/GravatarOpenAPIClient/Models/SearchProfilesByVerifiedAccount200Response.swift
Sources/GravatarOpenAPIClient/Models/SetEmailAvatarRequest.swift
Sources/GravatarOpenAPIClient/Models/UpdateAvatarRequest.swift
Sources/GravatarOpenAPIClient/Models/UpdateProfileRequest.swift
Expand Down
Loading
Loading