Class to retrieve data from Terra REST API
This class allows you to retrieve data from Terra's REST API.
Usage of this class requires an X-API-Key request to the backend which may be unsafe. Use at your own risk!
Initialisation
let terra: TerraClient = TerraClient(userId: String, devId: String, xAPIKey: String)
userId: String
➡ The user_id you wish to query for
devId: String
➡ Dev-id given to you upon sign up with terra on Developer Dashboard
xAPIKey: String
➡ XAPIKey given to you upon sign up with terra on Developer Dashboard
Instance Methods
Authentication - API
func authenticateUser(forResource resource: Resource,
completion: @escaping (AuthenticateUserPayload) -> Void)
forResource resource: Resource
➡ The resource you wish to authenticate a user for
completion: @escaping (AuthenticateUserPayload) -> Void
➡ A completion function returning the data returned from the request.
func deauthenticateUser(forUser userId: String,
completion: @escaping (DeauthenticateUserPayload) -> Void)
forResource resource: Resource
➡ The resource you wish to authenticate a user for
completion: @escaping (DeauthenticateUserPayload) -> Void
➡ A completion function returning the data returned from the request.
func getActivity(startDate: Date,
endDate: Date,
toWebhook: Bool = true,
completion: @escaping(TerraActivityDataPayloadModel) -> Void)
func getActivity(startDate: TimeInterval
endDate: TimeInterval,
toWebhook: Bool = true,
completion: @escaping(TerraActivityDataPayloadModel) -> Void)
startDate: Date
or startDate: TimeInterval
➡ The beginning time of the request
endDate: Date
or endDate: TimeInterval
➡ The end time of the request
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraActivityDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.
func getDaily(startDate: Date,
endDate: Date,
toWebhook: Bool = true,
completion: @escaping(TerraDailyDataPayloadModel) -> Void)
func getDaily(startDate: TimeInterval
endDate: TimeInterval,
toWebhook: Bool = true,
completion: @escaping(TerraDailyDataPayloadModel) -> Void)
startDate: Date
or startDate: TimeInterval
➡ The beginning time of the request
endDate: Date
or endDate: TimeInterval
➡ The end time of the request
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraDailyDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.
func getSleep(startDate: Date,
endDate: Date,
toWebhook: Bool = true,
completion: @escaping(TerraSleepDataPayloadModel) -> Void)
func getSleep(startDate: TimeInterval
endDate: TimeInterval,
toWebhook: Bool = true,
completion: @escaping(TerraSleepDataPayloadModel) -> Void)
startDate: Date
or startDate: TimeInterval
➡ The beginning time of the request
endDate: Date
or endDate: TimeInterval
➡ The end time of the request
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraSleepDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.
func getBody(startDate: Date,
endDate: Date,
toWebhook: Bool = true,
completion: @escaping(TerraBodyDataPayloadModel) -> Void)
func getBody(startDate: TimeInterval
endDate: TimeInterval,
toWebhook: Bool = true,
completion: @escaping(TerraBodyDataPayloadModel) -> Void)
startDate: Date
or startDate: TimeInterval
➡ The beginning time of the request
endDate: Date
or endDate: TimeInterval
➡ The end time of the request
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraBodyDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.
func getNutrition(startDate: Date,
endDate: Date,
toWebhook: Bool = true,
completion: @escaping(TerraNutritionDataPayloadModel) -> Void)
func getNutrition(startDate: TimeInterval
endDate: TimeInterval,
toWebhook: Bool = true,
completion: @escaping(TerraNutritionDataPayloadModel) -> Void)
startDate: Date
or startDate: TimeInterval
➡ The beginning time of the request
endDate: Date
or endDate: TimeInterval
➡ The end time of the request
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraNutritionDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.
func getMenstruation(startDate: Date,
endDate: Date,
toWebhook: Bool = true,
completion: @escaping(TerraMenstruationDataPayloadModel) -> Void)
func getMenstruation(startDate: TimeInterval
endDate: TimeInterval,
toWebhook: Bool = true,
completion: @escaping(TerraMenstruationDataPayloadModel) -> Void)
startDate: Date
or startDate: TimeInterval
➡ The beginning time of the request
endDate: Date
or endDate: TimeInterval
➡ The end time of the request
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraMenstruationDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.
func getAthlete(toWebhook: Bool = true,
completion: @escaping(TerraAthleteDataPayloadModel) -> Void)
toWebhook: Bool
➡ Determines if the data is sent to your webhook or returned here.
completion: @escaping (TerraAthleteDataPayloadModel) -> Void
➡ A completion function returning the data returned from the request.