zendesk2 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,16 +17,12 @@ class Zendesk2::Client::Category < Zendesk2::Model
17
17
  # @return [String] The API url of this category
18
18
  attribute :url, type: :string
19
19
 
20
- def destroy
20
+ def destroy!
21
21
  requires :id
22
22
 
23
23
  connection.destroy_category("id" => self.id)
24
24
  end
25
25
 
26
- def destroyed?
27
- !self.reload
28
- end
29
-
30
26
  def save!
31
27
  data = if new_record?
32
28
  requires :name
@@ -21,16 +21,12 @@ class Zendesk2::Client::Forum < Zendesk2::Model
21
21
  assoc_accessor :organization
22
22
  assoc_accessor :category
23
23
 
24
- def destroy
24
+ def destroy!
25
25
  requires :identity
26
26
 
27
27
  connection.destroy_forum("id" => self.identity)
28
28
  end
29
29
 
30
- def destroyed?
31
- !self.reload
32
- end
33
-
34
30
  def save!
35
31
  data = if new_record?
36
32
  requires :name
@@ -29,7 +29,7 @@ class Zendesk2::Client::Group < Zendesk2::Model
29
29
  merge_attributes(data)
30
30
  end
31
31
 
32
- def destroy
32
+ def destroy!
33
33
  requires :identity
34
34
 
35
35
  connection.destroy_group("id" => self.identity)
@@ -21,16 +21,6 @@ class Zendesk2::Client::Organization < Zendesk2::Model
21
21
  connection.destroy_organization("id" => self.identity)
22
22
  end
23
23
 
24
- def destroy
25
- destroy!
26
- rescue Zendesk2::Error
27
- false
28
- end
29
-
30
- def destroyed?
31
- !self.reload
32
- end
33
-
34
24
  def save!
35
25
  data = if new_record?
36
26
  requires :name
@@ -42,6 +32,7 @@ class Zendesk2::Client::Organization < Zendesk2::Model
42
32
  merge_attributes(data)
43
33
  end
44
34
 
35
+ # @return [Zendesk2::Client::Users] users associated with this organization
45
36
  def users
46
37
  requires :identity
47
38
  data = connection.get_organization_users("id" => self.identity).body["users"]
@@ -49,6 +40,7 @@ class Zendesk2::Client::Organization < Zendesk2::Model
49
40
  connection.users.load(data)
50
41
  end
51
42
 
43
+ # @return [Zendesk2::Client::Tickets] tickets associated with this organization
52
44
  def tickets
53
45
  requires :identity
54
46
  data = connection.get_organization_tickets("id" => self.identity).body["tickets"]
@@ -75,7 +75,7 @@ class Zendesk2::Client::Ticket < Zendesk2::Model
75
75
  merge_attributes(data)
76
76
  end
77
77
 
78
- def destroy
78
+ def destroy!
79
79
  requires :identity
80
80
 
81
81
  connection.destroy_ticket("id" => self.identity)
@@ -24,16 +24,12 @@ class Zendesk2::Client::Topic < Zendesk2::Model
24
24
  assoc_accessor :forum
25
25
 
26
26
 
27
- def destroy
27
+ def destroy!
28
28
  requires :identity
29
29
 
30
30
  connection.destroy_topic("id" => self.identity)
31
31
  end
32
32
 
33
- def destroyed?
34
- !self.reload
35
- end
36
-
37
33
  def save!
38
34
  data = if new_record?
39
35
  requires :title, :body
@@ -26,7 +26,7 @@ class Zendesk2::Client::TopicComment < Zendesk2::Model
26
26
  assoc_accessor :user
27
27
  assoc_accessor :topic
28
28
 
29
- def destroy
29
+ def destroy!
30
30
  requires :identity
31
31
 
32
32
  connection.destroy_topic_comment("id" => self.identity, "topic_id" => self.topic_id)
@@ -84,12 +84,6 @@ class Zendesk2::Client::User < Zendesk2::Model
84
84
  merge_attributes(data)
85
85
  end
86
86
 
87
- def destroy
88
- destroy!
89
- rescue Zendesk2::Error => e
90
- false
91
- end
92
-
93
87
  def destroyed?
94
88
  !reload || !self.active
95
89
  end
@@ -91,7 +91,7 @@ class Zendesk2::Client < Cistern::Service
91
91
  attr_accessor :username, :url, :token, :logger
92
92
 
93
93
  def initialize(options={})
94
- url = options[:url] || begin
94
+ url = options[:url] || Zendesk2.defaults[:url] || begin
95
95
  host = options[:host]
96
96
  subdomain = options[:subdomain] || Zendesk2.defaults[:subdomain]
97
97
 
@@ -110,8 +110,8 @@ class Zendesk2::Client < Cistern::Service
110
110
  @username = options[:username] || Zendesk2.defaults[:username]
111
111
  token = options[:token] || Zendesk2.defaults[:token]
112
112
  password = options[:password] || Zendesk2.defaults[:password]
113
- @username += "/token" if token
114
- @auth_token = token || password
113
+ @auth_token = password || token
114
+ @username += "/token" if @auth_token == token
115
115
 
116
116
  raise "Missing required options: :username" unless @username
117
117
  raise "Missing required options: :password or :token" unless password || token
@@ -133,7 +133,7 @@ class Zendesk2::Client < Cistern::Service
133
133
 
134
134
  def request(options={})
135
135
  method = options[:method] || :get
136
- url = File.join(@url, "/api/v2", options[:path])
136
+ url = options[:url] || File.join(@url, "/api/v2", options[:path])
137
137
  params = options[:params] || {}
138
138
  body = options[:body]
139
139
  headers = {"User-Agent" => USER_AGENT}.merge(options[:headers] || {})
@@ -20,4 +20,10 @@ class Zendesk2::Model < Cistern::Model
20
20
  def destroyed?
21
21
  !self.reload
22
22
  end
23
+
24
+ def destroy
25
+ destroy!
26
+ rescue Zendesk2::Error
27
+ false
28
+ end
23
29
  end
@@ -6,9 +6,10 @@ module Zendesk2::Searchable
6
6
  def search(parameters)
7
7
  body = connection.send(self.class.search_request, parameters.merge("type" => self.class.search_type)).body
8
8
  if data = body.delete("results")
9
- load(data)
9
+ collection = self.clone.load(data)
10
+ collection.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
11
+ collection
10
12
  end
11
- merge_attributes(body)
12
13
  end
13
14
 
14
15
  module Attributes
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cistern