Sha256: 8009dbe4cb9dcecef0645ed7ee960d47bdc4f88a27b86a45d7b2211156deba41
Contents?: true
Size: 1.06 KB
Versions: 3
Compression:
Stored size: 1.06 KB
Contents
#!/usr/bin/env ruby require 'httparty' require 'pp' require 'erb' SPEC_PATH = 'lib/linodeapi/spec.rb' TEMPLATE = '## # Dynamically updated spec from the api.spec call # rubocop:disable all module LinodeAPI SPEC = <%= clean %> end ' raw = HTTParty.get('https://api.linode.com/?api_action=api.spec').body raw = JSON.parse(raw)['DATA']['METHODS'] spec = raw.reduce(Hash.new) do |acc, (method, info)| groups = method.split('.').map(&:to_sym) name = groups.pop params = info['PARAMETERS'].map do |k, v| [ k.downcase.to_sym, { desc: v['DESCRIPTION'], type: v['TYPE'].to_sym, required: v['REQUIRED'], } ] end local = groups.reduce(acc) do |layout, new| layout[new] ||= { type: :group, subs: {} } layout[new][:subs] end local[name] = { type: :call, desc: info['DESCRIPTION'], throws: info['THROWS'].split(','), params: Hash[params], } acc end clean = '' PP.pp({ type: 'group', subs: spec }, clean) File.open(SPEC_PATH, 'w') { |fh| fh.write ERB.new(TEMPLATE).result } puts 'Updated spec file'
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
linodeapi-0.0.4 | dev/update_spec.rb |
linodeapi-0.0.2 | dev/update_spec.rb |
linodeapi-0.0.1 | dev/update_spec.rb |