class Resource
Public Class Methods
new(endpoint, client)
click to toggle source
# File lib/spos-client/resource.rb, line 2 def initialize(endpoint, client) @endpoint = endpoint @client = client end
Public Instance Methods
custom(path, body = nil, opts = nil, method = nil)
click to toggle source
# File lib/spos-client/resource.rb, line 38 def custom(path, body = nil, opts = nil, method = nil) if(body.is_a?(OpenStruct)) body = body.to_h end @client.request(path, body, opts, method) end
get(opts = nil)
click to toggle source
# File lib/spos-client/resource.rb, line 7 def get(opts = nil) if(!opts.nil? && opts.has_key?("id")) getById(opts[:id]) else getMany(opts) end end
getById(id, filled = false)
click to toggle source
# File lib/spos-client/resource.rb, line 15 def getById(id, filled = false) fill = filled ? "/filled" : "" @client.request("#{@endpoint}/#{id}#{fill}") end
getMany(opts)
click to toggle source
# File lib/spos-client/resource.rb, line 20 def getMany(opts) @client.request(@endpoint, nil, opts) end
save(body)
click to toggle source
# File lib/spos-client/resource.rb, line 24 def save(body) if(body.is_a?(OpenStruct)) body = body.to_h end if(body.has_key?("id")) path = "#{@endpoint}/#{body['id']}" else path = @endpoint end @client.request(path, body) end