apidragon 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/VERSION +1 -1
- data/bin/apidragon +1 -1
- data/lib/apidragon/api.rb +3 -3
- data/lib/apidragon/macro.rb +9 -5
- data/plugin_examples/GitClone.rb +20 -0
- metadata +3 -4
- data/plugin_examples/apidragonconf.yaml +0 -10
- data/plugin_examples/gitclone.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d574a6823e741959e5a118293c024bda6976c10
|
4
|
+
data.tar.gz: 1f2837d48a7f9efde33b6f54fe7a6701df30ff92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdf123732451aa9f62564945a9140f43824c04162da3a0369e5d14c62e9ed9daa94584e83bcefa577648904738fe425af990295fc0bb8dc0a10eb0885559485b
|
7
|
+
data.tar.gz: c5ab8987a6a25209d03f4065f7d463ec8f233d9e0821bc9ad07c079056baa69b8e2f45d472caa73dc359067f461b2678507b604f243e1dc7721f6f460cde506c
|
data/README.md
CHANGED
@@ -71,7 +71,7 @@ Makes an api call using the respective HTTP verb through curl.
|
|
71
71
|
|
72
72
|
Evaluates the given line of ruby code through `eval()`.
|
73
73
|
- e.g.:
|
74
|
-
-
|
74
|
+
- Plugin.rb (@/tmp/apidragonplugins/):
|
75
75
|
```ruby
|
76
76
|
class Plugin
|
77
77
|
def initialize(message)
|
@@ -83,14 +83,15 @@ Evaluates the given line of ruby code through `eval()`.
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
```
|
86
|
+
Notes: Filename and classname are arbitrary but should be the same as each other. Plugins must contain the above initialize method and a run method which can call any code desired.
|
86
87
|
- apidragonconf.yaml:
|
87
88
|
```yaml
|
88
89
|
vars:
|
89
90
|
test: test
|
90
91
|
example:
|
91
92
|
test:
|
92
|
-
function: Plugin
|
93
|
-
plugin:
|
93
|
+
function: Plugin # apidragon will attempt to load the class, call .new passing the @arg_bucket and then calling .run
|
94
|
+
plugin: Plugin # loads this file from /tmp/apidragonplugins/
|
94
95
|
mode: plugin
|
95
96
|
```
|
96
97
|
- ouput of `apidragon do example`:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.2
|
data/bin/apidragon
CHANGED
@@ -6,7 +6,7 @@ require_relative '../lib/apidragon.rb'
|
|
6
6
|
|
7
7
|
Commander.configure do
|
8
8
|
program :name, 'apidragon'
|
9
|
-
program :version, '1.6.
|
9
|
+
program :version, '1.6.2'
|
10
10
|
program :description, 'CLI for automating api requests'
|
11
11
|
program :help, 'Author', 'Isaiah Thiessen <isaiah.thiessen@telus.com>'
|
12
12
|
|
data/lib/apidragon/api.rb
CHANGED
@@ -16,7 +16,7 @@ class Api < ArgBucket
|
|
16
16
|
|
17
17
|
def initialize(macro_name, config, username, password)
|
18
18
|
@config_file = config
|
19
|
-
|
19
|
+
Dir.mkdir PLUGINS unless Dir.exist? PLUGINS
|
20
20
|
@arg_bucket = {}
|
21
21
|
set 'username', username unless username.nil?
|
22
22
|
set 'password', password unless password.nil?
|
@@ -35,9 +35,9 @@ class Api < ArgBucket
|
|
35
35
|
@macro.each_pair do |_key, value|
|
36
36
|
call = Call.new(value, @arg_bucket)
|
37
37
|
@arg_bucket = call.run
|
38
|
-
|
38
|
+
unless value['record'].nil?
|
39
39
|
value['record'].each do |var|
|
40
|
-
add_config_var var, get(var)
|
40
|
+
if value['record'].include?(var) then add_config_var var, get(var) end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/lib/apidragon/macro.rb
CHANGED
@@ -13,9 +13,9 @@ class Call < ArgBucket
|
|
13
13
|
puts 'Plugin failed to load. Custom functions will not be run.'
|
14
14
|
@plugin = nil
|
15
15
|
end
|
16
|
-
@function = value['function']
|
16
|
+
@function = "#{value['function']}"
|
17
17
|
credential_sub get('username'), get('password')
|
18
|
-
@mode = value['mode']
|
18
|
+
@mode = "#{value['mode']}"
|
19
19
|
check_constraints
|
20
20
|
@output = value['output']
|
21
21
|
@logging = value['logging']
|
@@ -37,7 +37,7 @@ class Call < ArgBucket
|
|
37
37
|
@input = {}
|
38
38
|
input.each do |arg|
|
39
39
|
value = get arg
|
40
|
-
if arg.nil? then
|
40
|
+
if arg.nil? then fail "Required argument '#{arg}' not defined." end
|
41
41
|
@input[arg] = value
|
42
42
|
end
|
43
43
|
end
|
@@ -54,7 +54,11 @@ class Call < ArgBucket
|
|
54
54
|
curl_request command
|
55
55
|
@response = `#{command}`
|
56
56
|
when 'plugin'
|
57
|
-
|
57
|
+
begin
|
58
|
+
Object.const_get(@plugin).new(@arg_bucket).run
|
59
|
+
rescue
|
60
|
+
puts 'Plugin initialization failed. Class or methods may be incorrectly defined.'
|
61
|
+
end
|
58
62
|
else
|
59
63
|
puts "#{@mode} not supported."
|
60
64
|
end
|
@@ -63,7 +67,7 @@ class Call < ArgBucket
|
|
63
67
|
xml_to_json
|
64
68
|
if @logging == true then log_response end
|
65
69
|
@response = JSON.parse @response
|
66
|
-
if @stdout==true then puts JSON.pretty_generate @response end
|
70
|
+
if @stdout == true then puts JSON.pretty_generate @response end
|
67
71
|
parse_response unless @output.nil?
|
68
72
|
end
|
69
73
|
return @arg_bucket
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class GitClone
|
2
|
+
def initialize(args={})
|
3
|
+
@args = args
|
4
|
+
end
|
5
|
+
|
6
|
+
def run
|
7
|
+
gitintegration
|
8
|
+
end
|
9
|
+
|
10
|
+
def gitintegration
|
11
|
+
repo = @args['repo']
|
12
|
+
dir = repo.split('/').last
|
13
|
+
if Dir.exist? dir
|
14
|
+
out = `cd #{dir}; git pull`
|
15
|
+
else
|
16
|
+
`git clone #{repo};`
|
17
|
+
end
|
18
|
+
return "#{`pwd`}/#{dir}".gsub!("\n",'')
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apidragon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- isaiah thiessen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -256,8 +256,7 @@ files:
|
|
256
256
|
- lib/apidragon/log.rb
|
257
257
|
- lib/apidragon/macro.rb
|
258
258
|
- lib/apidragon/parser.rb
|
259
|
-
- plugin_examples/
|
260
|
-
- plugin_examples/gitclone.rb
|
259
|
+
- plugin_examples/GitClone.rb
|
261
260
|
homepage: http://github.com/isand3r/apidragon
|
262
261
|
licenses:
|
263
262
|
- MIT
|
@@ -1,10 +0,0 @@
|
|
1
|
-
---
|
2
|
-
vars:
|
3
|
-
repo: /some/repo # define the repo location
|
4
|
-
directory: /some/directory/path # define the directory you want to clone to
|
5
|
-
macros:
|
6
|
-
myfirstmacro:
|
7
|
-
gitclone:
|
8
|
-
function: MyClass.new(@arg_bucket).run # instantiates MyClass with @arg_bucket (contains vars from config) and calls .run
|
9
|
-
mode: plugin
|
10
|
-
plugin: gitclone # causes the gitclone.rb file in /tmp/apidragonplugins/
|
data/plugin_examples/gitclone.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'apidragon' # require the gem. you can use any gems you like!
|
2
|
-
|
3
|
-
class MyClass < ArgBucket # inherit from the ArgBucket class for the 'get' and 'set' methods on @arg_bucket
|
4
|
-
def initialize(args)
|
5
|
-
@arg_bucket = args
|
6
|
-
puts @arg_bucket
|
7
|
-
end
|
8
|
-
|
9
|
-
def run
|
10
|
-
directory = get 'directory'
|
11
|
-
repo_name = get 'repo'
|
12
|
-
repo = 'http://github.com/isand3r' << repo_name
|
13
|
-
puts repo
|
14
|
-
puts directory
|
15
|
-
if Dir.exist?(directory) && Dir.exist?("#{directory}/#{repo_name}/.git")
|
16
|
-
`cd #{directory}/#{repo_name}; git pull`
|
17
|
-
else
|
18
|
-
puts "cloning #{repo}"
|
19
|
-
`mkdir #{directory}; cd #{directory}; git clone #{repo}`
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|