module JSONAPI::SimpleClient
Constants
- VERSION
Public Class Methods
create(url, headers = {}, payload = {})
click to toggle source
@see jsonapi.org/format/#crud-creating @param url [String] @param headers [Hash] @param payload [Hash] @return [JSONAPI::Types::Success, JSONAPI::Types::Document, JSONAPI::Types::Failure]
# File lib/jsonapi/simple_client.rb, line 18 def self.create(url, headers = {}, payload = {}) response = Request.new(url, headers).post(payload) case response.status when 201 JSONAPI::Types::Success.parse(response.to_s) when 202, 204 JSONAPI::Types::Document.parse(response.to_s) when 400, 422 JSONAPI::Types::Failure.parse(response.to_s) end end
delete(url, headers = {})
click to toggle source
@see jsonapi.org/format/#crud-deleting @param url [String] @param headers [Hash] @return [JSONAPI::Types::Info, JSONAPI::Types::Document, JSONAPI::Types::Failure]
# File lib/jsonapi/simple_client.rb, line 53 def self.delete(url, headers = {}) response = Request.new(url, headers).delete case response.status when 200 JSONAPI::Types::Info.parse(response.to_s) when 202, 204 JSONAPI::Types::Document.parse(response.to_s) when 400, 422 JSONAPI::Types::Failure.parse(response.to_s) end end
fetch(url, headers = {}, params = {})
click to toggle source
@see jsonapi.org/format/#fetching @param url [String] @param headers [Hash] @param params [Hash] @return [JSONAPI::Types::Success, JSONAPI::Types::Failure]
# File lib/jsonapi/simple_client.rb, line 71 def self.fetch(url, headers = {}, params = {}) response = Request.new(url, headers).get(params) case response.status when 200 JSONAPI::Types::Success.parse(response.to_s) when 400 JSONAPI::Types::Failure.parse(response.to_s) end end
update(url, headers = {}, payload = {})
click to toggle source
@see jsonapi.org/format/#crud-updating @param url [String] @param headers [Hash] @param payload [Hash] @return [JSONAPI::Types::Success, JSONAPI::Types::Document, JSONAPI::Types::Failure]
# File lib/jsonapi/simple_client.rb, line 36 def self.update(url, headers = {}, payload = {}) response = Request.new(url, headers).patch(payload) case response.status when 200 JSONAPI::Types::Success.parse(response.to_s) when 202, 204 JSONAPI::Types::Document.parse(response.to_s) when 400, 422 JSONAPI::Types::Failure.parse(response.to_s) end end