Class: Pagaris::Client
- Inherits:
-
Object
- Object
- Pagaris::Client
- Defined in:
- lib/pagaris/client.rb
Overview
In charge of the HTTP calls to the API
Constant Summary collapse
- DOMAIN =
ENV.fetch('PAGARIS_DOMAIN', 'https://pagaris.com')
- API_PREFIX =
'/api/v1/'
- BASE_URL =
DOMAIN + API_PREFIX
Class Method Summary collapse
-
.get(path) ⇒ Hash
Makes a GET HTTP request to the given ‘path`.
-
.post(path, body = nil) ⇒ Hash
Makes a POST HTTP request to the given ‘path`, with the given `body`.
-
.put(path, body = nil) ⇒ Hash
Makes a PUT HTTP request to the given ‘path`, with the given `body`.
Class Method Details
.get(path) ⇒ Hash
Makes a GET HTTP request to the given ‘path`
27 28 29 30 31 |
# File 'lib/pagaris/client.rb', line 27 def self.get(path) response = HTTParty.get(BASE_URL + path, (path, 'GET')) throw_error(response) unless [200, 201].include?(response.code) JSON.parse(response.body, symbolize_names: true) end |
.post(path, body = nil) ⇒ Hash
Makes a POST HTTP request to the given ‘path`, with the given `body`
49 50 51 52 53 54 55 56 |
# File 'lib/pagaris/client.rb', line 49 def self.post(path, body = nil) response = HTTParty.post( BASE_URL + path, (path, 'POST', body) ) throw_error(response) unless [200, 201].include?(response.code) JSON.parse(response.body, symbolize_names: true) end |
.put(path, body = nil) ⇒ Hash
Makes a PUT HTTP request to the given ‘path`, with the given `body`
74 75 76 77 78 79 80 81 |
# File 'lib/pagaris/client.rb', line 74 def self.put(path, body = nil) response = HTTParty.put( BASE_URL + path, (path, 'PUT', body) ) throw_error(response) unless [200, 201].include?(response.code) JSON.parse(response.body, symbolize_names: true) end |