vimaly 0.2.2 → 1.0.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
- SHA1:
3
- metadata.gz: 9096c5aaa8c67a33674de730a6f59333237ab1de
4
- data.tar.gz: 8b93b163163beb27266c42f7cf4f5f5d9229186c
2
+ SHA256:
3
+ metadata.gz: b0a5b2991366fa54ec8d160b894d4393236d24362d8e659b7bdb2222be9001a9
4
+ data.tar.gz: 200257d646a0a01284c5d26dae3be16c1c3f31e92fb5e3c9704223b00c8584a6
5
5
  SHA512:
6
- metadata.gz: aef40b111d7794708b3ad2fd96c6822faf1617e9ed965479a7afeccf16818f05452b36d8e2a0f8a22be9e2c717e4e961dfb146e0d52b78cfc0393bad41f8bfbb
7
- data.tar.gz: 4606c1b59c0160dde277990657a6ca07efd05634e0fb81ef0230db556dfe48abb8b66ced8b7d6038d24b018b13cce96976e8825421720cb7bd89f40474a8d5c5
6
+ metadata.gz: 529972ff9c59f81cf30ea2f0fcc81e09a51a8a8479b3e0a79929ce806001f3004b98368ef56953489d0721fe68462e74d1ce23f84d4a2df573c5525fdea4859f
7
+ data.tar.gz: 78d667532eb197842526a3e9a51584c07d8fef4530fff79a4c4f2124645760d3d0e5057a4c99c242b5812d3f07e9715627aea8ef73f62e7427ea17429373c26e
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.5.3
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
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
+ before_install: gem install bundler
data/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.0
4
+
5
+ * allow adding attachments with providing a content-type [#15](https://github.com/sharesight/vimaly/pull/15)
6
+
7
+ ## 0.5.3
8
+
9
+ * add support for Ruby `2.5.3` [#14](https://github.com/sharesight/vimaly/pull/14)
10
+
11
+ ## 0.5.2
12
+
13
+ * return the correct ticket-id after creating a ticket [#13](https://github.com/sharesight/vimaly/pull/13)
14
+
15
+ ## 0.5.1
16
+
17
+ * return the ticket-id after updating a ticket [#12](https://github.com/sharesight/vimaly/pull/12)
18
+
19
+ ## 0.5.0
20
+
21
+ * add support for adding attachments to tickets [#11](https://github.com/sharesight/vimaly/pull/11)
22
+
23
+ ## 0.4.0
24
+
25
+ * support API version 2 [#10](https://github.com/sharesight/vimaly/pull/10)
26
+
27
+ ## 0.3.1
28
+
29
+ * use Ruby `2.5.1` [#9](https://github.com/sharesight/vimaly/pull/9)
30
+
31
+ ## 0.3.0
32
+
33
+ * ask for more bins [#8](https://github.com/sharesight/vimaly/pull/8)
34
+
35
+ ## 0.2.5
36
+
37
+ * Ruby 2.5.0 support
38
+
39
+ ## 0.2.4
40
+
41
+ * Ruby 2.4.2 support
42
+
43
+ ## 0.2.3
44
+
45
+ * Ruby 2.4.1 support
46
+
3
47
  ## 0.2.2
4
48
 
5
49
  * 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,18 @@ 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 add_attachment(ticket_id, file_name, file_content, request_options={})
58
+ response = post("/tickets/#{ticket_id}/attachments?name=#{file_name}", file_content, request_options)
59
+ case response.status
47
60
  when 200..299
48
61
  true
49
62
  else
@@ -64,7 +77,7 @@ module Vimaly
64
77
 
65
78
  def bins
66
79
  @bins ||= begin
67
- get('/bins').map do |bin_data|
80
+ get('/bins?max-results=500').map do |bin_data|
68
81
  Bin.new(bin_data['_id'], bin_data['name'])
69
82
  end
70
83
  end
@@ -139,8 +152,8 @@ module Vimaly
139
152
  end
140
153
 
141
154
  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' })
155
+ response = faraday.get("/rest/2/#{@company_id}#{api_path}") do |request|
156
+ update_request_headers(request)
144
157
  end
145
158
  unless response.success?
146
159
  raise Vimaly::ConnectionError.new("Vimaly #{api_path} call failed with response #{response.status}")
@@ -148,25 +161,31 @@ module Vimaly
148
161
  JSON.parse(response.body)
149
162
  end
150
163
 
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' })
164
+ def post(api_path, content, headers={})
165
+ faraday.post("/rest/2/#{@company_id}#{api_path}", content) do |request|
166
+ update_request_headers(request, headers)
154
167
  end
155
168
  end
156
169
 
157
170
  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' })
171
+ faraday.put("/rest/2/#{@company_id}#{api_path}", json) do |request|
172
+ update_request_headers(request)
160
173
  end
161
174
  end
162
175
 
163
176
  def faraday
164
177
  @faraday ||= Faraday.new(VIMALY_ROOT_URL).tap do |connection|
165
- connection.basic_auth(@username, @password)
178
+ connection.basic_auth(@user_credentials[:username], @user_credentials[:password]) if @user_credentials
166
179
  connection.request(:json)
167
180
  end
168
181
  end
169
182
 
183
+ def update_request_headers(request, headers={})
184
+ request.headers.update({ accept: 'application/json', content_type: 'application/json' })
185
+ request.headers.update({ authorization: "bearer #{@auth_key}" }) if @auth_key
186
+ request.headers.update(headers)
187
+ end
188
+
170
189
  def log_warn(s)
171
190
  @logger.warn(s) if @logger
172
191
  end
@@ -1,3 +1,3 @@
1
1
  module Vimaly
2
- VERSION = "0.2.2"
2
+ VERSION = "1.0.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: 0.2.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Boettger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2019-02-21 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
@@ -180,8 +181,7 @@ 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
184
+ rubygems_version: 3.0.2
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Wrapper for the Vimaly API