Giter Site home page Giter Site logo

api_helper's Introduction

api_helper

Contain files:

  • api.py : home of API requests function (get, post, put, delete)

  • oauth.py : dealing with getting API token

  • sample_auth_file : This is a sample auth file. Please modify it accordingly

  • test.py : Contains an example on how to use api_helper. Including GET, POST, PUT, DELETE

    note: the default name for auth_file is config.conf. you can change the default auth_file name in test.py


More on test.py - How to make API calls:

These functions can deal with both v1 and v2 endpoints. Simply add the version number in api endpoint

  1. Get Request Example:
    • api_endpoint: v1/servers, v2/issues

      self.api.get(api_endpoint)
  2. Post Request Example:
    • api_endpoint: v1/policies, v2/policies

    • update body:

      body = {
          "policy": {
              "name": "test_policy"
          }
      }
      
      self.api.post(api_endpoint, body)
  3. Put Request Example:
    • api_endpoint: v1/policies/{policy_id}, v2/policies/{policy_id}

    • update body:

      body = {
          "policy": {
              "name": "update_policy"
          }
      }
      
      self.api.put(api_endpoint, body)
  4. Delete Request Example:
    • api_endpoint: v1/policies/{policy_id}, v2/policies/{policy_id}

      self.api.delete(api_endpoint)

Setting up get.py

  1. Set up your ~/.bash_profile
     vim ~/.bash_profile
     
     alias get='python ~/{where you store api_helper}/get.py'
     #save and quit#
     source ~/.bash_profile
    
  2. open get.py
    config.read(os.path.abspath('./api_helper/config.conf'))
    #make sure the above path is where you store your api_helper#
    
  3. go to one directory above /api_helper and type in get {endpoint} in the terminal. This should return all the API output of that endpoint.

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.