class Core::Client::V1::Base
Public Class Methods
all()
click to toggle source
# File lib/core/client/v1/base.rb, line 18 def all where({}) end
client()
click to toggle source
# File lib/core/client/v1/base.rb, line 11 def client @client ||= RestClient::Resource.new( "#{ENV['CORE_URL'] || 'https://core.able.co'}/api", headers: { "Authorization" => "Bearer #{ENV['CORE_API_TOKEN']}" } ) end
count()
click to toggle source
# File lib/core/client/v1/base.rb, line 30 def count all.count end
find(id)
click to toggle source
# File lib/core/client/v1/base.rb, line 34 def find(id) new(get("#{table_name}/#{id}")) end
first()
click to toggle source
# File lib/core/client/v1/base.rb, line 22 def first all.first end
last()
click to toggle source
# File lib/core/client/v1/base.rb, line 26 def last all.last end
where(conditions)
click to toggle source
# File lib/core/client/v1/base.rb, line 38 def where(conditions) get(table_name, conditions).map do |item| new(item) end end
Private Class Methods
get(path, params = {})
click to toggle source
# File lib/core/client/v1/base.rb, line 46 def get(path, params = {}) suburl = "#{path}?#{Rack::Utils.build_query(params)}" JSON.parse(client[suburl].get.body) end
table_name()
click to toggle source
# File lib/core/client/v1/base.rb, line 52 def table_name ActiveSupport::Inflector.tableize(self.name).split("/").pop end