Using your generated Ruby SDK

This article is now deprecated. SDK usage instructions are now contained in the generated SDK.

See the new APIMATIC docs.

In this article, we will walk you through the generation of the SDK and how to use it.

The following covers the following aspects:

  1. Setting up the environment 
  2. SDK generation instructions
  3. SDK installation instructions
  4. Creating a sample application that uses our SDK

Note: The code for this tutorial is provided as a zip file available for download here.

1. Setting up the environment:

Following this tutorial here, a library is already generated, downloaded, and ready for use.

You can use your favorite text editor.

2. SDK generation instructions:

After choosing Ruby as your code language, as shown in Figure 1, a zipped file will be downloaded. This file contains the code for the APIMATICCalculator library we will be using in our project. 

Image not found
Figure 1: Choosing Ruby as the language of generation.


3. SDK installation instructions:

In order to use your library, you have to unzip it and build it first. 

Extract the unzipped file to a new folder, as shown in Figure 2. 

Image not found
Figure 2: Unzipped library contents.



To use this library in a Ruby application, you have to build it first. This will produce a gem file, that can be later added to your application for later use.  

To build your library, open your command prompt and navigate to your unzipped generated SDK directory. 

>cd /generated-code..

 then to buildy your library, type in

>gem build apimatic_calculator.gemspec
Image not found
Figure 3: Building our library.



To install the library, type in following command

>gem install ./apimatic_calculator-1.0.gem
Image not found
Figure 4: Installing our library.


4. Creating a sample application:

The following section explains how to create a new project that uses your generated apimatic-calculator gem.

 4.1 Starting a new project

On starting a new project, create a new folder with your project name "myCalculator".

Inside this folder, there should be:

  1. A new file with the file extension (.rb). This file will have the Ruby code that will use your library. 
  2. "apimatic_calculator" Gem file genertaed from previous step.

Create a "main.rb" file inside myCalculator folder. Figure 5 shows the correct folder contents. 

Image not found
Figure 5: Folder contents.


4.2 Using your library in your project:

In order to use your library, first you have to "require" it in your class. 

After that, you need to instantiate its objects and invoke their functions.

To get our calculator running, we need to invoke the asynchronized function get_calculate(), shown in Figure 4, on the controller object.

Image not found
Figure 6: get_calculate() function.


This method takes the following parameters:

  1. An operation of type enum (e.g. SUM) 
  2. Two doubles; x and y. 


Figure 7 shows how your main class should look like after doing the following steps in order:

  1. Adding your library at the top of your class (line 1).
  2. Instantiating the SimpleCalculatorController (line 3).
  3. Invoking the get_calculate() method on it (line 7).
  4. Providing the three parameters; operation (defined in line 5) and two doubles.
  5. Printing the result to the console (line 8).

Image not found

Figure 7: Main class that uses the apimatic_calculator gem.


You are ready to run the project.


4.3 Running your project:

To run your project, open your command prompt and navigate to your myCalculator project directory. 

>cd /myCalculator

 then to run your main.rb, type in

>ruby main.rb

Figure 8 the correct result printed to the console after running our Ruby application.

Image not found

Figure 8: successfully running main.rb



Go to top

Download files below.

Have more questions? Submit a request