Class: SendGridWebApi::Base
- Inherits:
-
Object
- Object
- SendGridWebApi::Base
- Defined in:
- lib/base.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_user ⇒ Object
Returns the value of attribute api_user.
Instance Method Summary collapse
- #builder_options(options) ⇒ Object
-
#initialize(api_user, api_key) ⇒ Base
constructor
A new instance of Base.
- #make_request_url(url, options) ⇒ Object
- #query_api(url, options) ⇒ Object
- #query_post_api(url, options) ⇒ Object
- #session ⇒ Object
- #to_query(options) ⇒ Object
Constructor Details
#initialize(api_user, api_key) ⇒ Base
Returns a new instance of Base.
7 8 9 10 |
# File 'lib/base.rb', line 7 def initialize api_user, api_key @api_user = api_user @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/base.rb', line 5 def api_key @api_key end |
#api_user ⇒ Object
Returns the value of attribute api_user.
5 6 7 |
# File 'lib/base.rb', line 5 def api_user @api_user end |
Instance Method Details
#builder_options(options) ⇒ Object
16 17 18 19 |
# File 'lib/base.rb', line 16 def .merge!(:api_user => @api_user, :api_key => @api_key) to_query() end |
#make_request_url(url, options) ⇒ Object
12 13 14 |
# File 'lib/base.rb', line 12 def make_request_url url, "#{url}?#{()}" end |
#query_api(url, options) ⇒ Object
21 22 23 |
# File 'lib/base.rb', line 21 def query_api url, session.get(make_request_url(url, )).body end |
#query_post_api(url, options) ⇒ Object
25 26 27 28 |
# File 'lib/base.rb', line 25 def query_post_api url, () session.post(url, ()).body end |
#session ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/base.rb', line 34 def session @connection ||= ::Faraday.new base_url do |conn| # Forces the connection request and response to be JSON even though # Sendgrids API headers do not specify the content type is JSON conn.request :url_encoded conn.response :json #, :content_type => /\bjson$/ conn.adapter Faraday.default_adapter end end |
#to_query(options) ⇒ Object
30 31 32 |
# File 'lib/base.rb', line 30 def to_query() Faraday::Utils.build_nested_query() end |