Yotpo integration on mobile apps: libraries for Android and iOS developed in-house

Written by AMARO Mobile Team

AMARO
AMARO
5 min readOct 11, 2018

--

Yotpo is a platform that let companies request content from their users and customers in the form of reviews and Q&As (questions and answers). The platform provides e-Commerce businesses with a tool to collect authentic reviews, photos and other types of user-generated content in order to leverage them across their marketing efforts increasing traffic, sales, and customer retention.

Android app displaying Yotpos information

Yotpo offers a RESTFul API to integrate different types of solutions. This API can be reached from web apps and mobile native apps. The challenge that the development team faced was to integrate our native apps with Yotpo API. Since it doesn’t provide native SDK either for Android or iOS, we need to take care of that and build one.

The problem was to build this new integration inside our app without adding more complexity to our code. In order to help us on that journey, some principles should be taken. SOLID was one of them.

SOLID Principles

First presented by Robert C. Martin in the year of 2000, SOLID is a mnemonic acronym of design principles with the intention to help software development become easier to maintain and easier to understand. It is composed of 5 letters and it’s presented as follows.

Single responsibility principle

Single responsibility is the first letter of SOLID mnemonic acronym that is an aggregation of object-oriented programing principles. Single responsibility is a principle that describes how a module of a system should be written. This principle preaches that every module should take care of a single functionality in a system.

Robert C. Martin describes this principle as “A class should have only one reason to change”. In other words, if a class has two or more reasons to be changed or refactored, it’s not making use of Single Responsibility.

With that principle in mind, the integration of Yotpo API in our project started taking shape. Since we do not want to increase our code complexity and ensure that every class has one and only one responsibility, Yotpos integration should be separated from our main code. All API communication should be in a single module.

This single module, Yotpos communication, would be used in multiple parts of our app. In order to make this module reusable, we could make it a library or a framework. To build libraries and frameworks is a good practice when we need to create pieces of code that will be reused later.

Libraries and Frameworks

A framework is a modular set of code and assets that handle a specific feature or function. This functions could be of any kind, such as network communication or screen animations. Once this framework is built, it can be reused an infinite number of times.

On a mobile device environment, frameworks and libraries help developers to take advantage of the single responsibility principle. It also keeps technical debts and bugs isolated.

Keeping all the Yotpos communication in its own module makes it easier to test the integration. Writing unit tests and increasing the test coverage is more reliable when you have all this set of code separated from everything else.

Framework on iOS

The name given to our framework on iOS was Yotpo Kit. It was separated into two main pieces, Services and Models. Services were again separated into two pieces, Questions and Reviews. Alongside this Service module, we created a Model module. In this Model structure, we store all data that could be sent or received from Yotpo API.

Reviews module, as its own name says, handle all communication when the customer wants to review a specific product. It is responsible for fetching all reviews of a given product. Detail a specific review. It is also in charge of persisting and update reviews.

Questions module provides an interesting feature to the user. When a user has some questions about a product, in order to gather more information, he can ask it by himself. This module also lists all answers given to a specific question.

One special part of Yotpo Kit framework is another framework. Alamofire is an HTTP networking library. In order to make all networking communication seamless throughout our framework, we make use of this library. It encapsulates all requests and handles all JSON parsing work. This way the developers can focus on features that reflect real value to the framework.

Framework on Android

The library that was made for Android holds no big secrets, it’s all written in Java and the main class Yotpo.java uses a singleton pattern to hold only one instance of it. It exposes a few public methods, which allows all integration that developers will need from Yotpo services.

The initialization is made by Yotpo.initializeServices, this method call is mandatory before any other and it should be called from your application onCreate().

Another mandatory method call is Yotpo.setApiKey(<MY-API-KEY>) where you should pass your unique project API key provided by Yotpo.

Retrieves reviews service, it can be used to send votes and review info provided by the user to a specific product and also get reviews info by product id using methods like getProductReviews, voteUp, voteDown, removeVoteUp, removeVoteDown.

Conclusion

Isolate Yotpo API inside of an exclusive module, on its own Framework helped project growth and testability. On the target project, the developer can focus on activities that matter to its solution and let the framework deal with all that, regards to Yotpo API.

Inside this framework, you can store its own Unit Test. Making use of Dependency Injection to help enhance mocking scenarios, or making asynchronous calls. Test coverage will increase and your test will better reflect the real states that could occur in a production environment.

Now that this brand new framework is ready, we can use it in countless numbers of projects. Since all communication and under the hood code was written, plugging your project to make use of Yotpo API is super simple. Now all developers need to do is to include this framework and you are good to go.

--

--

AMARO
AMARO

We build the future of retail through best-in-class technology and data