class SmtpLw::Client
Attributes
api_endpoint[RW]
api_token[RW]
per_page[RW]
timeout[RW]
Public Class Methods
new(options = {})
click to toggle source
# 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
Public Instance Methods
get(uri, options = {})
click to toggle source
Make a HTTP GET request
@param uri [String] The path, relative to {#api_endpoint} @param options [Hash] Query and header params for request @return [Faraday::Response]
# File lib/smtp_lw/client.rb, line 23 def get(uri, options = {}) connection.get(uri, options) end
next_page(raw)
click to toggle source
# 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 = {})
click to toggle source
Make a HTTP POST request
@param uri [String] The path, relative to {#api_endpoint} @param options [Hash] Body and header params for request @return [Faraday::Response]
# File lib/smtp_lw/client.rb, line 32 def post(uri, options = {}) connection.post(uri, options) end
put(uri, options = {})
click to toggle source
Make a HTTP PUT request
@param uri [String] The path, relative to {#api_endpoint} @param options [Hash] Body and header params for request @return [Faraday::Response]
# File lib/smtp_lw/client.rb, line 41 def put(uri, options = {}) connection.put(uri, options) end
Private Instance Methods
connection()
click to toggle source
# File lib/smtp_lw/client.rb, line 54 def connection conn = Faraday.new(url: (@api_endpoint || SmtpLw.api_endpoint), ssl: { verify: false }) do |c| c.request :json c.response :json c.adapter Faraday.default_adapter end conn.headers['User-Agent'] = "SMTP LW Ruby API Client v#{VERSION}" conn.headers['x-auth-token'] = @api_token || SmtpLw.api_token conn end