attask 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88ed344df13fb30c56ff6c2a2b08f087451e2655
4
- data.tar.gz: 19e3128dcfd64a64e8dc15fc6d24ecfe9f90917b
3
+ metadata.gz: 9e3a1d68670cb5fd2f28639ab038293367eaed6a
4
+ data.tar.gz: a509263ae912cd9d9f438690926c0ba37f37ffab
5
5
  SHA512:
6
- metadata.gz: aa7d63596bb8e7810d30ba6937841994a80fa7e074ca98692ba2984057f61d4edac4ecfc5888736b639ed28ea8a7bda569ffad953ac09ab526fcb7b2e85126f9
7
- data.tar.gz: ad277c829fed7b1731aee522b6191b79a6e4a5c1b929ae4ba945bfaf6ffbfa2c6f55e2e8a24bc1246b48bd34a49ae392ab6a90228df3b5fdd1a992912c59b842
6
+ metadata.gz: 288900f25fad2c60ab3fc48e6adc52c18da16738b0eb8c4f1563a690ba5bdd5a5f4616456921ef97024cae4988af3d6cadc42879a065d12d343003950700f2b1
7
+ data.tar.gz: 44911bb28f9f867c30e75960853d5f5ac99f158fdae1533505ceae2bb1a4ac9e950a89bfd5a3c8435ce000eccaab2d639ce9826221e5d1568fde74da8bafa5ca
data/README.md CHANGED
@@ -0,0 +1,83 @@
1
+ # Attask
2
+
3
+ A classe Attask::Client é a interface HTTP da Attask onde é possível fazer as requisições encontradas na [https://developers.workfront.com/api-docs/#Actions](documentação).
4
+
5
+ ## Como usar
6
+
7
+ Configure os dados de acesso
8
+
9
+ ```ruby
10
+ # Exemplo:
11
+ Attask.configure do |config|
12
+  config.username = ENV['ATTASK_USERNAME']
13
+  config.password = ENV['ATTASK_PASSWORD']
14
+ end
15
+ ```
16
+
17
+ ### Queries
18
+
19
+ **Queries aceitas:** `eq`, `ne`, `gte`, `lte`, `isnull`, `notnull` e `contains`.
20
+
21
+ Exemplo de uma query usando between:
22
+
23
+ ```ruby
24
+ require_relative 'lib/attask/client.rb'
25
+
26
+ # Setando o objeto que quero` buscar
27
+ object = 'TASK'
28
+
29
+ # Montando a query
30
+ query = {
31
+ 'plannedCompletionDate' => '$$TODAY-7',
32
+ 'plannedCompletionDate_Range' => '$$TODAY',
33
+ 'plannedCompletionDate_Mod' => 'between'
34
+ }
35
+
36
+ client = Attask::Client.new({ timeout: 120 })
37
+ client.search(object, query)
38
+ ```
39
+
40
+ ### Fields
41
+
42
+ Para cada Objeto, existem uma quantidade de campos (`fields`) que você pode obter a partir dele em seu retorno. Para saber os campos que cada objeto, entre neste [https://developers.workfront.com/api-docs/api-explorer/](link). Lembrando que atualmente utilizamos a versão 6.0 da API da attask.
43
+
44
+ Exemplo utilizando o objeto `DOCU`, solicitando o campo `downloadURL`:
45
+
46
+ ```ruby
47
+ require_relative 'lib/attask/client.rb'
48
+ # Setando o objeto que quero buscar
49
+ object = 'DOCU'
50
+
51
+ # definindo os campos que eu quero que retorne
52
+ fields = ['downloadURL']
53
+
54
+ client = Attask::Client.new({ timeout: 120 })
55
+ client.search(object, { '$$LIMIT' => 2000 }, fields)
56
+ ```
57
+
58
+ ## Upload de arquivos
59
+
60
+ ```ruby
61
+ require_relative 'lib/attask/client.rb'
62
+ client = Attask::Client.new
63
+
64
+ filename = 'teste.txt'
65
+ description = 'descricao'
66
+ object_code = 'TASK'
67
+ object_id = '586ab38f001b36bfbb586053760aec3d'
68
+
69
+ # Crie um handle
70
+ handle = client.handle("./#{filename}", 'text/plain')
71
+
72
+ # Com o handle em mãos, faca a requisição para envio de um documento
73
+
74
+ params = {
75
+ description: description,
76
+ docObjCode: object_code,
77
+ objID: object_id,
78
+ handle: handle,
79
+ name: filename
80
+ }.to_json
81
+
82
+ client.upload(params)
83
+ ```
data/lib/attask/client.rb CHANGED
@@ -4,10 +4,10 @@
4
4
  module Attask
5
5
  # lib/attask/client.rb
6
6
  class Client
7
- ENDPOINT = 'https://fcbbrasil.attask-ondemand.com/attask/api/v6.0'
8
-
9
- def initialize(opts = {})
7
+ def initialize(app, opts = {})
8
+ @app = app
10
9
  @opts = opts
10
+ @endpoint = "https://#{app}.attask-ondemand.com/attask/api/v6.0"
11
11
  @session_id = session_id
12
12
  end
13
13
 
@@ -60,10 +60,19 @@ module Attask
60
60
  request(:post, path)
61
61
  end
62
62
 
63
+ def download(download_url, filename, save_to)
64
+ params = @session_id
65
+ s_id = @session_id['sessionID']
66
+ path =
67
+ "https://#{@app}.attask-ondemand.com/#{download_url}&sessionID=#{s_id}"
68
+ response = request(:get, path)
69
+ save_file(filename, response)
70
+ end
71
+
63
72
  private
64
73
 
65
74
  def mount_path(object_code, object_id = '')
66
- "#{ENDPOINT}/#{object_code}#{object_id}"
75
+ "#{@endpoint}/#{object_code}#{object_id}"
67
76
  end
68
77
 
69
78
  def session_id
@@ -83,6 +92,10 @@ module Attask
83
92
  end
84
93
  end
85
94
 
95
+ def save_file(filename, file)
96
+ File.open(filename, 'wb') { |f| f.write(file) }
97
+ end
98
+
86
99
  def request(method, path, params = {}, headers = {})
87
100
  Request.new(path, @opts).send(method, '', params, headers).body
88
101
  end
@@ -35,11 +35,9 @@ module Attask
35
35
 
36
36
  def make_request(method, path, params = {}, headers = {})
37
37
  response = @conn.send(method, path, params, headers)
38
- if response.headers['Content-Type'].match?(%r{^application/json})
39
- Response.new(Oj.load(response.body))
40
- else
41
- Response.new(response.body)
42
- end
38
+ body = response.body
39
+ return Response.new(body) if response.headers['Content-Type'].nil?
40
+ Response.new(Oj.load(body))
43
41
  end
44
42
  end
45
43
  end
@@ -3,5 +3,5 @@
3
3
 
4
4
  module Attask
5
5
  # The current Attask version.
6
- VERSION = '0.0.1'
6
+ VERSION = '0.0.2'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attask
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Henrique Bruce