zammad_api 1.3.0 → 1.3.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
2
  SHA256:
3
- metadata.gz: 42c75fd97c167f27bec8282ccd8214f3885e051691c042ad0e8e491651814d81
4
- data.tar.gz: 949a756e4310f53f9ca929a9e973dcb30af4a80e494e55059da6cac345a8bc28
3
+ metadata.gz: e210909fb0d53e8184097f0ac41021ae674a5981b80e4e405631d33d6d07623e
4
+ data.tar.gz: 83e7ac5be2b238ce682b9f478d0bc7dbab3a00308367a01b95e5fc3c9ee586f5
5
5
  SHA512:
6
- metadata.gz: b6625e7abed25c87ae3fe46bf543c9095cc092f61eacc23fded2af1a9807a0fc8ebf589221d6afbb57414704e3c732e9f629f89bf460791cffecd91448398a38
7
- data.tar.gz: '0379ee29e881afe691eb7d47b0c2c3dbe01ae0a6eddd73e783d24ec8c07fc0dd635dca03148c9a539c006e5b2ad6c87173b944e5511024849727ffcff58be454'
6
+ metadata.gz: c8122abe30faebe219bea0e71ac5220a060b6c2f1ac08e2d86783987c4de5280daccd9341627a49da41e2e9eb24d88e7db84350b21d0f9f47feda364066deb8b
7
+ data.tar.gz: 72f47ce52a5f80a4a17f56bb652324cebee7b07c32ae944901065b09b5850d634081b0ae7278327074f6e546c9be6a68714ce842c078979c13294650f9b771f9
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ module ZammadAPI
4
+ module JsonHelper
5
+ def safe_json_parse(string)
6
+ JSON.parse(string)
7
+ rescue JSON::ParserError
8
+ {}
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,9 @@
1
+ require 'zammad_api/json_helper'
2
+
1
3
  module ZammadAPI
2
4
  class ListBase
3
5
  include Enumerable
6
+ include ZammadAPI::JsonHelper
4
7
 
5
8
  def initialize(resource, transport, parameter = {})
6
9
  @resource = resource
@@ -59,7 +62,7 @@ module ZammadAPI
59
62
  }.join('&')
60
63
 
61
64
  response = @transport.get(url: url)
62
- data = JSON.parse(response.body)
65
+ data = safe_json_parse(response.body)
63
66
  if response.status != 200
64
67
  raise "Can't get .#{request} of object (#{@resource.class.name}): #{data['error']}"
65
68
  end
@@ -1,10 +1,13 @@
1
1
  require 'cgi'
2
- require 'json'
2
+ require 'zammad_api/json_helper'
3
3
  require 'zammad_api/transport'
4
4
 
5
5
  module ZammadAPI
6
6
  module Resources
7
7
  class Base
8
+ include ZammadAPI::JsonHelper
9
+ extend ZammadAPI::JsonHelper
10
+
8
11
  attr_accessor :new_instance, :url, :attributes
9
12
  attr_reader :changes
10
13
 
@@ -41,7 +44,7 @@ module ZammadAPI
41
44
  def destroy
42
45
  response = @transport.delete(url: "#{@url}/#{@attributes[:id]}")
43
46
  if response.body.to_s != '' && response.body.to_s != ' '
44
- data = JSON.parse(response.body)
47
+ data = safe_json_parse(response.body)
45
48
  end
46
49
  return true if response.status == 200
47
50
 
@@ -76,7 +79,7 @@ module ZammadAPI
76
79
 
77
80
  def self.find(transport, id)
78
81
  response = transport.get(url: "#{@url}/#{id}?expand=true")
79
- data = JSON.parse(response.body)
82
+ data = safe_json_parse(response.body)
80
83
  if response.status != 200
81
84
  raise "Can't find object (#{self.class.name}): #{data['error']}"
82
85
  end
@@ -108,7 +111,7 @@ module ZammadAPI
108
111
 
109
112
  def save_new
110
113
  response = @transport.post(url: "#{@url}?expand=true", params: @attributes)
111
- attributes = JSON.parse(response.body)
114
+ attributes = safe_json_parse(response.body)
112
115
  return attributes if response.status == 201
113
116
 
114
117
  save_error(attributes)
@@ -120,7 +123,7 @@ module ZammadAPI
120
123
  attributes_to_post[name] = values[1]
121
124
  end
122
125
  response = @transport.put(url: "#{@url}/#{@attributes[:id]}?expand=true", params: attributes_to_post)
123
- attributes = JSON.parse(response.body)
126
+ attributes = safe_json_parse(response.body)
124
127
 
125
128
  return attributes if response.status == 200
126
129
 
@@ -3,7 +3,7 @@ class ZammadAPI::Resources::Ticket < ZammadAPI::Resources::Base
3
3
 
4
4
  def articles
5
5
  response = @transport.get(url: "/api/v1/ticket_articles/by_ticket/#{id}?expand=true")
6
- data = JSON.parse(response.body)
6
+ data = safe_json_parse(response.body)
7
7
  if response.status != 200
8
8
  raise "Can't get articles (#{self.class.name}): #{data['error']}"
9
9
  end
@@ -13,7 +13,7 @@ class ZammadAPI::Resources::TicketArticleAttachment < ZammadAPI::Resources::Base
13
13
  response = @transport.get(url: "/api/v1/ticket_attachment/#{ticket_id}/#{article_id}/#{id}")
14
14
  return response.body if response.status == 200
15
15
 
16
- data = JSON.parse(response.body)
16
+ data = safe_json_parse(response.body)
17
17
  raise "Can't get articles (#{self.class.name}): #{data['error']}"
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module ZammadAPI
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zammad_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Edenhofer
@@ -34,6 +34,7 @@ files:
34
34
  - lib/zammad_api.rb
35
35
  - lib/zammad_api/client.rb
36
36
  - lib/zammad_api/dispatcher.rb
37
+ - lib/zammad_api/json_helper.rb
37
38
  - lib/zammad_api/list_all.rb
38
39
  - lib/zammad_api/list_base.rb
39
40
  - lib/zammad_api/list_search.rb