Git Product home page Git Product logo

commandcar's Introduction

Vizsla

commandcar - curl on steroids

Join the chat at https://gitter.im/tikalk/commandcar

commandcar is a CLI tool that can easily communicate with any API. It simplifies unreadable and complicated curl commands, and has some nice features to make automation of API calls much simpler and bash scripts more streamlined.

Here's an example of what it can look like

commandcar facebook.like --post_id 123456789 --access_token abcdefghijklmnopqrstuvwxyz 

Installing

use npm to install commandcar.

sudo npm install commandcar -g

Using commandcar

A fresh commandcar install is a powerful yet empty skeleton. In order to make commandcar usable you need to install API definitions, and that's how you extend its power.

API Definitions are swagger2.0 files. You can create them yourself -- for example if you're developing an API and want to use commandcar to run automated tests against it -- or you can use existing public files. commandcar accepts either json or yaml swagger files.

Installing an API

There are three methods to install an API definition:

Installing a local file

commandcar install --name my_api --file ~/dev/commandcar/apis/my_api.json

Installing from a URL

commandcar install --name my_api --url http://some.domain.com/my/api/swagger.yaml

Installing from api-models

api-models is a GitHub repository of public available swagger files for many public APIs.

commandcar install --name instagram --api_model instagram.com/1.0.0

You can browse through the available APIs here and use the relative path to the directory containing the swagger file from this path onward. For example, the instagram API v1 resides here: https://github.com/APIs-guru/api-models/tree/master/APIs/instagram.com/1.0.0. Use "instagram.com/1.0.0" as the value for the --api_model argument. No trailing slashes please.

Upgrading/modifying an installed API

Simply run install again, it will overwrite the existing installation.

Uninstall

commandcar uninstall --name instagram

Invoking APIs using commandcar

Once you've installed API definitions, you can use commandcar -h to see the new commands and options you can use. Here's an example of the command output after installing the instagram API:

  Commands:

    instagram.get_geographies_media_recent [options] 
    instagram.get_locations_search [options]         
    instagram.get_locations [options]                
    instagram.get_locations_media_recent [options]   
    instagram.get_media_popular [options]            
    instagram.get_media_search [options]             
    instagram.get_media_shortcode [options]          
    instagram.get_media [options]                    
    instagram.get_media_comments [options]           
    instagram.post_media_comments [options]          
    instagram.delete_media_comments [options]        
    instagram.delete_media_likes [options]           
    instagram.get_media_likes [options]              
    instagram.post_media_likes [options]             
    instagram.get_tags_search [options]              
    instagram.get_tags [options]                     
    instagram.get_tags_media_recent [options]        
    instagram.get_users_search [options]             
    instagram.get_users_self_feed [options]          
    instagram.get_users_self_media_liked [options]   
    instagram.get_users_self_requested_by [options]  
    instagram.get_users [options]                    
    instagram.get_users_followed_by [options]        
    instagram.get_users_follows [options]            
    instagram.get_users_media_recent [options]       
    instagram.get_users_relationship [options]       
    instagram.post_users_relationship [options]      
    instagram.use [options]                          
    instagram.unuse                                  
    install [options]                                   
    uninstall [options]                                   

  Options:

    -h, --help  output usage information

You can then run help for any given command and see what your options are. For example, commandcar instagram.get_media_search -h will result in:

  Usage: instagram.get_media_search [options]

  Options:

    -h, --help                           output usage information
    -a, --access_token <access_token>    access_token
    -r, --ret [return value]             specify return value
    -l, --lat <lat>                      Latitude of the center search coordinate. If used, `lng` is required.
    -L, --lng <lng>                      Longitude of the center search coordinate. If used, `lat` is required.
    -m, --min_timestamp [min_timestamp]  A unix timestamp. All media returned will be taken later than this timestamp.
    -M, --max_timestamp [max_timestamp]  A unix timestamp. All media returned will be taken earlier than this timestamp.
    -d, --distance [distance]            Default is 1km (distance=1000), max distance is 5km.

use command

use is a special command that is added to any API that has securityDefinitions. If you're doing a lot of API calls with identical authorization parameters, for instance an Oauth2 access_token, then you can use them instead, and then they will be included in any following call to the API, until you unuse it or until you use another parameter value.

for example:

commandcar facebook.use --access_token abcdefghijklmnopqrstuvwxyz
commandcar facebook.like --post_id 1234567
commandcar facebook.comment --post_id 1234567 --text "what a cool post"
commandcar facebook.add_friend --uid 987654321

Note: Facebook is used as an example API throughout this doc, though we didn't practically implement it as a swagger file.

-r --ret

This is an option that is attached automatically to any command and enables you to specify exactly what you wish to receive as output.

So for example let's assume you make this call:

commandcar facebook.get_user --accees_token 123456 --ret first_name

Now let's assume that the API response is:

{
   "uid": "123456789",
   "first_name": "John",
   "last_name": "Doe"
}

Then the output would be simply John instead of the entire json.

Known issues

  • --ret can only work on json responses
  • command line functionality itself, i.e. required arguments are not enforced etc.
  • program can be heavy with lots of APIs installed. Needs to imporve caching for consecutive invokations

Gitter

We're on gitter if you want to talk with us.

commandcar's People

Contributors

darkstar avatar gitter-badger avatar ivangoncharov avatar shaharsol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

commandcar's Issues

Error when trying to load API

Hello

When I try to load an API with
commandcar load --location ...

I get the following error
12 : Error: rsync exited with code 12

Could you help me ?
Thank you

GraphQL

Will this project support GraphQL based APIs?

APIs.guru integration

I like your idea about having API collection, because I'm working on very similar project.
I'm trying to create open catalog of API specification, right now it has 172 specs including all Google services, Trello, Instagram, Spotify, etc.
All specs are validated and also keep in sync with their source, which is official API docs in almost all cases.
But more importantly I have an API and it already used by other projects:

Integration with your tool is very interesting for me.
If you interested and want to discuss it further we can chat in Gitter or you can call me in Skype: ivangon4arov

Invalid JSON in instagram example

All bar one of the files in commandcar/apis/instagram/commands are missing an doublequote

download

Also, the users_get.json file there mentions "facebook user id", should this be "instagram user id"?

Instagram API can not be installed on Mac

I get this error when I try to install the instagram API:

> sudo commandcar install --api instagram   
installing @commandcar/instagram
validateTree              - |####################################################################################---------------------------------------------------------------|
/usr/local/lib/node_modules/commandcar/node_modules/npm/lib/install/filter-invalid-actions.js:24
    if (pkg.isInLink || pkg.parent.target || pkg.parent.isLink) {
                                  ^

TypeError: Cannot read property 'target' of null
    at module.exports (/usr/local/lib/node_modules/commandcar/node_modules/npm/lib/install/filter-invalid-actions.js:24:35)
    at Array.<anonymous> (/usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
    at LOOP (/usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/chain.js:15:14)
    at /usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/chain.js:18:7
    at Object.Installer.computeLinked (/usr/local/lib/node_modules/commandcar/node_modules/npm/lib/install.js:411:41)
    at Array.<anonymous> (/usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
    at LOOP (/usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/chain.js:15:14)
    at /usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/chain.js:18:7
    at module.exports (/usr/local/lib/node_modules/commandcar/node_modules/npm/lib/install/diff-trees.js:50:3)
    at Array.<anonymous> (/usr/local/lib/node_modules/commandcar/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)

npm version 3.3.9, [email protected].

Please ping me if you need more information.

SyntaxError: Unexpected token <

[Solution: Make sure your call returns a JSON response not an XML one (use format=json or something similar)]

I'm trying to create an API for last.fm, but I'm getting this error:

SyntaxError: Unexpected token <
    at Object.parse (native)
    at Request._callback (/usr/local/lib/node_modules/commandcar/main.js:346:21)
    at Request.self.callback (/usr/local/lib/node_modules/commandcar/node_modules/request/request.js:198:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/usr/local/lib/node_modules/commandcar/node_modules/request/request.js:1035:10)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/commandcar/node_modules/request/request.js:962:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

when I call commandcar thus:
commandcar lastfm.artist_getSimilar --artist airbag -k myapikey
after a
sudo commandcar load --location ~/projects/commandcar/lastfm

The lastfm folder contains the api.json file:

{
    "protocol": "https",
    "hostname": "ws.audioscrobbler.com/2.0",
    "use_options": [
        {
            "short": "k",
            "long": "api_key",
            "def": "api_key",
            "desc": "api_key",
        }
    ]
}

and a commands folder inside it with the artist_getSimilar.json file:

{
    "path_template": "/?method=artist.getSimilar&artist={artist}&limit=5&api_key={api_key}",
    "ret": "name",
    "options": [
        {
            "short": "a",
            "long": "artist",
            "def": "artist name",
            "desc": "artist",
        },
        {
            "short": "k",
            "long": "api_key",
            "def": "apikey",
            "desc": "access token",
        }
    ]
}

The response I'm getting in the browser, with the following call
https://ws.audioscrobbler.com/2.0/?method=artist.getSimilar&artist=airbag&limit=5&api_key=myapikey
is something like this:

<?xml version="1.0" encoding="UTF-8" ?>
<lfm status="ok"><similarartists artist="Airbag"><artist><name>Nosound</name>
<mbid>797c5264-2edc-4718-b3fc-ee30b343a0fd</mbid>
<match>1</match>
<url>http://www.last.fm/music/Nosound</url>
<image size="small">http://img2-ak.lst.fm/i/u/34s/b7b889567c9245b292ed8fc034edf8ec.png</image>
<image size="medium">http://img2-ak.lst.fm/i/u/64s/b7b889567c9245b292ed8fc034edf8ec.png</image>
<image size="large">http://img2-ak.lst.fm/i/u/174s/b7b889567c9245b292ed8fc034edf8ec.png</image>
<image size="extralarge">http://img2-ak.lst.fm/i/u/300x300/b7b889567c9245b292ed8fc034edf8ec.png</image>
<image size="mega">http://img2-ak.lst.fm/i/u/b7b889567c9245b292ed8fc034edf8ec.png</image>
<image size="">http://img2-ak.lst.fm/i/u/arQ/b7b889567c9245b292ed8fc034edf8ec.png</image>
<streamable>0</streamable>
</artist>
<artist><name>RPWL</name>
<mbid>80301f91-cb5a-4f02-bd2a-ead999a7dc06</mbid>
<match>0.778902</match>
<url>http://www.last.fm/music/RPWL</url>
<image size="small">http://img2-ak.lst.fm/i/u/34s/e3e2a5496af34b64bf3ad02d983986ea.png</image>
<image size="medium">http://img2-ak.lst.fm/i/u/64s/e3e2a5496af34b64bf3ad02d983986ea.png</image>
<image size="large">http://img2-ak.lst.fm/i/u/174s/e3e2a5496af34b64bf3ad02d983986ea.png</image>
<image size="extralarge">http://img2-ak.lst.fm/i/u/300x300/e3e2a5496af34b64bf3ad02d983986ea.png</image>
<image size="mega">http://img2-ak.lst.fm/i/u/e3e2a5496af34b64bf3ad02d983986ea.png</image>
<image size="">http://img2-ak.lst.fm/i/u/arQ/e3e2a5496af34b64bf3ad02d983986ea.png</image>
<streamable>0</streamable>
</artist>
...
</similarartists>
</lfm>

Installation on mac fails?

After installing (npm install -g commandcar), and running commandcar with no arguments I get

error building db: Error: ENOENT, no such file or directory '/usr/local/lib/node_modules/commandcar/node_modules/@commandcar'

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.