handler

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetGetURLHandler

func AssetGetURLHandler(payload *router.Payload, response *router.Response)

func AssetUploadURLHandler

func AssetUploadURLHandler(payload *router.Payload, response *router.Response)

AssetUploadURLHandler receives and persists a file to be associated by Record.

Example curl:

curl -XPUT \
	-H 'X-Skygear-API-Key: apiKey' \
	-H 'Content-Type: text/plain' \
	--data-binary '@file.txt' \
	http://localhost:3000/files/filename

func DeviceRegisterHandler

func DeviceRegisterHandler(rpayload *router.Payload, response *router.Response)

DeviceRegisterHandler creates or updates a device and associates it to a user

Example to create a new device:

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
	"action": "device:register",
	"access_token": "some-access-token",
	"type": "ios",
	"device_token": "some-device-token"
}
EOF

Example to update an existing device:

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
	"action": "device:register",
	"access_token": "some-access-token",
	"id": "existing-device-id",
	"type": "ios",
	"device_token": "new-device-token"
}
EOF

func HomeHandler

func HomeHandler(playload *router.Payload, response *router.Response)

HomeHandler temp landing. FIXME

func LoginHandler

func LoginHandler(payload *router.Payload, response *router.Response)

LoginHandler authenticate user with password

The user can be either identified by username or password.

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "auth:login",
    "username": "rickmak",
    "email": "rick.mak@gmail.com",
    "password": "123456"
}

EOF

func LogoutHandler

func LogoutHandler(payload *router.Payload, response *router.Response)

LogoutHandler receives an access token and invalidates it

func NewPubSubHandler

func NewPubSubHandler(ws *pubsub.WsPubSub) router.Handler

func PasswordHandler

func PasswordHandler(payload *router.Payload, response *router.Response)

PasswordHandler change the current user password

PasswordHandler receives three parameters:

* old_password (string, required) * password (string, required)

If user is not logged in, an 404 not found will return.

 Current implementation
	curl -X POST -H "Content-Type: application/json" \
	  -d @- http://localhost:3000/ <<EOF
	{
	    "action": "auth:password",
	    "old_password": "rick.mak@gmail.com",
	    "password": "123456"
	}
	EOF

Response return existing access toektn if not invalidate

TODO: Input accept `user_id` and `invalidate`. If `user_id` is supplied, will check authorization policy and see if existing accept `invalidate` and invaldate all existing access token. Return userInfoID with new AccessToken if the invalidate is true

func PushToDeviceHandler

func PushToDeviceHandler(rpayload *router.Payload, response *router.Response)

func PushToUserHandler

func PushToUserHandler(rpayload *router.Payload, response *router.Response)

func RecordDeleteHandler

func RecordDeleteHandler(payload *router.Payload, response *router.Response)

RecordDeleteHandler is dummy implementation on delete Records

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "record:delete",
    "access_token": "validToken",
    "database_id": "_private",
    "ids": ["note/EA6A3E68-90F3-49B5-B470-5FFDB7A0D4E8"]
}

EOF

func RecordFetchHandler

func RecordFetchHandler(payload *router.Payload, response *router.Response)

RecordFetchHandler is dummy implementation on fetching Records

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "record:fetch",
    "access_token": "validToken",
    "database_id": "_private",
    "ids": ["note/1004", "note/1005"]
}

EOF

func RecordQueryHandler

func RecordQueryHandler(payload *router.Payload, response *router.Response)

RecordQueryHandler is dummy implementation on fetching Records

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "record:query",
    "access_token": "validToken",
    "database_id": "_private",
    "record_type": "note",
    "sort": [
        [{"$val": "noteOrder", "$type": "desc"}, "asc"]
    ]
}

EOF

func RecordSaveHandler

func RecordSaveHandler(payload *router.Payload, response *router.Response)

RecordSaveHandler is dummy implementation on save/modify Records

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "record:save",
    "access_token": "validToken",
    "database_id": "_private",
    "records": [{
        "_id": "note/EA6A3E68-90F3-49B5-B470-5FFDB7A0D4E8",
        "content": "ewdsa",
        "_access": [{
            "relation": "friend",
            "level": "write"
        }]
    }]
}

EOF

Save with reference

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
  "action": "record:save",
  "database_id": "_private",
  "access_token": "986bee3b-8dd9-45c2-b40c-8b6ef274cf12",
  "records": [
    {
      "collection": {
        "$type": "ref",
        "$id": "collection/10"
      },
      "noteOrder": 1,
      "content": "hi",
      "_id": "note/71BAE736-E9C5-43CB-ADD1-D8633B80CAFA",
      "_type": "record"
    }
  ]
}

EOF

func RelationAddHandler

func RelationAddHandler(rpayload *router.Payload, response *router.Response)

RelationAddHandler add current user relation

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "relation:add",
    "access_token": "ACCESS_TOKEN",
    "name": "follow",
    "targets": [
        "1001",
        "1002"
    ]
}

EOF

{
    "request_id": "REQUEST_ID",
    "result": [
        {
            "id": "1001",
            "type": "user",
            "data": {
                "_id": "1001",
                "username": "user1001",
                "email": "user1001@skygear.io"
            }
        },
        {
            "id": "1002",
            "type": "error",
            "data": {
                "type": "ResourceFetchFailure",
                "code": 101,
                "message": "failed to fetch user id = 1002"
            }
        }
    ]
}

func RelationQueryHandler

func RelationQueryHandler(rpayload *router.Payload, response *router.Response)

RelationQueryHandler query user from current users' relation

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "relation:query",
    "access_token": "ACCESS_TOKEN",
    "name": "follow",
    "direction": "outward"
	   "limit": 2
	   "offset": 0
}

EOF

{
    "request_id": "REQUEST_ID",
    "result": [
        {
            "id": "1001",
            "type": "user",
            "data": {
                "_id": "1001",
                "username": "user1001",
                "email": "user1001@skygear.io"
            }
        },
        {
            "id": "1002",
            "type": "user",
            "data": {
                "_id": "1002",
                "username": "user1002",
                "email": "user1001@skygear.io"
            }
        }
    ],
    "info": {
        "count": 2
    }
}

func RelationRemoveHandler

func RelationRemoveHandler(rpayload *router.Payload, response *router.Response)

RelationRemoveHandler remove a users' relation to other users

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "relation:remove",
    "access_token": "ACCESS_TOKEN",
    "name": "follow",
    "targets": [
        "1001",
        "1002"
    ]
}

EOF

func SignupHandler

func SignupHandler(payload *router.Payload, response *router.Response)

SignupHandler creates an UserInfo with the supplied information.

SignupHandler receives three parameters:

* username (string, unique, optional) * email (string, unqiue, optional) * password (string, optional)

If both username and email is not supplied, an anonymous user is created and have user_id auto-generated. SignupHandler writes an error to response.Result if the supplied username or email collides with an existing username.

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "auth:signup",
    "username": "rickmak",
    "email": "rick.mak@gmail.com",
    "password": "123456"
}
EOF

func SubscriptionDeleteHandler

func SubscriptionDeleteHandler(rpayload *router.Payload, response *router.Response)

SubscriptionDeleteHandler deletes subscriptions from the specified Database.

Example curl:

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "subscription:delete",
    "access_token": "ACCESS_TOKEN",
    "database_id": "_private",
    "subscription_ids": ["SUBSCRIPTION_ID"]
}
EOF

func SubscriptionFetchAllHandler

func SubscriptionFetchAllHandler(rpayload *router.Payload, response *router.Response)

SubscriptionFetchAllHandler fetches all subscriptions of a device

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "subscription:fetch_all",
    "access_token": "ACCESS_TOKEN",
    "database_id": "_private",
    "device_id": "DEVICE_ID"
}
EOF

func SubscriptionFetchHandler

func SubscriptionFetchHandler(rpayload *router.Payload, response *router.Response)

SubscriptionFetchHandler fetches subscriptions from the specified Database.

Example curl:

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "subscription:fetch",
    "access_token": "ACCESS_TOKEN",
    "database_id": "_private",
    "device_id": "DEVICE_ID",
    "subscription_ids": ["SUBSCRIPTION_ID"]
}
EOF

func SubscriptionSaveHandler

func SubscriptionSaveHandler(rpayload *router.Payload, response *router.Response)

SubscriptionSaveHandler saves one or more subscriptions associate with a database.

Example curl:

curl -X POST -H "Content-Type: application/json" \
  -d @- http://localhost:3000/ <<EOF
{
    "action": "subscription:save",
    "access_token": "ACCESS_TOKEN",
    "database_id": "_private",
    "device_id": "DEVICE_ID",
    "subscriptions": [
        {
            "id": "SUBSCRIPTION_ID",
            "notification_info": {
                "aps": {
                    "alert": {
                        "body": "BODY_TEXT",
                        "action-loc-key": "ACTION_LOC_KEY",
                        "loc-key": "LOC_KEY",
                        "loc-args": ["LOC_ARGS"],
                        "launch-image": "LAUNCH_IMAGE"
                    },
                    "sound": "SOUND_NAME",
                    "should-badge": true,
                    "should-send-content-available": true
                }
            },
            "type": "query",
            "query": {
                "record_type": "RECORD_TYPE",
                "predicate": {}
            }
        }
    ]
}
EOF

func UserLinkHandler

func UserLinkHandler(payload *router.Payload, response *router.Response)

UserLinkHandler lets user associate third-party accounts with the user, with third-party authentication handled by plugin.

func UserQueryHandler

func UserQueryHandler(payload *router.Payload, response *router.Response)

func UserUpdateHandler

func UserUpdateHandler(payload *router.Payload, response *router.Response)

Types

type DeviceReigsterResult

type DeviceReigsterResult struct {
	ID string `json:"id"`
}

DeviceReigsterResult is the result put onto response.Result on successful call of DeviceRegisterHandler

type QueryParser

type QueryParser struct {
	UserID string
}

QueryParser is a context for parsing raw query to skydb.Query

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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