Class: Desmoservice::Conf

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_url: nil, desmo_name: nil, lang: nil, dsmd_script: nil) ⇒ Conf

Returns a new instance of Conf.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/conf.rb', line 8

def initialize(service_url: nil, desmo_name: nil, lang: nil, dsmd_script: nil)
  raise "Missing service_url" if service_url.nil?
  raise "Missing desmo_name" if desmo_name.nil?
  raise "Missing lang" if lang.nil?
  if service_url[-1] != "/"
    service_url << "/"
  end
  @service_url = service_url
  @desmo_name = desmo_name
  @lang = lang
  @dsmd_script = dsmd_script
end

Instance Attribute Details

#desmo_nameObject (readonly)

Returns the value of attribute desmo_name.



6
7
8
# File 'lib/conf.rb', line 6

def desmo_name
  @desmo_name
end

#dsmd_scriptObject (readonly)

Returns the value of attribute dsmd_script.



6
7
8
# File 'lib/conf.rb', line 6

def dsmd_script
  @dsmd_script
end

#langObject (readonly)

Returns the value of attribute lang.



6
7
8
# File 'lib/conf.rb', line 6

def lang
  @lang
end

#service_urlObject (readonly)

Returns the value of attribute service_url.



6
7
8
# File 'lib/conf.rb', line 6

def service_url
  @service_url
end

Instance Method Details

#build_dsmd_urlObject



36
37
38
39
40
41
42
# File 'lib/conf.rb', line 36

def build_dsmd_url
  dsmd_url = @service_url + "export/" + @desmo_name + "_" + @lang + ".dsmd"
  if @dsmd_script
    dsmd_url += "?script=" + @dsmd_script
  end
  return dsmd_url
end

#build_edition_uriObject



32
33
34
# File 'lib/conf.rb', line 32

def build_edition_uri
  return URI(@service_url + 'edition?desmo=' + @desmo_name)
end

#build_json_uri(parameters = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/conf.rb', line 21

def build_json_uri(parameters=nil)
  map = {"desmo" => @desmo_name, "lang" => @lang}
  if not parameters.nil?
    map.merge!(parameters)
  end
  map.delete_if { |k, v| v.nil? }
  uri = URI(@service_url + 'json')
  uri.query = URI.encode_www_form(map)
  return uri
end