Class: Sheetsu::Client

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



4
5
6
7
# File 'lib/sheetsu/client.rb', line 4

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



9
10
11
12
13
14
15
# File 'lib/sheetsu/client.rb', line 9

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



31
32
33
34
35
# File 'lib/sheetsu/client.rb', line 31

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



17
18
19
# File 'lib/sheetsu/client.rb', line 17

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

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



21
22
23
24
25
26
27
28
29
# File 'lib/sheetsu/client.rb', line 21

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