zendesk2 0.0.2 → 0.0.3

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.
@@ -5,19 +5,26 @@ class Zendesk2::Client < Cistern::Service
5
5
 
6
6
  model :organization
7
7
  collection :organizations
8
+ model :ticket
9
+ collection :tickets
8
10
  model :user
9
11
  collection :users
10
12
 
11
13
  request :create_organization
14
+ request :create_ticket
12
15
  request :create_user
13
16
  request :destroy_organization
17
+ request :destroy_ticket
14
18
  request :destroy_user
15
19
  request :get_current_user
16
20
  request :get_organization
21
+ request :get_ticket
17
22
  request :get_user
18
23
  request :get_organizations
24
+ request :get_tickets
19
25
  request :get_users
20
26
  request :update_organization
27
+ request :update_ticket
21
28
  request :update_user
22
29
 
23
30
  recognizes :url, :subdomain, :host, :port, :path, :scheme, :logger, :adapter
@@ -91,8 +98,9 @@ class Zendesk2::Client < Cistern::Service
91
98
 
92
99
  def self.data
93
100
  @data ||= {
94
- :users => {},
101
+ :users => {},
95
102
  :organizations => {},
103
+ :tickets => {},
96
104
  }
97
105
  end
98
106
 
@@ -0,0 +1,55 @@
1
+ class Zendesk2::Client::Ticket < Cistern::Model
2
+ include Zendesk2::Errors
3
+ identity :id
4
+ attribute :external_id
5
+ attribute :via
6
+ attribute :created_at, type: :time
7
+ attribute :updated_at, type: :time
8
+ attribute :type
9
+ attribute :subject
10
+ attribute :description
11
+ attribute :priority
12
+ attribute :status
13
+ attribute :recipient
14
+ attribute :requester_id
15
+ attribute :submitter_id
16
+ attribute :assignee_id
17
+ attribute :organization_id
18
+ attribute :group_id
19
+ attribute :collaborator_ids, type: :array
20
+ attribute :forum_topic_id
21
+ attribute :problem_id
22
+ attribute :has_incidents
23
+ attribute :due_at
24
+ attribute :tags
25
+ attribute :fields
26
+
27
+ def save
28
+ if new_record?
29
+ requires :subject, :description
30
+ data = connection.create_ticket(attributes).body["ticket"]
31
+ merge_attributes(data)
32
+ else
33
+ requires :identity
34
+ params = {
35
+ "id" => self.identity,
36
+ "subject" => self.subject,
37
+ "description" => self.description,
38
+ }
39
+ data = connection.update_ticket(params).body["ticket"]
40
+ merge_attributes(data)
41
+ end
42
+ end
43
+
44
+ def destroy
45
+ requires :identity
46
+
47
+ connection.destroy_ticket("id" => self.identity)
48
+ end
49
+
50
+ def destroyed?
51
+ self.reload
52
+ rescue not_found
53
+ true
54
+ end
55
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client::Tickets < Cistern::Collection
2
+ include Zendesk2::PagedCollection
3
+
4
+ model Zendesk2::Client::Ticket
5
+
6
+ self.collection_method= :get_tickets
7
+ self.collection_root= "tickets"
8
+ self.model_method= :get_ticket
9
+ self.model_root= "ticket"
10
+
11
+ def search(term)
12
+ body = connection.search_ticket("query" => term).body
13
+ if data = body.delete("results")
14
+ load(data)
15
+ end
16
+ merge_attributes(body)
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def create_ticket(params={})
4
+ request(
5
+ :body => {"ticket" => params},
6
+ :method => :post,
7
+ :path => "/tickets.json",
8
+ )
9
+ end
10
+ end # Real
11
+
12
+ class Mock
13
+ def create_ticket(params={})
14
+ identity = self.class.new_id
15
+
16
+ record = {
17
+ "id" => identity,
18
+ "url" => url_for("/tickets/#{identity}.json"),
19
+ "created_at" => Time.now.iso8601,
20
+ "updated_at" => Time.now.iso8601,
21
+ }.merge(params)
22
+
23
+ self.data[:tickets][identity]= record
24
+
25
+ response(
26
+ :method => :post,
27
+ :body => {"ticket" => record},
28
+ :path => "/tickets.json"
29
+ )
30
+ end
31
+ end # Mock
32
+ end
@@ -0,0 +1,27 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def destroy_ticket(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :delete,
8
+ :path => "/tickets/#{id}.json"
9
+ )
10
+ end
11
+ end
12
+
13
+ class Mock
14
+ def destroy_ticket(params={})
15
+ id = params["id"]
16
+ body = self.data[:tickets].delete(id)
17
+
18
+ response(
19
+ :method => :delete,
20
+ :path => "/tickets/#{id}.json",
21
+ :body => {
22
+ "ticket" => body,
23
+ },
24
+ )
25
+ end
26
+ end
27
+ end
@@ -5,7 +5,7 @@ class Zendesk2::Client
5
5
 
6
6
  request(
7
7
  :method => :get,
8
- :path => "/organizations/#{id}.json"
8
+ :path => "/organizations/#{id}.json"
9
9
  )
10
10
  end
11
11
  end # Real
@@ -0,0 +1,33 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_ticket(params={})
4
+ id = params["id"]
5
+
6
+ request(
7
+ :method => :get,
8
+ :path => "/tickets/#{id}.json"
9
+ )
10
+ end
11
+ end # Real
12
+
13
+ class Mock
14
+ def get_ticket(params={})
15
+ id = params["id"]
16
+ if body = self.data[:tickets][id]
17
+
18
+ response(
19
+ :path => "/tickets/#{id}.json",
20
+ :body => {
21
+ "ticket" => body
22
+ },
23
+ )
24
+ else
25
+ r = response(
26
+ :path => "/tickets/#{id}.json",
27
+ :status => 404
28
+ )
29
+ raise not_found!(nil, r)
30
+ end
31
+ end
32
+ end # Mock
33
+ end
@@ -0,0 +1,18 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def get_tickets(params={})
4
+ page_params = Zendesk2.paging_parameters(params)
5
+
6
+ request(
7
+ :params => page_params,
8
+ :method => :get,
9
+ :path => "/tickets.json",
10
+ )
11
+ end
12
+ end
13
+ class Mock
14
+ def get_tickets(params={})
15
+ page(params, :tickets, "/tickets.json", "tickets")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ class Zendesk2::Client
2
+ class Real
3
+ def update_ticket(params={})
4
+ id = params.delete("id")
5
+
6
+ request(
7
+ :method => :put,
8
+ :path => "/tickets/#{id}.json",
9
+ :body => {
10
+ "ticket" => params
11
+ },
12
+ )
13
+ end
14
+ end
15
+ class Mock
16
+ def update_ticket(params={})
17
+ id = params.delete("id")
18
+ body = self.data[:tickets][id].merge!(params)
19
+
20
+ response(
21
+ :method => :put,
22
+ :path => "/tickets/#{id}.json",
23
+ :body => {
24
+ "ticket" => body
25
+ },
26
+ )
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "tickets" do
4
+ let(:client) { create_client }
5
+ it_should_behave_like "a resource",
6
+ :tickets,
7
+ lambda { {subject: Zendesk2.uuid, description: Zendesk2.uuid} },
8
+ lambda { {subject: Zendesk2.uuid} }
9
+ 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.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -110,25 +110,33 @@ files:
110
110
  - lib/zendesk2/errors.rb
111
111
  - lib/zendesk2/models/organization.rb
112
112
  - lib/zendesk2/models/organizations.rb
113
+ - lib/zendesk2/models/ticket.rb
114
+ - lib/zendesk2/models/tickets.rb
113
115
  - lib/zendesk2/models/user.rb
114
116
  - lib/zendesk2/models/users.rb
115
117
  - lib/zendesk2/paged_collection.rb
116
118
  - lib/zendesk2/requests/create_organization.rb
119
+ - lib/zendesk2/requests/create_ticket.rb
117
120
  - lib/zendesk2/requests/create_user.rb
118
121
  - lib/zendesk2/requests/destroy_organization.rb
122
+ - lib/zendesk2/requests/destroy_ticket.rb
119
123
  - lib/zendesk2/requests/destroy_user.rb
120
124
  - lib/zendesk2/requests/get_current_user.rb
121
125
  - lib/zendesk2/requests/get_organization.rb
122
126
  - lib/zendesk2/requests/get_organizations.rb
127
+ - lib/zendesk2/requests/get_ticket.rb
128
+ - lib/zendesk2/requests/get_tickets.rb
123
129
  - lib/zendesk2/requests/get_user.rb
124
130
  - lib/zendesk2/requests/get_users.rb
125
131
  - lib/zendesk2/requests/update_organization.rb
132
+ - lib/zendesk2/requests/update_ticket.rb
126
133
  - lib/zendesk2/requests/update_user.rb
127
134
  - lib/zendesk2/version.rb
128
135
  - spec/organizations_spec.rb
129
136
  - spec/shared/resource.rb
130
137
  - spec/spec_helper.rb
131
138
  - spec/support/client_helper.rb
139
+ - spec/tickets_spec.rb
132
140
  - spec/users_spec.rb
133
141
  - zendesk2.gemspec
134
142
  homepage: ''
@@ -160,5 +168,6 @@ test_files:
160
168
  - spec/shared/resource.rb
161
169
  - spec/spec_helper.rb
162
170
  - spec/support/client_helper.rb
171
+ - spec/tickets_spec.rb
163
172
  - spec/users_spec.rb
164
173
  has_rdoc: