lib/mailgun/client.rb in mailgun-ruby-1.2.12 vs lib/mailgun/client.rb in mailgun-ruby-1.2.13

- old
+ new

@@ -7,10 +7,11 @@ # wrapper around RestClient so you don't have to worry about the HTTP aspect # of communicating with our API. # # See the Github documentation for full examples. class Client + SUBACCOUNT_HEADER = 'X-Mailgun-On-Behalf-Of'.freeze def initialize(api_key = Mailgun.api_key, api_host = Mailgun.api_host || 'api.mailgun.net', api_version = Mailgun.api_version || 'v3', ssl = true, @@ -46,9 +47,19 @@ end # Change API key def set_api_key(api_key) @http_client.options[:password] = api_key + end + + # Add subaccount id to headers + def set_subaccount(subaccount_id) + @http_client.options[:headers] = { SUBACCOUNT_HEADER => subaccount_id } + end + + # Reset subaccount for primary usage + def reset_subaccount + @http_client.options[:headers].delete(SUBACCOUNT_HEADER) end # Client is in test mode? # # @return [Boolean] Is the client set in test mode?