Class: SendGrid::API
- Inherits:
-
Object
- Object
- SendGrid::API
- Defined in:
- lib/sendgrid/client.rb
Overview
Initialize the HTTP client
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#request_headers ⇒ Object
readonly
Returns the value of attribute request_headers.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(api_key: nil, host: nil, request_headers: nil, version: nil) ⇒ API
constructor
-
Args : -
api_key
-> your SendGrid API key -host
-> the base URL for the API -request_headers
-> any headers that you want to be globally applied -version
-> the version of the API you wish to access, currently only “v3” is supported.
-
Constructor Details
#initialize(api_key: nil, host: nil, request_headers: nil, version: nil) ⇒ API
-
Args :
-
api_key
-> your SendGrid API key -
host
-> the base URL for the API -
request_headers
-> any headers that you want to be globally applied -
version
-> the version of the API you wish to access,currently only "v3" is supported
-
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sendgrid/client.rb', line 17 def initialize(api_key: nil, host: nil, request_headers: nil, version: nil) @api_key = api_key @host = host ? host : 'https://api.sendgrid.com' @version = version ? version : 'v3' @user_agent = "sendgrid/#{SendGrid::VERSION};ruby" @request_headers = JSON.parse(' { "Authorization": "Bearer ' + @api_key + '", "Accept": "application/json" } ') @request_headers = @request_headers.merge(request_headers) if request_headers @client = Client.new(host: "#{@host}/#{@version}", request_headers: @request_headers) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/sendgrid/client.rb', line 8 def client @client end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/sendgrid/client.rb', line 9 def host @host end |
#request_headers ⇒ Object (readonly)
Returns the value of attribute request_headers.
9 10 11 |
# File 'lib/sendgrid/client.rb', line 9 def request_headers @request_headers end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/sendgrid/client.rb', line 9 def version @version end |