zendesk2 0.1.1 → 0.1.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.
data/README.md CHANGED
@@ -52,12 +52,16 @@ Zendesk2::Client.new(url: "http://support.cloud.engineyard.com", username: "mate
52
52
 
53
53
  Currently support resources
54
54
 
55
+ * Audit Events
55
56
  * Categories
56
57
  * Forums
57
58
  * Organization
58
- * Ticket
59
+ * Ticket Audits
60
+ * Tickets
61
+ * Topic Comments
59
62
  * Topics
60
- * User
63
+ * User Identities
64
+ * Users
61
65
 
62
66
  All collection are accessed like so:
63
67
 
@@ -3,15 +3,25 @@ class Zendesk2::Client::TopicComment < Zendesk2::Model
3
3
 
4
4
  PARAMS = %w[id topic_id user_id body informative]
5
5
 
6
- identity :id, type: :integer # ro[integer] mandatory [yes] Automatically assigned upon creation
7
- attribute :url, type: :string # ro[yes] mandatory [no] The API url of this topic comment
8
- attribute :topic_id, type: :integer # ro[no] mandatory [yes] The id of the topic this comment was made on
9
- attribute :user_id, type: :integer # ro[no] mandatory [yes] The id of the user making the topic comment
10
- attribute :body, type: :string # ro[no] mandatory [yes] The comment body
11
- attribute :informative, type: :boolean # ro[no] mandatory [no] If the comment has been flagged as informative
12
- attribute :attachments, type: :array # ro[yes] mandatory [no] Attachments to this comment as Attachment objects
13
- attribute :created_at, type: :date # ro[yes] mandatory [no] The time the topic_comment was created
14
- attribute :updated_at, type: :date # ro[yes] mandatory [no] The time of the last update of the topic_comment
6
+ # @return [Integer] Automatically assigned upon creation
7
+ identity :id, type: :integer
8
+
9
+ # @return [Array] Attachments to this comment as Attachment objects
10
+ attribute :attachments, type: :array
11
+ # @return [String] The comment body
12
+ attribute :body, type: :string
13
+ # @return [Time] The time the topic_comment was created
14
+ attribute :created_at, type: :time
15
+ # @return [Boolean] If the comment has been flagged as informative
16
+ attribute :informative, type: :boolean
17
+ # @return [Integer] The id of the topic this comment was made on
18
+ attribute :topic_id, type: :integer
19
+ # @return [Time] The time of the last update of the topic_comment
20
+ attribute :updated_at, type: :time
21
+ # @return [String] The API url of this topic comment
22
+ attribute :url, type: :string
23
+ # @return [Integer] The id of the user making the topic comment
24
+ attribute :user_id, type: :integer
15
25
 
16
26
  assoc_accessor :user
17
27
  assoc_accessor :topic
@@ -4,7 +4,7 @@ class Zendesk2::Client::TopicComments < Zendesk2::Collection
4
4
 
5
5
  model Zendesk2::Client::TopicComment
6
6
 
7
- attribute :topic_id
7
+ attribute :topic_id, type: :integer
8
8
 
9
9
  self.collection_method = :get_topic_comments
10
10
  self.collection_root = "topic_comments"
@@ -3,35 +3,63 @@ class Zendesk2::Client::User < Zendesk2::Model
3
3
 
4
4
  PARAMS = %w[name email organization_id external_id alias verified locate_id time_zone phone signature details notes role custom_role_id moderator ticket_restriction only_private_comments]
5
5
 
6
- identity :id, type: :id
7
- attribute :url
8
- attribute :external_id
9
- attribute :name
10
- attribute :alias
11
- attribute :created_at, type: :time
12
- attribute :updated_at, type: :time
13
- attribute :active, type: :boolean
14
- attribute :verified, type: :boolean
15
- attribute :shared, type: :boolean
16
- attribute :locale_id, type: :integer
17
- attribute :locale
18
- attribute :time_zone
19
- attribute :last_login_at, type: :time
20
- attribute :email
21
- attribute :phone
22
- attribute :signature
23
- attribute :details, type: :string
24
- attribute :notes
25
- attribute :organization_id, type: :integer
26
- attribute :role
27
- attribute :custom_role_id, type: :integer
28
- attribute :moderator, type: :boolean
29
- attribute :ticket_restriction
6
+ # @return [Integer] Automatically assigned when creating users
7
+ identity :id, type: :integer
8
+
9
+ # @return [Boolean] Users that have been deleted will have the value false here
10
+ attribute :active, type: :boolean
11
+ # @return [String] Agents can have an alias that is displayed to end-users
12
+ attribute :alias, type: :string
13
+ # @return [Time] The time the user was created
14
+ attribute :created_at, type: :time
15
+ # @return [Integer] A custom role on the user if the user is an agent on the entreprise plan
16
+ attribute :custom_role_id, type: :integer
17
+ # @return [String] In this field you can store any details obout the user. e.g. the address
18
+ attribute :details, type: :string
19
+ # @return [String] The primary email address of this user
20
+ attribute :email, type: :string
21
+ # @return [String] A unique id you can set on a user
22
+ attribute :external_id, type: :string
23
+ # @return [Array] Array of user identities (e.g. email and Twitter) associated with this user. See User Identities
24
+ attribute :identities, type: :array
25
+ # @return [Time] A time-stamp of the last time this user logged in to Zendesk
26
+ attribute :last_login_at, type: :time
27
+ # @return [Integer] The language identifier for this user
28
+ attribute :locale_id, type: :integer
29
+ # @return [Boolean] Designates whether this user has forum moderation capabilities
30
+ attribute :moderator, type: :boolean
31
+ # @return [String] The name of the user
32
+ attribute :name, type: :string
33
+ # @return [String] In this field you can store any notes you have about the user
34
+ attribute :notes, type: :string
35
+ # @return [Boolean] true if this user only can create private comments
30
36
  attribute :only_private_comments, type: :boolean
31
- attribute :tags, type: :array
32
- attribute :suspended, type: :boolean
33
- attribute :photo
34
- attribute :authenticity_token
37
+ # @return [Integer] The id of the organization this user is associated with
38
+ attribute :organization_id, type: :integer
39
+ # @return [String] The primary phone number of this user
40
+ attribute :phone, type: :string
41
+ # @return [Attachment] The user's profile picture represented as an Attachment object
42
+ attribute :photo, type: :Attachment
43
+ # @return [String] The role of the user. Possible values: "end-user", "agent", "admin"
44
+ attribute :role, type: :string
45
+ # @return [Boolean] If this user is shared from a different Zendesk, ticket sharing accounts only
46
+ attribute :shared, type: :boolean
47
+ # @return [String] The signature of this user. Only agents and admins can have signatures
48
+ attribute :signature, type: :string
49
+ # @return [Boolean] Tickets from suspended users are also suspended, and these users cannot log in to the end-user portal
50
+ attribute :suspended, type: :boolean
51
+ # @return [Array] The tags of the user. Only present if your account has user tagging enabled
52
+ attribute :tags, type: :array
53
+ # @return [String] Specified which tickets this user has access to. Possible values are: "organization", "groups", "assigned", "requested", null
54
+ attribute :ticket_restriction, type: :string
55
+ # @return [String] The time-zone of this user
56
+ attribute :time_zone, type: :string
57
+ # @return [Time] The time of the last update of the user
58
+ attribute :updated_at, type: :time
59
+ # @return [String] The API url of this user
60
+ attribute :url, type: :string
61
+ # @return [Boolean] Zendesk has verified that this user is who he says he is
62
+ attribute :verified, type: :boolean
35
63
 
36
64
  attr_accessor :errors
37
65
  assoc_accessor :organization
@@ -4,7 +4,7 @@ class Zendesk2::Client::UserIdentities < Zendesk2::Collection
4
4
 
5
5
  model Zendesk2::Client::UserIdentity
6
6
 
7
- attribute :user_id
7
+ attribute :user_id, type: :integer
8
8
 
9
9
  self.collection_method = :get_user_identities
10
10
  self.collection_root = "identities"
@@ -12,14 +12,6 @@ class Zendesk2::Client::UserIdentities < Zendesk2::Collection
12
12
  self.model_root = "identity"
13
13
  self.search_type = "identity"
14
14
 
15
- def create(attributes={})
16
- super(attributes.merge("user_id" => self.user_id))
17
- end
18
-
19
- def create!(attributes={})
20
- super(attributes.merge("user_id" => self.user_id))
21
- end
22
-
23
15
  def all(params={})
24
16
  body = connection.send(collection_method, params.merge("user_id" => self.user_id)).body
25
17
 
@@ -4,11 +4,12 @@ class Zendesk2::Client::Users < Zendesk2::Collection
4
4
 
5
5
  model Zendesk2::Client::User
6
6
 
7
- self.collection_method= :get_users
8
- self.collection_root= "users"
9
- self.model_method= :get_user
10
- self.model_root= "user"
11
- self.search_type= "user"
7
+ self.collection_method = :get_users
8
+ self.collection_root = "users"
9
+ self.model_method = :get_user
10
+ self.model_root = "user"
11
+ self.search_type = "user"
12
+ self.search_request = :search_user
12
13
 
13
14
  def current
14
15
  new(connection.get_current_user.body["user"])
@@ -21,8 +21,8 @@ class Zendesk2::Client
21
21
  "collaborator_ids" => [],
22
22
  }.merge(params)
23
23
 
24
- record["requester_id"] ||= current_user_id
25
- record["submitter_id"] = current_user_id
24
+ record["requester_id"] ||= current_user["id"]
25
+ record["submitter_id"] = current_user["id"]
26
26
 
27
27
  # FIXME: throw error if user doesn't exist?
28
28
  requester = self.data[:users][record["requester_id"]]
@@ -2,10 +2,12 @@ class Zendesk2::Client
2
2
  class Real
3
3
  def create_topic_comment(params={})
4
4
  topic_id = params.delete("topic_id")
5
+ path = "/topics/#{topic_id}/comments.json"
6
+
5
7
  request(
6
8
  :body => {"topic_comment" => params},
7
9
  :method => :post,
8
- :path => "/topics/#{topic_id}/comments.json",
10
+ :path => path,
9
11
  )
10
12
  end
11
13
  end # Real
@@ -13,15 +15,16 @@ class Zendesk2::Client
13
15
  class Mock
14
16
  def create_topic_comment(params={})
15
17
  identity = self.class.new_id
18
+ topic_id = params["topic_id"]
19
+ path = "/topics/#{topic_id}/comments.json"
16
20
 
17
21
  record = {
18
22
  "id" => identity,
19
- "url" => url_for("/topic_comments/#{identity}.json"),
23
+ "url" => url_for("/topics/#{topic_id}/comments/#{identity}.json"),
20
24
  "created_at" => Time.now.iso8601,
21
25
  "updated_at" => Time.now.iso8601,
22
26
  }.merge(params)
23
27
 
24
- path = "/topic_comments.json"
25
28
  self.data[:topic_comments][identity]= record
26
29
 
27
30
  response(
@@ -11,18 +11,18 @@ class Zendesk2::Client
11
11
 
12
12
  class Mock
13
13
  def create_user(params={})
14
- identity = self.class.new_id
14
+ user_id = self.class.new_id
15
+ path = "/users.json"
15
16
 
16
17
  record = {
17
- "id" => identity,
18
- "url" => url_for("/users/#{identity}.json"),
18
+ "id" => user_id,
19
+ "url" => url_for("/users/#{user_id}.json"),
19
20
  "created_at" => Time.now.iso8601,
20
21
  "updated_at" => Time.now.iso8601,
21
22
  "active" => true,
22
23
  }.merge(params)
23
24
 
24
- path = "/users.json"
25
- if (email = record["email"]) && self.data[:users].find{|k,u| u["email"] == email && k != identity}
25
+ if (email = record["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
26
26
  response(
27
27
  :method => :put,
28
28
  :path => path,
@@ -38,22 +38,22 @@ class Zendesk2::Client
38
38
  }
39
39
  )
40
40
  else
41
- user_identity_identity = self.class.new_id # ugh
41
+ user_identity_id = self.class.new_id # ugh
42
42
 
43
43
  user_identity = {
44
- "id" => user_identity_identity,
45
- "url" => url_for("/users/#{identity}/identities/#{user_identity_identity}.json"),
44
+ "id" => user_identity_id,
45
+ "url" => url_for("/users/#{user_id}/identities/#{user_identity_id}.json"),
46
46
  "created_at" => Time.now.iso8601,
47
47
  "updated_at" => Time.now.iso8601,
48
48
  "type" => "email",
49
49
  "value" => record["email"],
50
50
  "verified" => false,
51
51
  "primary" => true,
52
- "user_id" => identity,
52
+ "user_id" => user_id,
53
53
  }
54
54
 
55
- self.data[:identities][user_identity_identity] = user_identity
56
- self.data[:users][identity] = record
55
+ self.data[:identities][user_identity_id] = user_identity
56
+ self.data[:users][user_id] = record.reject{|k,v| k == "email"}
57
57
 
58
58
  response(
59
59
  :method => :post,
@@ -10,14 +10,9 @@ class Zendesk2::Client
10
10
 
11
11
  class Mock
12
12
  def get_current_user
13
- body = self.data[:users][@current_user_id]
13
+ current_user # re-seed if necessary
14
14
 
15
- response(
16
- :path => "/users/me.json",
17
- :body => {
18
- "user" => body
19
- },
20
- )
15
+ get_user("id" => @current_user["id"])
21
16
  end
22
17
  end # Mock
23
18
  end
@@ -3,25 +3,33 @@ class Zendesk2::Client
3
3
  def get_topic_comment(params={})
4
4
  id = params["id"]
5
5
  topic_id = params["topic_id"]
6
+ path = "/topics/#{topic_id}/comments/#{id}.json"
6
7
 
7
8
  request(
8
9
  :method => :get,
9
- :path => "/topics/#{topic_id}/comments/#{id}.json"
10
+ :path => path,
10
11
  )
11
12
  end
12
13
  end # Real
13
14
 
14
15
  class Mock
15
16
  def get_topic_comment(params={})
16
- id = params["id"]
17
+ id = params["id"]
18
+ topic_id = params["topic_id"]
19
+ path = "/topics/#{topic_id}/comments/#{id}.json"
20
+
17
21
  body = self.data[:topic_comments][id]
18
22
 
19
- response(
20
- :path => "/topic_comments/#{id}.json",
21
- :body => {
22
- "topic_comment" => body
23
- },
24
- )
23
+ unless (topic_comment = self.data[:topic_comments][id]) && topic_comment["topic_id"] == topic_id
24
+ response(status: 404)
25
+ else
26
+ response(
27
+ :path => "/topic_comments/#{id}.json",
28
+ :body => {
29
+ "topic_comment" => topic_comment,
30
+ },
31
+ )
32
+ end
25
33
  end
26
34
  end # Mock
27
35
  end
@@ -13,14 +13,22 @@ class Zendesk2::Client
13
13
  class Mock
14
14
  def get_user(params={})
15
15
  id = params["id"]
16
- body = self.data[:users][id]
16
+ if body = self.data[:users][id]
17
17
 
18
- response(
19
- :path => "/users/#{id}.json",
20
- :body => {
21
- "user" => body
22
- },
23
- )
18
+ identities = self.data[:identities].values.select{|i| i["user_id"] == id}
19
+ identity = identities.find{|i| i["type"] == "email" && i["primary"]} || identities.find{|i| i["type"] == "email"}
20
+
21
+ # @todo what happens if no identity?
22
+
23
+ response(
24
+ :path => "/users/#{id}.json",
25
+ :body => {
26
+ "user" => body.merge("email" => identity["value"]),
27
+ },
28
+ )
29
+ else
30
+ response(status: 404)
31
+ end
24
32
  end
25
33
  end # Mock
26
34
  end
@@ -0,0 +1,25 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ alias search_user search
4
+ end # Real
5
+
6
+ class Mock
7
+ def search_user(query)
8
+ query.delete("type") # context already provided
9
+
10
+ collection = self.data[:users].values
11
+ collection = collection.map do |user|
12
+ self.data[:identities].values.select{|i| i["type"] == "email" && i["user_id"] == user["id"]}.map do |identity|
13
+ user.merge("email" => identity["value"])
14
+ end
15
+ end.flatten
16
+
17
+ results = collection.select{|v| query.all?{|term, condition| v[term.to_s] == condition}}
18
+
19
+ response(
20
+ :path => "/search.json",
21
+ :body => {"results" => results},
22
+ )
23
+ end
24
+ end # Mock
25
+ end
@@ -23,7 +23,7 @@ class Zendesk2::Client
23
23
  "id" => audit_id,
24
24
  "ticket_id" => ticket_id,
25
25
  "created_at" => Time.now,
26
- "author_id" => current_user_id,
26
+ "author_id" => current_user["id"],
27
27
  "via" => {
28
28
  "channel" => "api",
29
29
  "source" => {
@@ -45,7 +45,7 @@ class Zendesk2::Client
45
45
  "events" => [
46
46
  "id" => self.class.new_id,
47
47
  "type" => "Comment",
48
- "author_id" => current_user_id,
48
+ "author_id" => current_user["id"],
49
49
  "body" => comment["body"],
50
50
  "html_body" => "<p>#{comment["body"]}</p>",
51
51
  "public" => comment["public"].nil? ? true : comment["public"],
@@ -1,11 +1,13 @@
1
1
  class Zendesk2::Client
2
2
  class Real
3
3
  def update_topic_comment(params={})
4
- id = params.delete("id")
4
+ id = params.delete("id")
5
+ topic_id = params.delete("topic_id")
6
+ path = "/topics/#{topic_id}/comments/#{id}.json"
5
7
 
6
8
  request(
7
9
  :method => :put,
8
- :path => "/topic_comments/#{id}.json",
10
+ :path => path,
9
11
  :body => {
10
12
  "topic_comment" => params
11
13
  },
@@ -14,17 +16,22 @@ class Zendesk2::Client
14
16
  end
15
17
  class Mock
16
18
  def update_topic_comment(params={})
17
- id = params.delete("id")
18
- path = "/topic_comments/#{id}.json"
19
+ id = params.delete("id")
20
+ topic_id = params.delete("topic_id")
21
+ path = "/topics/#{topic_id}/comments/#{id}.json"
19
22
 
20
- body = self.data[:topic_comments][id].merge!(params)
21
- response(
22
- :method => :put,
23
- :path => path,
24
- :body => {
25
- "topic_comment" => body
26
- },
27
- )
23
+ unless (topic_comment = self.data[:topic_comments][id]) && topic_comment["topic_id"] == topic_id
24
+ response(status: 404)
25
+ else
26
+ body = topic_comment.merge!(params)
27
+ response(
28
+ :method => :put,
29
+ :path => path,
30
+ :body => {
31
+ "topic_comment" => body
32
+ },
33
+ )
34
+ end
28
35
  end
29
36
  end
30
37
  end
@@ -14,9 +14,10 @@ class Zendesk2::Client
14
14
  end
15
15
  class Mock
16
16
  def update_user(params={})
17
- id = params.delete("id")
18
- path = "/users/#{id}.json"
19
- if params["email"] && self.data[:users].find{|k,u| u["email"] == params["email"] && k != id}
17
+ user_id = params.delete("id")
18
+ path = "/users/#{user_id}.json"
19
+
20
+ if (email = params["email"]) && self.data[:identities].find{|k,i| i["type"] == "email" && i["value"] == email}
20
21
  response(
21
22
  :method => :put,
22
23
  :path => path,
@@ -31,7 +32,22 @@ class Zendesk2::Client
31
32
  }
32
33
  )
33
34
  else
34
- body = self.data[:users][id].merge!(params)
35
+ user_identity_id = self.class.new_id # ugh
36
+
37
+ user_identity = {
38
+ "id" => user_identity_id,
39
+ "url" => url_for("/users/#{user_id}/identities/#{user_identity_id}.json"),
40
+ "created_at" => Time.now.iso8601,
41
+ "updated_at" => Time.now.iso8601,
42
+ "type" => "email",
43
+ "value" => params["email"],
44
+ "verified" => false,
45
+ "primary" => false,
46
+ "user_id" => user_id,
47
+ }
48
+
49
+ self.data[:identities][user_identity_id] = user_identity
50
+ body = self.data[:users][user_id].merge!(params)
35
51
  response(
36
52
  :method => :put,
37
53
  :path => path,
@@ -65,6 +65,7 @@ class Zendesk2::Client < Cistern::Service
65
65
  request :get_user_identity
66
66
  request :get_users
67
67
  request :search
68
+ request :search_user
68
69
  request :mark_user_identity_primary
69
70
  request :update_category
70
71
  request :update_forum
@@ -139,7 +140,7 @@ class Zendesk2::Client < Cistern::Service
139
140
 
140
141
  class Mock
141
142
 
142
- attr_reader :username, :url, :token, :current_user_id
143
+ attr_reader :username, :url, :token
143
144
 
144
145
  def self.data
145
146
  @data ||= {
@@ -183,14 +184,17 @@ class Zendesk2::Client < Cistern::Service
183
184
  @username, @password = options[:username], options[:password]
184
185
  @token = options[:token]
185
186
 
186
- @current_user_id = self.class.new_id
187
+ @current_user ||= self.create_user("email" => @username, "name" => "Mock Agent").body["user"]
188
+ @current_user_identity ||= self.data[:identities].values.first
189
+ end
187
190
 
188
- self.data[:users][@current_user_id]= {
189
- "id" => @current_user_id,
190
- "email" => @username,
191
- "name" => "Mock Agent",
192
- "url" => url_for("/users/#{@current_user_id}.json"),
193
- }
191
+ # Lazily re-seeds data after reset
192
+ # @return [Hash] current user response
193
+ def current_user
194
+ self.data[:users][@current_user["id"]] ||= @current_user
195
+ self.data[:identities][@current_user_identity["id"]] ||= @current_user_identity
196
+
197
+ @current_user
194
198
  end
195
199
 
196
200
  def url_for(path)
@@ -1,6 +1,19 @@
1
+ # @abstract adds {#create!} method
1
2
  class Zendesk2::Collection < Cistern::Collection
3
+
4
+ # Attempt creation of resource and explode if unsuccessful
5
+ # @raise [Zendesk2::Error] if creation was unsuccessful
6
+ # @return [Cistern::Model]
2
7
  def create!(attributes={})
3
- model = self.new(attributes)
8
+ model = self.new(attributes.merge(Zendesk2.stringify_keys(self.attributes)))
4
9
  model.save!
5
10
  end
11
+
12
+ # Quietly attempt creation of resource. Check {#new_record?} and {#errors} for success
13
+ # @see {#create!} to raise an exception on failure
14
+ # @return [Cistern::Model]
15
+ def create(attributes={})
16
+ model = self.new(attributes.merge(Zendesk2.stringify_keys(self.attributes)))
17
+ model.save
18
+ end
6
19
  end
@@ -1,11 +1,19 @@
1
+ # @abstract subclass and implement {#save!}
1
2
  class Zendesk2::Model < Cistern::Model
2
-
3
3
  attr_accessor :errors
4
4
 
5
+ # @abstract override in subclass
6
+ # @raise [Zendesk2::Error] if unsuccessful
7
+ def save!
8
+ raise NotImplementError
9
+ end
10
+
11
+ # calls {#save!} and sets {#errors} if unsuccessful and applicable
12
+ # @return [Zendesk2::Model] self, regardless of success
5
13
  def save
6
14
  save!
7
15
  rescue Zendesk2::Error => e
8
- self.errors= e.response[:body]["details"].inject({}){|r,(k,v)| r.merge(k => v.map{|e| e["type"] || e["description"]})} rescue nil
16
+ self.errors = e.response[:body]["details"].inject({}){|r,(k,v)| r.merge(k => v.map{|e| e["type"] || e["description"]})} rescue nil
9
17
  self
10
18
  end
11
19
 
@@ -4,7 +4,7 @@ module Zendesk2::Searchable
4
4
  end
5
5
 
6
6
  def search(parameters)
7
- body = connection.search(parameters.merge("type" => self.class.search_type)).body
7
+ body = connection.send(self.class.search_request, parameters.merge("type" => self.class.search_type)).body
8
8
  if data = body.delete("results")
9
9
  load(data)
10
10
  end
@@ -13,5 +13,10 @@ module Zendesk2::Searchable
13
13
 
14
14
  module Attributes
15
15
  attr_accessor :search_type
16
+ attr_writer :search_request
17
+
18
+ def search_request
19
+ @search_request ||= :search
20
+ end
16
21
  end
17
22
  end
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -2,8 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "organizations" do
4
4
  let(:client) { create_client }
5
- it_should_behave_like "a resource",
6
- :organizations,
5
+ it_should_behave_like "a resource", :organizations,
7
6
  lambda { {name: Zendesk2.uuid} },
8
7
  lambda { {name: Zendesk2.uuid} }
9
8
 
data/spec/spec_helper.rb CHANGED
@@ -13,8 +13,9 @@ end
13
13
  Cistern.formatter = Cistern::Formatter::AwesomePrint
14
14
 
15
15
  RSpec.configure do |config|
16
- config.before(:all) do
16
+ config.before(:each) do
17
17
  Zendesk2::Client.reset! if Zendesk2::Client.mocking?
18
18
  end
19
+ config.order = "random"
19
20
  config.filter_run_excluding(:mock_only => true) unless Zendesk2::Client.mocking?
20
21
  end
@@ -3,6 +3,7 @@ require 'logger'
3
3
  module ClientHelper
4
4
  def create_client(options={})
5
5
  options.merge!(logger: Logger.new(STDOUT)) if ENV['VERBOSE']
6
+ options = {username: "zendesk2@example.org", password: "password"}.merge(Zendesk2.defaults).merge(options)
6
7
  Zendesk2::Client.new(options)
7
8
  end
8
9
  end
data/spec/users_spec.rb CHANGED
@@ -2,20 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe "users" do
4
4
  let(:client) { create_client }
5
- it_should_behave_like "a resource",
6
- :users,
5
+ it_should_behave_like "a resource", :users,
7
6
  lambda { {email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, verified: true} },
8
7
  lambda { {name: Zendesk2.uuid} }
9
8
 
10
9
  it "should get current user" do
11
10
  current_user = client.users.current
12
- current_user.should be_a(Zendesk2::Client::User)
13
11
  current_user.email.should == client.username
14
12
  end
15
13
 
16
14
  describe do
17
15
  before(:each) do
18
- @user = client.users.create(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid)
16
+ @user = client.users.create!(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid)
19
17
  end
20
18
 
21
19
  let(:user) { @user }
@@ -103,6 +101,25 @@ describe "users" do
103
101
  user.errors.should == {"email" => ["Email: #{email} is already being used by another user"]}
104
102
  end
105
103
 
104
+ it "should create another identity when updating email" do
105
+ original_email = user.email
106
+ user.email = (new_email = "zendesk2+#{Zendesk2.uuid}@example.org")
107
+ user.save!
108
+
109
+ (identities = user.identities.all).size.should == 2
110
+ new_identity = identities.find{|i| i.value == new_email}
111
+ new_identity.should_not be_nil
112
+
113
+ new_identity.primary.should be_false
114
+
115
+ original_identity = identities.find{|i| i.value == original_email}
116
+ original_identity.should_not be_nil
117
+
118
+ original_identity.primary.should be_true
119
+
120
+ user.reload.email.should == original_email
121
+ end
122
+
106
123
  it "should form login url" do
107
124
  return_to = "http://engineyard.com"
108
125
  uri = Addressable::URI.parse(user.login_url(Time.now.to_s, return_to: return_to))
metadata CHANGED
@@ -1,80 +1,80 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk2
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.1.2
4
5
  prerelease:
5
- version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Lane
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2012-12-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
+ name: cistern
15
16
  prerelease: false
16
- type: :runtime
17
- version_requirements: !ruby/object:Gem::Requirement
18
- none: false
17
+ requirement: !ruby/object:Gem::Requirement
19
18
  requirements:
20
19
  - - ~>
21
20
  - !ruby/object:Gem::Version
22
21
  version: 0.1.3
23
- name: cistern
24
- requirement: !ruby/object:Gem::Requirement
25
22
  none: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
28
  version: 0.1.3
29
+ none: false
30
30
  - !ruby/object:Gem::Dependency
31
+ name: faraday
31
32
  prerelease: false
32
- type: :runtime
33
- version_requirements: !ruby/object:Gem::Requirement
34
- none: false
33
+ requirement: !ruby/object:Gem::Requirement
35
34
  requirements:
36
35
  - - ! '>='
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
- name: faraday
40
- requirement: !ruby/object:Gem::Requirement
41
38
  none: false
39
+ type: :runtime
40
+ version_requirements: !ruby/object:Gem::Requirement
42
41
  requirements:
43
42
  - - ! '>='
44
43
  - !ruby/object:Gem::Version
45
44
  version: '0'
45
+ none: false
46
46
  - !ruby/object:Gem::Dependency
47
+ name: faraday_middleware
47
48
  prerelease: false
48
- type: :runtime
49
- version_requirements: !ruby/object:Gem::Requirement
50
- none: false
49
+ requirement: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - ! '>='
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- name: faraday_middleware
56
- requirement: !ruby/object:Gem::Requirement
57
54
  none: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ! '>='
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
61
+ none: false
62
62
  - !ruby/object:Gem::Dependency
63
+ name: addressable
63
64
  prerelease: false
64
- type: :runtime
65
- version_requirements: !ruby/object:Gem::Requirement
66
- none: false
65
+ requirement: !ruby/object:Gem::Requirement
67
66
  requirements:
68
67
  - - ! '>='
69
68
  - !ruby/object:Gem::Version
70
69
  version: '0'
71
- name: addressable
72
- requirement: !ruby/object:Gem::Requirement
73
70
  none: false
71
+ type: :runtime
72
+ version_requirements: !ruby/object:Gem::Requirement
74
73
  requirements:
75
74
  - - ! '>='
76
75
  - !ruby/object:Gem::Version
77
76
  version: '0'
77
+ none: false
78
78
  description: Zendesk V2 API client
79
79
  email:
80
80
  - me@joshualane.com
@@ -154,6 +154,7 @@ files:
154
154
  - lib/zendesk2/client/requests/get_users.rb
155
155
  - lib/zendesk2/client/requests/mark_user_identity_primary.rb
156
156
  - lib/zendesk2/client/requests/search.rb
157
+ - lib/zendesk2/client/requests/search_user.rb
157
158
  - lib/zendesk2/client/requests/update_category.rb
158
159
  - lib/zendesk2/client/requests/update_forum.rb
159
160
  - lib/zendesk2/client/requests/update_organization.rb
@@ -188,17 +189,17 @@ rdoc_options: []
188
189
  require_paths:
189
190
  - lib
190
191
  required_ruby_version: !ruby/object:Gem::Requirement
191
- none: false
192
192
  requirements:
193
193
  - - ! '>='
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
- required_rubygems_version: !ruby/object:Gem::Requirement
197
196
  none: false
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - ! '>='
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
+ none: false
202
203
  requirements: []
203
204
  rubyforge_project:
204
205
  rubygems_version: 1.8.24