Class: ApiMapper::Client
- Inherits:
-
Object
- Object
- ApiMapper::Client
- Defined in:
- lib/api_mapper/client.rb
Overview
API client class
Provides methods to access API endpoints
Instance Attribute Summary collapse
-
#router ⇒ ApiMapper::Router
writeonly
router used for processing requests.
Instance Method Summary collapse
-
#authorization(authorization) ⇒ String
Authorize client using ‘Authorization` HTTP header.
-
#get(path) ⇒ Array, Object
Make HTTP GET request.
-
#initialize(base_url) ⇒ ApiMapper::Client
constructor
A new instance of ApiMapper::Client.
-
#patch(path, payload) ⇒ Array, Object
Make HTTP PATCH request.
-
#post(path, payload) ⇒ Array, Object
Make HTTP POST request.
Constructor Details
#initialize(base_url) ⇒ ApiMapper::Client
A new instance of ApiMapper::Client
20 21 22 23 |
# File 'lib/api_mapper/client.rb', line 20 def initialize(base_url) @base_url = base_url @router = Router.new end |
Instance Attribute Details
#router=(value) ⇒ ApiMapper::Router (writeonly)
router used for processing requests
13 14 15 |
# File 'lib/api_mapper/client.rb', line 13 def router=(value) @router = value end |
Instance Method Details
#authorization(authorization) ⇒ String
Authorize client using ‘Authorization` HTTP header
79 80 81 |
# File 'lib/api_mapper/client.rb', line 79 def () @authorization = end |
#get(path) ⇒ Array, Object
Make HTTP GET request
33 34 35 36 37 38 |
# File 'lib/api_mapper/client.rb', line 33 def get(path) response = response(:get, path) mapper = mapper(:get, path) map_response(mapper, response) end |
#patch(path, payload) ⇒ Array, Object
Make HTTP PATCH request
49 50 51 52 53 54 |
# File 'lib/api_mapper/client.rb', line 49 def patch(path, payload) mapper = mapper(:patch, path) response = response(:patch, path, payload) map_response(mapper, response) end |
#post(path, payload) ⇒ Array, Object
Make HTTP POST request
65 66 67 68 69 70 |
# File 'lib/api_mapper/client.rb', line 65 def post(path, payload) mapper = mapper(:post, path) response = response(:post, path, payload) map_response(mapper, response) end |