Class: SmtpLw::Client

Inherits:
Object
  • Object
show all
Includes:
Messages
Defined in:
lib/smtp_lw/client.rb,
lib/smtp_lw/client/messages.rb

Defined Under Namespace

Modules: Messages

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Messages

#get_message, #list_messages, #send_message

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
# File 'lib/smtp_lw/client.rb', line 10

def initialize(options = {})
  SmtpLw::Configurable.keys.each do |key|
    instance_variable_set(
      :"@#{key}", options[key] || SmtpLw.instance_variable_get(:"@#{key}")
    )
  end
end

Instance Attribute Details

#api_endpointObject

Returns the value of attribute api_endpoint.



7
8
9
# File 'lib/smtp_lw/client.rb', line 7

def api_endpoint
  @api_endpoint
end

#api_tokenObject

Returns the value of attribute api_token.



7
8
9
# File 'lib/smtp_lw/client.rb', line 7

def api_token
  @api_token
end

#per_pageObject

Returns the value of attribute per_page.



7
8
9
# File 'lib/smtp_lw/client.rb', line 7

def per_page
  @per_page
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/smtp_lw/client.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#get(uri, options = {}) ⇒ Faraday::Response

Make a HTTP GET request

Parameters:

  • uri (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (Faraday::Response)


23
24
25
# File 'lib/smtp_lw/client.rb', line 23

def get(uri, options = {})
  connection.get(uri, options)
end

#next_page(raw) ⇒ Object



45
46
47
48
49
50
# File 'lib/smtp_lw/client.rb', line 45

def next_page(raw)
  next_uri = raw['links']['next']
  return nil unless next_uri
  response = connection.get(next_uri)
  response.body
end

#post(uri, options = {}) ⇒ Faraday::Response

Make a HTTP POST request

Parameters:

  • uri (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Faraday::Response)


32
33
34
# File 'lib/smtp_lw/client.rb', line 32

def post(uri, options = {})
  connection.post(uri, options)
end

#put(uri, options = {}) ⇒ Faraday::Response

Make a HTTP PUT request

Parameters:

  • uri (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (Faraday::Response)


41
42
43
# File 'lib/smtp_lw/client.rb', line 41

def put(uri, options = {})
  connection.put(uri, options)
end