matchmaker

package module
v0.0.0-...-2df0e36 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 20 Imported by: 0

README

MatchMaker

MatchMaker is a lightweight, easy-to-use Go library for interacting with Tinder's API.

Features

  • Simple, idiomatic interface for interacting with Tinder's API. here
  • Full Go module compatibility and support for Semantic Versioning.
  • Helpful debug logging to assist with troubleshooting.

Installation

Use the package manager to install matchmaker.

go get github.com/0xzer/matchmaker

Usage

For more usage examples you can check here, it should contain everything.

package main

import (
	"github.com/0xzer/matchmaker"
	"github.com/0xzer/matchmaker/debug"
)

var client *matchmaker.Client
func main() {
    // nil for new device
    // alternatively pass an empty instance of zerolog.Logger{} to disable logging
    client = matchmaker.NewClient(nil, debug.NewLogger(), nil)
    client.SetEventHandler(evHandler)

    smsSent, err := client.Authenticator.SendSMS("someNumber...")
    if err != nil {
       client.Logger.Fatal().Err(err).Msg("Failed to send sms")
    }
    client.Logger.Info().Any("data", smsSent).Msg("Sent sms")
    // there is a possibility for this to not return the loginresult, that is if the device is not recognized and needs email validation aswell.
    verifiedOTP, err2 := client.Authenticator.VerifyOTP("OTP...")
    if err2 != nil {
	client.Logger.Fatal().Err(err2).Msg("Failed to verify OTP")
    }
    client.Logger.Info().Any("data", verifiedOTP).Msg("Verified OTP")

    socketErr := client.Connect()
    if socketErr != nil {
	client.Logger.Fatal().Err(socketErr).Msg("Failed to connect to socket")
    }
}

func evHandler(rawEvt interface{}) {
	switch evt := rawEvt.(type) {
        case matchmaker.Event_NewMessage:
            msg := evt.Message
            client.Logger.Info().
            Any("from", msg.From).
            Any("from_me", evt.IsMe()).
            Any("content", msg.Message).
            Any("message_id", msg.ID).
            Any("type", msg.Type).
            Msg("New Message!")
	case matchmaker.Event_ClientReady:
	    client.Logger.Info().Any("data",evt).Msg("Client is ready and connected!")
    }
}

Documentation

See the GoDoc page for this.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyRefreshing   = errors.New("already attempting to refresh")
	ErrInvalidRefreshToken = errors.New("invalid refreshToken")
)
View Source
var (
	ErrSocketClosed      = errors.New("socket is closed")
	ErrSocketAlreadyOpen = errors.New("socket is already open")
)
View Source
var (
	ErrUnauthorized = errors.New("invalid authToken, try refreshing it")
)
View Source
var HubbleInstrumentEvents = util.PreAuthHubbleEvents{
	LoginFacebookTap:              "f554b19e-dfcd",
	LoginGoogleTap:                "4de5c7d5-a28e",
	LoginSMSTap:                   "f353c681-565a",
	SplashImpression:              "4a354f6c-c875",
	LoginImpression:               "5375cf05-3088",
	WelcomeBackImpression:         "9a0d4099-f8a1",
	LoginPushTap:                  "677ba945-c261",
	WelcomeBackTextTap:            "53e9081c-5571",
	PushAuthDeviceCheckImpression: "a3af5a55-71cf",
	Default:                       "1b7aaa2d-ccb7",
}

Functions

func SetHeaders

func SetHeaders(h *http.Header, headers interface{})

Types

type API

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

The API struct which contains all the functions to interact with the TinderAPI

func (*API) GetMatches

func (a *API) GetMatches(count string, pageToken *string) (response.MatchesResponse, error)

Count is max 100 and min 1

func (*API) GetMessages

func (a *API) GetMessages(matchId string, count string, pageToken *string) (response.MessagesResponse, error)

func (*API) GetProfile

func (a *API) GetProfile() (response.ProfileResponse, error)

func (*API) GetUpdates

func (a *API) GetUpdates(lastActivityDate time.Time, nudge bool) (response.UpdatesResponse, error)

func (*API) GetUser

func (a *API) GetUser(userId string) (response.UserResponse, error)

func (*API) SearchGifs

func (a *API) SearchGifs(query string) (response.GifSearchResponse, error)

func (*API) SeenMatch

func (a *API) SeenMatch(matchId string) (response.MetaResponse, error)

func (*API) SendAPIRequest

func (a *API) SendAPIRequest(url string, contentType string, method string, payload *[]byte) (*http.Response, error)

func (*API) SendBuckets

func (a *API) SendBuckets() (response.BucketResponse, error)

Tells the TinderAPI that the device is ready to use the API and if it should grant access to any experiments, this also returns every single path their API has to offer. Guessing that's just how their infrastructure works

func (*API) SendMessage

func (a *API) SendMessage(matchId string, messagePayload payload.MessagePayload) (response.Message, error)

func (*API) StartTyping

func (a *API) StartTyping(userId string, matchId string) error

func (*API) TrendingGifs

func (a *API) TrendingGifs() (response.GifResponse, error)

type Authenticator

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

func (*Authenticator) RefreshAuth

func (a *Authenticator) RefreshAuth() (*bin.LoginResult, error)

func (*Authenticator) Reset

func (a *Authenticator) Reset()

func (*Authenticator) SendSMS

func (a *Authenticator) SendSMS(number string) (response.SentSMSResponse, error)

Phone numbers should always start with the country code representative of their originating country.

func (*Authenticator) SetPhone

func (a *Authenticator) SetPhone(number string)

func (*Authenticator) SetRefreshToken

func (a *Authenticator) SetRefreshToken(refreshToken string)

func (*Authenticator) SetRefreshing

func (a *Authenticator) SetRefreshing(v bool)

func (*Authenticator) UpdateDeviceData

func (a *Authenticator) UpdateDeviceData(loginResult *bin.LoginResult)

func (*Authenticator) ValidateEmailOTP

func (a *Authenticator) ValidateEmailOTP(otp string) (response.ValidateEmailOTPResponse, error)

func (*Authenticator) VerifyOTP

func (a *Authenticator) VerifyOTP(otp string) (response.VerifyOTPResponse, error)

there is a possibility for this to not return the loginresult, that is if the device is not recognized and needs email validation aswell.

type Client

type Client struct {
	App             *util.App
	Device          *util.Device
	Api             *API
	KeepAliveSocket *KeepAliveSocket
	EventResponses  *EventResponses

	Authenticator  *Authenticator
	EventContainer *bin.AppEventData

	Logger *zerolog.Logger

	CurrentUser *util.CurrentUser
	// contains filtered or unexported fields
}

func NewClient

func NewClient(device *util.Device, logger zerolog.Logger, proxy *string) *Client

NewClient is a constructor function for creating a new instance of the Client struct.

Parameters:

  • device: a pointer to a util.Device instance. If this is nil, a new device template is created. If the device is not nil, the AuthSession, Session, and UserSession of the device are reset. If the UserSession contains a UserId or RefreshToken, these are also reset and the RefreshToken is assigned to the authenticator.
  • logger: an instance of zerolog.Logger that will be used for logging information and errors in the client. Pass an empty zerolog.Logger instance to disable logging completely.
  • proxy: a string pointer representing a proxy address. If this is not nil, the client will try to set this proxy address. If the proxy address cannot be set, an error is logged and the function continues.

The function constructs a new Client instance with the following properties:

  • App: an instance of util.App with predefined properties.
  • KeepAliveSocket: an empty instance of KeepAliveSocket.
  • Device: the passed in device or a new device template if the passed in device was nil.
  • Api: an empty instance of API.
  • EventResponses: an empty instance of EventResponses.
  • Authenticator: the authenticator constructed earlier in the function.
  • EventContainer: an instance of bin.AppEventData with a BatchId set to a new UUIDv4 and an empty events array.
  • http: an instance of http.Client.
  • Logger: a pointer to the passed in logger.

After creating the Client instance, the function assigns the Client instance to the client properties of Api, KeepAliveSocket, Authenticator, and EventResponses.

Then the function logs the initialized device and checks if a proxy was passed in. If so, it tries to set the proxy. If setting the proxy fails, an error is logged and the program closes.

Next, the function sends a buckets request. If this fails, an error is logged and the program closes.

The function then tries to publish events. If this fails, an error is logged and the program closes.

Then the function tries to cache the current user. If this fails, an error is logged, and the program closes.

The function then caches the last activity date and returns the Client instance.

Return:

  • a pointer to the newly constructed Client instance.

func (*Client) AddInitialEvents

func (c *Client) AddInitialEvents()

func (*Client) AddNewEvent

func (c *Client) AddNewEvent(PlatformEvent *bin.AppPlatformEvent)

func (*Client) Connect

func (c *Client) Connect() error

func (*Client) Disconnect

func (c *Client) Disconnect(reason *string) error

func (*Client) GetEventSession

func (c *Client) GetEventSession() *bin.AppEventSession

func (*Client) GetRequest

func (c *Client) GetRequest(url string, headers interface{}) (*http.Response, error)

func (*Client) HandleAppActionEvent

func (c *Client) HandleAppActionEvent(actionEvent *bin.AppAction)

func (*Client) HandleSocketMessage

func (c *Client) HandleSocketMessage(msgType int, data []byte)

func (*Client) HandleUpdateEvent

func (c *Client) HandleUpdateEvent(ev *bin.SocketEvents)

func (*Client) PostRequest

func (c *Client) PostRequest(url string, payload []byte, headers interface{}) (*http.Response, error)

func (*Client) PublishEvents

func (c *Client) PublishEvents() (*bin.AppPublishInitialData, error)

func (*Client) SetEventHandler

func (c *Client) SetEventHandler(evHandler EventHandler)

func (*Client) SetProxy

func (c *Client) SetProxy(proxy string) error

http://host:port

type EventHandler

type EventHandler func(evt interface{})

type EventPublishHeaders

type EventPublishHeaders struct {
	ContentType string `json:"content-type" header:"content-type"`
	UserAgent   string `json:"user-agent" header:"user-agent"`
}

type EventResponses

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

func (*EventResponses) NewAddedImage

func (e *EventResponses) NewAddedImage(data *bin.AddedImage) Event_AddedImage

func (*EventResponses) NewBlock

func (e *EventResponses) NewBlock(matchId string) Event_Block

func (*EventResponses) NewConnectionFromAnotherClient

func (e *EventResponses) NewConnectionFromAnotherClient(data *bin.ConnectedOnAnotherClient) Event_ConnectionFromAnotherClient

func (*EventResponses) NewLikedMessage

func (e *EventResponses) NewLikedMessage(data response.LikedMessage) Event_LikedMessage

func (*EventResponses) NewMatch

func (e *EventResponses) NewMatch(match response.Match) Event_NewMatch

func (*EventResponses) NewMessage

func (e *EventResponses) NewMessage(message Event_NewMessage) Event_NewMessage

func (*EventResponses) NewStartedTyping

func (e *EventResponses) NewStartedTyping(data *bin.StartTyping) Event_StartedTyping

type Event_AddedImage

type Event_AddedImage struct {
	Id          string                    `json:"id,omitempty"`
	OriginalUrl string                    `json:"original_url,omitempty"`
	Images      []response.ProcessedFiles `json:"images,omitempty"`
	ImagesAdded int32                     `json:"images_added,omitempty"`
}

type Event_Block

type Event_Block struct {
	MatchId string `json:"match_id,omitempty"`
	// contains filtered or unexported fields
}

type Event_ClientReady

type Event_ClientReady struct {
	Connected bool `json:"connected,omitempty"`
}

type Event_Closed

type Event_Closed struct {
	Reason *string `json:"reason,omitempty"`
}

type Event_ConnectionFromAnotherClient

type Event_ConnectionFromAnotherClient struct {
	Timestamp Ts `json:"timestamp,omitempty"`
}

type Event_LikedMessage

type Event_LikedMessage struct {
	MessageID string    `json:"message_id,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	LikerID   string    `json:"liker_id,omitempty"`
	MatchID   string    `json:"match_id,omitempty"`
	IsLiked   bool      `json:"is_liked,omitempty"`
	// contains filtered or unexported fields
}

func (*Event_LikedMessage) IsMe

func (m *Event_LikedMessage) IsMe() bool

type Event_NewMatch

type Event_NewMatch struct {
	Match response.Match `json:"match,omitempty"`
	// contains filtered or unexported fields
}

type Event_NewMessage

type Event_NewMessage struct {
	Message response.Message
	/*
		Additional fields that aren't included in the message itself
	*/
	MatchId                 string               `json:"_id,omitempty"`
	LastActivityDate        time.Time            `json:"last_activity_date,omitempty"`
	ReadReceipt             response.ReadReceipt `json:"readreceipt,omitempty"`
	HasShownInitialInterest bool                 `json:"has_shown_initial_interest,omitempty"`
	IsNewMessage            bool                 `json:"is_new_message,omitempty"`
	IsArchived              bool                 `json:"is_archived,omitempty"`
	Seen                    response.Seen        `json:"seen,omitempty"`
	// contains filtered or unexported fields
}

func (*Event_NewMessage) IsMe

func (m *Event_NewMessage) IsMe() bool

type Event_StartedTyping

type Event_StartedTyping struct {
	MatchId   string `json:"match_id,omitempty"`
	UserId    string `json:"user_id,omitempty"`
	Timestamp Ts     `json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

type KeepAliveSocket

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

func NewKeepAliveSocket

func NewKeepAliveSocket(client *Client) *KeepAliveSocket

func (*KeepAliveSocket) CloseHandler

func (s *KeepAliveSocket) CloseHandler(code int, text string) error

func (*KeepAliveSocket) Connect

func (socket *KeepAliveSocket) Connect() error

func (*KeepAliveSocket) IsConnected

func (s *KeepAliveSocket) IsConnected() bool

func (*KeepAliveSocket) SendData

func (s *KeepAliveSocket) SendData(msgType int, data []byte) error

type Proxy

type Proxy func(*http.Request) (*url.URL, error)

type ServerTimestamps

type ServerTimestamps struct {
	Timestamp1 Ts `json:"timestamp1,omitempty"`
	Timestamp2 Ts `json:"timestamp2,omitempty"`
}

type Ts

type Ts struct {
	Nanos   int32 `json:"nanos,omitempty"`
	Seconds int64 `json:"seconds,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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