Accessing the Ruby SDK object model
Learn about Quickstart and how you can use it to quickly set up and run eSignature REST API code examples.
Instantiating the models
When making a specific eSignature REST API call using the Ruby SDK, you usually have to include a specific class used for the data sent or returned as part of that API request. The Ruby classes used to pass data to and from API endpoints are called
models, and all use Ruby attribute accessors to enable users to get and set property values. We will use the
Brand object as an example. The
Brand class can be found in our open-source GitHub repository. Each data member of the class is defined using
attr_accessor, which automatically generates public getter and setter methods for that property.
brand_name is an example of a property of the
Brand class. To set the
brand_name property of a
Brand object, use this code:
To get the value of the
brand_name property, you can simply use the string that it returns, like this:
Most Ruby SDK models also provide a constructor that enables developers to initialize many of the object’s properties at the same time that it is created. For example, you could instantiate a new
Brand object and set some of its properties at the same time, like this:
Making API calls
To construct an API call, you need to include both the model and the
account_id of the account making the API call each time you make a request. That information is not part of the
ApiClient object, but is required by the SDK to be able to generate the URL for the specific endpoint.
For example, to create a new brand, you would instantiate a
Brand object and populate it with initial values as shown above, then use it along with the
account_id to call the API, as shown below.
Naming conventions
The Ruby SDK uses the naming conventions in The Ruby Style Guide. All classes and modules use PascalCase and all methods, parameters, and variables use snake_case.
-
The categories in the API Reference are called
Apisin the Ruby SDK. As an example, theAccountsApiclass would be the class you use to make API calls for endpoints in the Accounts Category in the API Reference. -
The resources within each category in the API Reference do not have direct counterparts in the Ruby SDK. Instead, each API method in each resource corresponds to a Ruby method within the class corresponding to the top-level category. The method name is always snake_case and is a combination of the verb and the object that is being worked upon. For example, for the AccountBrands: update API method, the Ruby method within the
AccountsApiclass is namedupdate_brand. -
The parameters for each API method are based on the API Reference. Every API call has to specify the
account_idas its first parameter, required to determine which account is making the API request. The remaining parameters are defined per API call in the documentation and may include optional parameters. Parameter names are always written in snake_case. -
The request and response objects (if they exist; some methods have one or the other) are all defined as public classes. These classes are a deserialized version of the JSON that is sent by the REST API. For example, the
update_brandmethod returns an object calledBrand, which represents the response of the API call. Models do not include any methods; they only include properties (all written in snake_case) that have getters and setters. For any array returned by the JSON, the model would include anArray<T>with elements corresponding to that information whereTcan be another model or a simple type (typically a string).