vimaly 0.2.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +62 -3
- data/lib/vimaly.rb +1 -0
- data/lib/vimaly/client.rb +51 -25
- data/lib/vimaly/exceptions.rb +3 -0
- data/lib/vimaly/ticket.rb +23 -9
- data/lib/vimaly/version.rb +1 -1
- data/vimaly.gemspec +3 -2
- metadata +30 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42d7553c8960f23093c3fd2deafc378f7970fc0b62d35ceafc94b42a0473c970
|
4
|
+
data.tar.gz: a8ddca4b4d5421ad916b69d11e9d69e1fb48fe0b1bdca933ff70162a56d170f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dd8df6c3e2fe09a36ff2be2f48ed21a2d8a7338cf69e4c17b407c5a51af0828bb5ec1c072bc1886a853b6fa8e4c551e3fa708b9f11cc6c60a984e90bcf2dd98
|
7
|
+
data.tar.gz: a593b96cd95a00e11712080109af2d9e35668ee2cdaeafc833f8703eb8647a374ded79ff97413c9af9b286d7b7df0fa4e2111ca6897a4d0a3cd4fb6a7b0219f0
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,71 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.1.0
|
4
4
|
|
5
|
-
|
5
|
+
* add support for searching tickets [#19](https://github.com/sharesight/vimaly/pull/19)
|
6
|
+
|
7
|
+
## 1.0.2
|
8
|
+
|
9
|
+
* Fix unfriendly filenames not attaching to Vimaly tickets [#17](https://github.com/sharesight/vimaly/pull/17)
|
10
|
+
|
11
|
+
## 1.0.1
|
12
|
+
|
13
|
+
* Update for Ruby 2.6.3 compatibility.
|
14
|
+
|
15
|
+
## 1.0.0
|
16
|
+
|
17
|
+
* allow adding attachments with providing a content-type [#15](https://github.com/sharesight/vimaly/pull/15)
|
18
|
+
|
19
|
+
## 0.5.3
|
20
|
+
|
21
|
+
* add support for Ruby `2.5.3` [#14](https://github.com/sharesight/vimaly/pull/14)
|
22
|
+
|
23
|
+
## 0.5.2
|
24
|
+
|
25
|
+
* return the correct ticket-id after creating a ticket [#13](https://github.com/sharesight/vimaly/pull/13)
|
26
|
+
|
27
|
+
## 0.5.1
|
28
|
+
|
29
|
+
* return the ticket-id after updating a ticket [#12](https://github.com/sharesight/vimaly/pull/12)
|
30
|
+
|
31
|
+
## 0.5.0
|
32
|
+
|
33
|
+
* add support for adding attachments to tickets [#11](https://github.com/sharesight/vimaly/pull/11)
|
34
|
+
|
35
|
+
## 0.4.0
|
36
|
+
|
37
|
+
* support API version 2 [#10](https://github.com/sharesight/vimaly/pull/10)
|
38
|
+
|
39
|
+
## 0.3.1
|
40
|
+
|
41
|
+
* use Ruby `2.5.1` [#9](https://github.com/sharesight/vimaly/pull/9)
|
42
|
+
|
43
|
+
## 0.3.0
|
44
|
+
|
45
|
+
* ask for more bins [#8](https://github.com/sharesight/vimaly/pull/8)
|
46
|
+
|
47
|
+
## 0.2.5
|
48
|
+
|
49
|
+
* Ruby 2.5.0 support
|
50
|
+
|
51
|
+
## 0.2.4
|
52
|
+
|
53
|
+
* Ruby 2.4.2 support
|
54
|
+
|
55
|
+
## 0.2.3
|
56
|
+
|
57
|
+
* Ruby 2.4.1 support
|
58
|
+
|
59
|
+
## 0.2.2
|
60
|
+
|
61
|
+
* handle Bad Gateway 502 errors
|
62
|
+
|
63
|
+
## 0.2.1
|
64
|
+
|
65
|
+
* Fix creation of duplicated tickets (due to caching)
|
6
66
|
|
7
67
|
## 0.2.0
|
8
68
|
|
9
69
|
* Support the ability to retrieve all tickets for a bin, and to run a matcher through this
|
10
70
|
* Support custom fields on ticket
|
11
71
|
* Add an integration test (site configured)
|
12
|
-
|
data/lib/vimaly.rb
CHANGED
data/lib/vimaly/client.rb
CHANGED
@@ -8,10 +8,10 @@ module Vimaly
|
|
8
8
|
VIMALY_ROOT_URL = "https://o1.vimaly.com"
|
9
9
|
CUSTOM_FIELD_TYPES = [::NilClass, ::String, ::Float, ::Integer, ::Array, ::Date]
|
10
10
|
|
11
|
-
def initialize(company_id,
|
11
|
+
def initialize(company_id, user_credentials: nil, auth_key: nil, logger: nil)
|
12
12
|
@company_id = company_id
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@user_credentials = user_credentials
|
14
|
+
@auth_key = auth_key
|
15
15
|
@logger = logger
|
16
16
|
|
17
17
|
@bin_tickets = {}
|
@@ -27,11 +27,12 @@ module Vimaly
|
|
27
27
|
merge(others)
|
28
28
|
)
|
29
29
|
|
30
|
+
ticket_id = next_ticket_id
|
30
31
|
ticket_to_json = ticket.to_json(custom_field_name_map)
|
31
|
-
response = post("/tickets/#{
|
32
|
+
response = post("/tickets/#{ticket_id}", ticket_to_json)
|
32
33
|
case response.status
|
33
34
|
when 200..299
|
34
|
-
|
35
|
+
ticket_id
|
35
36
|
else
|
36
37
|
log_warn "status: #{response.status}"
|
37
38
|
log_warn " #{response.inspect}"
|
@@ -44,12 +45,33 @@ module Vimaly
|
|
44
45
|
|
45
46
|
response = put("/tickets/#{id}", ticket.to_json(custom_field_name_map, true))
|
46
47
|
case response.status
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
when 200..299
|
49
|
+
id
|
50
|
+
else
|
51
|
+
log_warn "status: #{response.status}"
|
52
|
+
log_warn " #{response.inspect}"
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def search_tickets(query_string, state: 'active')
|
58
|
+
ticket_type_map = Hash[ticket_types.map { |t| [t.id, t] }]
|
59
|
+
bin_map = Hash[bins.map { |b| [b.id, b] }]
|
60
|
+
|
61
|
+
get("/ticket-search?text=#{query_string}&state=#{state}").map do |ticket_data|
|
62
|
+
Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_attachment(ticket_id, file_name, file_content, request_options={})
|
67
|
+
response = post("/tickets/#{ticket_id}/attachments?name=#{CGI.escape(file_name)}", file_content, request_options)
|
68
|
+
case response.status
|
69
|
+
when 200..299
|
70
|
+
true
|
71
|
+
else
|
72
|
+
log_warn "status: #{response.status}"
|
73
|
+
log_warn " #{response.inspect}"
|
74
|
+
false
|
53
75
|
end
|
54
76
|
end
|
55
77
|
|
@@ -64,7 +86,7 @@ module Vimaly
|
|
64
86
|
|
65
87
|
def bins
|
66
88
|
@bins ||= begin
|
67
|
-
get('/bins').map do |bin_data|
|
89
|
+
get('/bins?max-results=500').map do |bin_data|
|
68
90
|
Bin.new(bin_data['_id'], bin_data['name'])
|
69
91
|
end
|
70
92
|
end
|
@@ -97,10 +119,8 @@ module Vimaly
|
|
97
119
|
ticket_type_map = Hash[ticket_types.map { |t| [t.id, t] }]
|
98
120
|
bin_map = Hash[bins.map { |b| [b.id, b] }]
|
99
121
|
|
100
|
-
|
101
|
-
|
102
|
-
Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
|
103
|
-
end
|
122
|
+
get("/tickets?bin_id=#{bin_id}").map do |ticket_data|
|
123
|
+
Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
|
104
124
|
end
|
105
125
|
end
|
106
126
|
|
@@ -140,34 +160,40 @@ module Vimaly
|
|
140
160
|
end
|
141
161
|
|
142
162
|
def get(api_path)
|
143
|
-
response = faraday.get("/rest/
|
144
|
-
request
|
163
|
+
response = faraday.get("/rest/2/#{@company_id}#{api_path}") do |request|
|
164
|
+
update_request_headers(request)
|
145
165
|
end
|
146
166
|
unless response.success?
|
147
|
-
raise("Vimaly #{api_path} call failed")
|
167
|
+
raise Vimaly::ConnectionError.new("Vimaly #{api_path} call failed with response #{response.status}")
|
148
168
|
end
|
149
169
|
JSON.parse(response.body)
|
150
170
|
end
|
151
171
|
|
152
|
-
def post(api_path,
|
153
|
-
faraday.post("/rest/
|
154
|
-
request
|
172
|
+
def post(api_path, content, headers={})
|
173
|
+
faraday.post("/rest/2/#{@company_id}#{api_path}", content) do |request|
|
174
|
+
update_request_headers(request, headers)
|
155
175
|
end
|
156
176
|
end
|
157
177
|
|
158
178
|
def put(api_path, json)
|
159
|
-
faraday.put("/rest/
|
160
|
-
request
|
179
|
+
faraday.put("/rest/2/#{@company_id}#{api_path}", json) do |request|
|
180
|
+
update_request_headers(request)
|
161
181
|
end
|
162
182
|
end
|
163
183
|
|
164
184
|
def faraday
|
165
185
|
@faraday ||= Faraday.new(VIMALY_ROOT_URL).tap do |connection|
|
166
|
-
connection.basic_auth(@username, @password)
|
186
|
+
connection.basic_auth(@user_credentials[:username], @user_credentials[:password]) if @user_credentials
|
167
187
|
connection.request(:json)
|
168
188
|
end
|
169
189
|
end
|
170
190
|
|
191
|
+
def update_request_headers(request, headers={})
|
192
|
+
request.headers.update({ accept: 'application/json', content_type: 'application/json' })
|
193
|
+
request.headers.update({ authorization: "bearer #{@auth_key}" }) if @auth_key
|
194
|
+
request.headers.update(headers)
|
195
|
+
end
|
196
|
+
|
171
197
|
def log_warn(s)
|
172
198
|
@logger.warn(s) if @logger
|
173
199
|
end
|
data/lib/vimaly/ticket.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
require "active_support/core_ext/hash/indifferent_access"
|
2
|
+
|
1
3
|
module Vimaly
|
2
4
|
class Ticket
|
3
5
|
|
4
6
|
# title, description, format, ticket_type, bin, id=nil
|
5
7
|
def initialize(*params)
|
6
8
|
if params.first.is_a?(Hash)
|
7
|
-
@ticket_fields = params.first
|
9
|
+
@ticket_fields = HashWithIndifferentAccess.new(params.first)
|
8
10
|
else
|
9
|
-
@ticket_fields =
|
11
|
+
@ticket_fields = HashWithIndifferentAccess.new
|
10
12
|
[:title, :description, :format, :ticket_type, :bin, :id].each_with_index do |param_key, idx|
|
11
13
|
break if idx>=params.size
|
12
14
|
@ticket_fields[param_key] = params[idx]
|
@@ -44,19 +46,22 @@ module Vimaly
|
|
44
46
|
def to_vimaly(custom_field_name_map, for_update=false)
|
45
47
|
vimaly_fields = Hash[@ticket_fields.map do |field_name, field_value|
|
46
48
|
case(field_name)
|
47
|
-
when
|
49
|
+
when 'id'
|
50
|
+
nil # id should not be in ticket body
|
51
|
+
when 'format'
|
48
52
|
['rtformat', field_value]
|
49
|
-
when
|
53
|
+
when 'title'
|
50
54
|
['name', field_value]
|
51
|
-
when
|
55
|
+
when 'description'
|
52
56
|
['description', normalise(field_value)]
|
53
|
-
when
|
57
|
+
when 'ticket_type'
|
54
58
|
['ticketType_id', field_value.id]
|
55
|
-
when
|
59
|
+
when 'bin'
|
56
60
|
['bin_id', field_value.id]
|
57
61
|
else
|
58
62
|
if for_update
|
59
|
-
fdef = custom_field_name_map[field_name
|
63
|
+
fdef = custom_field_name_map[field_name]
|
64
|
+
raise "Field type #{field_name} is not a defined custom or standard field in Vimaly" unless fdef
|
60
65
|
["customFields.#{fdef[:id]}", cast_to_vimaly(field_value, fdef[:type])]
|
61
66
|
else
|
62
67
|
nil
|
@@ -66,7 +71,7 @@ module Vimaly
|
|
66
71
|
]
|
67
72
|
|
68
73
|
unless for_update
|
69
|
-
custom_fields = @ticket_fields.select {|fn, _v| ![:format, :title, :description, :ticket_type, :bin].include?(fn) }
|
74
|
+
custom_fields = @ticket_fields.select {|fn, _v| ![:format, :title, :description, :ticket_type, :bin].include?(fn.to_sym) }
|
70
75
|
if custom_fields && !custom_fields.empty?
|
71
76
|
vimaly_fields['customFields'] =
|
72
77
|
Hash[custom_fields.map do |field_name, field_value|
|
@@ -98,6 +103,11 @@ module Vimaly
|
|
98
103
|
to_vimaly(custom_field_name_map, for_update).to_json
|
99
104
|
end
|
100
105
|
|
106
|
+
def add_id(id)
|
107
|
+
raise "Ticket already has id #{@ticket_fields[:'_id']} and we try and add #{id}" if @ticket_fields[:'_id']
|
108
|
+
@ticket_fields['_id'] = id
|
109
|
+
end
|
110
|
+
|
101
111
|
def [](name)
|
102
112
|
@ticket_fields[name]
|
103
113
|
end
|
@@ -108,6 +118,10 @@ module Vimaly
|
|
108
118
|
super
|
109
119
|
end
|
110
120
|
|
121
|
+
def update_fields(fields)
|
122
|
+
@ticket_fields.merge!(fields)
|
123
|
+
end
|
124
|
+
|
111
125
|
private
|
112
126
|
|
113
127
|
def normalise(text)
|
data/lib/vimaly/version.rb
CHANGED
data/vimaly.gemspec
CHANGED
@@ -21,9 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency "faraday"
|
23
23
|
spec.add_dependency "faraday_middleware"
|
24
|
+
spec.add_dependency "activesupport"
|
24
25
|
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
27
28
|
spec.add_development_dependency "pry"
|
28
29
|
spec.add_development_dependency "maxitest", '~> 1'
|
29
30
|
spec.add_development_dependency "shoulda-context"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vimaly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorsten Boettger
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,34 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: pry
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +144,7 @@ extensions: []
|
|
130
144
|
extra_rdoc_files: []
|
131
145
|
files:
|
132
146
|
- ".gitignore"
|
147
|
+
- ".ruby-version"
|
133
148
|
- ".travis.yml"
|
134
149
|
- CHANGELOG.md
|
135
150
|
- CODE_OF_CONDUCT.md
|
@@ -142,6 +157,7 @@ files:
|
|
142
157
|
- lib/vimaly.rb
|
143
158
|
- lib/vimaly/bin.rb
|
144
159
|
- lib/vimaly/client.rb
|
160
|
+
- lib/vimaly/exceptions.rb
|
145
161
|
- lib/vimaly/ticket.rb
|
146
162
|
- lib/vimaly/ticket_type.rb
|
147
163
|
- lib/vimaly/version.rb
|
@@ -150,7 +166,7 @@ homepage: https://github.com/sharesight/vimaly
|
|
150
166
|
licenses:
|
151
167
|
- MIT
|
152
168
|
metadata: {}
|
153
|
-
post_install_message:
|
169
|
+
post_install_message:
|
154
170
|
rdoc_options: []
|
155
171
|
require_paths:
|
156
172
|
- lib
|
@@ -165,9 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
181
|
- !ruby/object:Gem::Version
|
166
182
|
version: '0'
|
167
183
|
requirements: []
|
168
|
-
|
169
|
-
|
170
|
-
signing_key:
|
184
|
+
rubygems_version: 3.0.6
|
185
|
+
signing_key:
|
171
186
|
specification_version: 4
|
172
187
|
summary: Wrapper for the Vimaly API
|
173
188
|
test_files: []
|