GithubHelp home page GithubHelp logo

arunbandari / dexi-io-codegen Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dexiio/dexi-io-codegen

0.0 0.0 0.0 150 KB

SDK generator for dexi.io

JavaScript 35.23% Java 17.05% HTML 21.01% Shell 1.43% Python 12.36% PHP 7.15% C# 5.77%

dexi-io-codegen's Introduction

DexiIO CodeGen

API client source code generator for DexiIO http://dexi.io

Requirements

Generator

  • Grunt
  • npm

Python module

  • Python 2.7
  • virtualenv

Java module

  • Java 1.7
  • Maven 3.2

Usage

Default task generates all clients and run tests:

grunt

You can also generate sources for a particular client:

grunt generate:python

Or run tests for it:

grunt test:python

Please note that you need to have the following environment variables set in order to run tests:
DEXI_TEST_ACCOUNT_ID
DEXI_TEST_ACCESS_TOKEN
DEXI_TEST_RUN_ID
DEXI_TEST_EXECUTION_ID
DEXI_TEST_FILE_ID

Pseudo-Code specs

Every SDK client implementation has the following base structure:


# Main entry class - this is what the user will instantiate
- class Dexi

  # Create new instance of the Dexi class
  - constructor(String accountId, String apiKey)

  # Set custom endpoint
  - void setEndpoint(String url)

  # Set custom request timeout
  - void setRequestTimeout(int timeout)

  # Set custom user agent
  - void setUserAgent(String userAgent)

  # Get dexi endpoint - defaults to https://api.dexi.io
  - String getEndpoint()

  # Get the request timeout in seconds - defaults to 3600 (1 hour)
  - String getRequestTimeout()

  # Get the user agent - defaults to "Dexi-<language>/<version>
  - String getUserAgent()

  # Calculates the MD5 checksum of (accountId + apiKey) - e.g. MD5(accountId + apiKey)
  - protected String calculateAccessKey(accountId, apiKey);

  # This is an example of a generated controller
  - ExecutionsController executions()  

  # This is an example of a generated controller
  - RunsController runs() 


# Class for all HTTP responses
- class DexiAPIResponse
  
  # the HTTP status code 
  - int getStatusCode()
  
  # A byte array containing the raw response body
  - byte[] getResponseBody()
  
  # A key/value map/object of the response headers
  - Map<String,String> getHeaders();


# General API exception class
- class DexiAPIException

  # The status code of the HTTP response
  - int getStatusCode()
  
  # The raw response body as a string
  - String getResponseBody()
  
  # An error message
  - String getMessage()


# Used for sending the actual HTTP requests
- class DexiAPIHelper

  # Create new instance of DexiAPIHelper
  - constructor(Dexi dexiInstance, String accountId, String accessKey); //Uses the configurations found on the Dexi class for creating the requests
  
  # Send HTTP request to url using httpMethod (can be an enum where applicable) - with optional requestBody
  - APIResponse sendRequest(String url, String httpMethod, String requestBody = null, Map<String,String> requestHeaders = {}) throws DexiAPIException;


# Base class of all the generated controllers
- class DexiAbstractController
  
  #This should be initialized in the constructor:
  - protected DexiAPIHelper api;
  
  # constructor for DexiAbstractController - reimplement as-is in all sub classes
  - constructor(Dexi dexiInstance, String accountId, String accessKey);

  #Takes a url pattern like "/executions/{executionId}" and object: {executionId: "test"} and makes "/executions/test":
  - protected String makeUrl(String urlPattern, Map<String,Object> urlParameters, Map<String,Object> queryParameters);

  #JSON serialization of an object/array
  - protected String serialize(T object); 

  #JSON deserialization of an object
  - protected T deserialize(byte[] json, Class<T> objectType); 


# Base of all generated models  - when applicable
- class DexiBaseModel


# Binary data response  
- class DexiBinaryResponse
  
  # Get the mimetype from the Content-Type header and set the data
  - constructor(DexiAPIResponse response)
  
  # The binary data itself
  - byte[] getData();
  
  # The mime type of the data (Taken from the Content-Type header)
  - String getMimeType();

There might be slight differences in async languages (nodejs etc.) which will return promises and non-type-safe languages for serialization / deserialization.

The generated controller methods should be type-safe and do json serialization / deserialization where applicable

Example of a generated controller (Pseudo-code):


public class ExecutionsController extends DexiAbstractController {
    
    private final Dexi dexiInstance;
    
    private final DexiAPIHelper api;
    
    public ExecutionsController(Dexi dexiInstance, String accountId, String accessKey) {
        this.api = new DexiAPIHelper(dexiInstance, accountId, accessKey);
        this.dexiInstance = dexiInstance;
    }
    
    public ExecutionDTO getExecution(String executionId) throws DexiAPIException {
        String url = this.makeUrl("executions/{executionId}", {executionId: "test"}, {format:"json"});
        DexiAPIResponse response = this.api.sendRequest(url, DexiAPIHelper::HTTP_GET);
        return this.deserialize(response.getResponseBody(), ExecutionDTO.class);
    }
    
    
    public DexiBinaryResponse getBinaryFile(String executionId) throws DexiAPIException {
        String url = this.makeUrl("executions/{executionId}/file", {executionId: "test"}, {format:"json"});
        DexiAPIResponse response = this.api.sendRequest(url, DexiAPIHelper::HTTP_GET);
        return new DexiBinaryResponse(response);
    }
}

dexi-io-codegen's People

Contributors

hofmeister avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.