attask 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +15 -0
- data/README.md +0 -0
- data/lib/attask.rb +23 -0
- data/lib/attask/client.rb +90 -0
- data/lib/attask/config.rb +12 -0
- data/lib/attask/errors.rb +8 -0
- data/lib/attask/errors/attask_error.rb +11 -0
- data/lib/attask/request.rb +45 -0
- data/lib/attask/version.rb +7 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88ed344df13fb30c56ff6c2a2b08f087451e2655
|
4
|
+
data.tar.gz: 19e3128dcfd64a64e8dc15fc6d24ecfe9f90917b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa7d63596bb8e7810d30ba6937841994a80fa7e074ca98692ba2984057f61d4edac4ecfc5888736b639ed28ea8a7bda569ffad953ac09ab526fcb7b2e85126f9
|
7
|
+
data.tar.gz: ad277c829fed7b1731aee522b6191b79a6e4a5c1b929ae4ba945bfaf6ffbfa2c6f55e2e8a24bc1246b48bd34a49ae392ab6a90228df3b5fdd1a992912c59b842
|
data/Gemfile
ADDED
data/README.md
ADDED
File without changes
|
data/lib/attask.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'faraday'
|
6
|
+
require 'json'
|
7
|
+
require 'oj'
|
8
|
+
require 'patron'
|
9
|
+
|
10
|
+
require 'attask/client'
|
11
|
+
require 'attask/config'
|
12
|
+
require 'attask/errors'
|
13
|
+
require 'attask/request'
|
14
|
+
require 'attask/version'
|
15
|
+
|
16
|
+
require 'attask/errors/attask_error'
|
17
|
+
|
18
|
+
# lib/attask.rb
|
19
|
+
module Attask
|
20
|
+
def self.configure
|
21
|
+
yield Config
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Attask
|
5
|
+
# lib/attask/client.rb
|
6
|
+
class Client
|
7
|
+
ENDPOINT = 'https://fcbbrasil.attask-ondemand.com/attask/api/v6.0'
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
@opts = opts
|
11
|
+
@session_id = session_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def search(object_code, params = {}, fields = [])
|
15
|
+
params = merge_hashes(@session_id, params, fields: fields.join(','))
|
16
|
+
path = mount_path(object_code, '/search')
|
17
|
+
request(:get, path, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_list(object_code, ids = [], fields = [])
|
21
|
+
fields = fields.join(',')
|
22
|
+
params = merge_hashes(@session_id, { id: ids.join(',') }, fields: fields)
|
23
|
+
path = mount_path(object_code, '')
|
24
|
+
request(:get, path, params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(object_code, object_id, params = {}, fields = [])
|
28
|
+
params = merge_hashes(@session_id, params, fields: fields.join(','))
|
29
|
+
path = mount_path(object_code, object_id)
|
30
|
+
request(:get, path, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def put(object_code, object_id, params = {}, fields = [])
|
34
|
+
params = merge_hashes(@session_id, params, fields: fields.join(','))
|
35
|
+
path = mount_path(object_code, object_id)
|
36
|
+
request(:put, path, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def post(object_code, object_id, params = {}, fields = [])
|
40
|
+
params = merge_hashes(@session_id, params, fields: fields.join(','))
|
41
|
+
path = mount_path(object_code, object_id)
|
42
|
+
request(:post, path, params)
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete(object_code, object_id, params)
|
46
|
+
path = mount_path(object_code, object_id)
|
47
|
+
request(:delete, path, params)
|
48
|
+
end
|
49
|
+
|
50
|
+
def handle(image_path, multipart_data_format)
|
51
|
+
upload_io = Faraday::UploadIO.new(image_path, multipart_data_format)
|
52
|
+
params = { uploadedFile: upload_io }
|
53
|
+
path = mount_path("upload?sessionID=#{session_id['sessionID']}")
|
54
|
+
request(:post, path, params)['data']['handle']
|
55
|
+
end
|
56
|
+
|
57
|
+
def upload(updates)
|
58
|
+
s_id = @session_id['sessionID']
|
59
|
+
path = mount_path("document?sessionID=#{s_id}&updates=#{updates}")
|
60
|
+
request(:post, path)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def mount_path(object_code, object_id = '')
|
66
|
+
"#{ENDPOINT}/#{object_code}#{object_id}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def session_id
|
70
|
+
{ 'sessionID' => login['data']['sessionID'] }
|
71
|
+
end
|
72
|
+
|
73
|
+
def login
|
74
|
+
config = Config
|
75
|
+
params = { username: config.username, password: config.password }
|
76
|
+
path = mount_path('login', '')
|
77
|
+
request(:post, path, params)
|
78
|
+
end
|
79
|
+
|
80
|
+
def merge_hashes(*objs)
|
81
|
+
objs.inject({}) { |obj, query| query.merge(obj) }.delete_if do |_, v|
|
82
|
+
v.empty?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def request(method, path, params = {}, headers = {})
|
87
|
+
Request.new(path, @opts).send(method, '', params, headers).body
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Attask
|
5
|
+
# lib/attask/request.rb
|
6
|
+
class Request
|
7
|
+
Response = Struct.new(:body)
|
8
|
+
|
9
|
+
def initialize(endpoint, opts = {})
|
10
|
+
@conn = Faraday::Connection.new(endpoint) do |faraday|
|
11
|
+
faraday.request :multipart
|
12
|
+
faraday.request :url_encoded
|
13
|
+
faraday.adapter :patron
|
14
|
+
faraday.options.merge!(opts)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(path, params = {}, headers = {})
|
19
|
+
make_request(:get, path, params, headers)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(path, params = {}, headers = {})
|
23
|
+
make_request(:post, path, params, headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(path, params = {}, headers = {})
|
27
|
+
make_request(:put, path, params, headers)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(path, params = {}, headers = {})
|
31
|
+
make_request(:delete, path, params, headers)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def make_request(method, path, params = {}, headers = {})
|
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
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: attask
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paulo Henrique Bruce
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oj
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.18'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.18'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: patron
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.5'
|
83
|
+
description: This gem is prepared to integrate with Attask
|
84
|
+
email:
|
85
|
+
- brucepaulohenrique@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- README.md
|
92
|
+
- lib/attask.rb
|
93
|
+
- lib/attask/client.rb
|
94
|
+
- lib/attask/config.rb
|
95
|
+
- lib/attask/errors.rb
|
96
|
+
- lib/attask/errors/attask_error.rb
|
97
|
+
- lib/attask/request.rb
|
98
|
+
- lib/attask/version.rb
|
99
|
+
homepage: https://github.com/phbruce/attask
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.3.6
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.6.8
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Ruby interface for the Attask API
|
123
|
+
test_files: []
|