Skip to content

Commit

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

import Foundation

public struct Region: Codable {
public var region: String
public var fleetApiBaseUrl: String

enum CodingKeys: String, CodingKey {
case region
case fleetApiBaseUrl = "fleet_api_base_url"
}
}
5 changes: 4 additions & 1 deletion Sources/TeslaSwift/TeslaEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum Endpoint {
case oAuth2revokeCN(token: String)

case me
case region

case partnerAccounts
case vehicles
Expand Down Expand Up @@ -62,6 +63,8 @@ extension Endpoint {

case .me:
return "/api/1/users/me"
case .region:
return "/api/1/users/region"
// Vehicle Data and Commands
case .vehicles:
return "/api/1/vehicles"
Expand Down Expand Up @@ -116,7 +119,7 @@ extension Endpoint {
switch self {
case .revoke, .oAuth2Token, .oAuth2TokenCN, .wakeUp, .partnerAccounts, .chargeHistory, .command:
return "POST"
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:
case .me, .region, .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
15 changes: 13 additions & 2 deletions Sources/TeslaSwift/TeslaSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,26 @@ extension TeslaSwift {
//MARK: User APIs
extension TeslaSwift {
/**
Fetchs the list of your vehicles including not yet delivered ones
Fetchs info about the user

- returns: An array of Vehicles.
- returns: the user info
*/
public func me() async throws -> Me {
_ = try await checkAuthentication()
let response: Response<Me> = try await request(.me, body: nullBody)
return response.response
}

/**
Fetchs the uer region

- returns: the user region
*/
public func region() async throws -> Region {
_ = try await checkAuthentication()
let response: Response<Region> = try await request(.region, body: nullBody)
return response.response
}
}

//MARK: Control APIs
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 @@ -95,6 +95,7 @@
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 */; };
CFCA838B2AEF0AFE001A1B0C /* Region.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFCA838A2AEF0AFE001A1B0C /* Region.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 @@ -225,6 +226,7 @@
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>"; };
CFCA838A2AEF0AFE001A1B0C /* Region.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Region.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 @@ -301,6 +303,7 @@
CF0D2F1F1D95A4A900E5A304 /* GuiSettings.swift */,
1AA73E8B235B3FA40088D66A /* MaxDefrostCommandOptions.swift */,
CFCA83882AEF09E1001A1B0C /* Me.swift */,
CFCA838A2AEF0AFE001A1B0C /* Region.swift */,
65F055172173DB3D00BE3BE5 /* ShareToVehicleOptions.swift */,
170D32D222D0EBCD00B6A51A /* NearbyChargingSites.swift */,
1AA73E85235B37560088D66A /* HomeLinkCommandOptions.swift */,
Expand Down Expand Up @@ -694,6 +697,7 @@
CF0D2F2A1D95A4A900E5A304 /* ClimateState.swift in Sources */,
CF0D2F341D95A4A900E5A304 /* OpenTrunkOptions.swift in Sources */,
CFD2E7DC1C8A13D60005E882 /* TeslaSwiftTests.swift in Sources */,
CFCA838B2AEF0AFE001A1B0C /* Region.swift in Sources */,
708FBA58274E9D1A0026CEEF /* BatteryData.swift in Sources */,
CF0D2F3C1D95A4A900E5A304 /* VehicleState.swift in Sources */,
CF1BD5971DD5051600E4C493 /* SetTemperatureCommandOptions.swift in Sources */,
Expand Down

0 comments on commit 6c62484

Please sign in to comment.