Module: Hetzner::API::Traffic
- Included in:
- Hetzner::API
- Defined in:
- lib/hetzner/api/traffic.rb
Instance Method Summary collapse
-
#traffic?(options = {}) ⇒ Boolean
returns the traffic information for an IP and/or subnet according to the selected time frame.
Instance Method Details
#traffic?(options = {}) ⇒ Boolean
returns the traffic information for an IP and/or subnet according to the selected time frame.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hetzner/api/traffic.rb', line 5 def traffic?( = {}) ips = [:ips] subnets = [:subnets] from = [:from] to = [:to] type = [:type].to_sym from = DateTime.parse(from) unless from.is_a? Date to = DateTime.parse(to) unless to.is_a? Date case type when :year format = "%Y-%m" # 2010-01 from_date = from.strftime format to_date = to.strftime format when :month format = "%Y-%m-%d" # 2010-12-30 from_date = from.strftime format to_date = to.strftime format when :day format = "%Y-%m-%dT%H" # 2010-01-01T15 from_date = from.strftime format to_date = to.strftime format else raise ArgumentError, 'Invalid time frame type. Must be one of: :year, :month, :day' end validate_dates_and_type from, to, type perform_post "/traffic", :query => { :ip => ips, :subnet => subnets, :from => from_date, :to => to_date, :type => type } end |