This article is outdated. Please click here to see the newer version.
In this article, we will walk you through the generation of the SDK and how to use it.
The following covers the following aspects:
- Setting up the environment?
- SDK generation instructions
- SDK installation instructions
- Creating a sample application that uses our SDK
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.
3. SDK installation instructions:
In order to use your library, you have to unzip, build, and install it first.
Extract the unzipped file to a new folder, as shown in Figure 2.
To use this library in a Ruby application, you have to build it first. This will produce a gem file, that can be added to your application for later use.
To build your library, open your command prompt and navigate to your unzipped generated SDK directory.
then to build, type in
>gem build apimatic_calculator.gemspec
To install the library, type in following command
>gem install ./apimatic_calculator-1.0.gem
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:
- A new file with the file extension (.rb). This file will have the Ruby code that will use your library.
- "apimatic_calculator" Gem file genertaed from previous step.
Create a "main.rb" file inside myCalculator folder.
Figure 5 shows the correct 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.
This method takes the following parameters:
- An operation of type enum (e.g. SUM)
- Two doubles; x and y.
Figure 7 shows how your main class should look like after doing the following steps in order:
- Adding your library at the top of your class (line 1).
- Instantiating the SimpleCalculatorController (line 3).
- Invoking the get_calculate() method on it (line 7).
- Providing the three parameters; operation (defined in line 5) and two doubles.
- Printing the result to the console (line 8).
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.
then to run your main.rb, type in
Figure 8 the correct result printed to the console after running our Ruby application.