Not all ruby public instance methods are available. Methods are whitelisted to ensure security. The Workato SDK Framework also exposes some methods to make building SDKs convenient.
Here is a list of methods available:
- get(url, input)
- post(url, input)
- put(url, input)
- patch(url, input)
- delete(url, input)
Each REST verb method must be provided a url
string as the first argument. The second argument (optional) can be in 2 forms.
Firstly, input
can be passed as a single hash. This hash can simply be the input
of the execute
or poll
argument, such as the following:
execute: lambda do |connection, input|
get("https://www.some_api_endpoint.com/api", input)
end
The hash can also be formed before like this:
execute: lambda do |connection, input|
params = {
"id" => input["id"]
}
get("https://www.some_api_endpoint.com/api", params)
end
The SDK framework processes this hash value and transforms it into the respective data format. For GET requests, the hash data is formed as part of URL parameters. For POST, PUT and PATCH, a payload body will be generated.
The other method of passing request data is as a series of key/value pairs.
execute: lambda do |connection, input|
post("https://www.some_api_endpoint.com/api", name: input["name"], email: input["email"])
end
All arguments after the first (URL string) will be transformed into request data. In this case, since the default data format is JSON, the following request body is formed:
{
"name": "Ee Shan",
"email": "eeshan@workato.com"
}
For a GET request, the following URL parameters are formed.
execute: lambda do |connection, input|
get("https://www.some_api_endpoint.com/api", name: input["name"], email: input["email"])
end
The request URL query string will be:
?name%3DEe%20Shan%26email%3Deeshan%40workato.com
Method | Description |
---|---|
each | Basic iterator[1, 2, 3].each { |i| puts i } |
group_by | Group arrays into sets |
headers | Add headers to a request.headers(Authorization: "Bearer HTB674HJK1") |
params | Add parameter to a request.params(api_key: "HTB674HJK1") |
payload | Add payload to a request.payload(id: "345") |
ignored | Ignore a comma-separate list of fieldsobject_definition["user"].ignored("id", "created_at") |
only | White list a comma-separate of fieldsobject_definition["user"].only("id", "name") |
required | Make a comma-separate list of fields requiredobject_definition["user"].required("id", "created_at") |
inject | Combine elements in an array using an operation |
iso8601 | Convert a date/date-time variable to ISO8601 format |
map | Returns a new array after invoking block on each element |
merge | Returns a new hash containing merged contents of another hash |
pluck | Select one or more attributes from an array of objects[{"id": 1, "name": "David"},{"id": 2, "name": "Peter"}].pluck("id") returns [1, 2] |
rand | Random number between 0 and 1 |
select | Selectively returns elements for which the block returns true |
reject | Selectively returns elements for which the block returns false (similar but opposite of select) |
sort | Sort function returning new sorted array |
sort_by | Sort function returning self |
utc | Convert Time to utc |
puts | ruby version of console.log/stdout, not the same as put |
while | while loop statement |
(This list can and will be expanded constantly, feel free to contact us to update/add to this list)