zammad_api 1.0.1 → 1.0.2
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 +4 -4
- data/lib/zammad_api/resources/base.rb +39 -31
- data/lib/zammad_api/resources/ticket.rb +4 -5
- data/lib/zammad_api/resources/ticket_article.rb +9 -0
- data/lib/zammad_api/resources/ticket_article_attachment.rb +20 -0
- data/lib/zammad_api/resources.rb +1 -0
- data/lib/zammad_api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f34fd120446932dde693b5e5e364c7b3d39c038
|
4
|
+
data.tar.gz: f352194c6b650b5522579df5ffa68878e5f6014f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff79410da2f92e251a5e8383802b4d1dd1f2d721bf65bb1e4eed1ae35ebb3e2f2dfd5534849c82762a9bfbe0cc9c7d34a50491de87549f93ba9874ce4846b8b2
|
7
|
+
data.tar.gz: a539ce959dc74ffcf223669289feca88751379191d9e54c26c2a6c210397f2603e82051d25b837d69bebbf449e8485f5b0e772318d6458407457740efc2172f6
|
@@ -22,12 +22,11 @@ module ZammadAPI
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def method_missing(method, *args)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@attributes[method]
|
25
|
+
return @attributes[method] if !method.end_with?('=')
|
26
|
+
method = method.to_s[0, method.length - 1].to_sym
|
27
|
+
@changes[method] = [@attributes[method], args[0]]
|
28
|
+
@attributes[method] = args[0]
|
29
|
+
nil
|
31
30
|
end
|
32
31
|
|
33
32
|
def new_record?
|
@@ -35,8 +34,7 @@ module ZammadAPI
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def changed?
|
38
|
-
|
39
|
-
true
|
37
|
+
@changes.present?
|
40
38
|
end
|
41
39
|
|
42
40
|
def destroy
|
@@ -44,35 +42,17 @@ module ZammadAPI
|
|
44
42
|
if response.body.to_s != '' && response.body.to_s != ' '
|
45
43
|
data = JSON.parse(response.body)
|
46
44
|
end
|
47
|
-
if response.status
|
48
|
-
|
49
|
-
end
|
50
|
-
true
|
45
|
+
return true if response.status == 200
|
46
|
+
raise "Can't destroy object (#{self.class.name}): #{data['error']}"
|
51
47
|
end
|
52
48
|
|
53
49
|
def save
|
54
|
-
|
55
|
-
response = @transport.post(url: "#{@url}?expand=true", params: @attributes)
|
56
|
-
attributes = JSON.parse(response.body)
|
57
|
-
if response.status != 201
|
58
|
-
raise "Can't create new object (#{self.class.name}): #{attributes['error']}"
|
59
|
-
end
|
60
|
-
else
|
61
|
-
attributes_to_post = {}
|
62
|
-
@changes.each { |name, values|
|
63
|
-
attributes_to_post[name] = values[1]
|
64
|
-
}
|
65
|
-
response = @transport.put(url: "#{@url}/#{@attributes[:id]}?expand=true", params: attributes_to_post)
|
66
|
-
attributes = JSON.parse(response.body)
|
67
|
-
if response.status != 200
|
68
|
-
raise "Can't update new object (#{self.class.name}): #{attributes['error']}"
|
69
|
-
end
|
70
|
-
end
|
50
|
+
attributes = saved_attributes
|
71
51
|
symbolize_keys_deep!(attributes)
|
72
52
|
attributes.delete(:article)
|
73
|
-
@attributes
|
53
|
+
@attributes = attributes
|
74
54
|
@new_instance = false
|
75
|
-
@changes
|
55
|
+
@changes = {}
|
76
56
|
true
|
77
57
|
end
|
78
58
|
|
@@ -117,6 +97,34 @@ module ZammadAPI
|
|
117
97
|
|
118
98
|
private
|
119
99
|
|
100
|
+
def saved_attributes
|
101
|
+
return save_new if @new_instance
|
102
|
+
save_existing
|
103
|
+
end
|
104
|
+
|
105
|
+
def save_new
|
106
|
+
response = @transport.post(url: "#{@url}?expand=true", params: @attributes)
|
107
|
+
attributes = JSON.parse(response.body)
|
108
|
+
return attributes if response.status == 201
|
109
|
+
save_error(attributes)
|
110
|
+
end
|
111
|
+
|
112
|
+
def save_existing
|
113
|
+
attributes_to_post = {}
|
114
|
+
@changes.each { |name, values|
|
115
|
+
attributes_to_post[name] = values[1]
|
116
|
+
}
|
117
|
+
response = @transport.put(url: "#{@url}/#{@attributes[:id]}?expand=true", params: attributes_to_post)
|
118
|
+
attributes = JSON.parse(response.body)
|
119
|
+
|
120
|
+
return attributes if response.status == 200
|
121
|
+
save_error(attributes)
|
122
|
+
end
|
123
|
+
|
124
|
+
def save_error(attributes)
|
125
|
+
raise "Can't save object (#{self.class.name}): #{attributes['error']}"
|
126
|
+
end
|
127
|
+
|
120
128
|
def symbolize_keys_deep!(hash)
|
121
129
|
hash.keys.each do |key|
|
122
130
|
key_symbol = key.respond_to?(:to_sym) ? key.to_sym : key
|
@@ -7,17 +7,16 @@ class ZammadAPI::Resources::Ticket < ZammadAPI::Resources::Base
|
|
7
7
|
if response.status != 200
|
8
8
|
raise "Can't get articles (#{self.class.name}): #{data['error']}"
|
9
9
|
end
|
10
|
-
|
11
|
-
data.
|
10
|
+
|
11
|
+
data.collect { |raw|
|
12
12
|
item = ZammadAPI::Resources::TicketArticle.new(@transport, raw)
|
13
13
|
item.new_instance = false
|
14
|
-
|
14
|
+
item
|
15
15
|
}
|
16
|
-
articles
|
17
16
|
end
|
18
17
|
|
19
18
|
def article(data)
|
20
|
-
data[
|
19
|
+
data[:ticket_id] = @attributes[:id]
|
21
20
|
item = ZammadAPI::Resources::TicketArticle.new(@transport, data)
|
22
21
|
item.save
|
23
22
|
item
|
@@ -1,3 +1,12 @@
|
|
1
1
|
class ZammadAPI::Resources::TicketArticle < ZammadAPI::Resources::Base
|
2
2
|
url '/api/v1/ticket_articles'
|
3
|
+
|
4
|
+
def attachments
|
5
|
+
@attributes[:attachments].collect { |raw|
|
6
|
+
raw[:ticket_id] = @attributes[:ticket_id]
|
7
|
+
raw[:article_id] = @attributes[:id]
|
8
|
+
ZammadAPI::Resources::TicketArticleAttachment.new(@transport, raw)
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
3
12
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ZammadAPI::Resources::TicketArticleAttachment < ZammadAPI::Resources::Base
|
2
|
+
|
3
|
+
def initialize(transport, attributes = {})
|
4
|
+
@transport = transport
|
5
|
+
@attributes = attributes
|
6
|
+
symbolize_keys_deep!(@attributes)
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(method, *_args)
|
10
|
+
@attributes[method.to_sym]
|
11
|
+
end
|
12
|
+
|
13
|
+
def download
|
14
|
+
response = @transport.get(url: "/api/v1/ticket_attachment/#{ticket_id}/#{article_id}/#{id}")
|
15
|
+
return response.body if response.status == 200
|
16
|
+
data = JSON.parse(response.body)
|
17
|
+
raise "Can't get articles (#{self.class.name}): #{data['error']}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/zammad_api/resources.rb
CHANGED
@@ -7,6 +7,7 @@ require 'zammad_api/resources/group'
|
|
7
7
|
require 'zammad_api/resources/organization'
|
8
8
|
require 'zammad_api/resources/ticket'
|
9
9
|
require 'zammad_api/resources/ticket_article'
|
10
|
+
require 'zammad_api/resources/ticket_article_attachment'
|
10
11
|
require 'zammad_api/resources/ticket_state'
|
11
12
|
require 'zammad_api/resources/ticket_priority'
|
12
13
|
|
data/lib/zammad_api/version.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Edenhofer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/zammad_api/resources/organization.rb
|
102
102
|
- lib/zammad_api/resources/ticket.rb
|
103
103
|
- lib/zammad_api/resources/ticket_article.rb
|
104
|
+
- lib/zammad_api/resources/ticket_article_attachment.rb
|
104
105
|
- lib/zammad_api/resources/ticket_priority.rb
|
105
106
|
- lib/zammad_api/resources/ticket_state.rb
|
106
107
|
- lib/zammad_api/resources/user.rb
|