class Juno::Resource
Public Class Methods
delete(path)
click to toggle source
# File lib/juno/resource.rb, line 20 def delete(path) req(:delete, path) end
get(path)
click to toggle source
# File lib/juno/resource.rb, line 16 def get(path) req(:get, path) end
patch(path, body)
click to toggle source
# File lib/juno/resource.rb, line 12 def patch(path, body) req(:patch, path, body) end
post(path, body)
click to toggle source
# File lib/juno/resource.rb, line 8 def post(path, body) req(:post, path, body) end
put(path, body = {})
click to toggle source
# File lib/juno/resource.rb, line 24 def put(path, body = {}) req(:put, path, body) end
Private Class Methods
endpoint()
click to toggle source
# File lib/juno/resource.rb, line 42 def endpoint Juno.configuration.endpoint_for(:resource) end
headers()
click to toggle source
# File lib/juno/resource.rb, line 46 def headers { 'Content-Type': 'application/json;charset=UTF-8', 'X-Resource-Token': Juno.configuration.private_token, 'Authorization': "Bearer #{Juno::Authorization.token}", 'X-Api-Version': 2 } end
req(method, path, body = {}, fallback = true)
click to toggle source
# File lib/juno/resource.rb, line 30 def req(method, path, body = {}, fallback = true) res = HTTP.headers(headers).send(method, "#{endpoint}#{path}", json: body) if res.code.eql?(401) && fallback Juno::Authorization.refresh_token req(method, path, body, false) else body = res.code.eql?(204) ? '' : JSON.parse(res.body.to_s) { body: body, code: res.code } end end