Class: RubyPhpipam::Query

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

Class Method Summary collapse

Class Method Details

.get(url) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby_phpipam/query.rb', line 3

def self.get(url)
  RubyPhpipam.auth.validate_token!

  response = HTTParty.get(RubyPhpipam.gen_url(url),
      headers: {token: RubyPhpipam.auth.token}
    )

  body = JSON.parse(response.body, symbolize_names: true)

  unless body[:success] && body[:code] >= 200 && body[:code] < 400
    raise RequestFailed.new(body[:code], body[:message])
  end

  body[:data]
end

.get_array(url) ⇒ Object



19
20
21
22
23
24
# File 'lib/ruby_phpipam/query.rb', line 19

def self.get_array(url)
  data = self.get(url)

  return [] if data.nil?
  return data
end