class Attask::Client
lib/attask/client.rb
Public Class Methods
new(app, opts = {})
click to toggle source
# File lib/attask/client.rb, line 6 def initialize(app, opts = {}) @app = app @opts = opts @endpoint = "https://#{app}.attask-ondemand.com/attask/api/v6.0" @session_id = session_id end
Public Instance Methods
delete(object_code, object_id, params = {})
click to toggle source
# File lib/attask/client.rb, line 43 def delete(object_code, object_id, params = {}) path = mount_path(object_code, object_id) request(:delete, path, params) end
download(download_url, filename)
click to toggle source
# File lib/attask/client.rb, line 55 def download(download_url, filename) path = mount_download_path(download_url) response = request(:get, path) save_file(filename, response) end
get(object_code, object_id, params = {}, fields = [])
click to toggle source
# File lib/attask/client.rb, line 25 def get(object_code, object_id, params = {}, fields = []) params = merge_hashes(params, fields: fields.join(',')) path = mount_path(object_code, object_id) request(:get, path, params) end
get_list(object_code, ids = [], fields = [])
click to toggle source
# File lib/attask/client.rb, line 19 def get_list(object_code, ids = [], fields = []) params = merge_hashes({ id: ids.join(',') }, fields: fields.join(',')) path = mount_path(object_code, '') request(:get, path, params) end
post(object_code, object_id, params = {}, fields = [])
click to toggle source
# File lib/attask/client.rb, line 37 def post(object_code, object_id, params = {}, fields = []) params = merge_hashes(params, fields: fields.join(',')) path = mount_path(object_code, object_id) request(:post, path, params) end
put(object_code, object_id, params = {}, fields = [])
click to toggle source
# File lib/attask/client.rb, line 31 def put(object_code, object_id, params = {}, fields = []) params = merge_hashes(params, fields: fields.join(',')) path = mount_path(object_code, object_id) request(:put, path, params) end
search(object_code, params = {}, fields = [])
click to toggle source
# File lib/attask/client.rb, line 13 def search(object_code, params = {}, fields = []) params = merge_hashes(params, fields: fields.join(',')) path = mount_path(object_code, '/search') request(:get, path, params) end
upload(updates, image_path, data_format)
click to toggle source
# File lib/attask/client.rb, line 48 def upload(updates, image_path, data_format) updates[:handle] = handle(image_path, data_format) params = { updates: updates.to_json } path = mount_path('document') request(:post, path, params) end
Private Instance Methods
handle(image_path, data_format)
click to toggle source
# File lib/attask/client.rb, line 73 def handle(image_path, data_format) params = payload_file(image_path, data_format) path = mount_path('upload') request(:post, path, params)['data']['handle'] end
login()
click to toggle source
# File lib/attask/client.rb, line 87 def login params = { username: Config.username, password: Config.password } path = mount_path('login', '', true) request(:post, path, params) end
merge_hashes(*objs)
click to toggle source
# File lib/attask/client.rb, line 93 def merge_hashes(*objs) objs.inject({}) { |obj, query| query.merge(obj) }.delete_if do |_, v| v.empty? end end
mount_download_path(download_url)
click to toggle source
# File lib/attask/client.rb, line 68 def mount_download_path(download_url) s_id = @session_id "https://#{@app}.attask-ondemand.com/#{download_url}&sessionID=#{s_id}" end
mount_path(object_code, object_id = '', login_path = false)
click to toggle source
# File lib/attask/client.rb, line 63 def mount_path(object_code, object_id = '', login_path = false) return "#{@endpoint}/#{object_code}#{object_id}" if login_path "#{@endpoint}/#{object_code}#{object_id}?sessionID=#{@session_id}" end
payload_file(image_path, data_format)
click to toggle source
# File lib/attask/client.rb, line 79 def payload_file(image_path, data_format) { uploadedFile: Faraday::UploadIO.new(image_path, data_format) } end
request(method, path, params = {}, headers = {})
click to toggle source
# File lib/attask/client.rb, line 103 def request(method, path, params = {}, headers = {}) Request.new(path, @opts).send(method, '', params, headers).body end
save_file(filename, file)
click to toggle source
# File lib/attask/client.rb, line 99 def save_file(filename, file) File.open(filename, 'wb') { |f| f.write(file) } end
session_id()
click to toggle source
# File lib/attask/client.rb, line 83 def session_id login['data']['sessionID'] end