class Layer::Client
Attributes
app_id[W]
token[W]
Public Class Methods
app_id()
click to toggle source
# File lib/layer/client.rb, line 13 def app_id @app_id || ENV['LAYER_APP_ID'] end
authenticate(app_id = self.app_id, &block)
click to toggle source
# File lib/layer/client.rb, line 29 def authenticate(app_id = self.app_id, &block) Layer::Client::REST.new(app_id, &block) end
configure() { |self| ... }
click to toggle source
# File lib/layer/client.rb, line 21 def configure yield self end
normalize_id(id)
click to toggle source
# File lib/layer/client.rb, line 25 def normalize_id(id) id.to_s.split('/').last end
token()
click to toggle source
# File lib/layer/client.rb, line 17 def token @token ||= ENV['LAYER_PLATFORM_TOKEN'] end
Public Instance Methods
delete(*args)
click to toggle source
# File lib/layer/client.rb, line 52 def delete(*args) request(:delete, *args) end
get(*args)
click to toggle source
# File lib/layer/client.rb, line 34 def get(*args) request(:get, *args) end
head(*args)
click to toggle source
# File lib/layer/client.rb, line 56 def head(*args) request(:head, *args) end
options(*args)
click to toggle source
# File lib/layer/client.rb, line 60 def options(*args) request(:options, *args) end
patch(url, payload = {}, headers = {})
click to toggle source
# File lib/layer/client.rb, line 42 def patch(url, payload = {}, headers = {}) headers['Content-Type'] = 'application/vnd.layer-patch+json' request(:patch, url, payload, headers) end
post(*args)
click to toggle source
# File lib/layer/client.rb, line 38 def post(*args) request(:post, *args) end
put(*args)
click to toggle source
# File lib/layer/client.rb, line 48 def put(*args) request(:put, *args) end
Private Instance Methods
request(method, url, payload = {}, headers = {})
click to toggle source
# File lib/layer/client.rb, line 66 def request(method, url, payload = {}, headers = {}) url = "https://api.layer.com#{url}" unless url.start_with?('https://api.layer.com') headers = { 'Accept' => 'application/vnd.layer+json; version=1.0', 'Content-Type' => 'application/json', 'If-None-Match' => SecureRandom.uuid }.merge(headers) payload = payload.to_json response = RestClient::Request.execute(method: method, url: url, payload: payload, headers: headers) response.empty? ? nil : JSON.parse(response) rescue RestClient::Exception raise Layer::Exceptions.build_exception($!) end