lib/sheetsu/client.rb in sheetsu-0.1.1 vs lib/sheetsu/client.rb in sheetsu-1.0.0

- old
+ new

@@ -1,31 +1,38 @@ module Sheetsu class Client - include HTTParty - def initialize(id) - @id = id - self.class.base_uri "https://sheetsu.com/apis" + def initialize(api_url, auth_credentials={}) + @api_url = Sheetsu::Util.parse_api_url(api_url) + @http_basic_auth = auth_credentials end - def get - response = self.class.get("/#{@id}") + 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 - ErrorHandler.response_code_to_exception response - response + def read(options={}) + Sheetsu::Read.new(@api_url, @http_basic_auth).rows(options) end - def get_column(name) - response = self.class.get("/#{@id}/column/#{name}") + def update(column, value, data, update_whole=false, sheet=nil) + options = { column: column, value: value, data: data, update_whole: update_whole, sheet: sheet } - ErrorHandler.response_code_to_exception response - response + 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 - def create(row) - response = self.class.post("/#{@id}", body: row.to_json, headers: { 'Content-Type' => 'application/json' }) + def delete(column, value, sheet=nil) + options = { column: column, value: value, sheet: sheet } - ErrorHandler.response_code_to_exception response - response + Sheetsu::Delete.new(@api_url, @http_basic_auth).rows(options) end + end end