module LinodeAPI

Linode API wrapper

Raw API wrapper, dynamically loaded from the published spec

Constants

DEFAULT_ENDPOINT

Default API endpoint

SPEC_URL
VALIDATION_METHODS
VERSION

Public Class Methods

spec() click to toggle source
# File lib/linodeapi.rb, line 15
def spec
  @spec ||= { type: :group, subs: parse_spec }
end
spec_version() click to toggle source
# File lib/linodeapi.rb, line 19
def spec_version
  @spec_version ||= raw_spec['DATA']['VERSION'].to_s
end

Private Class Methods

add_call(spec, groups, name, params, info) click to toggle source
# File lib/linodeapi.rb, line 37
def add_call(spec, groups, name, params, info)
  subgroup = nest_spec(spec, groups)
  subgroup[name] = {
    type: :call,
    desc: info['DESCRIPTION'],
    throws: info['THROWS'].split(','),
    params: Hash[params]
  }
end
nest_spec(spec, groups) click to toggle source
# File lib/linodeapi.rb, line 47
def nest_spec(spec, groups)
  groups.reduce(spec) do |layout, new|
    layout[new] ||= { type: :group, subs: {} }
    layout[new][:subs]
  end
end
parse_args(args) click to toggle source
# File lib/linodeapi.rb, line 68
def parse_args(args)
  {
    desc: args['DESCRIPTION'],
    type: args['TYPE'].to_sym,
    required: args['REQUIRED']
  }
end
parse_method(method) click to toggle source
# File lib/linodeapi.rb, line 54
def parse_method(method)
  keys = method.split('.').map(&:to_sym)
  [keys.pop, keys]
end
parse_params(params) click to toggle source
# File lib/linodeapi.rb, line 59
def parse_params(params)
  params.map do |k, v|
    [
      k.downcase.to_sym,
      parse_args(v)
    ]
  end
end
parse_spec() click to toggle source
# File lib/linodeapi.rb, line 29
def parse_spec
  raw_spec['DATA']['METHODS'].each_with_object({}) do |(method, info), spec|
    name, groups = parse_method(method)
    params = parse_params(info['PARAMETERS'])
    add_call(spec, groups, name, params, info)
  end
end
raw_spec() click to toggle source
# File lib/linodeapi.rb, line 25
def raw_spec
  @raw_spec ||= JSON.parse(HTTParty.get(SPEC_URL).body)
end