lib/promoter/campaign.rb in promoter-0.1.5 vs lib/promoter/campaign.rb in promoter-0.1.6
- old
+ new
@@ -15,12 +15,24 @@
@eligible_count = attrs["eligible_count"]
@last_surveyed_date = Time.parse(attrs["last_surveyed_date"]) if attrs["last_surveyed_date"]
@launch_date = Time.parse(attrs["launch_date"]) if attrs["launch_date"]
end
- def self.all(page=1)
- response = Request.get("#{API_URL}/?page=#{page}")
+ # Parameter Optional? Description
+ # page yes Returns which page of results to return.
+ # Defaults to 1
+ def self.all(options={})
+ if !options.is_a?(Hash)
+ puts "-- DEPRECATION WARNING--"
+ puts "Passing in a number as a page is deprecated and will be removed from future versions of this gem.\nInstead pass in a hash of attributes.\n\n e.g. Promoter::Campaign.all(page: 2)"
+ query_string = "page=#{options}"
+ else
+ # default to first page
+ options[:page] ||= 1
+ query_string = URI.encode_www_form(options)
+ end
+ response = Request.get("#{API_URL}/?#{query_string}")
response['results'].map {|attrs| new(attrs)}
end
# Parameter Optional? Description
# all_contacts yes Can be set to true,false
@@ -44,6 +56,6 @@
def self.create(attributes)
response = Request.post(API_URL + "/", attributes)
new(response)
end
end
-end
\ No newline at end of file
+end