Module: SendGridWebApi::Helper
Instance Method Summary collapse
-
#create_sub_user_account(apikey, users) ⇒ Object
this accepts subuser array.
- #run_sendgrid_query(apikey) ⇒ Object
Instance Method Details
#create_sub_user_account(apikey, users) ⇒ Object
this accepts subuser array
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 |
# File 'lib/helper.rb', line 11 def create_sub_user_account(apikey, users) users.each do |user, data| #load users run_sendgrid_query(apikey) do @client.sub_user.management.add(data[:account].merge!(:username => user)) end #active user for send email run_sendgrid_query(apikey){@client.sub_user.management.enable(:user => user)} #assign ip unless data[:assigned_ips].empty? run_sendgrid_query(apikey){@client.sub_user.ip_management.assign_ip :user => user, :ip => data[:assigned_ips]} end #load apps unless data[:applications].empty? data[:applications].each do |app_name, | run_sendgrid_query(apikey){@client.sub_user.apps.activate(:user => user, :name => app_name)} unless .empty? run_sendgrid_query(apikey){@client.sub_user.apps.customize(.merge!(:user => user, :name => app_name))} end end end end end |
#run_sendgrid_query(apikey) ⇒ Object
4 5 6 7 8 |
# File 'lib/helper.rb', line 4 def run_sendgrid_query(apikey) @client = SendGridWebApi::Client.new(apikey) result = yield raise "it returns the following errors: #{result}" unless result.eql?({"message"=>"success"}) end |