Class: NinjaVan::Request
- Inherits:
-
Object
- Object
- NinjaVan::Request
- Defined in:
- lib/ninja_van/request.rb
Class Method Summary collapse
- .delete(endpoint, params = {}) ⇒ Object
- .get(endpoint, params = {}) ⇒ Object
- .post(endpoint, params = {}) ⇒ Object
- .post_without_token(endpoint, params = {}) ⇒ Object
Class Method Details
.delete(endpoint, params = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ninja_van/request.rb', line 36 def self.delete(endpoint, params={}) full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}" response = Http.headers(content_type: 'application/json', accept: 'application/json') .auth("Bearer #{NinjaVan.setup.get_token_from_cache}") .delete(full_endpoint, params: params) raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403 raise NinjaVan::NotFoundError.new(response.parse) if response.code == 404 raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500 response.parse end |
.get(endpoint, params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ninja_van/request.rb', line 25 def self.get(endpoint, params={}) full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}" response = Http.headers(content_type: 'application/json', accept: 'application/json') .auth("Bearer #{NinjaVan.setup.get_token_from_cache}") .get(full_endpoint, params: params) raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403 raise NinjaVan::NotFoundError.new(response.parse) if response.code == 404 raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500 response.parse end |
.post(endpoint, params = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/ninja_van/request.rb', line 4 def self.post(endpoint, params={}) full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}" response = Http.headers(content_type: 'application/json', accept: 'application/json') .auth("Bearer #{NinjaVan.setup.get_token_from_cache}") .post(full_endpoint, json: params) raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403 raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500 raise NinjaVan::RequestError.new(response.parse) if response.parse.is_a?(Hash) && !response.parse['error'].nil? response.parse end |
.post_without_token(endpoint, params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ninja_van/request.rb', line 15 def self.post_without_token(endpoint, params={}) full_endpoint = "#{NinjaVan.setup.require!(:domain)}#{endpoint}" response = Http.headers(content_type: 'application/json', accept: 'application/json') .post(full_endpoint, json: params) raise NinjaVan::ForbiddenError.new(full_endpoint) if response.code == 403 raise NinjaVan::ServerError.new(full_endpoint) if response.code == 500 raise NinjaVan::RequestError.new(response.parse) unless response.parse['error'].nil? response.parse end |