vimaly 0.2.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9096c5aaa8c67a33674de730a6f59333237ab1de
4
- data.tar.gz: 8b93b163163beb27266c42f7cf4f5f5d9229186c
2
+ SHA256:
3
+ metadata.gz: 24a7563b37e94b8774a431498191ea44c158f630b84f1effda7a5dea0b4380c4
4
+ data.tar.gz: 0eea178740c3bff79d23b16d6b69e7e283eebee640acef16a1d260c2c62486ef
5
5
  SHA512:
6
- metadata.gz: aef40b111d7794708b3ad2fd96c6822faf1617e9ed965479a7afeccf16818f05452b36d8e2a0f8a22be9e2c717e4e961dfb146e0d52b78cfc0393bad41f8bfbb
7
- data.tar.gz: 4606c1b59c0160dde277990657a6ca07efd05634e0fb81ef0230db556dfe48abb8b66ced8b7d6038d24b018b13cce96976e8825421720cb7bd89f40474a8d5c5
6
+ metadata.gz: 49b0c813976c5901e34b0e3dfffa411c2cdaf465be30d05687b6bbb2fe1f558ce444bc14e0a86bee9346010407121b4bd91db1fbe00675b2e4a72e9d8a4de499
7
+ data.tar.gz: 0e590b435fe14297a656c187eef8c861531715def1479f4d8c636ef6b1eecf6958028f85ec6f70f3012bbd823ad69ec5bced1b8088b3a208e4ff73e904021681
data/.gitignore CHANGED
@@ -7,7 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- .ruby-version
11
10
  .ruby-gemset
12
11
  /_ignore
13
12
  .idea/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.5
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.12.5
4
+ - 2.5.3
5
+ - 2.6.3
6
+ before_install: gem install bundler
data/CHANGELOG.md CHANGED
@@ -1,5 +1,65 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.1
4
+
5
+ * add support for more than 500 bins [#20](https://github.com/sharesight/vimaly/pull/20)
6
+
7
+ ## 1.1.0
8
+
9
+ * add support for searching tickets [#19](https://github.com/sharesight/vimaly/pull/19)
10
+
11
+ ## 1.0.2
12
+
13
+ * Fix unfriendly filenames not attaching to Vimaly tickets [#17](https://github.com/sharesight/vimaly/pull/17)
14
+
15
+ ## 1.0.1
16
+
17
+ * Update for Ruby 2.6.3 compatibility.
18
+
19
+ ## 1.0.0
20
+
21
+ * allow adding attachments with providing a content-type [#15](https://github.com/sharesight/vimaly/pull/15)
22
+
23
+ ## 0.5.3
24
+
25
+ * add support for Ruby `2.5.3` [#14](https://github.com/sharesight/vimaly/pull/14)
26
+
27
+ ## 0.5.2
28
+
29
+ * return the correct ticket-id after creating a ticket [#13](https://github.com/sharesight/vimaly/pull/13)
30
+
31
+ ## 0.5.1
32
+
33
+ * return the ticket-id after updating a ticket [#12](https://github.com/sharesight/vimaly/pull/12)
34
+
35
+ ## 0.5.0
36
+
37
+ * add support for adding attachments to tickets [#11](https://github.com/sharesight/vimaly/pull/11)
38
+
39
+ ## 0.4.0
40
+
41
+ * support API version 2 [#10](https://github.com/sharesight/vimaly/pull/10)
42
+
43
+ ## 0.3.1
44
+
45
+ * use Ruby `2.5.1` [#9](https://github.com/sharesight/vimaly/pull/9)
46
+
47
+ ## 0.3.0
48
+
49
+ * ask for more bins [#8](https://github.com/sharesight/vimaly/pull/8)
50
+
51
+ ## 0.2.5
52
+
53
+ * Ruby 2.5.0 support
54
+
55
+ ## 0.2.4
56
+
57
+ * Ruby 2.4.2 support
58
+
59
+ ## 0.2.3
60
+
61
+ * Ruby 2.4.1 support
62
+
3
63
  ## 0.2.2
4
64
 
5
65
  * handle Bad Gateway 502 errors
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, username, password, logger=nil)
11
+ def initialize(company_id, user_credentials: nil, auth_key: nil, logger: nil)
12
12
  @company_id = company_id
13
- @username = username
14
- @password = password
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/#{next_ticket_id}", ticket_to_json)
32
+ response = post("/tickets/#{ticket_id}", ticket_to_json)
32
33
  case response.status
33
34
  when 200..299
34
- true
35
+ ticket_id
35
36
  else
36
37
  log_warn "status: #{response.status}"
37
38
  log_warn " #{response.inspect}"
@@ -44,6 +45,27 @@ module Vimaly
44
45
 
45
46
  response = put("/tickets/#{id}", ticket.to_json(custom_field_name_map, true))
46
47
  case response.status
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
47
69
  when 200..299
48
70
  true
49
71
  else
@@ -64,7 +86,11 @@ module Vimaly
64
86
 
65
87
  def bins
66
88
  @bins ||= begin
67
- get('/bins').map do |bin_data|
89
+ per_page = 500
90
+ data = (0..1).inject([]) do |list, page|
91
+ list += get("/bins?max-results=#{per_page}&page-token=#{page * 500}")
92
+ end
93
+ data.map do |bin_data|
68
94
  Bin.new(bin_data['_id'], bin_data['name'])
69
95
  end
70
96
  end
@@ -100,7 +126,6 @@ module Vimaly
100
126
  get("/tickets?bin_id=#{bin_id}").map do |ticket_data|
101
127
  Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
102
128
  end
103
-
104
129
  end
105
130
 
106
131
  def matching_tickets_in_named_bin(bin_name, title_matcher)
@@ -139,8 +164,8 @@ module Vimaly
139
164
  end
140
165
 
141
166
  def get(api_path)
142
- response = faraday.get("/rest/1/#{@company_id}#{api_path}") do |request|
143
- request.headers.update({ accept: 'application/json', content_type: 'application/json' })
167
+ response = faraday.get("/rest/2/#{@company_id}#{api_path}") do |request|
168
+ update_request_headers(request)
144
169
  end
145
170
  unless response.success?
146
171
  raise Vimaly::ConnectionError.new("Vimaly #{api_path} call failed with response #{response.status}")
@@ -148,25 +173,31 @@ module Vimaly
148
173
  JSON.parse(response.body)
149
174
  end
150
175
 
151
- def post(api_path, json)
152
- faraday.post("/rest/1/#{@company_id}#{api_path}", json) do |request|
153
- request.headers.update({ accept: 'application/json', content_type: 'application/json' })
176
+ def post(api_path, content, headers={})
177
+ faraday.post("/rest/2/#{@company_id}#{api_path}", content) do |request|
178
+ update_request_headers(request, headers)
154
179
  end
155
180
  end
156
181
 
157
182
  def put(api_path, json)
158
- faraday.put("/rest/1/#{@company_id}#{api_path}", json) do |request|
159
- request.headers.update({ accept: 'application/json', content_type: 'application/json' })
183
+ faraday.put("/rest/2/#{@company_id}#{api_path}", json) do |request|
184
+ update_request_headers(request)
160
185
  end
161
186
  end
162
187
 
163
188
  def faraday
164
189
  @faraday ||= Faraday.new(VIMALY_ROOT_URL).tap do |connection|
165
- connection.basic_auth(@username, @password)
190
+ connection.basic_auth(@user_credentials[:username], @user_credentials[:password]) if @user_credentials
166
191
  connection.request(:json)
167
192
  end
168
193
  end
169
194
 
195
+ def update_request_headers(request, headers={})
196
+ request.headers.update({ accept: 'application/json', content_type: 'application/json' })
197
+ request.headers.update({ authorization: "bearer #{@auth_key}" }) if @auth_key
198
+ request.headers.update(headers)
199
+ end
200
+
170
201
  def log_warn(s)
171
202
  @logger.warn(s) if @logger
172
203
  end
@@ -1,3 +1,3 @@
1
1
  module Vimaly
2
- VERSION = "0.2.2"
2
+ VERSION = "1.1.1".freeze
3
3
  end
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: 0.2.2
4
+ version: 1.1.1
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: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -144,6 +144,7 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - ".ruby-version"
147
148
  - ".travis.yml"
148
149
  - CHANGELOG.md
149
150
  - CODE_OF_CONDUCT.md
@@ -165,7 +166,7 @@ homepage: https://github.com/sharesight/vimaly
165
166
  licenses:
166
167
  - MIT
167
168
  metadata: {}
168
- post_install_message:
169
+ post_install_message:
169
170
  rdoc_options: []
170
171
  require_paths:
171
172
  - lib
@@ -180,9 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  - !ruby/object:Gem::Version
181
182
  version: '0'
182
183
  requirements: []
183
- rubyforge_project:
184
- rubygems_version: 2.6.8
185
- signing_key:
184
+ rubygems_version: 3.2.17
185
+ signing_key:
186
186
  specification_version: 4
187
187
  summary: Wrapper for the Vimaly API
188
188
  test_files: []