callbacks

package
v0.0.0-...-c9f6891 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

Callbacks

PANTAHUB Callback api's for db changes

NOTE: Basic Authentication is required(username:saadmin,paassword:value of PANTAHUB_SA_ADMIN_SECRET in env)

NOTE: The optional param:'timemodified'(format:RFC3339Nano or 2006-01-02T15:04:05.999999999Z07:00) is used to cancel old update callbacks

NOTE: For the url param 'timemodified' value, please use '%2B' instead of '+' symbol for appending timezone offset while testing the api, eg: timemodified=2006-01-02T15:04:05.999%2B07:00

NOTE: For the url param 'timemodified' value, please append 'Z' symbol to use the default db timezone, eg: timemodified=2006-01-02T15:04:05.999Z

Callback api for device changes

Example 1: Using default db timezone by appending 'Z' in the value of param:'timemodified'
http PUT localhost:12365/callbacks/devices/<ID|DEVICE_NICK>?timemodified=2006-01-02T15:04:05.999Z

HTTP/1.1 200 OK
Content-Length: 331
Content-Type: application/json; charset=utf-8
Date: Wed, 23 Apr 2020 21:13:08 GMT
X-Powered-By: go-json-rest

{
    "device_id": 5e9ef0cefb1395295dc24173,
    "steps_marked_as_non_public": 1,
    "steps_marked_as_public": 0
}

Example 2: Using a given timezone(+05:30) by using '%2B' instead of '+' symbol
http PUT localhost:12365/callbacks/devices/<ID|DEVICE_NICK>?timemodified=2006-01-02T15:04:05.999%2B05:30

HTTP/1.1 200 OK
Content-Length: 331
Content-Type: application/json; charset=utf-8
Date: Wed, 23 Apr 2020 21:13:08 GMT
X-Powered-By: go-json-rest

{
    "device_id": 5e9ef0cefb1395295dc24173,
    "steps_marked_as_non_public": 1,
    "steps_marked_as_public": 0
}

Callback api for step changes

Example 1: Using the default db timezone by appending 'Z' in the value of param:'timemodified'
http PUT localhost:12365/callbacks/steps/<ID>?timemodified=2006-01-02T15:04:05.999Z

HTTP/1.1 200 OK
Content-Length: 331
Content-Type: application/json; charset=utf-8
Date: Wed, 23 Apr 2020 21:13:08 GMT
X-Powered-By: go-json-rest

{
    "step_id": "5e9ef0cefb1395295dc24173-1",
    "owner": "prn:pantahub.com:auth:/user1",
    "device_id": "5e9ef0cefb1395295dc24173",
    "object_sha": [
        "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE7"
    ],
    "public": true,
    "garbage": false,
    "created_at": "2020-04-23T07:05:39.807101269+05:30",
    "updated_at": "2020-04-23T07:05:39.807101269+05:30"
}

Example 2: Using a given timezone(+05:30) by using '%2B' instead of '+' symbol
http PUT localhost:12365/callbacks/steps/<ID>?timemodified=2006-01-02T15:04:05.999%2B05:30

HTTP/1.1 200 OK
Content-Length: 331
Content-Type: application/json; charset=utf-8
Date: Wed, 23 Apr 2020 21:13:08 GMT
X-Powered-By: go-json-rest

{
    "step_id": "5e9ef0cefb1395295dc24173-1",
    "owner": "prn:pantahub.com:auth:/user1",
    "device_id": "5e9ef0cefb1395295dc24173",
    "object_sha": [
        "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE7"
    ],
    "public": true,
    "garbage": false,
    "created_at": "2020-04-23T07:05:39.807101269+05:30",
    "updated_at": "2020-04-23T07:05:39.807101269+05:30"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	API *rest.Api
	// contains filtered or unexported fields
}

App define a new rest application for profiles

func Build

func Build(mongoClient *mongo.Client) *App

Build factory a new Callback App only with mongoClient

func New

func New(jwtMiddleware *jwt.JWTMiddleware,
	mongoClient *mongo.Client) *App

New create a callbacks rest application

func (*App) FindPublicStep

func (a *App) FindPublicStep(ctx context.Context, StepID string, publicStep *PublicStep) error

FindPublicStep is to find public step

func (*App) GetStepObjectShas

func (a *App) GetStepObjectShas(ctx context.Context, step *trailmodels.Step) ([]string, error)

GetStepObjectShas is to get step object shas

func (*App) IsObjectExistsInDb

func (a *App) IsObjectExistsInDb(ctx context.Context, Sha string) (bool, error)

IsObjectExistsInDb is to check wether an object exists in db or not

func (*App) MarkDeviceAsProcessed

func (a *App) MarkDeviceAsProcessed(ctx context.Context, ID primitive.ObjectID) error

MarkDeviceAsProcessed is used to mark a device as processed

func (*App) MarkDeviceStepsPublicFlag

func (a *App) MarkDeviceStepsPublicFlag(ctx context.Context, ID primitive.ObjectID, public bool) (int, error)

MarkDeviceStepsPublicFlag mark all device steps public flag by device ID

func (*App) MarkStepAsProcessed

func (a *App) MarkStepAsProcessed(ctx context.Context, ID string) error

MarkStepAsProcessed is to mark step as processed

func (*App) SavePublicStep

func (a *App) SavePublicStep(ctx context.Context, step *trailmodels.Step, publicStep *PublicStep) error

SavePublicStep is used to save public step

type ProcessDeviceResult

type ProcessDeviceResult struct {
	DeviceID               string `json:"device_id,omitempty"`
	StepsMarkedAsPublic    int    `json:"steps_marked_as_public"`
	StepsMarkedAsNonPublic int    `json:"steps_marked_as_non_public"`
}

ProcessDeviceResult api response

type PublicStep

type PublicStep struct {
	StepID       string    `json:"step_id" bson:"step_id"`
	Owner        string    `json:"owner"`
	DeviceID     string    `json:"device_id" bson:"device_id"`
	ObjectSha    []string  `bson:"object_sha" json:"object_sha"`
	IsPublic     bool      `json:"public" bson:"ispublic"`
	Garbage      bool      `json:"garbage" bson:"garbage"`
	TimeModified time.Time `json:"timemodified" bson:"timemodified"`
	CreatedAt    time.Time `json:"created_at" bson:"created_at"`
	UpdatedAt    time.Time `json:"updated_at" bson:"updated_at"`
}

PublicStep is a structure of a public step

Jump to

Keyboard shortcuts

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