Methods

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.

REST verb methods

These methods are synonymous to HTTP verbs (GET, POST, PUT, PATCH AND DELETE). These methods are provide you with a very easy way to build and execute HTTP requests without having to think about other details like timeouts, HTTP connection, streaming etc.

Learn how to make HTTP requests using the HTTP verb methods here.

Ruby methods

Method Description
at Creates a new time object with the given argument.
More details here.
compact Returns a hash with non nil values.
More details here.
dig Retrieves the value object corresponding to the index passed in
The dig method is often used to strip away layers in nested arrays/hashes. For example, we use the dig method often when dealing with XML data formats.
More details here.
each Basic iterator
[1, 2, 3].each { |i| puts i }
each_with_index Iterator returned with an index
[1, 2, 3].each_with_index { |item, index| puts "#{index}:#{item}" }
More details here.
even? Returns true if integer is an even number
More details here.
fetch Returns a value from the hash for the given key.
More details here.
format_json Convert request to json format and expect response body in json format
format_xml Convert request to XML format and expect response body in XML format
group_by Group arrays into sets.
More details here.
has_key? Returns true if the given key is present in hash.
More details here.
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 fields
object_definition["user"].ignored("id", "created_at")
inject Combines all elements of enum by applying a binary operation
More details here.
is_a? Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.
Workato currently supports the following classes - Array, Hash, Time, String, Integer, Float
More details here.
iso8601 This method is equivalent to strftime(‘%F’).
More details here.
map Returns a new array with the results of running block once for every element in enum.
More details here.
merge Merges two hashes
More details here.
odd? Returns true if integer is an odd number
More details here.
only White list a comma-separate of fields
object_definition["user"].only("id", "name")
parse_json Works the same way as json.parse
More details here.
pluralize Returns the plural form of the word in the string
More details here.
puts ruby version of console.log or stdout, not the same as put method
request_format_json Convert request to json format
request_format_multipart_form Convert request to multipart_form format
request_format_www_form_urlencoded Convert request to url-encoded format
request_format_xml Convert request to XML format
required Make a comma-separate list of fields required
object_definition["user"].required("id", "created_at")
response_format_json Expect response in json format
response_format_raw Expect response in raw format
response_format_xml Expect response in XML format
inject Combine elements in an array using an operation.
More details here.
iso8601 Convert a date/date-time variable to ISO8601 format
is_true? Converts a value to boolean and returns true if value is truthy.
is_not_true? Converts a value to boolean and returns true if value is not truthy.
map Returns a new array after invoking block on each element
merge Returns a new hash containing merged contents.
More details here.
next Returns the next object in the enumerator, and move the internal position forward.
This is often used in config_fields where you can use next as a way to add a guard clause that checks inputs before the lambda function is executed.
object_definition: {
  document: {
    fields: lambda do |connection, config_fields|
      next [] if config_fields.blank?
      get("https://www.webmerge.me/api/documents/#{config_fields["document_id"]}/fields").
        map { |field| field.slice("name") }
    end
  }
}
More details here.
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.
More details here.
error raise a job error with a user-defined error body.
error("Unable to find Account with ID: 123")
reject Selectively returns elements for which the block returns false. Similar but opposite of select.
More details here.
sort Sort function returning new sorted array.
More details here.
sort_by Sort function returning self.
More details here.
tap Yields x to the block, and then returns x.
The tap method is often used for transformation. For example, we use the tap method below to transform a webhook's payload. If a webhook payload is deliever in this format.
{
  "id" => {"value" => 1},
  "name" => {"value" => 2}
}
You can use tap to transform it into a more user friendly JSON.
webhook_notification: lambda do |input, payload|
  payload.tap do |output|
    output.each { |k, v| output[k] = v["value"] }
  end
end
The final JSON will look like this {"id"=>1, "name"=>2}
More details here.
utc Convert Time to UTC timezone.
More details here.
while while loop statement.
More details here.
with_index Iterates the given block for each element with an index
More details here.
wrap Wraps its argument in an array unless it is already an array
The wrap method is often used in the execute block.
execute: lambda do |connection, input|
  {
    accounts: Array.wrap(get("/accounts", input)["records"])
  }
end
This ensures that the accounts variable is always an array in spite of whatever return. At Workato, we often use this to guard against unexpected returns from the various APIs we work with.
More details here.
zip Used as a method called by arrays. Converts any arguments to arrays, then merges elements of self with corresponding elements from each argument.
More details here.

This list can and will be expanded constantly, feel free to contact us to update/add to this list.

Workato also supports custom reusable methods. See Reusable Methods for more information.

results matching ""

    No results matching ""