zendesk-api 0.3.3 → 0.3.4

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.
@@ -13,42 +13,54 @@ The unofficial Ruby Library for interacting with the [Zendesk REST API](http://w
13
13
 
14
14
  ## Install Instructions
15
15
  Normal install:
16
+
16
17
  gem install zendesk-api
17
18
 
18
19
  Bundler install:
20
+
19
21
  gem "zendesk-api", "latestversion"
20
22
 
21
23
  ## How to use it
22
24
  ### Basic
23
25
  Below outputs xml
26
+
24
27
  z = Zendesk::Main.new('subdomain', 'username', 'password')
25
28
  and outputs json
29
+
26
30
  z = Zendesk::Main.new('subdomain', 'username', 'password', :format => 'json')
27
31
 
28
32
  For the most part all functions is based on the following functions
29
33
  REST function_names = %{user, organization, group, ticket,attachement, tag, forum, entries, search}
30
34
 
31
35
  ### Show
36
+
32
37
  z.get_function_name(user_id)
33
38
  e.g.
39
+
34
40
  z.get_user(121)
35
41
  ### List
42
+
36
43
  z.get_function_names #with a s in the end, for plural
37
44
  e.g.
45
+
38
46
  z.get_users
39
47
 
40
48
  ### Create
41
49
  with string
50
+
42
51
  z.create_function_name("<user><email>email@company.com</email><name>John Doe</name></user>")
43
52
  with hash(array is not supported yet)
53
+
44
54
  z.create_function_name({:email => 'email@company.com', :name => 'John Doe'})
45
55
 
46
56
  ### Update
47
57
  Not supported yet
48
58
 
49
59
  ### Destroy
60
+
50
61
  z.destroy_function_name(id)
51
62
  e.g.
63
+
52
64
  z.destroy_user(234)
53
65
 
54
66
 
@@ -22,4 +22,5 @@ require 'zendesk/tag'
22
22
  require 'zendesk/forum'
23
23
  require 'zendesk/entry'
24
24
  require 'zendesk/search'
25
+ require 'zendesk/comment'
25
26
  require 'zendesk/main'
@@ -17,7 +17,9 @@ module Zendesk
17
17
 
18
18
  def main_url
19
19
  url_prefix = @options[:ssl] ? "https://" : "http://"
20
- url_postfix = ".zendesk.com/"
20
+ url_postfix = '.zendesk.com/'
21
+ url_postfix << "api/v#{@options[:api_version]}/" if @options[:api_version]
22
+
21
23
  url = url_prefix + @account + url_postfix
22
24
  end
23
25
 
@@ -50,23 +52,29 @@ module Zendesk
50
52
  end
51
53
  end
52
54
 
53
- def make_request(end_url, body = {})
55
+ def make_request(end_url, body = {}, options = {})
56
+ options.reverse_merge!({:on_behalf_of => nil})
57
+
54
58
  curl = Curl::Easy.new(main_url + end_url + ".#{@format}")
55
59
  curl.userpwd = "#{@username}:#{@password}"
60
+
61
+ curl.headers={}
62
+ curl.headers.merge!({"X-On-Behalf-Of" => options[:on_behalf_of]}) if options[:on_behalf_of].present?
63
+
56
64
  if body.empty? or body[:list]
57
65
  curl.url = curl.url + params_list(body[:list]) if body[:list]
58
66
  curl.perform
59
67
  elsif body[:post]
60
- curl.headers = "Content-Type: application/xml"
68
+ curl.headers.merge!({"Content-Type" => "application/xml"})
61
69
  curl.http_post
62
70
  elsif body[:create]
63
- curl.headers = "Content-Type: application/xml"
71
+ curl.headers.merge!({"Content-Type" => "application/xml"})
64
72
  curl.http_post(string_body(body))
65
73
  elsif body[:update]
66
74
  # PUT seems badly broken, at least I can't get it to work without always
67
75
  # raising an exception about rewinding the data stream
68
76
  # curl.http_put(final_body)
69
- curl.headers = { "Content-Type" => "application/xml", "X-Http-Method-Override" => "put" }
77
+ curl.headers.merge!({ "Content-Type" => "application/xml", "X-Http-Method-Override" => "put" })
70
78
  curl.http_post(string_body(body))
71
79
  elsif body[:destroy]
72
80
  curl.http_delete
@@ -119,5 +127,6 @@ module Zendesk
119
127
  include Zendesk::Forum
120
128
  include Zendesk::Entry
121
129
  include Zendesk::Search
130
+ include Zendesk::Comment
122
131
  end
123
132
  end
@@ -9,12 +9,12 @@ module Zendesk
9
9
  make_request("tickets/#{id}")
10
10
  end
11
11
 
12
- def create_ticket(input)
13
- make_request("tickets", :create => Zendesk::Main.to_xml('ticket', input))
12
+ def create_ticket(input, options = {})
13
+ make_request("tickets", {:create => Zendesk::Main.to_xml('ticket', input)}, options)
14
14
  end
15
15
 
16
- def update_ticket(input)
17
- make_request("tickets", :update => Zendesk::Main.to_xml('ticket', input))
16
+ def update_ticket(id, input, options = {})
17
+ make_request("tickets/#{id}", {:update => Zendesk::Main.to_xml('ticket', input)}, options)
18
18
  end
19
19
 
20
20
  def delete_ticket(id)
@@ -1,47 +1,123 @@
1
1
  require "spec"
2
- require 'lib/zendesk-api'
3
-
4
- describe Zendesk::Main, "basic" do
5
- before(:each) do
6
- @account = "this_account"
7
- @username = "this_username"
8
- @password = "this_password"
9
- @zendesk = Zendesk::Main.new(@account, @username, @password)
10
- end
2
+ require 'zendesk-api'
11
3
 
12
- it "should have the correct mail_url with no ssl options" do
13
- @zendesk.main_url.should == "http://#{@account}.zendesk.com/"
14
- end
4
+ describe Zendesk::Main do
5
+ describe "basic" do
6
+ before(:each) do
7
+ @account = "this_account"
8
+ @username = "this_username"
9
+ @password = "this_password"
10
+ @zendesk = Zendesk::Main.new(@account, @username, @password)
11
+ end
15
12
 
16
- it "should have the correct mail_url with ssl options" do
17
- @zendesk = Zendesk::Main.new(@account, @username, @password, :ssl => true)
18
- @zendesk.main_url.should == "https://#{@account}.zendesk.com/"
19
- end
20
- end
13
+ it "should have the correct mail_url with no ssl options" do
14
+ @zendesk.main_url.should == "http://#{@account}.zendesk.com/"
15
+ end
16
+
17
+ it "should have the correct mail_url with ssl options" do
18
+ @zendesk = Zendesk::Main.new(@account, @username, @password, :ssl => true)
19
+ @zendesk.main_url.should == "https://#{@account}.zendesk.com/"
20
+ end
21
21
 
22
- describe Zendesk::Main, 'make_request' do
23
- before do
24
- curl_object = Curl::Easy.method(:new)
25
- Curl::Easy.stub!(:new).and_return do |*args|
26
- curl = curl_object.call(*args)
27
- curl.should_receive(:perform)
28
- curl.stub!(:header_str) { "adsf\r\ndsaf"}
29
- curl
22
+ it "should add the api version to the URL if one is specified" do
23
+ @zendesk = Zendesk::Main.new(@account, @username, @password, :ssl => true, :api_version => 1)
24
+ @zendesk.main_url.should == "https://#{@account}.zendesk.com/api/v1/"
30
25
  end
31
26
  end
32
27
 
33
- it "should construct array url for search" do
34
- zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
35
- params = {
36
- :foo => "bar",
37
- :foo_list => [1, 2, 3]
38
- }
28
+ describe 'make_request' do
29
+ context "searching" do
30
+ before do
31
+ curl_object = Curl::Easy.method(:new)
32
+ Curl::Easy.stub!(:new).and_return do |* args|
33
+ curl = curl_object.call(* args)
34
+ curl.should_receive(:perform)
35
+ curl
36
+ end
37
+ end
38
+
39
+ it "should construct array url for search" do
40
+ zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
41
+ params = {
42
+ :foo => "bar",
43
+ :foo_list => [1, 2, 3]
44
+ }
45
+
46
+ response = zendesk.make_request("search", :list => params)
47
+ response.url.should =~ /foo=bar/
48
+ response.url.should =~ /foo_list\[\]=1/
49
+ response.url.should =~ /foo_list\[\]=2/
50
+ response.url.should =~ /foo_list\[\]=3/
51
+
52
+ end
53
+ end
54
+
55
+ context "headers" do
56
+ before(:each) do
57
+ @zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
58
+ @mock_object = mock('curl_connection')
59
+ @mock_object.stub!(:userpwd=).and_return(true)
60
+ @mock_object.stub!(:headers=).and_return({})
61
+ @mock_object.stub!(:headers).and_return({})
62
+ @mock_object.stub!(:body_str).and_return("body")
63
+ @mock_object.stub!(:header_str).and_return("header")
64
+ @mock_object.stub!(:url).and_return("url")
65
+ @mock_object.stub!(:response_code).and_return("response_code")
66
+ @mock_object.should_receive(:http_post).and_return(true)
67
+ @curl_object = Curl::Easy.should_receive(:new).and_return(@mock_object)
68
+ end
69
+ it "should use default options if none are passed" do
70
+ params = {"subject" => "rspec rulez", "description" => "description", "status_id"=>1}
71
+ options_hash = {:on_behalf_of => "test@test.com"}
72
+
73
+ options_hash.should_receive(:reverse_merge!).once.with({:on_behalf_of => nil})
74
+ @mock_object.headers.should_receive(:merge!).once.with({"Content-Type" => "application/xml"}).and_return(true)
75
+ @mock_object.headers.should_receive(:merge!).once.with({"X-On-Behalf-Of" => "test@test.com"}).and_return(true)
39
76
 
40
- response = zendesk.make_request("search", :list => params)
41
- response.url.should =~ /foo=bar/
42
- response.url.should =~ /foo_list\[\]=1/
43
- response.url.should =~ /foo_list\[\]=2/
44
- response.url.should =~ /foo_list\[\]=3/
77
+ @zendesk.make_request("ticket", {:create => params}, options_hash)
78
+ end
45
79
 
80
+ it "should format headers for creation" do
81
+ params = {"subject" => "rspec rulez", "description" => "description", "status_id"=>1}
82
+
83
+ @mock_object.headers.should_receive(:merge!).with({"Content-Type" => "application/xml"}).any_number_of_times.and_return(true)
84
+
85
+ @zendesk.make_request("ticket", :create => params)
86
+ end
87
+ it "should add X-On-Behalf-Of if passed in options" do
88
+ params = {"subject" => "rspec rulez", "description" => "description", "status_id"=>1}
89
+
90
+ @mock_object.headers.should_receive(:merge!).once.with({"Content-Type" => "application/xml"}).and_return(true)
91
+ @mock_object.headers.should_receive(:merge!).once.with({"X-On-Behalf-Of" => "test@test.com"}).and_return(true)
92
+
93
+ @zendesk.make_request("ticket", {:create => params}, {:on_behalf_of => "test@test.com"})
94
+ end
95
+ it "should not add X-On-Behalf-Of if not passed in options" do
96
+ params = {"subject" => "rspec rulez", "description" => "description", "status_id"=>1}
97
+
98
+ @mock_object.headers.should_receive(:merge!).once.with({"Content-Type" => "application/xml"}).and_return(true)
99
+ @mock_object.headers.should_not_receive(:merge!).with({"X-On-Behalf-Of" => ""}).and_return(true)
100
+
101
+ @zendesk.make_request("ticket", {:create => params}, {:on_behalf_of => ""})
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#self.to_xml" do
107
+ context "comments" do
108
+ it "should output correctly formatted XML" do
109
+ input = {"value" => "new comment", "public" => true}
110
+ xml = Zendesk::Main.to_xml('comment', input)
111
+ xml.should =~ /<comment>\s*<public type=\"boolean\">true<\/public>\s*<value>new comment<\/value>\s*<\/comment>/
112
+ end
113
+ end
114
+
115
+ context "tickets" do
116
+ it "should output correctly formatted XML" do
117
+ input = {"subject" => "rspec rulez", "description" => "description", "status_id"=>1}
118
+ xml = Zendesk::Main.to_xml('ticket', input)
119
+ xml.should =~ /<ticket>\s*<subject>rspec rulez<\/subject>\s*<status-id type=\"integer\">1<\/status-id>\s*<description>description<\/description>\s*<\/ticket>/
120
+ end
121
+ end
46
122
  end
47
- end
123
+ end
@@ -1,5 +1,5 @@
1
1
  require "spec"
2
- require 'lib/zendesk-api'
2
+ require 'zendesk-api'
3
3
 
4
4
  describe Zendesk::Main, 'user api' do
5
5
  # before do
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{zendesk-api}
5
- s.version = "0.3.3"
5
+ s.version = "0.3.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Peter Ericson"]
9
- s.date = %q{2010-12-27}
8
+ s.authors = ["Peter Glerup Ericson"]
9
+ s.date = %q{2012-04-30}
10
10
  s.description = %q{RubyGem wrapper for REST API to http://zendesk.com}
11
11
  s.email = %q{pg.ericson@gmail.com}
12
12
  s.extra_rdoc_files = ["README.markdown", "lib/console.rb", "lib/zendesk-api.rb", "lib/zendesk.rb", "lib/zendesk/attachment.rb", "lib/zendesk/entry.rb", "lib/zendesk/forum.rb", "lib/zendesk/group.rb", "lib/zendesk/main.rb", "lib/zendesk/organization.rb", "lib/zendesk/search.rb", "lib/zendesk/tag.rb", "lib/zendesk/ticket.rb", "lib/zendesk/user.rb", "lib/zendesk/user_identity.rb"]
metadata CHANGED
@@ -1,61 +1,53 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zendesk-api
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.4
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - Peter Ericson
7
+ authors:
8
+ - Peter Glerup Ericson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-12-27 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: crack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 0
32
- - 1
33
- - 8
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.1.8
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: activesupport
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 5
46
- segments:
47
- - 2
48
- - 3
49
- version: "2.3"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2.3'
50
38
  type: :runtime
51
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2.3'
52
46
  description: RubyGem wrapper for REST API to http://zendesk.com
53
47
  email: pg.ericson@gmail.com
54
48
  executables: []
55
-
56
49
  extensions: []
57
-
58
- extra_rdoc_files:
50
+ extra_rdoc_files:
59
51
  - README.markdown
60
52
  - lib/console.rb
61
53
  - lib/zendesk-api.rb
@@ -71,7 +63,7 @@ extra_rdoc_files:
71
63
  - lib/zendesk/ticket.rb
72
64
  - lib/zendesk/user.rb
73
65
  - lib/zendesk/user_identity.rb
74
- files:
66
+ files:
75
67
  - Manifest
76
68
  - README.markdown
77
69
  - Rakefile
@@ -93,45 +85,35 @@ files:
93
85
  - spec/zendesk/main_spec.rb
94
86
  - spec/zendesk/user_spec.rb
95
87
  - zendesk-api.gemspec
96
- has_rdoc: true
97
88
  homepage: http://github.com/pgericson/zendesk-api
98
89
  licenses: []
99
-
100
90
  post_install_message:
101
- rdoc_options:
91
+ rdoc_options:
102
92
  - --line-numbers
103
93
  - --inline-source
104
94
  - --title
105
95
  - Zendesk-api
106
96
  - --main
107
97
  - README.markdown
108
- require_paths:
98
+ require_paths:
109
99
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
100
+ required_ruby_version: !ruby/object:Gem::Requirement
111
101
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
119
- required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
107
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 11
125
- segments:
126
- - 1
127
- - 2
128
- version: "1.2"
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '1.2'
129
112
  requirements: []
130
-
131
113
  rubyforge_project: zendesk-api
132
- rubygems_version: 1.3.7
114
+ rubygems_version: 1.8.23
133
115
  signing_key:
134
116
  specification_version: 3
135
117
  summary: RubyGem wrapper for REST API to http://zendesk.com
136
118
  test_files: []
137
-
119
+ has_rdoc: