zendesk 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/VERSION +1 -1
- data/lib/zendesk.rb +19 -3
- data/lib/zendesk/comment.rb +1 -1
- data/lib/zendesk/lib/rest_object.rb +3 -3
- data/lib/zendesk/ticket.rb +4 -3
- data/zendesk.gemspec +1 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/zendesk.rb
CHANGED
@@ -6,10 +6,26 @@ require 'yaml'
|
|
6
6
|
|
7
7
|
module Zendesk
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
class ConfigurationNotFound < NameError;
|
10
|
+
end
|
11
11
|
|
12
|
-
|
12
|
+
|
13
|
+
ZENDESK_ROOT = File.expand_path((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ".") unless defined?(ZENDESK_ROOT)
|
14
|
+
DEFAULT_CONFIG_PATH = File.join(ZENDESK_ROOT, 'config', 'zendesk.yml')
|
15
|
+
|
16
|
+
def self.load_configuration(config_path)
|
17
|
+
exists = config_path && File.exists?(config_path)
|
18
|
+
raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
|
19
|
+
YAML.load_file(config_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.config
|
23
|
+
@configuration ||= load_configuration(DEFAULT_CONFIG_PATH)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.resource
|
27
|
+
@resource ||= RestClient::Resource.new config['host'], :user => config['user'], :password => config['password'], :timeout => 20, :open_timeout => 1
|
28
|
+
end
|
13
29
|
|
14
30
|
autoload :Resource, File.dirname(__FILE__) + '/zendesk/resource.rb'
|
15
31
|
autoload :Comment, File.dirname(__FILE__) + '/zendesk/comment.rb'
|
data/lib/zendesk/comment.rb
CHANGED
@@ -18,7 +18,7 @@ class Zendesk::Comment < Zendesk::Resource
|
|
18
18
|
|
19
19
|
def save
|
20
20
|
begin
|
21
|
-
response =
|
21
|
+
response = resource["tickets/#{ticket_id}.xml"].put self.to_xml, :content_type => 'application/xml'
|
22
22
|
return (200..300).include?(response.headers[:status].to_i)
|
23
23
|
rescue Exception => e
|
24
24
|
puts e.message
|
@@ -23,9 +23,9 @@ module Zendesk::RestObject
|
|
23
23
|
def save
|
24
24
|
begin
|
25
25
|
response = if self.id
|
26
|
-
Zendesk
|
26
|
+
Zendesk.resource["#{path}/#{id}.xml"].put self.to_xml, :content_type => 'application/xml'
|
27
27
|
else
|
28
|
-
Zendesk
|
28
|
+
Zendesk.resource["#{path}.xml"].post self.to_xml, :content_type => 'application/xml'
|
29
29
|
end
|
30
30
|
if (200..300).include?(response.headers[:status].to_i)
|
31
31
|
load(id || response.headers[:location].scan(/\d+/).first.to_i)
|
@@ -51,7 +51,7 @@ module Zendesk::RestObject
|
|
51
51
|
|
52
52
|
def load(id)
|
53
53
|
begin
|
54
|
-
data = load_data(Zendesk
|
54
|
+
data = load_data(Zendesk.resource["#{path}/#{id}.xml"].get)[path.singularize]
|
55
55
|
load_attributes(data)
|
56
56
|
load_protected_attributes(data)
|
57
57
|
load_field_entries(data) if respond_to?(:load_field_entries)
|
data/lib/zendesk/ticket.rb
CHANGED
@@ -18,10 +18,12 @@ class Zendesk::Ticket < Zendesk::Resource
|
|
18
18
|
super
|
19
19
|
end
|
20
20
|
|
21
|
+
# Filling field methods from imported data.
|
22
|
+
# If field is not pointed in config it will be missed
|
21
23
|
def load_field_entries(data)
|
22
24
|
data['ticket_field_entries'].each do |field_entry|
|
23
25
|
method_name = @field_ids.index(field_entry['ticket_field_id'])
|
24
|
-
send("#{method_name}=", field_entry['value'])
|
26
|
+
send("#{method_name}=", field_entry['value']) if method_name
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -76,7 +78,7 @@ class Zendesk::Ticket < Zendesk::Resource
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def load_fields
|
79
|
-
attr_keys = Zendesk
|
81
|
+
attr_keys = Zendesk.config['ticket'] || {}
|
80
82
|
@field_ids = {}
|
81
83
|
field_names = attr_keys.keys
|
82
84
|
unless field_names.blank?
|
@@ -87,5 +89,4 @@ class Zendesk::Ticket < Zendesk::Resource
|
|
87
89
|
field_names.each{ |field_name| self.class.attributes field_name.to_sym }
|
88
90
|
end
|
89
91
|
end
|
90
|
-
|
91
92
|
end
|
data/zendesk.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrey Deryabin
|