Skip to content
Lucas Dohring edited this page Dec 6, 2013 · 3 revisions

OOP Api

Constants

  • blob_enc_key The encryption key
  • pattern The pattern for creating the hash
  • secret An secret for creating the hash
  • static_token Static token for initial login and register.
  • hostname API hostname (So you can do debuging)
  • user_agent The user agent.

Functions

hash(String, String)

return a req_token. First param is typically the auth_token. Second param is typically the timestamp.

postCall(String endpoint, Object post_data, String param1, String param2, Boolean raw=false)

Make a post call and sign it with a req_token.

  • endpoint The endpoint to call eg: '/ph/login'
  • post_data Data
  • param1 Usually the auth_token
  • param2 Usually the timestamp
  • raw If true, return a stream instead of a string. The stream will be paused to avoid data loss

login(String username, String password)

  • username
  • password

Returns a promise of sync_data

###register(String username, String email, String password) Register an account. On success, it will return sync data.

  • username
  • email
  • password

sync(String username, String auth_token, Object json={})

Get current state and optionally update it

  • username
  • auth_token
  • json An object optionally containing fields to update.

The current state

getBlob(String username, String auth_token, String id)

Fetch a blob

  • username
  • auth_token
  • id The blob's id (This is a number followed r)

Returns a promise of a paused stream.

upload(String username, String auth_token, Stream blob, Boolean isVideo)

Upload an blob

  • username
  • auth_token
  • blob A Readable stream of an image or video to upload. (The official app can view jpeg and pngs images; and mp4 video. It cannot view gifs. [possibly more])
  • isVideo Set this to true if you are uploading a video.

Returns a promise of the blob's media_id

send(String username, String auth_token, String mediaId, Array(String) recipients, Number time=undefined)

Send the snap to people

  • username
  • auth_token
  • mediaId The blobs's media_id
  • friends A list of people to send the snap to.
  • time How long (in seconds) a snap should be visible. This should only be set if the snap is a picture.

###addFriend(String username, String auth_token, String friend) Add a friend

  • username
  • auth_token
  • friend The username of your soon-to-be friend

###rename(String username, String auth_token, String friend, String newName) Set a friend's display name.

  • username
  • auth_token
  • friend The friend to rename.
  • newName Their new display name.

###unfriend(String username, String auth_token, String friend) Remove a friend.

  • username
  • auth_token
  • friend The friend to remove

Client#privacy(String username, String auth_token, Boolean onlyFriends)

Update your privacy setting

  • username
  • auth_token
  • onlyFriends If true, only friends can send you snaps.

Client#updateEmail(String username, String auth_token, String email)

Change your email

  • username
  • auth_token
  • email Your new email