zendesk2 0.0.19 → 0.0.20

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/Gemfile CHANGED
@@ -4,6 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rake'
7
+ gem 'cistern'#, :path => "~/p/cistern"
7
8
 
8
9
  group :test do
9
10
  gem 'guard-rspec'
@@ -45,6 +45,10 @@ class Zendesk2::Client::Topic < Zendesk2::Model
45
45
  merge_attributes(data)
46
46
  end
47
47
 
48
+ def comments
49
+ self.topic_comments(topic_id: topic_id)
50
+ end
51
+
48
52
  private
49
53
 
50
54
  def params
@@ -19,11 +19,7 @@ class Zendesk2::Client::TopicComment < Zendesk2::Model
19
19
  def destroy
20
20
  requires :identity
21
21
 
22
- connection.destroy_topic_comment("id" => self.identity)
23
- end
24
-
25
- def destroyed?
26
- !self.reload
22
+ connection.destroy_topic_comment("id" => self.identity, "topic_id" => self.topic_id)
27
23
  end
28
24
 
29
25
  def save!
@@ -37,6 +33,16 @@ class Zendesk2::Client::TopicComment < Zendesk2::Model
37
33
  merge_attributes(data)
38
34
  end
39
35
 
36
+ def reload
37
+ requires :identity
38
+
39
+ if data = collection.get(topic_id, identity)
40
+ new_attributes = data.attributes
41
+ merge_attributes(new_attributes)
42
+ self
43
+ end
44
+ end
45
+
40
46
  private
41
47
 
42
48
  def params
@@ -2,11 +2,29 @@ class Zendesk2::Client::TopicComments < Zendesk2::Collection
2
2
  include Zendesk2::PagedCollection
3
3
  include Zendesk2::Searchable
4
4
 
5
+ attribute :topic_id
6
+
5
7
  model Zendesk2::Client::TopicComment
6
8
 
7
- self.collection_method= :get_topic_comments
8
- self.collection_root= "topic_comments"
9
- self.model_method= :get_topic_comment
10
- self.model_root= "topic_comment"
11
- self.search_type= "topic_comment"
9
+ self.collection_method = :get_topic_comments
10
+ self.collection_root = "topic_comments"
11
+ self.model_method = :get_topic_comment
12
+ self.model_root = "topic_comment"
13
+ self.search_type = "topic_comment"
14
+
15
+ def all(params={})
16
+ body = connection.send(collection_method, params.merge("topic_id" => self.topic_id)).body
17
+
18
+ collection = self.clone.load(body[collection_root])
19
+ collection.merge_attributes(Cistern::Hash.slice(body, "count", "next_page", "previous_page"))
20
+ collection
21
+ end
22
+
23
+ def get(topic_id, topic_comment_id)
24
+ if data = self.connection.send(model_method, {"topic_id" => topic_id, "id" => topic_comment_id}).body[self.model_root]
25
+ new(data)
26
+ end
27
+ rescue Zendesk2::Error
28
+ nil
29
+ end
12
30
  end
@@ -1,10 +1,11 @@
1
1
  class Zendesk2::Client
2
2
  class Real
3
3
  def create_topic_comment(params={})
4
+ topic_id = params.delete("topic_id")
4
5
  request(
5
6
  :body => {"topic_comment" => params},
6
7
  :method => :post,
7
- :path => "/topic_comments.json",
8
+ :path => "/topics/#{topic_id}/comments.json",
8
9
  )
9
10
  end
10
11
  end # Real
@@ -1,19 +1,21 @@
1
1
  class Zendesk2::Client
2
2
  class Real
3
3
  def destroy_topic_comment(params={})
4
- id = params["id"]
4
+ id = params["id"]
5
+ topic_id = params["topic_id"]
5
6
 
6
7
  request(
7
8
  :method => :delete,
8
- :path => "/topic_comments/#{id}.json"
9
+ :path => "/topics/#{topic_id}/comments/#{id}.json"
9
10
  )
10
11
  end
11
12
  end
12
13
 
13
14
  class Mock
14
15
  def destroy_topic_comment(params={})
15
- id = params["id"]
16
- path = "/topic_comments/#{id}.json"
16
+ id = params["id"]
17
+ topic_id = params["topic_id"]
18
+ path = "/topics/#{topic_id}/comments/#{id}.json"
17
19
 
18
20
  body = self.data[:topic_comments].delete(id)
19
21
  response(
@@ -1,11 +1,12 @@
1
1
  class Zendesk2::Client
2
2
  class Real
3
3
  def get_topic_comment(params={})
4
- id = params["id"]
4
+ id = params["id"]
5
+ topic_id = params["topic_id"]
5
6
 
6
7
  request(
7
8
  :method => :get,
8
- :path => "/topic_comments/#{id}.json"
9
+ :path => "/topics/#{topic_id}/comments/#{id}.json"
9
10
  )
10
11
  end
11
12
  end # Real
@@ -1,18 +1,22 @@
1
1
  class Zendesk2::Client
2
2
  class Real
3
3
  def get_topic_comments(params={})
4
+ topic_id = params.delete("topic_id")
4
5
  page_params = Zendesk2.paging_parameters(params)
5
6
 
6
7
  request(
7
- :params => page_params,
8
- :method => :get,
9
- :path => "/topic_comments.json",
8
+ :params => page_params,
9
+ :path => "/topics/#{topic_id}/comments.json",
10
10
  )
11
11
  end
12
12
  end
13
13
  class Mock
14
14
  def get_topic_comments(params={})
15
- page(params, :topic_comments, "/topic_comments.json", "topic_comments")
15
+ topic_id = params["topic_id"]
16
+ topic = self.data[:topics][topic_id] # TODO: 404 if !topic
17
+ filter = lambda{|comments| comments.select{|c| c["topic_id"] == topic_id}}
18
+
19
+ page(params, :topic_comments, "/topics/#{topic_id}/comments.json", "topic_comments", filter: filter)
16
20
  end
17
21
  end
18
22
  end
@@ -8,4 +8,8 @@ class Zendesk2::Model < Cistern::Model
8
8
  self.errors= e.response[:body]["details"].inject({}){|r,(k,v)| r.merge(k => v.map{|e| e["type"] || e["description"]})} rescue nil
9
9
  self
10
10
  end
11
+
12
+ def destroyed?
13
+ !self.reload
14
+ end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Zendesk2
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
@@ -1,13 +1,20 @@
1
- shared_examples "a resource" do |_collection, _params, _update_params|
2
- let(:collection) { client.send(_collection) }
3
- let(:params) { instance_exec(&_params) || {} }
1
+ shared_examples "a resource" do |_collection, _params, _update_params, _options|
2
+ let(:options) { _options || {} }
3
+ let(:collection) { options[:collection] ? instance_exec(&options[:collection]) : client.send(_collection) }
4
+ let(:params) { instance_exec(&_params) || {} }
4
5
  let(:update_params) { instance_exec(&_update_params) }
6
+ let(:fetch_params) { options[:fetch_params] || lambda {|r| r.identity} }
5
7
 
6
8
  it "by creating a record" do
7
- record = collection.create(params)
9
+ record = collection.create!(params)
8
10
  record.identity.should_not be_nil
9
11
  end
10
12
 
13
+ it "by fetching a specific record" do
14
+ record = collection.create(params)
15
+ collection.get(*fetch_params.call(record)).should == record
16
+ end
17
+
11
18
  context "that is paged" do
12
19
  before(:each) do
13
20
  2.times.each { collection.create(instance_exec(&_params)) }
@@ -30,11 +37,6 @@ shared_examples "a resource" do |_collection, _params, _update_params|
30
37
  end
31
38
  end
32
39
 
33
- it "by fetching a specific record" do
34
- record = collection.create(params)
35
- collection.get(record.identity).should == record
36
- end
37
-
38
40
  it "by updating a record" do
39
41
  record = collection.create(params)
40
42
  record.merge_attributes(update_params)
@@ -2,11 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  describe "topic_comments" do
4
4
  let(:client) { create_client }
5
- let(:user) { client.users.create(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, verified: true) }
6
- let(:forum) { client.forums.create(name: Zendesk2.uuid) }
7
- let(:topic) { client.topics.create(title: Zendesk2.uuid, body: Zendesk2.uuid, forum: forum) }
5
+ let(:user) { client.users.create(email: "zendesk2+#{Zendesk2.uuid}@example.org", name: Zendesk2.uuid, verified: true) }
6
+ let(:forum) { client.forums.create(name: Zendesk2.uuid) }
7
+ let(:topic) { client.topics.create(title: Zendesk2.uuid, body: Zendesk2.uuid, forum: forum) }
8
8
  it_should_behave_like "a resource",
9
9
  :topic_comments,
10
10
  lambda { {body: Zendesk2.uuid, topic_id: topic.id, user_id: user.id} },
11
- lambda { {body: Zendesk2.uuid} }
11
+ lambda { {body: Zendesk2.uuid} },
12
+ {
13
+ :fetch_params => lambda {|tc| [tc.topic_id, tc.id]},
14
+ :collection => lambda { client.topic_comments(topic_id: topic.id) },
15
+ }
12
16
  end
data/zendesk2.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Zendesk2::VERSION
17
17
 
18
- gem.add_dependency "cistern", "~> 0.0.2"
18
+ gem.add_dependency "cistern"#, "~> 0.0.2"
19
19
  gem.add_dependency "faraday"
20
20
  gem.add_dependency "faraday_middleware"
21
21
  gem.add_dependency "addressable"
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.19
4
+ version: 0.0.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-20 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cistern
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.2
21
+ version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.2
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: faraday
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -200,4 +200,3 @@ test_files:
200
200
  - spec/topic_comments_spec.rb
201
201
  - spec/topics_spec.rb
202
202
  - spec/users_spec.rb
203
- has_rdoc: