class Naptime::REST
Public Class Methods
new(fileName)
click to toggle source
# File lib/naptime.rb, line 34 def initialize(fileName) @rest = Hash.new @restPath = Hash.new file = File.open(fileName, "rb") self.traverse(File.basename(fileName,".*"), JSON.parse(file.read), '/') end
Public Instance Methods
output()
click to toggle source
# File lib/naptime.rb, line 61 def output @rest.each do |noun, payload| @@crud.each do |action, info| path = @restPath[noun]['path'] + noun.to_s id = info['requires'] == 'id' ? '/[id]' : '' apiUri = "#{info['http']} #{path}#{id}\n" apiPayload = payload.to_json + "\n" if info['body'] print apiUri print apiPayload print "\n" end end end
traverse(noun, desc, path)
click to toggle source
# File lib/naptime.rb, line 45 def traverse(noun, desc, path) @rest[noun.to_sym] = Hash.new @restPath[noun.to_sym] = Hash.new @restPath[noun.to_sym]['path'] = path desc.each do |x,y| if y.respond_to?('each') self.traverse(x, y, path + noun + '/[id]/') else @rest[noun.to_sym][x] ||= y end end end