Class: Softlayer::Generator::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/softlayer/generator/service.rb

Defined Under Namespace

Classes: UnknownMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Service

Returns a new instance of Service.



6
7
8
9
# File 'lib/softlayer/generator/service.rb', line 6

def initialize(name)
  @name = name
  load_data_file
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/softlayer/generator/service.rb', line 4

def name
  @name
end

Instance Method Details

#document_method_params(name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/softlayer/generator/service.rb', line 16

def document_method_params(name)
  return nil if @document.nil?
  methods = []
  messages = @document.parser.sections["message"].select do |x|
    x.attributes["name"].value == Converter.message_name(name)
  end

  # raise UnknownMessage.new("#{name} has no message") if messages.empty?
  return [] if messages.nil? or messages.empty?

  # get parameters for message
  messages.first.css("part").each do |param|
    method_type = param["type"]
    method_type = process_method_type(method_type) if method_type.match(/\Atns:/)
    methods << {name: param["name"].underscore, type: Converter.type(method_type)}
  end
  methods
end

#document_method_response(name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/softlayer/generator/service.rb', line 45

def document_method_response(name)
  return nil if @document.nil?
  response_message = Converter.message_name(name)+"Response"
  messages = @document.parser.sections["message"].select do |x|
    x.attributes["name"].value == response_message
  end

  return nil if messages.empty?

  return_type = messages.first.css("part")[0]["type"]
  Converter.type(return_type)
end

#document_methodsObject



11
12
13
14
# File 'lib/softlayer/generator/service.rb', line 11

def document_methods
  return nil if @document.nil?
  @document.soap_actions
end

#message_needs_id?(message) ⇒ Boolean

Returns:



58
59
60
61
62
63
64
65
66
# File 'lib/softlayer/generator/service.rb', line 58

def message_needs_id?(message)
  return nil if @document.nil?
  section = @document.parser.sections["binding"].first
  needs_id = false
  section.css("operation[name=#{Converter.message_name(message)}] input").children.each do |header|
    needs_id = true if header["message"] == "tns:#{@name}InitParametersHeader"
  end
  needs_id
end

#process_method_type(type) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/softlayer/generator/service.rb', line 35

def process_method_type(type)
  return nil if @document.nil?
  type.sub!('tns:', '')
  object = @document.parser.sections["types"].first.css("[name='#{type}']").first
  return type if object.nil?
  object_type = object.children[1].attributes["base"].value
  object_type if object_type
  # type
end

#representation_hashObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/softlayer/generator/service.rb', line 68

def representation_hash
  return nil if @document.nil?
  rep = {}
  document_methods.each do |method|
    method_scope = :class
    method_scope = :instance if message_needs_id?(method)
    rep[method] = {
      input: document_method_params(method),
      return: document_method_response(method),
      method_scope: method_scope
    }
  end
  rep
end