Class: ISend::Client
Constant Summary collapse
- API_BASE_URL =
'https://www.isend.ai/api'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(api_key, config = {}) ⇒ Client
constructor
Create a new ISend::Client instance.
-
#send_email(email_data) ⇒ Hash
Send an email using isend.ai.
Constructor Details
#initialize(api_key, config = {}) ⇒ Client
Create a new ISend::Client instance
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/isend/client.rb', line 18 def initialize(api_key, config = {}) if api_key.nil? || api_key.strip.empty? raise ISend::InvalidArgumentError, 'API key is required' end @api_key = api_key.strip @timeout = config[:timeout] || 30 # Configure HTTParty self.class.base_uri API_BASE_URL self.class.default_timeout @timeout self.class.headers({ 'Authorization' => "Bearer #{@api_key}", 'Content-Type' => 'application/json', 'User-Agent' => "isend-ai-ruby-sdk/#{ISend::VERSION}" }) end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/isend/client.rb', line 10 def api_key @api_key end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/isend/client.rb', line 10 def timeout @timeout end |
Instance Method Details
#send_email(email_data) ⇒ Hash
Send an email using isend.ai
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/isend/client.rb', line 44 def send_email(email_data) validate_email_data(email_data) response = self.class.post('/send-email', { body: email_data.to_json, headers: { 'Content-Type' => 'application/json' } }) handle_response(response) end |