class SendgridThreads::Client
Constants
- HEADERS
- URL
- VERSION
Attributes
adapter[W]
conn[W]
key[R]
raise_exceptions[R]
secret[R]
url[R]
user_agent[R]
Public Class Methods
new( params = {} ) { |self| ... }
click to toggle source
# File lib/sendgrid_threads/client.rb, line 12 def initialize( params = {} ) @key = params.fetch(:key, SendgridThreads.config.key) @secret = params.fetch(:secret, SendgridThreads.config.secret) @url = params.fetch(:url, SendgridThreads.config.url || URL) @raise_exceptions = params.fetch(:raise_exceptions, SendgridThreads.config.raise_exceptions || true) @adapter = params.fetch(:adapter, adapter) @conn = params.fetch(:conn, conn) @user_agent = params.fetch(:user_agent, "sendgrid-threads/#{SendgridThreads::VERSION};ruby") yield self if block_given? end
Public Instance Methods
adapter()
click to toggle source
# File lib/sendgrid_threads/client.rb, line 43 def adapter @adapter ||= Faraday.default_adapter end
conn()
click to toggle source
# File lib/sendgrid_threads/client.rb, line 35 def conn @conn ||= Faraday.new(url: @url) do |conn| conn.request :url_encoded conn.request :basic_auth, @key, @secret conn.adapter adapter end end
post(endpoint, body = nil)
click to toggle source
# File lib/sendgrid_threads/client.rb, line 24 def post(endpoint, body = nil) endpoint_with_version = "/#{VERSION}/#{endpoint}" response = conn.post(endpoint_with_version) do |req| req.headers = HEADERS.merge('User-Agent' => @user_agent) req.body = JSON(body) if body end fail SendgridThreads::Exception, response.body if raise_exceptions? && response.status != 200 response end
raise_exceptions?()
click to toggle source
# File lib/sendgrid_threads/client.rb, line 47 def raise_exceptions? @raise_exceptions end