Class: ResoTransport::Metadata

Inherits:
Struct
  • Object
show all
Defined in:
lib/reso_transport/metadata.rb

Constant Summary collapse

MIME_TYPES =
{
  xml: "application/xml",
  json: "application/json"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



2
3
4
# File 'lib/reso_transport/metadata.rb', line 2

def client
  @client
end

Instance Method Details

#entity_setsObject



9
10
11
# File 'lib/reso_transport/metadata.rb', line 9

def entity_sets
  parser.entity_sets
end

#get_dataObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/reso_transport/metadata.rb', line 21

def get_data
  if client.md_file 
    if File.exist?(client.md_file) && File.size(client.md_file) > 0
      File.new(client.md_file)
    else
      File.open(client.md_file, "w") {|f| f.write(raw) }
      File.new(client.md_file)
    end
  else
    raw
  end
end

#parserObject



17
18
19
# File 'lib/reso_transport/metadata.rb', line 17

def parser
  @parser ||= MetadataParser.new.parse(get_data)
end

#rawObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/reso_transport/metadata.rb', line 34

def raw
  resp = client.connection.get("$metadata") do |req|
    req.headers['Accept'] = MIME_TYPES[client.vendor.fetch(:metadata_format, :xml).to_sym]
  end

  if resp.success?
    resp.body
  else
    puts resp.body
    raise "Error getting metadata!"
  end
end

#schemasObject



13
14
15
# File 'lib/reso_transport/metadata.rb', line 13

def schemas
  parser.schemas
end