Class: SupabaseApi::Client
- Inherits:
-
Object
- Object
- SupabaseApi::Client
- Includes:
- HTTParty
- Defined in:
- lib/supabase_api/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create(table_name, body) ⇒ Object
- #destroy(table_name, id) ⇒ Object
- #find(table_name, id) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #list(table_name, params = {}) ⇒ Object
- #update(table_name, id, body) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 |
# File 'lib/supabase_api/client.rb', line 22 def initialize @headers = { 'apikey': self.class.api_key, 'Authorization': "Bearer #{self.class.api_key}" } end |
Class Method Details
.api_key ⇒ Object
18 19 20 |
# File 'lib/supabase_api/client.rb', line 18 def self.api_key SupabaseApi::Config.api_key end |
.api_version ⇒ Object
14 15 16 |
# File 'lib/supabase_api/client.rb', line 14 def self.api_version SupabaseApi::Config.api_version || 'v1' end |
.base_url ⇒ Object
10 11 12 |
# File 'lib/supabase_api/client.rb', line 10 def self.base_url SupabaseApi::Config.base_url end |
Instance Method Details
#create(table_name, body) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/supabase_api/client.rb', line 42 def create(table_name, body) self.class.post( self.class.collection_endpoint(table_name), body: body.to_json, headers: @headers.merge({ 'Content-Type': 'application/json', 'Prefer': 'return=representation' }) ) end |
#destroy(table_name, id) ⇒ Object
64 65 66 67 68 |
# File 'lib/supabase_api/client.rb', line 64 def destroy(table_name, id) self.class.delete( self.class.list_endpoint(table_name, { id: id }) ) end |
#find(table_name, id) ⇒ Object
38 39 40 |
# File 'lib/supabase_api/client.rb', line 38 def find(table_name, id) list(table_name, { id: id }) end |
#list(table_name, params = {}) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/supabase_api/client.rb', line 29 def list(table_name, params = {}) self.class.get( self.class.list_endpoint(table_name, params), headers: @headers.merge({ 'Range': '0-9' }) ) end |
#update(table_name, id, body) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/supabase_api/client.rb', line 53 def update(table_name, id, body) self.class.patch( self.class.list_endpoint(table_name, { id: id }), body: body.to_json, headers: @headers.merge({ 'Content-Type': 'application/json', 'Prefer': 'return=representation' }) ) end |