puregym

package module
v0.0.0-...-7d4df54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 9 Imported by: 1

README

puregym-go

An API client for PureGym written in Go 💪

Getting Started

Installation

$ go get -u github.com/jackcoble/puregym-go

Usage Example

The code snippet below shows you how to use the PureGym API client and fetch the current number of people within your Home Gym.

package main

import (
	"context"
	"log"
	"os"

	"github.com/jackcoble/puregym-go"
)

func main() {
	ctx := context.Background()

	// Create new instance of the PureGym API Client
	pureGym, err := puregym.NewClient(os.Getenv("PUREGYM_EMAIL"), os.Getenv("PUREGYM_PIN"))
	if err != nil {
		log.Fatalf("%s", err.Error())
		return
	}

	// Authenticate against the API
	if err := pureGym.Authenticate(ctx); err != nil {
		log.Fatalf("unable to authenticate: %s", err.Error())
	}

	// Set the Home Gym for the client to use
	if err := pureGym.SetHomeGym(); err != nil {
		log.Printf("unable to set home gym for client: %s", err.Error())
	}

	// Get Live Capacity at Gym
	gymAttendance, err := pureGym.GetGymAttendance()
	if err != nil {
		log.Printf("unable to fetch live capacity: %s", err.Error())
	}

	log.Printf("Total number of people inside the Gym: %d.", gymAttendance.TotalPeopleInGym)
}

License

This project is licensed under the terms of the MIT License.

Documentation

Index

Constants

View Source
const (
	AUTH_URL       = "https://auth.puregym.com/connect/token"
	GYM_API_URL    = "https://capi.puregym.com/api/v1/gyms"
	MEMBER_API_URL = "https://capi.puregym.com/api/v1/member"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the PureGym API Client

func NewClient

func NewClient(email string, pin string) (*Client, error)

Return a new Client

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context) error

Authenticate against the PureGym API via OAuth2 to return an Access Token

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() (string, error)

Returns the access token that was set during authentication. The client will error if no access token is set.

func (*Client) GetGymAttendance

func (c *Client) GetGymAttendance(gymId ...int) (*types.GymAttendanceResponse, error)

Get the attendance information for the users Home Gym, or any ID provided

func (*Client) GetMemberInfo

func (c *Client) GetMemberInfo() (*types.MemberResponse, error)

Get member information

func (*Client) SetAccessToken

func (c *Client) SetAccessToken(token string) error

Set an access token. If a token is already obtained, it can be re-used here.

func (*Client) SetHomeGym

func (c *Client) SetHomeGym() error

Set the home gym in the Client for the user

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL