Class: RubyApiPackCore::Connection::Base
- Inherits:
-
Object
- Object
- RubyApiPackCore::Connection::Base
- Defined in:
- lib/ruby_api_pack_core/connection/base.rb
Overview
Shared HTTParty + Oj request/response plumbing for API pack connection
wrappers. Subclasses provide the vendor-specific piece by implementing
#auth_headers (a Hash merged into every request's headers). Everything
else -- URL building, verb dispatch, status handling, JSON parsing, and
error messages -- is identical across packs.
Instance Attribute Summary collapse
-
#api_path ⇒ Object
readonly
Returns the value of attribute api_path.
-
#api_url_base ⇒ Object
readonly
Returns the value of attribute api_url_base.
Instance Method Summary collapse
- #api_delete(params = {}) ⇒ Object
- #api_get(params = {}) ⇒ Object
- #api_post(params = {}) ⇒ Object
- #api_put(params = {}) ⇒ Object
-
#initialize(api_url_base, api_path) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(api_url_base, api_path) ⇒ Base
Returns a new instance of Base.
16 17 18 19 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 16 def initialize(api_url_base, api_path) @api_url_base = api_url_base @api_path = api_path end |
Instance Attribute Details
#api_path ⇒ Object (readonly)
Returns the value of attribute api_path.
14 15 16 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 14 def api_path @api_path end |
#api_url_base ⇒ Object (readonly)
Returns the value of attribute api_url_base.
14 15 16 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 14 def api_url_base @api_url_base end |
Instance Method Details
#api_delete(params = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 51 def api_delete(params = {}) response = HTTParty.delete( full_url, headers: auth_headers, query: params, ssl_version: :TLSv1_2 ) handle_response(response) end |
#api_get(params = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 21 def api_get(params = {}) response = HTTParty.get( full_url, headers: auth_headers, query: params, ssl_version: :TLSv1_2 ) handle_response(response) end |
#api_post(params = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 31 def api_post(params = {}) response = HTTParty.post( full_url, headers: auth_headers.merge('Content-Type' => 'application/json'), body: params.to_json, ssl_version: :TLSv1_2 ) handle_response(response) end |
#api_put(params = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_api_pack_core/connection/base.rb', line 41 def api_put(params = {}) response = HTTParty.put( full_url, headers: auth_headers.merge('Content-Type' => 'application/json'), body: params.to_json, ssl_version: :TLSv1_2 ) handle_response(response) end |