# apidragon: an Api Interaction Automation Framework These classes run a sequence of API calls using a configuration file. - config file is read and `vars` are dumped into an `arg_bucket` - `macros` are specified in the config and can be run from the command line # Requirements: - Ruby > 2.0 - Gems: `json`, `active_support`, `psych`, `rest-client` # How to Use: - `gem install apidragon` - Create `/tmp/apidragonconf.yaml` according to the examples below - Run from the command line with `apidragon do [command]` `[command]` is the name of one of the `macros` defined in the config file. So if I was using the config in the example, I could run `apidragon do macro_1`, which would then call `testcall` and `testcall2` in the order specified. # Configuration: Create `/tmp/apidragonconf.yaml`. It can contain any variables you need to access the API you are using, as well as `macros`. - Example config: ```yaml --- vars: test: value username: bob password: mypassword id: 123456abcdef macros: macro_1: testcall: function: username:password@test.net/api/test.do input: - id output: - tablename mode: get testcall2: function: username:password@test.net/api/test2.do input: - tablename output: - tablecontents mode: get ``` Each macro can have `n` number of calls like `testcall` in the example, each requiring a `function`, the necessary `input` and `output` variables, and the request `mode`. # Request modes Currently supported modes: - `get` - `post` - `put` - `delete` - `curl_get`, `curl_post` (uses curl instead of the `rest-client` gem for special cases) - Planned: `curl_put`, `curl_delete` # Further Options ## record Each call can have a `record` option, where you can specify what output variables you want to record to your config. - e.g.: ```yaml testcall: output: - id - userinfo record: - id ``` ## Qualifier variables Further, for more specific output parsing, you can specify a qualifier variable. As long as responses are returned as `xml` or `json`, output variables can be associated with one of your pre-defined values for cases like parsing lists of values that have several attribute fields. - e.g.: ```yaml testcall: output: - id: username - userinfo ``` So if the call returns a list like this: `[{username => bob, id => 1234}, {username => alice, id => 5678}]`, you can always return the `id` associated with the `username` variable defined in the `vars` section. ## logging For each call, set `logging` to `true` to enable or `false` to disable. - e.g.: ```yaml testcall: logging: true ``` ## plugin Each call can refer to a plugin file. The Plugin class should follow the structure outlined below. - e.g.: - example.rb (@ /tmp/apidragonplugins/) ```ruby class Plugin # class must be named Plugin def initialize(message) # pass only one parameter, which will be equal to the body of the call's http response @message = message end def run # main function must be named run and take no parameters. Run all your operations from here puts @message end end ``` ```yaml testcall: plugin: example #name of file minus .rb extension ``` # Planned Features - The ability to include custom scripts at the end of a call for extensibility - Support for multiple instances of variable names for different api's #License [MIT](https://tldrlegal.com/license/mit-license)