Module: TableCheckApi::Client
- Defined in:
- lib/table_check_api.rb
Overview
Central HTTP client for all TableCheck API communication. Service classes (Pos::V1::Shop, etc.) delegate to these methods.
Headers can be overridden per-request to support per-call key overrides:
Client.get('/path', headers: { 'Authorization' => 'Bearer other_key' })
Class Method Summary collapse
- .default_headers ⇒ Object
- .delete(path, headers: {}) ⇒ Object
- .get(path, params: {}, headers: {}) ⇒ Object
- .post(path, params: {}, headers: {}) ⇒ Object
- .put(path, params: {}, headers: {}) ⇒ Object
Class Method Details
.default_headers ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/table_check_api.rb', line 19 def self.default_headers { 'User-Agent' => "TableCheckAPIClient-v#{TableCheckApi::VERSION}", 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{TableCheckApi.key}" }.freeze end |
.delete(path, headers: {}) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/table_check_api.rb', line 52 def self.delete(path, headers: {}) HTTParty.delete( "#{TableCheckApi.base_url}#{path}", headers: default_headers.dup.merge(headers) ) end |
.get(path, params: {}, headers: {}) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/table_check_api.rb', line 28 def self.get(path, params: {}, headers: {}) HTTParty.get( "#{TableCheckApi.base_url}#{path}", query: params, headers: default_headers.dup.merge(headers) ) end |
.post(path, params: {}, headers: {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/table_check_api.rb', line 36 def self.post(path, params: {}, headers: {}) HTTParty.post( "#{TableCheckApi.base_url}#{path}", body: params.to_json, headers: default_headers.dup.merge(headers) ) end |
.put(path, params: {}, headers: {}) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/table_check_api.rb', line 44 def self.put(path, params: {}, headers: {}) HTTParty.put( "#{TableCheckApi.base_url}#{path}", body: params.to_json, headers: default_headers.dup.merge(headers) ) end |