vimaly 1.0.2 → 1.3.0

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
  SHA256:
3
- metadata.gz: d72a2025b7696e9d5282376e74beed0a99a089b9714cd9469bf93c0a4c636d39
4
- data.tar.gz: 7f27cc5960df434c36e292c7e61fc0723d5306d12601b8c628ed75033c024fbf
3
+ metadata.gz: 2fbe16192cd230b1bc9195d5ef9f8faea9c0bdd99041be3b04abf87fb26f27e6
4
+ data.tar.gz: 713fa776cc88c0cf8b37dcbeae00cc4a3faabc5da76e17ad36c1e4cfd37fe385
5
5
  SHA512:
6
- metadata.gz: efb54c0796cead3eec74b605aaf6106ecb612c2e9ff2442a57abe135264ee4cb9d9ee3bc7fddb692790c36f9e25e4549335ae69375028b99f68c1eacb946003b
7
- data.tar.gz: ea232fd63fa12c2cec8b52547a3741a7a8f760900ad8768ad6e889300055443a8a3b50a80806d6a02c1c3fad52fa33adcdee409d895bf3582cc159508d3df15a
6
+ metadata.gz: f68b2e105cf61343ac2d2eb452ac3bb1b427deef775fc0d31b9a327839debe8a403a2c37780bd013275b16b8b70fde7be07a2211ba2ce12b670a99711b05c416
7
+ data.tar.gz: c50e2bb91e042557c69a74a608c6625898b6272359822e4c10e846e86aaad959e1d408d3babcc194e6be130c94dd94449703294c7a412c8e0cffd5efdfc9a1e8
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ 2.6.5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.3.0
4
+
5
+ * add support for more than 200 results when searching for tickets [#22](https://github.com/sharesight/vimaly/pull/22)
6
+
7
+ ## 1.2.0
8
+
9
+ * add support for more than 500 bins, refactored and options added [#21](https://github.com/sharesight/vimaly/pull/21)
10
+
11
+ ## 1.1.1
12
+
13
+ * add support for more than 500 bins [#20](https://github.com/sharesight/vimaly/pull/20)
14
+
15
+ ## 1.1.0
16
+
17
+ * add support for searching tickets [#19](https://github.com/sharesight/vimaly/pull/19)
18
+
3
19
  ## 1.0.2
4
20
 
5
21
  * Fix unfriendly filenames not attaching to Vimaly tickets [#17](https://github.com/sharesight/vimaly/pull/17)
data/lib/vimaly/client.rb CHANGED
@@ -54,6 +54,38 @@ module Vimaly
54
54
  end
55
55
  end
56
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
+ tickets = []
62
+ i = 0
63
+
64
+ while (i * 500) <= 5000
65
+ # Without max-results the request defaults to 200.
66
+ # The maximum max-results is 500, so will do 10 requests to get our maximum of 5000 tickets.
67
+ search_response = get("/ticket-search?text=#{query_string}&state=#{state}&max-results=500&page-token=#{i * 500}")
68
+
69
+ response_tickets = case search_response
70
+ when Array
71
+ search_response.map do |ticket_data|
72
+ Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
73
+ end
74
+ when Hash # Will be a hash when only 1 ticket is returned.
75
+ [Ticket.from_vimaly(search_response, ticket_type_map, bin_map, custom_fields)]
76
+ else # If reponse is nil then we know we've got all the data
77
+ break
78
+ end
79
+
80
+ tickets.concat(response_tickets)
81
+ break if response_tickets.size < 500 # Can finish search because we've returned all there is.
82
+
83
+ i += 1
84
+ end
85
+
86
+ tickets
87
+ end
88
+
57
89
  def add_attachment(ticket_id, file_name, file_content, request_options={})
58
90
  response = post("/tickets/#{ticket_id}/attachments?name=#{CGI.escape(file_name)}", file_content, request_options)
59
91
  case response.status
@@ -75,10 +107,25 @@ module Vimaly
75
107
  end
76
108
  end
77
109
 
78
- def bins
110
+ def bins(options={})
79
111
  @bins ||= begin
80
- get('/bins?max-results=500').map do |bin_data|
81
- Bin.new(bin_data['_id'], bin_data['name'])
112
+ # 500 is the vimaly limit
113
+ bins_per_request = options[:bins_per_request] || 500
114
+ # 5000 is just a random value here; hopefully we never reach this limit
115
+ max_number_of_bins = options[:max_number_of_bins] || 5000
116
+
117
+ bins = []
118
+ current_page = 0
119
+ while bins.size < max_number_of_bins
120
+ # those request parameters are not documented, maybe this gets added at some
121
+ # point to https://vimaly.com/public/rest-help.html#Bins
122
+ chunk_of_bins = get("/bins?max-results=#{bins_per_request}&page-token=#{current_page * bins_per_request}")
123
+ current_page += 1
124
+ bins += chunk_of_bins
125
+ break if chunk_of_bins.size < bins_per_request
126
+ end
127
+ bins.map do |bin|
128
+ Bin.new(bin['_id'], bin['name'])
82
129
  end
83
130
  end
84
131
  end
@@ -113,7 +160,6 @@ module Vimaly
113
160
  get("/tickets?bin_id=#{bin_id}").map do |ticket_data|
114
161
  Ticket.from_vimaly(ticket_data, ticket_type_map, bin_map, custom_fields)
115
162
  end
116
-
117
163
  end
118
164
 
119
165
  def matching_tickets_in_named_bin(bin_name, title_matcher)
@@ -1,3 +1,3 @@
1
1
  module Vimaly
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.3.0".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: 1.0.2
4
+ version: 1.3.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: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -166,7 +166,7 @@ homepage: https://github.com/sharesight/vimaly
166
166
  licenses:
167
167
  - MIT
168
168
  metadata: {}
169
- post_install_message:
169
+ post_install_message:
170
170
  rdoc_options: []
171
171
  require_paths:
172
172
  - lib
@@ -181,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
- rubygems_version: 3.0.4
185
- signing_key:
184
+ rubygems_version: 3.0.6
185
+ signing_key:
186
186
  specification_version: 4
187
187
  summary: Wrapper for the Vimaly API
188
188
  test_files: []