Categories
AI & Tech

How to generate Client side Java Client using Swagger Codegen?

Swagger (hyperlink to this site http://swagger.io) provides the most simple, yet powerful representation of your API’s. Most of the cases what you would want to do after generating a thorough set of API’s is to have a simple Java client to access these – and Swagger comes to rescue here, by providing an open source tool just to do that.

Here in this article, we would be using Swagger Codegen tool to generate our Client side code. You can simply download the Swagger Codegen zip file from this location (link to this site https://github.com/swagger-api/swagger-codegen)

Open the link and then click on the green coloured button ‘Clone or download’ and from the drop-down click on ‘Download Zip’.

How to build Swagger Codegen?

After downloading the source zip file from the site above, you would have to build this project. You could use either ANT or MAVEN to build the project, but the downloaded file is a MAVEN project. Hence there is a prerequisite that you need to have MAVEN installed and configured on the system.

Now with all the pre-requisite being handled and answered, let’s get down to business in building the Swagger Codegen project that you’ve downloaded in the last step.

  • Extract the zip file to a location which you would be referring to from a command line tool
  • Fire the following command to on a command prompt to build the project
  • mvn package

 

How to generate Client-side code using Swagger Codegen?

The above step would download all the requisite dependencies on to your local system, which is something that MAVEN handles on its own. Along with the dependencies, it will also generate the needed modules under this directory which will be used in the steps below. With the above step done, you’ll need to follow the steps below to get the client-side code generated using Swagger Codegen.

  • There are a plenty of supported languages to choose from (like Clojure, Groovy, Haskell, Java) but I will try to keep this article targeted to be used with JAVA.
  • With the choice made above, all you need to have is a YAML or a JSON input file, which would be used to represent the API using Swagger.
  • You can take any of the sample YAML/JSON files provided by Swagger themselves, or write your own YAML by hand and use the same as the input
    • You can use Swagger editor (link to this site: http://editor.swagger.io/#/) to write your own YAML / JSON input files.
    • If you decide to go by having your own YAML / JSON input file, then this Swagger specifications (link to this site: http://swagger.io/specification/) should be followed with due respect.
  • From the same location as above, fire the command below:
    • This command will work if you are using any of the sample YAML / JSON files provided by Swagger itself
    • java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
      
              -i http://petstore.swagger.io/v2/swagger.json
      
              -l java
      
              -o samples/client/petstore/java

       

 

  • The following command will work if you are using any of your own input YAML file to generate client-side code with an assumption that the YAML file is placed under the folder structure shown in the command below.
  • java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
    
            -i modules/swagger-codegen-cli/target/sample_api.yaml
    
            -l java
    
            -o samples/client/java
    
    

     

    Choose whichever the case as you like and it will generate a java project with the package structure as mentioned in the command above with the -o

How to use the generated client-side code?

Now that the toughest part of the task being completed, you could use the generated client side code in whichever way that you wish.

  • You could import this code as a Java project into any IDE of your choice or you could very well zip the project as a JAR and ship to it whoever wants to gain access to your API’s that are generated.
  • If you take a look into the code that has been created, you would find a package named ‘io.swagger.client.api’ and under which you’d find 3 classes. Using these you would be able to do whatever you want with the API specification that you have.
  • A sample code to say update a pet and display it’s name can be done using the following code.
package io.swagger.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.ls.LSException;

import io.swagger.client.ApiException;
import io.swagger.client.api.*;

public class test 
{
  public static void main(String[] args) throws IOException
  {
    List<String> status = new ArrayList<String>();
    status.add("sold");
    PetApi pet = new PetApi();

    try 
    {
      pet.updatePetWithForm("1", "nicky", "available");
      System.out.println(pet.getPetById((long) 1).getName());
    }
    catch (ApiException e) 
    {
      e.printStackTrace();
    }
  }
}

 

 

Categories
Mobile

How to Turn off the Badge Count for Single App

With the help of the technology and mobile apps evolution, spreading information or marketing about a brand or product has been very simple and also proved to be very economical, unlike the traditional SMS where the user has to no control over the Inbox and it is cluttered with different messages and doesn’t have any segregation.


With the help of mobile application, information is pushed to their devices by the vendors and it is all available within the mobile application. All these notifications are cluttered and they are all placed in notification tray for the mobile application and it is handy for the user and can check at ease. What if these notifications are not taken care off, obviously they pile up. When they are not checked at proper intervals the number goes up and the badge count looks ridiculous. Also ending up taking a lot of memory, reducing the battery life (iPhone Charging)

What is badge count?

Badge count is the number of un-noticed or not read messages/notifications within the single application. This is a reminder for the user and provokes him or her to check their messages and be up-to-date with offers or product launches. Usually, this is displayed next to the app icon and the number is highlighted in the red circle.

How to Turn off the Badge Count?

To turn off the badge count for a specific application:

  • Go to Settings on your iPhone (Full Review)
  • Tap on Notifications section on the screen
  • A list of all installed applications is displayed within this screen.

  • Tap on the application where you want to turn off the badge count.

  • Look for Badge count Info section and turn off that section.
We have selected Jabong mobile application to show this trick and its results . 

One has to follow the above process and trick works perfectly 🙂

 

You can apply this trick to the multiple applications according to your necessity. By doing this user will still receive notifications but the outstanding number is not displayed in badge count.

 What is the use of  Deactivating Badge Count?

  • Well, this is just an option that one can prefer and they can have a cleaner Home screen rather than cluttered with badge counts. Imagine this for all the applications installed.
  • It is useful within festive seasons, businesses generally pound on promoting their products to increase their sales during festive seasons.
  • It is another option that a user can try

 

 

Categories
Mobile

How to stop Saving Media automatically to your Camera Roll

With the help of internet and social applications getting in touch with like-minded individuals, this has become extremely easy. With the help of technology advancements, individuals can avail free video calling facility which is provided by “Apple”. On the flip side, if you have friends using Android phones a number of third party applications are available where you can chat and avail video calling facility. With third party applications all the media content that was transferred between your chats are stored automatically and in due course of time it will pile up and occupy most of your phone storage and lead  different issues.

This action is enabled and it is a user’s preference that can make the difference. The article will guide you in a step by step fashion to disable this option and no more media files that come from WhatsApp or Viber will be stored automatically. This will give freedom for the users to manage their phone storage smartly and also gives an option for the user to store only important images rather than storing all the unnecessary media content.

How To Disable WhatsApp Photo & Video Saving

  • Open WhatsApp
  • Tap on the settings icon (bottom right-hand corner). This will open up all the settings screen with
  • Tap on Chat
  • You will be able to disable the option for “Save Incoming Media”.

Following the above steps will make sure that all incoming media during the chats are not saved directly.

How to Save an Image from WhatsApp chat:

  • Open WhatsApp
  • Go into your chat lists
  • Tap one of the chat from the chat list
  • Tap on the image, a popup will appear with options “Save”, “Forward”, “Share”.
  • Tap on “Save” button and image is saved into your Photos

Disable Auto Media save in Viber:

Viber is one of the popular chatting application which is available  both Android and iOS platform. The user has an option to disable auto-saving of images into Camera Roll by following these steps:

  • Open Viber App
  • Tap on “More” icon (bottom right-hand corner). User will be directed to a screen where all the settings can be configured
  • Tap on Settings
  • The user has to disable “Save to Gallery” option.

Following the above steps will make sure that media content is not automatically downloaded into your Photo App.

If you are thinking only WhatsApp and Viber are actually automatically saving media content then you are wrong. A lot of third party apps actually have this option and I would recommend one to go through the settings tab of the downloaded applications and protect your privacy

Exit mobile version