Skip to content

Commit

Permalink
Add command Me
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasman committed Oct 29, 2023
1 parent 883237a commit 0bd4a82
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Sources/TeslaSwift/Model/Me.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Me.swift
// TeslaSwiftDemoTests
//
// Created by João Nunes on 29/10/2023.
// Copyright © 2023 Joao Nunes. All rights reserved.
//

import Foundation

public struct Me: Codable {
public var email: String
public var fullName: String
public var profileImageUrl: String

enum CodingKeys: String, CodingKey {
case email
case fullName = "full_name"
case profileImageUrl = "profile_image_url"
}
}
8 changes: 7 additions & 1 deletion Sources/TeslaSwift/TeslaEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum Endpoint {
case oAuth2TokenCN
case oAuth2revoke(token: String)
case oAuth2revokeCN(token: String)

case me

case partnerAccounts
case vehicles
case vehicleSummary(vehicleID: String)
Expand Down Expand Up @@ -56,6 +59,9 @@ extension Endpoint {
return "/oauth2/v3/revoke"
case .partnerAccounts:
return "/api/1/partner_accounts"

case .me:
return "/api/1/users/me"
// Vehicle Data and Commands
case .vehicles:
return "/api/1/vehicles"
Expand Down Expand Up @@ -110,7 +116,7 @@ extension Endpoint {
switch self {
case .revoke, .oAuth2Token, .oAuth2TokenCN, .wakeUp, .partnerAccounts, .chargeHistory, .command:
return "POST"
case .vehicles, .vehicleSummary, .mobileAccess, .allStates, .chargeState, .climateState, .driveState, .guiSettings, .vehicleState, .vehicleConfig, .nearbyChargingSites, .oAuth2Authorization, .oAuth2revoke, .oAuth2AuthorizationCN, .oAuth2revokeCN, .products, .getEnergySiteStatus, .getEnergySiteLiveStatus, .getEnergySiteInfo, .getEnergySiteHistory, .getBatteryStatus, .getBatteryData, .getBatteryPowerHistory:
case .me, .vehicles, .vehicleSummary, .mobileAccess, .allStates, .chargeState, .climateState, .driveState, .guiSettings, .vehicleState, .vehicleConfig, .nearbyChargingSites, .oAuth2Authorization, .oAuth2revoke, .oAuth2AuthorizationCN, .oAuth2revokeCN, .products, .getEnergySiteStatus, .getEnergySiteLiveStatus, .getEnergySiteInfo, .getEnergySiteHistory, .getBatteryStatus, .getBatteryData, .getBatteryPowerHistory:
return "GET"
}
}
Expand Down
14 changes: 14 additions & 0 deletions Sources/TeslaSwift/TeslaSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ extension TeslaSwift {
}
}

//MARK: User APIs
extension TeslaSwift {
/**
Fetchs the list of your vehicles including not yet delivered ones
- returns: An array of Vehicles.
*/
public func me() async throws -> Me {
_ = try await checkAuthentication()
let response: Response<Me> = try await request(.me, body: nullBody)
return response.response
}
}

//MARK: Control APIs
extension TeslaSwift {
/**
Expand Down
4 changes: 4 additions & 0 deletions TeslaSwiftDemo/TeslaSwiftDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
CFC819A41DBBA2EA00A8E47B /* VehicleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFC819A31DBBA2EA00A8E47B /* VehicleViewController.swift */; };
CFCA83852AEEC55F001A1B0C /* Partner.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFCA83842AEEC55F001A1B0C /* Partner.swift */; };
CFCA83872AEEFF08001A1B0C /* ChargeHistory.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFCA83862AEEFF08001A1B0C /* ChargeHistory.swift */; };
CFCA83892AEF09E1001A1B0C /* Me.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFCA83882AEF09E1001A1B0C /* Me.swift */; };
CFD2E7C51C8A13D60005E882 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD2E7C41C8A13D60005E882 /* AppDelegate.swift */; };
CFD2E7C71C8A13D60005E882 /* FirstViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD2E7C61C8A13D60005E882 /* FirstViewController.swift */; };
CFD2E7C91C8A13D60005E882 /* SecondViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFD2E7C81C8A13D60005E882 /* SecondViewController.swift */; };
Expand Down Expand Up @@ -223,6 +224,7 @@
CFC819A31DBBA2EA00A8E47B /* VehicleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VehicleViewController.swift; sourceTree = "<group>"; };
CFCA83842AEEC55F001A1B0C /* Partner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Partner.swift; sourceTree = "<group>"; };
CFCA83862AEEFF08001A1B0C /* ChargeHistory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChargeHistory.swift; sourceTree = "<group>"; };
CFCA83882AEF09E1001A1B0C /* Me.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Me.swift; sourceTree = "<group>"; };
CFD2E7C11C8A13D60005E882 /* TeslaSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TeslaSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
CFD2E7C41C8A13D60005E882 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
CFD2E7C61C8A13D60005E882 /* FirstViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -298,6 +300,7 @@
CF0D2F1E1D95A4A900E5A304 /* GenericResponse.swift */,
CF0D2F1F1D95A4A900E5A304 /* GuiSettings.swift */,
1AA73E8B235B3FA40088D66A /* MaxDefrostCommandOptions.swift */,
CFCA83882AEF09E1001A1B0C /* Me.swift */,
65F055172173DB3D00BE3BE5 /* ShareToVehicleOptions.swift */,
170D32D222D0EBCD00B6A51A /* NearbyChargingSites.swift */,
1AA73E85235B37560088D66A /* HomeLinkCommandOptions.swift */,
Expand Down Expand Up @@ -669,6 +672,7 @@
1AA73E87235B37560088D66A /* HomeLinkCommandOptions.swift in Sources */,
708FBA49274E9CE40026CEEF /* EnergySiteStatus.swift in Sources */,
CF0D2F381D95A4A900E5A304 /* Vehicle.swift in Sources */,
CFCA83892AEF09E1001A1B0C /* Me.swift in Sources */,
CF0D2F261D95A4A900E5A304 /* Authentication.swift in Sources */,
CF5FF50E21AADC3E007B6306 /* ShareToVehicleOptions.swift in Sources */,
CF0D2F301D95A4A900E5A304 /* GenericResponse.swift in Sources */,
Expand Down

0 comments on commit 0bd4a82

Please sign in to comment.