Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Added support for analysis_queries param for Account Identity Limits
Browse files Browse the repository at this point in the history
  • Loading branch information
dugjason committed Jul 21, 2016
1 parent a199a46 commit 0b3266c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
8 changes: 5 additions & 3 deletions examples/account_identity_limit_eg.rb
Expand Up @@ -19,7 +19,8 @@ def run
puts @datasift.account_identity_limit.create(
identity_id,
'facebook',
100_000
100_000,
50
)[:data].to_json

puts "\nList all existing Limits for this Service"
Expand All @@ -33,11 +34,12 @@ def run
'facebook'
)[:data].to_json

puts "\nUpdate a Limit for a given Identity"
puts "\nUpdate just the daily interaction limit for a Limit for a given Identity"
puts @datasift.account_identity_limit.update(
identity_id,
'facebook',
250_000
250_000,
nil
)[:data].to_json

puts "\nRemove the Limit from a given Identity and Service"
Expand Down
31 changes: 18 additions & 13 deletions lib/account_identity_limit.rb
Expand Up @@ -8,16 +8,17 @@ class AccountIdentityLimit < DataSift::ApiResource
# a limit
# @param service [String] The service this limit will apply to. For example;
# 'facebook'
# @param total_allowance [Integer] The limit for this Identity
# @param total_allowance [Integer] (Optional) The daily interaction limit for this Identity
# @param analyze_queries [Integer] (Optional) The hourly analysis query limit for this Identity
# @return [Object] API reponse object
def create(identity_id = '', service = '', total_allowance = nil)
def create(identity_id = '', service = '', total_allowance = nil, analyze_queries = nil)
fail BadParametersError, 'identity_id is required' if identity_id.empty?
fail BadParametersError, 'service is required' if service.empty?
fail BadParametersError, 'total_allowance can not be "nil"' if total_allowance.nil?
params = {
service: service,
total_allowance: total_allowance
}
fail BadParametersError, 'Must set total_allowance or analyze_queries' if
total_allowance.nil? && analyze_queries.nil?
params = { service: service }
params[:total_allowance] = total_allowance unless total_allowance.nil?
params[:analyze_queries] = analyze_queries unless analyze_queries.nil?

DataSift.request(:POST, "account/identity/#{identity_id}/limit", @config, params)
end
Expand Down Expand Up @@ -46,8 +47,8 @@ def list(service = '', per_page = '', page = '')
fail BadParametersError, 'service is required' if service.empty?

params = {}
params.merge!(per_page: per_page) unless per_page.empty?
params.merge!(page: page) unless page.empty?
params[:per_page] = per_page unless per_page.empty?
params[:page] = page unless page.empty?

DataSift.request(:GET, "account/identity/limit/#{service}", @config, params)
end
Expand All @@ -58,13 +59,17 @@ def list(service = '', per_page = '', page = '')
# a limit
# @param service [String] The service this limit will apply to. For example;
# 'facebook'
# @param total_allowance [Integer] The new limit for this Identity
# @param total_allowance [Integer] (Optional) The daily interaction limit for this Identity
# @param analyze_queries [Integer] (Optional) The hourly analysis query limit for this Identity
# @return [Object] API reponse object
def update(identity_id = '', service = '', total_allowance = nil)
def update(identity_id = '', service = '', total_allowance = nil, analyze_queries = nil)
fail BadParametersError, 'identity_id is required' if identity_id.empty?
fail BadParametersError, 'service is required' if service.empty?
fail BadParametersError, 'total_allowance can not be "nil"' if total_allowance.nil?
params = { total_allowance: total_allowance }
fail BadParametersError, 'Must set total_allowance or analyze_queries' if
total_allowance.nil? && analyze_queries.nil?
params = {}
params[:total_allowance] = total_allowance unless total_allowance.nil?
params[:analyze_queries] = analyze_queries unless analyze_queries.nil?

DataSift.request(:PUT, "account/identity/#{identity_id}/limit/#{service}", @config, params)
end
Expand Down

0 comments on commit 0b3266c

Please sign in to comment.