Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added group_by to recent method

  • Loading branch information...
commit 518e0d95dafb43749f7f2f10536eb9aa0c1ffa93 1 parent ddd7bd9
@emptyflask authored
View
5 lib/neuron-client/model/ad.rb
@@ -72,9 +72,11 @@ def recent(statistic, parameters={})
connected_to_admin!
by = (parameters[:by] || parameters['by']).to_s
minutes = parameters[:minutes] || parameters['minutes']
+ group_by = parameters[:group_by] || parameters['group_by']
parameters = {}
parameters['by'] = by unless by.blank?
parameters['minutes'] = minutes.to_i if minutes.to_i > 0
+ parameters['group_by'] = group_by.to_s unless group_by.blank?
if validate?
unless STATISTIC_TYPES.include?(statistic.to_s)
raise "Unsupported statistic: #{statistic}"
@@ -85,6 +87,9 @@ def recent(statistic, parameters={})
unless minutes.blank? || minutes.to_i > 0
raise "Unsupported minutes: #{minutes}"
end
+ unless group_by.blank? || group_by == 'hour'
+ raise "Unsupported group_by: #{group_by}"
+ end
end
connection.get("ads/#{id}/recent/#{statistic}", parameters)
View
31 lib/neuron-client/model/zone.rb
@@ -58,6 +58,35 @@ def find_ad(ad_id)
Ad.find(ad_id)
end
+ STATISTIC_TYPES = %w(requests blocks defaults unitloads selections undeliveries impressions redirects clicks)
+
+ def recent(statistic, parameters={})
+ connected_to_admin!
+ by = (parameters[:by] || parameters['by']).to_s
+ minutes = parameters[:minutes] || parameters['minutes']
+ group_by = parameters[:group_by] || parameters['group_by']
+ parameters = {}
+ parameters['by'] = by unless by.blank?
+ parameters['minutes'] = minutes.to_i if minutes.to_i > 0
+ parameters['group_by'] = group_by.to_s unless group_by.blank?
+ if validate?
+ unless STATISTIC_TYPES.include?(statistic.to_s)
+ raise "Unsupported statistic: #{statistic}"
+ end
+ unless by.blank? || by == 'zone'
+ raise "Unsupported by: #{by}"
+ end
+ unless minutes.blank? || minutes.to_i > 0
+ raise "Unsupported minutes: #{minutes}"
+ end
+ unless group_by.blank? || group_by == 'hour'
+ raise "Unsupported group_by: #{group_by}"
+ end
+ end
+
+ connection.get("zones/#{id}/recent/#{statistic}", parameters)
+ end
+
def unlink(ad_id)
connected_to_admin!
validate_id!(ad_id)
@@ -76,4 +105,4 @@ def ads_by_priority
end
end
end
-end
+end
View
2  lib/neuron-client/version.rb
@@ -1,5 +1,5 @@
module Neuron
module Client
- VERSION = "0.4.4"
+ VERSION = "0.4.5"
end
end
View
9 spec/lib/model/zone_spec.rb
@@ -110,6 +110,15 @@ module Client
end
end
+ describe "recent(statistic, by=nil)" do
+ it "should call the expected method and return the expected result" do
+ zone = Zone.new(@minimal_attributes.merge('id' => 'z99'))
+ @connection.should_receive(:get).with('zones/z99/recent/impressions', {'by' => 'zone'}).and_return('return_value')
+
+ zone.recent('impressions', :by => 'zone').should == 'return_value'
+ end
+ end
+
describe "unlink(ad_id)" do
it "should call the expected method and return the expected results" do
zone = Zone.new(@minimal_attributes.merge('id' => 'z99'))
Please sign in to comment.
Something went wrong with that request. Please try again.