Class: Oxidized::Source::HTTP

Inherits:
JSONFile show all
Defined in:
lib/oxidized/source/http.rb

Instance Method Summary collapse

Methods inherited from Source

#map_group, #map_model, #node_var_interpolate

Constructor Details

#initializeHTTP

Returns a new instance of HTTP.



5
6
7
8
# File 'lib/oxidized/source/http.rb', line 5

def initialize
  super
  @cfg = Oxidized.config.source.http
end

Instance Method Details

#load(node_want = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/oxidized/source/http.rb', line 34

def load(node_want = nil)
  uri = URI.parse(@cfg.url)
  data = JSON.parse(read_http(uri, node_want))
  node_data = data
  node_data = string_navigate_object(data, @cfg.hosts_location) if @cfg.hosts_location?
  node_data = pagination(data, node_want) if @cfg.pagination?

  transform_json(node_data)
end

#setupObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oxidized/source/http.rb', line 10

def setup
  Oxidized.setup_logger
  if @cfg.empty?
    Oxidized.asetus.user.source.http.url       = 'https://url/api'
    Oxidized.asetus.user.source.http.map.name  = 'name'
    Oxidized.asetus.user.source.http.map.model = 'model'
    Oxidized.asetus.save :user

    raise NoConfig, "No source http config, edit #{Oxidized::Config.configfile}"
  end

  # check for mandatory attributes
  if !@cfg.has_key?('url')
    raise InvalidConfig, "url is a mandatory http source attribute, edit #{Oxidized::Config.configfile}"
  elsif !@cfg.map.has_key?('name')
    raise InvalidConfig, "map/name is a mandatory source attribute, edit #{Oxidized::Config.configfile}"
  end
end