Class: Mailjet::Connection
- Inherits:
-
Object
- Object
- Mailjet::Connection
- Defined in:
- lib/mailjet/connection.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#options ⇒ Object
Returns the value of attribute options.
-
#perform_api_call ⇒ Object
Returns the value of attribute perform_api_call.
-
#public_operations ⇒ Object
Returns the value of attribute public_operations.
-
#read_only ⇒ Object
(also: #read_only?)
Returns the value of attribute read_only.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #[](suburl, &new_block) ⇒ Object
- #concat_urls(suburl) ⇒ Object
- #delete(additional_headers = {}, &block) ⇒ Object
- #get(additional_headers = {}, &block) ⇒ Object
-
#initialize(end_point, api_key, secret_key, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(payload, additional_headers = {}, &block) ⇒ Object
- #put(payload, additional_headers = {}, &block) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(end_point, api_key, secret_key, options = {}) ⇒ Connection
Returns a new instance of Connection.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mailjet/connection.rb', line 19 def initialize(end_point, api_key, secret_key, = {}) self. = self.api_key = api_key self.secret_key = secret_key self.public_operations = [:public_operations] || [] self.read_only = [:read_only] self.adapter = Faraday.new(end_point, ssl: { verify: false }) do |conn| conn.response :raise_error, include_request: true conn.request :authorization, :basic, api_key, secret_key conn.headers['Content-Type'] = 'application/json' end self.perform_api_call = .key?(:perform_api_call) ? [:perform_api_call] : true end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def adapter @adapter end |
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def api_key @api_key end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def end |
#perform_api_call ⇒ Object
Returns the value of attribute perform_api_call.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def perform_api_call @perform_api_call end |
#public_operations ⇒ Object
Returns the value of attribute public_operations.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def public_operations @public_operations end |
#read_only ⇒ Object Also known as: read_only?
Returns the value of attribute read_only.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def read_only @read_only end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
7 8 9 |
# File 'lib/mailjet/connection.rb', line 7 def secret_key @secret_key end |
Instance Method Details
#[](suburl, &new_block) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/mailjet/connection.rb', line 10 def [](suburl, &new_block) broken_url = uri.path.split("/") if broken_url.include?("contactslist") && broken_url.include?("managemanycontacts") && broken_url.last.to_i > 0 self.class.new(uri, api_key, secret_key, ) else self.class.new(concat_urls(suburl), api_key, secret_key, ) end end |
#concat_urls(suburl) ⇒ Object
49 50 51 |
# File 'lib/mailjet/connection.rb', line 49 def concat_urls(suburl) self.adapter.build_url(suburl.to_s) end |
#delete(additional_headers = {}, &block) ⇒ Object
45 46 47 |
# File 'lib/mailjet/connection.rb', line 45 def delete(additional_headers = {}, &block) handle_api_call(:delete, additional_headers, &block) end |
#get(additional_headers = {}, &block) ⇒ Object
33 34 35 |
# File 'lib/mailjet/connection.rb', line 33 def get(additional_headers = {}, &block) handle_api_call(:get, additional_headers, &block) end |
#post(payload, additional_headers = {}, &block) ⇒ Object
37 38 39 |
# File 'lib/mailjet/connection.rb', line 37 def post(payload, additional_headers = {}, &block) handle_api_call(:post, additional_headers, payload, &block) end |
#put(payload, additional_headers = {}, &block) ⇒ Object
41 42 43 |
# File 'lib/mailjet/connection.rb', line 41 def put(payload, additional_headers = {}, &block) handle_api_call(:put, additional_headers, payload, &block) end |
#uri ⇒ Object
53 54 55 |
# File 'lib/mailjet/connection.rb', line 53 def uri self.adapter.build_url end |