Class: NationBuilder::SpecParser

Inherits:
Object
  • Object
show all
Defined in:
lib/nationbuilder/spec_parser.rb

Class Method Summary collapse

Class Method Details

.parse(spec_path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nationbuilder/spec_parser.rb', line 3

def self.parse(spec_path)
  spec = JSON.parse(File.read(spec_path))
  endpoints = []

  spec['endpoints'].each do |endpoint|
    nb_endpoint = NationBuilder::Endpoint.new(endpoint['name'])
    endpoints << nb_endpoint
    endpoint['methods'].each do |method|
      nb_method = NationBuilder::Method.new(method['MethodName'],
                                            method['HTTPMethod'],
                                            method['URI'],
                                            method['Synopsis'])
      nb_endpoint.register_method(nb_method)
      method['parameters'].each do |parameter|
        if (parameter['Required'] == 'Y') && (parameter['Name'] != 'body')
          nb_parameter = NationBuilder::Parameter.new(parameter['Name'])
          nb_method.register_parameter(nb_parameter)
        end
      end
    end
  end

  endpoints
end