lib/voucherify.rb in voucherify-0.2.0 vs lib/voucherify.rb in voucherify-0.3.0

- old
+ new

@@ -27,10 +27,11 @@ # - limit (default 10) # - skip (default 0) # - category # - campaign # - customer + # Sample query: { limit: 100, skip: 200, category: "Loyalty" } def list(query) url = @backend_url + "/vouchers/" response = RestClient.get(url, @headers.merge({ :params => query })) JSON.parse(response.body) end @@ -71,11 +72,19 @@ response = RestClient.post(url, payload.to_json, @headers.merge({ :content_type => :json })) JSON.parse(response.body) end def publish(campaign_name) - url = @backend_url + "/vouchers/publish?campaign=" + URI.encode(campaign_name) - response = RestClient.post(url, nil, @headers.merge({ :content_type => :json })) + url = @backend_url + "/vouchers/publish" + payload = {} + + if campaign_name.is_a? String + url += "?campaign=" + URI.encode(campaign_name) + elsif campaign_name.is_a? Hash + payload = campaign_name + end + + response = RestClient.post(url, payload.to_json, @headers.merge({ :content_type => :json })) JSON.parse(response.body) end # `code` is optional - will be generated if absent. # Sample `options` object: