Class: Sheetsu::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sheetsu.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_url, auth_credentials = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
# File 'lib/sheetsu.rb', line 10

def initialize(api_url, auth_credentials={})
  @api_url = Sheetsu::Util.parse_api_url(api_url)
  @http_basic_auth = auth_credentials
end

Instance Method Details

#create(data, sheet = nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/sheetsu.rb', line 15

def create(data, sheet=nil)
  if data.is_a?(Hash)
    Sheetsu::Create.new(@api_url, @http_basic_auth).row(data, { sheet: sheet })
  elsif data.is_a?(Array)
    Sheetsu::Create.new(@api_url, @http_basic_auth).rows(data, { sheet: sheet })
  end 
end

#delete(column, value, sheet = nil) ⇒ Object



37
38
39
40
41
# File 'lib/sheetsu.rb', line 37

def delete(column, value, sheet=nil)
  options = { column: column, value: value, sheet: sheet }

  Sheetsu::Delete.new(@api_url, @http_basic_auth).rows(options)
end

#read(options = {}) ⇒ Object



23
24
25
# File 'lib/sheetsu.rb', line 23

def read(options={})
  Sheetsu::Read.new(@api_url, @http_basic_auth).rows(options)
end

#update(column, value, data, update_whole = false, sheet = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/sheetsu.rb', line 27

def update(column, value, data, update_whole=false, sheet=nil)
  options = { column: column, value: value, data: data, update_whole: update_whole, sheet: sheet }

  if update_whole
    Sheetsu::Update.new(@api_url, @http_basic_auth).put(options)
  else
    Sheetsu::Update.new(@api_url, @http_basic_auth).patch(options)
  end
end