class Api

Public Class Methods

new(macro_name, config, username, password) click to toggle source

Uses the configuration data in config.yaml to run a sequence of api calls. All variables are dumped into a variable bucket (@arg_bucket) so that they can be used as parameters for function calls.

# File lib/apidragon/api.rb, line 17
def initialize(macro_name, config, username, password)
  @config_file = config
  Dir.mkdir PLUGINS unless Dir.exist? PLUGINS
  @arg_bucket = {}
  set 'username', username unless username.nil?
  set 'password', password unless password.nil?
  @config = load_config @config_file
  import @config['vars']
  @macro = @config['macros'][macro_name]
  if @macro.nil? then fail "Command: '#{macro_name}' is not defined." end
end

Public Instance Methods

add_config_var(key,value) click to toggle source
# File lib/apidragon/api.rb, line 52
def add_config_var(key,value)
  @config['vars'][key] = value
  file = File.open @config_file, 'w'
  file.write(@config.to_yaml.gsub("\n-", "\n\n-"))
  file.close
end
go() click to toggle source
# File lib/apidragon/api.rb, line 34
def go
  @macro.each_pair do |_key, value|
    call = Call.new(value, @arg_bucket)
    @arg_bucket = call.run
    unless value['record'].nil?
      value['record'].each do |var|
        if value['record'].include?(var) then add_config_var var, get(var) end
      end
    end
  end
end
import(args) click to toggle source
# File lib/apidragon/api.rb, line 46
def import(args)
  args.each_pair do |key, value|
    set key, value
  end
end
load_config(config) click to toggle source
# File lib/apidragon/api.rb, line 29
def load_config(config)
  if config.nil? then config = DEFAULT_CONFIG end
  YAML.load_file config
end