Module: StatisticsOpenApi

Includes:
AuthOpenApi, OpenApiKeys
Included in:
CdnetworksClient
Defined in:
lib/cdnetworks-client/statistics_open_api.rb

Constant Summary collapse

BANDWIDTH_PATH =
"/api/rest/traffic/edge"

Constants included from OpenApiKeys

OpenApiKeys::GET_KEY_PATH

Constants included from AuthOpenApi

AuthOpenApi::LOGIN_URL, AuthOpenApi::LOGOUT_URL

Instance Method Summary collapse

Methods included from OpenApiKeys

#get_api_key, #get_api_key_list

Methods included from AuthOpenApi

#get_session_token

Instance Method Details

#bandwidth_usage(service_name, from, to, time_interval = 2) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cdnetworks-client/statistics_open_api.rb', line 7

def bandwidth_usage(service_name, from, to, time_interval = 2)
  session_token = get_session_token

  api_key = get_api_key(session_token, service_name)

  opts = {
    sessionToken: session_token,
    apiKey: api_key,
    fromDate: from.strftime("%Y%m%d"),
    toDate: to.strftime("%Y%m%d"),
    timeInterval: time_interval,
    output: "json"
  }

  response = call(BANDWIDTH_PATH, opts)

  if response[:code].to_s == "404"
    0.0
  else
    Array.wrap(response[:body]['trafficResponse']['trafficItem']).map{|i| i['dataTransferred']}.inject(&:+)
  end
end