Class: OneAndOne::MonitoringCenter

Inherits:
Object
  • Object
show all
Defined in:
lib/1and1/monitoring_center.rb

Instance Method Summary collapse

Constructor Details

#initialize(test: false) ⇒ MonitoringCenter

Returns a new instance of MonitoringCenter.



7
8
9
10
11
12
13
14
15
16
# File 'lib/1and1/monitoring_center.rb', line 7

def initialize(test: false)

  # Check if hitting mock api or live api
  if test
    @connection = Excon.new($base_url, :mock => true)
  else
    @connection = Excon.new($base_url)
  end

end

Instance Method Details

#get(server_id: nil, period: nil, start_date: nil, end_date: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/1and1/monitoring_center.rb', line 51

def get(server_id: nil, period: nil, start_date: nil, end_date: nil)

    # Build hash for query parameters
    keyword_args = {
      :period => period,
      :start_date => start_date,
      :end_date => end_date
    }

    # Clean out null query parameters
    params = OneAndOne.clean_hash(keyword_args)

    # Build URL
    path = OneAndOne.build_url("/monitoring_center/#{server_id}")

    # Perform request
    response = @connection.request(:method => :get,
      :path => path,
      :headers => $header,
      :query => params)

    # Check response status
    OneAndOne.check_response(response.body, response.status)

    #JSON-ify the response string
    JSON.parse(response.body)

end

#list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/1and1/monitoring_center.rb', line 19

def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)

  # Build hash for query parameters
  keyword_args = {
    :page => page,
    :per_page => per_page,
    :sort => sort,
    :q => q,
    :fields => fields
  }

  # Clean out null query parameters
  params = OneAndOne.clean_hash(keyword_args)

  # Build URL
  path = OneAndOne.build_url('/monitoring_center')

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header,
    :query => params)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end