jamp/common

Source   Edit  

Types

Account = object
  name*: string
  isPersonal*: bool
  isReadOnly*: bool
Source   Edit  
AuthorisationError = object of JMAPError
Raised when there are problems with authenticating Source   Edit  
Blob = object
  accountId*, id*, fileType*: string
  size*: uint
Stores information about a blob Source   Edit  
Call[T] = object
  needed*: seq[string]
  invocation*: Invocation
Wrapper around Invocation that stores the needed capability and the type it returns Source   Edit  
CallError = object of JMAPError
  kind*: string
Raised if trying to access a call which failed. Check with ok first before accessing call to avoid Source   Edit  
CoreCapabilities = object
  maxSizeUpload*: uint
  maxConcurrentUpload*: uint
  maxSizeRequest*: uint
  maxCallsInRequest*: uint
  maxObjectsInGet*: uint
  maxObjectsInSet*: uint
  collationAlgorithms*: seq[string]
See 'capabilites' section here Source   Edit  
Invocation = ref object
  name*: string
  arguments*: JsonNode
  id*: string
An invocation represents a method call against the JMAP server Source   Edit  
JMAPError = object of CatchableError
Source   Edit  
JMAPRequest = object
  methodCalls*: seq[Invocation]
Source   Edit  
JMAPResponse = object
  methodResponses*: seq[Invocation]
  sessionState*: string
Source   Edit  
ResultReference = ref object
  resultOf*, name*, path*: string
Used to refer to a previous method in the same request
  • resultOf: ID of the call to reference
  • name: Name of the call e.g. "Core/Echo"
  • path: json pointer of the value to reuse
Source   Edit  
Session = object
  username*: string
  apiUrl*: string
  downloadUrl*: string
  uploadUrl*: string
  eventSourceUrl*: string
  state*: string
  accounts*: Table[string, Account]
  capabilities*: Table[string, JsonNode]
Source   Edit  
SetError = object
  description*: Option[string]
Source   Edit  

Procs

func `[]`(resp: JMAPResponse; id: string): JsonNode {....raises: [KeyError],
    tags: [], forbids: [].}
Gets the response data for an ID. If there are multiple responses for the method then all the returns values are joined together Source   Edit  
proc `[]`[T](resp: JMAPResponse; call: Call[T]): T {.inline.}
Gets response data for a call. Automatically parses the json and converts to the calls response type. Will throw an exception if trying to get value from Source   Edit  
func add(request: var JMAPRequest; call: Call) {....raises: [].}
Adds a call to the request. Automatically adds the needed capabilities to the request

Example: cmd: -d:ssl

import jamp
var req: JMAPRequest
# Build the request with your needed calls
req &= Core.echo(%* {
  "foo": "bar"
})
req &= Core.echo(%* {
  "data": 9
})
# Send the request off with the client
Source   Edit  
func addUsing(request: var JMAPRequest; capability: string) {....raises: [],
    tags: [], forbids: [].}
Adds a needed capability to the request. Not needed if Call specifies needed capabilities Source   Edit  
proc fromJsonHook(blob: var Blob; data: JsonNode) {....raises: [KeyError],
    tags: [], forbids: [].}
Source   Edit  
proc fromJsonHook(call: var Invocation; data: JsonNode) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func id(call: Call): string {.inline, ...raises: [].}
Returns invocation ID Source   Edit  
proc initCall[T](needed: seq[string]; name: string; args: sink JsonNode; id = ""): Call[
    T]
Creates a new call.
  • needed: Is the capabilities needed by the server to perform the method
  • id: ID to use for the call. If blank then a random one is generated
Source   Edit  
proc newInvocation(name: string; args: sink JsonNode; id = ""): Invocation {.
    ...raises: [OSError], tags: [], forbids: [].}

Creates a new invocation. If you don't provide an ID then it will auto generate one.

ID must only contain URL safe characters (A-) and is recommended that it starts with an alpha character to be safe

Source   Edit  
func ok(invoc: Invocation): bool {.inline, ...raises: [], tags: [], forbids: [].}
Returns false if the invocation is an error Source   Edit  
func ok(resp: JMAPResponse; call: Call): bool
Returns true if the call didn't return an error Source   Edit  
func ok(resp: JMAPResponse; id: string): bool {....raises: [], tags: [],
    forbids: [].}
Returns true if call associated with ID had no error Source   Edit  
proc toJsonHook(blob: Blob): JsonNode {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc toJsonHook(call: Invocation): JsonNode {....raises: [], tags: [], forbids: [].}
Source   Edit