apidragon 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e41e5bc988ba884ab696631671492e85beddb8b3
4
- data.tar.gz: dcb43d245c59ba67b6e4b5f2a6e1c4761ad98832
3
+ metadata.gz: 0d574a6823e741959e5a118293c024bda6976c10
4
+ data.tar.gz: 1f2837d48a7f9efde33b6f54fe7a6701df30ff92
5
5
  SHA512:
6
- metadata.gz: 3d74f475d60f93280196660b1316927829bd8ea530b56420f33a8b91f1e42ea05ebab38878ba36e02cf805a0b9f97c1c776b6841521d252300466de0dd997bd5
7
- data.tar.gz: bc96085bbcbd1a2285b00d66022d613c4fdce1350a6a175e582aebb928c589ad3bd0119aeae03c5e815cd2cba900f9dd8f6ce3354aea2547e804bc73c04ee2df
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
- - test.rb (@/tmp/apidragonplugins/):
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.new(@arg_bucket).run # initializes and calls the run function for my Plugin class, passing the arg_bucket.
93
- plugin: test
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
+ 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.1'
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
- `mkdir #{PLUGINS}` unless Dir.exist? PLUGINS
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
- if !value['record'].nil?
38
+ unless value['record'].nil?
39
39
  value['record'].each do |var|
40
- add_config_var var, get(var) unless var=='function'
40
+ if value['record'].include?(var) then add_config_var var, get(var) end
41
41
  end
42
42
  end
43
43
  end
@@ -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 puts "WARNING: required argument '#{arg}' not set." end
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
- Plugin.new(@response).run
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.1
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-14 00:00:00.000000000 Z
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/apidragonconf.yaml
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/
@@ -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