zendesk-api-naoya 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +20 -0
- data/README.markdown +76 -0
- data/Rakefile +17 -0
- data/geminstaller.yml +11 -0
- data/lib/console.rb +6 -0
- data/lib/zendesk-api.rb +26 -0
- data/lib/zendesk.rb +1 -0
- data/lib/zendesk/attachment.rb +5 -0
- data/lib/zendesk/entry.rb +24 -0
- data/lib/zendesk/forum.rb +24 -0
- data/lib/zendesk/group.rb +24 -0
- data/lib/zendesk/main.rb +132 -0
- data/lib/zendesk/organization.rb +24 -0
- data/lib/zendesk/search.rb +7 -0
- data/lib/zendesk/tag.rb +13 -0
- data/lib/zendesk/ticket.rb +24 -0
- data/lib/zendesk/user.rb +28 -0
- data/lib/zendesk/user_identity.rb +25 -0
- data/spec/zendesk/main_spec.rb +123 -0
- data/spec/zendesk/user_spec.rb +92 -0
- data/zendesk-api.gemspec +36 -0
- metadata +135 -0
data/Manifest
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Manifest
|
2
|
+
README.markdown
|
3
|
+
Rakefile
|
4
|
+
geminstaller.yml
|
5
|
+
lib/console.rb
|
6
|
+
lib/zendesk-api.rb
|
7
|
+
lib/zendesk.rb
|
8
|
+
lib/zendesk/attachment.rb
|
9
|
+
lib/zendesk/entry.rb
|
10
|
+
lib/zendesk/forum.rb
|
11
|
+
lib/zendesk/group.rb
|
12
|
+
lib/zendesk/main.rb
|
13
|
+
lib/zendesk/organization.rb
|
14
|
+
lib/zendesk/search.rb
|
15
|
+
lib/zendesk/tag.rb
|
16
|
+
lib/zendesk/ticket.rb
|
17
|
+
lib/zendesk/user.rb
|
18
|
+
lib/zendesk/user_identity.rb
|
19
|
+
spec/zendesk/main_spec.rb
|
20
|
+
spec/zendesk/user_spec.rb
|
data/README.markdown
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
Zendesk API
|
2
|
+
------------
|
3
|
+
|
4
|
+
The unofficial Ruby Library for interacting with the [Zendesk REST API](http://www.zendesk.com/api)
|
5
|
+
|
6
|
+
## Documentation & Requirements
|
7
|
+
* ActiveResource gem
|
8
|
+
* Curl
|
9
|
+
* Curb gem
|
10
|
+
|
11
|
+
## What
|
12
|
+
* Ruby wrapper around the Zendesk REST API
|
13
|
+
|
14
|
+
## Install Instructions
|
15
|
+
Normal install:
|
16
|
+
|
17
|
+
gem install zendesk-api
|
18
|
+
|
19
|
+
Bundler install:
|
20
|
+
|
21
|
+
gem "zendesk-api", "latestversion"
|
22
|
+
|
23
|
+
## How to use it
|
24
|
+
### Basic
|
25
|
+
Below outputs xml
|
26
|
+
|
27
|
+
z = Zendesk::Main.new('subdomain', 'username', 'password')
|
28
|
+
and outputs json
|
29
|
+
|
30
|
+
z = Zendesk::Main.new('subdomain', 'username', 'password', :format => 'json')
|
31
|
+
|
32
|
+
### Show
|
33
|
+
|
34
|
+
z.get_function_name(user_id)
|
35
|
+
|
36
|
+
where function_name is one the following:
|
37
|
+
user, organization, group, ticket, attachement, tag, forum, entries, search
|
38
|
+
|
39
|
+
e.g.
|
40
|
+
|
41
|
+
z.get_user(121)
|
42
|
+
### List
|
43
|
+
|
44
|
+
z.get_function_names #with a s in the end, for plural
|
45
|
+
e.g.
|
46
|
+
|
47
|
+
z.get_users
|
48
|
+
|
49
|
+
### Create
|
50
|
+
with string
|
51
|
+
|
52
|
+
z.create_user("<user><email>email@company.com</email><name>John Doe</name></user>")
|
53
|
+
with hash(array is not supported yet)
|
54
|
+
|
55
|
+
z.create_user({:email => 'email@company.com', :name => 'John Doe'})
|
56
|
+
|
57
|
+
### Update
|
58
|
+
Not supported yet
|
59
|
+
|
60
|
+
### Destroy
|
61
|
+
|
62
|
+
z.destroy_function_name(id)
|
63
|
+
e.g.
|
64
|
+
|
65
|
+
z.destroy_user(234)
|
66
|
+
|
67
|
+
|
68
|
+
## Using The Zendesk Console
|
69
|
+
|
70
|
+
The Zendesk library comes with a convenient console for testing and quick commands (or whatever else you want to use it for).
|
71
|
+
|
72
|
+
From /
|
73
|
+
|
74
|
+
irb -r lib/zendesk/console
|
75
|
+
z = Zendesk::Main.new('accountname', 'username', 'password')
|
76
|
+
z.get_users
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('zendesk-api', '0.3.2') do |p|
|
6
|
+
p.description = "RubyGem wrapper for REST API to http://zendesk.com"
|
7
|
+
p.author = "Peter Ericson"
|
8
|
+
p.url = "http://github.com/pgericson/zendesk-api"
|
9
|
+
p.email = "pg.ericson@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
p.runtime_dependencies = ["crack >=0.1.8", "activesupport >=2.3"]
|
13
|
+
end
|
14
|
+
# how to build the new gem ( I can't remember so here it is for all time)
|
15
|
+
# rake build_gemspec
|
16
|
+
|
17
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/geminstaller.yml
ADDED
data/lib/console.rb
ADDED
data/lib/zendesk-api.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'curb'
|
3
|
+
require 'crack'
|
4
|
+
gem 'activesupport'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/version'
|
7
|
+
# need to pull in the pieces we want with Rails 3
|
8
|
+
require 'active_support/core_ext' if ActiveSupport::VERSION::MAJOR == 3
|
9
|
+
|
10
|
+
module Zendesk
|
11
|
+
class Error < StandardError; end
|
12
|
+
class CouldNotAuthenticateYou < StandardError; end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'zendesk/user'
|
16
|
+
require 'zendesk/user_identity'
|
17
|
+
require 'zendesk/organization'
|
18
|
+
require 'zendesk/group'
|
19
|
+
require 'zendesk/ticket'
|
20
|
+
require 'zendesk/attachment'
|
21
|
+
require 'zendesk/tag'
|
22
|
+
require 'zendesk/forum'
|
23
|
+
require 'zendesk/entry'
|
24
|
+
require 'zendesk/search'
|
25
|
+
require 'zendesk/comment'
|
26
|
+
require 'zendesk/main'
|
data/lib/zendesk.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/zendesk"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module Entry
|
3
|
+
|
4
|
+
def get_entries(forum_id)
|
5
|
+
make_request("forums/#{forum_id}/entries")
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_entry(id)
|
9
|
+
make_request("entries/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_entrie(input)
|
13
|
+
make_request("entries", :create => Zendesk::Main.to_xml('entrie', input))
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_entrie(input)
|
17
|
+
make_request("entries", :update => Zendesk::Main.to_xml('entrie', input))
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_entrie(id)
|
21
|
+
make_request("entries/#{id}", :destroy => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module Forum
|
3
|
+
|
4
|
+
def get_forums
|
5
|
+
make_request("forums")
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_forum(id)
|
9
|
+
make_request("forums/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_forum(input)
|
13
|
+
make_request("forums", :create => Zendesk::Main.to_xml('forum', input))
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_forum(input)
|
17
|
+
make_request("forums", :update => Zendesk::Main.to_xml('forum', input))
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_forum(id)
|
21
|
+
make_request("forums/#{id}", :destroy => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module Group
|
3
|
+
|
4
|
+
def get_groups
|
5
|
+
make_request("groups")
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_group(id)
|
9
|
+
make_request("groups/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_group(input)
|
13
|
+
make_request("groups", :create => Zendesk::Main.to_xml('group', input))
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_group(input)
|
17
|
+
make_request("groups", :update => Zendesk::Main.to_xml('group', input))
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_group(id)
|
21
|
+
make_request("groups/#{id}", :destroy => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/zendesk/main.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
module Zendesk
|
2
|
+
class Main
|
3
|
+
attr_accessor :main_url, :format
|
4
|
+
attr_reader :response_raw, :response
|
5
|
+
|
6
|
+
def initialize(account, username, password, options = {})
|
7
|
+
@account = account
|
8
|
+
@username = username
|
9
|
+
@password = password
|
10
|
+
@options = options
|
11
|
+
if options[:format] && ['xml', 'json'].any?{|f| f == options[:format]}
|
12
|
+
@format = options[:format]
|
13
|
+
else
|
14
|
+
@format = 'xml'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def main_url
|
19
|
+
url_prefix = @options[:ssl] ? "https://" : "http://"
|
20
|
+
url_postfix = @options[:url_postfix] ? @options[:url_postfix]: '.zendesk.com/'
|
21
|
+
url_postfix << "api/v#{@options[:api_version]}/" if @options[:api_version]
|
22
|
+
|
23
|
+
url = url_prefix + @account + url_postfix
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.to_xml(function_name, input)
|
27
|
+
if input.is_a?(String)
|
28
|
+
input
|
29
|
+
else
|
30
|
+
input.to_xml({:root => function_name})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def params_list(list)
|
36
|
+
params = "?" + list.map do |k, v|
|
37
|
+
if v.is_a?(Array)
|
38
|
+
v.map do |val|
|
39
|
+
"#{k}[]=#{val}"
|
40
|
+
end.join("&")
|
41
|
+
else
|
42
|
+
"#{k}=#{v}"
|
43
|
+
end
|
44
|
+
end.join("&")
|
45
|
+
end
|
46
|
+
|
47
|
+
def string_body(body)
|
48
|
+
if body.values.first.is_a?(Hash)
|
49
|
+
body.values.first.to_xml.strip
|
50
|
+
elsif body.values.first.is_a?(String)
|
51
|
+
body.values.first
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def make_request(end_url, body = {}, options = {})
|
56
|
+
options.reverse_merge!({:on_behalf_of => nil})
|
57
|
+
|
58
|
+
curl = Curl::Easy.new(main_url + end_url + ".#{@format}")
|
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
|
+
|
64
|
+
if body.empty? or body[:list]
|
65
|
+
curl.url = curl.url + params_list(body[:list]) if body[:list]
|
66
|
+
curl.perform
|
67
|
+
elsif body[:post]
|
68
|
+
curl.headers.merge!({"Content-Type" => "application/xml"})
|
69
|
+
curl.http_post
|
70
|
+
elsif body[:create]
|
71
|
+
curl.headers.merge!({"Content-Type" => "application/xml"})
|
72
|
+
curl.http_post(string_body(body))
|
73
|
+
elsif body[:update]
|
74
|
+
# PUT seems badly broken, at least I can't get it to work without always
|
75
|
+
# raising an exception about rewinding the data stream
|
76
|
+
# curl.http_put(final_body)
|
77
|
+
curl.headers.merge!({ "Content-Type" => "application/xml", "X-Http-Method-Override" => "put" })
|
78
|
+
curl.http_post(string_body(body))
|
79
|
+
elsif body[:destroy]
|
80
|
+
curl.http_delete
|
81
|
+
end
|
82
|
+
|
83
|
+
if curl.body_str == "<error>Couldn't authenticate you</error>"
|
84
|
+
return "string" #raise CouldNotAuthenticateYou
|
85
|
+
end
|
86
|
+
Response.new(curl, format)
|
87
|
+
end
|
88
|
+
|
89
|
+
class Response
|
90
|
+
|
91
|
+
attr_reader :status, :body, :headers_raw, :headers, :curl, :url, :data
|
92
|
+
|
93
|
+
def initialize(curl, format)
|
94
|
+
@format=format
|
95
|
+
@curl = curl
|
96
|
+
@url = curl.url
|
97
|
+
@status = curl.response_code
|
98
|
+
@body = curl.body_str
|
99
|
+
@headers_raw = curl.header_str
|
100
|
+
parse_headers
|
101
|
+
# parse the data coming back
|
102
|
+
@data = Crack::XML.parse(@body || "") if @format == "xml"
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_headers
|
106
|
+
hs={}
|
107
|
+
return hs if headers_raw.nil? or headers_raw==""
|
108
|
+
headers_raw.split("\r\n")[1..-1].each do |h|
|
109
|
+
# Rails.logger.info h
|
110
|
+
m=h.match(/([^:]+):\s?(.*)/)
|
111
|
+
next if m.nil? or m[2].nil?
|
112
|
+
# Rails.logger.info m.inspect
|
113
|
+
hs[m[1]]=m[2]
|
114
|
+
end
|
115
|
+
@headers=hs
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
include Zendesk::User
|
121
|
+
include Zendesk::UserIdentity
|
122
|
+
include Zendesk::Organization
|
123
|
+
include Zendesk::Group
|
124
|
+
include Zendesk::Ticket
|
125
|
+
include Zendesk::Attachment
|
126
|
+
include Zendesk::Tag
|
127
|
+
include Zendesk::Forum
|
128
|
+
include Zendesk::Entry
|
129
|
+
include Zendesk::Search
|
130
|
+
include Zendesk::Comment
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module Organization
|
3
|
+
|
4
|
+
def get_organizations
|
5
|
+
make_request("organizations")
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_organization(id)
|
9
|
+
make_request("organizations/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_organization(input)
|
13
|
+
make_request("organizations", :create => Zendesk::Main.to_xml('organization', input))
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_organization(input)
|
17
|
+
make_request("organizations", :update => Zendesk::Main.to_xml('organization', input))
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_organization(id)
|
21
|
+
make_request("organizations/#{id}", :destroy => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/zendesk/tag.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module Ticket
|
3
|
+
|
4
|
+
def get_tickets(rule_id)
|
5
|
+
make_request("rules/#{rule_id}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_ticket(id)
|
9
|
+
make_request("tickets/#{id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_ticket(input, options = {})
|
13
|
+
make_request("tickets", {:create => Zendesk::Main.to_xml('ticket', input)}, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_ticket(id, input, options = {})
|
17
|
+
make_request("tickets/#{id}", {:update => Zendesk::Main.to_xml('ticket', input)}, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete_ticket(id)
|
21
|
+
make_request("tickets/#{id}", :destroy => true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/zendesk/user.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module User
|
3
|
+
|
4
|
+
def get_users(params = nil)
|
5
|
+
if params
|
6
|
+
make_request("users", :list => params)
|
7
|
+
else
|
8
|
+
make_request("users")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_user(id)
|
13
|
+
make_request("users/#{id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_user(input)
|
17
|
+
make_request("users", :create => Zendesk::Main.to_xml('user', input))
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_user(id, input)
|
21
|
+
make_request("users/#{id}", :update => Zendesk::Main.to_xml('user', input))
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_user(id)
|
25
|
+
make_request("users/#{id}", :destroy => true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Zendesk
|
2
|
+
module UserIdentity
|
3
|
+
|
4
|
+
def user_add_twitter(user_id, twitter)
|
5
|
+
make_request("users/#{user_id}/user_identities", :create => "<twitter>#{twitter}</twitter>")
|
6
|
+
end
|
7
|
+
|
8
|
+
def user_primary_identity(user_id, id)
|
9
|
+
make_request("users/#{user_id}/user_identities/#{id}/make_primary", :post => true)
|
10
|
+
end
|
11
|
+
|
12
|
+
def user_add_email(user_id, email)
|
13
|
+
make_request("users/#{user_id}/user_identities", :create => "<email>#{email}</email>")
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_delete_identity(user_id, id)
|
17
|
+
make_request("users/#{user_id}/user_identities/#{id}", :destroy => true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_identities(user_id)
|
21
|
+
make_request("users/#{user_id}/user_identities")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require "spec"
|
2
|
+
require 'zendesk-api'
|
3
|
+
|
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
|
12
|
+
|
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
|
+
|
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/"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
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)
|
76
|
+
|
77
|
+
@zendesk.make_request("ticket", {:create => params}, options_hash)
|
78
|
+
end
|
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
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "spec"
|
2
|
+
require 'zendesk-api'
|
3
|
+
|
4
|
+
describe Zendesk::Main, 'user api' do
|
5
|
+
# before do
|
6
|
+
# end
|
7
|
+
|
8
|
+
it "should be able to create" do
|
9
|
+
data={"email" => "bob@aol.com", "name" => "Bob Jones", "roles" => 0, "restriction-id" => 4}
|
10
|
+
curl_object = Curl::Easy.method(:new)
|
11
|
+
Curl::Easy.stub!(:new).and_return do |*args|
|
12
|
+
curl = curl_object.call(*args)
|
13
|
+
# curl.stub!(:http_post)
|
14
|
+
body=Zendesk::Main.to_xml('user', data)
|
15
|
+
curl.should_receive(:http_post).with(body)
|
16
|
+
curl.stub!(:perform)
|
17
|
+
curl.stub!(:header_str) { "\r\nLocation: http://account.zendesk.com/users/23.xml\r\ndsaf: smoke"}
|
18
|
+
curl.stub!(:response_code).and_return(201)
|
19
|
+
curl
|
20
|
+
end
|
21
|
+
zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
|
22
|
+
response = zendesk.create_user(data)
|
23
|
+
response.url.should =~ %r{/users.xml}
|
24
|
+
response.headers["Location"].should =~ %r{/users/23.xml}
|
25
|
+
response.status.should == 201
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to update" do
|
29
|
+
data={"email" => "bob@aol.com", "name" => "Bob Jones", "roles" => 0, "restriction-id" => 4}
|
30
|
+
curl_object = Curl::Easy.method(:new)
|
31
|
+
Curl::Easy.stub!(:new).and_return do |*args|
|
32
|
+
curl = curl_object.call(*args)
|
33
|
+
curl.stub!(:perform)
|
34
|
+
body=Zendesk::Main.to_xml('user', data)
|
35
|
+
curl.should_receive(:http_post).with(body)
|
36
|
+
curl.stub!(:header_str) { "\r\ntest: blah"}
|
37
|
+
curl.stub!(:response_code).and_return(200)
|
38
|
+
curl
|
39
|
+
end
|
40
|
+
zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
|
41
|
+
response = zendesk.update_user(39,data)
|
42
|
+
response.curl.headers["X-Http-Method-Override"].should == "put"
|
43
|
+
response.url.should =~ %r{/users/39.xml$}
|
44
|
+
response.status.should == 200
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be able to get" do
|
48
|
+
curl_object = Curl::Easy.method(:new)
|
49
|
+
Curl::Easy.stub!(:new).and_return do |*args|
|
50
|
+
curl = curl_object.call(*args)
|
51
|
+
curl.stub!(:perform)
|
52
|
+
curl.stub!(:header_str) { "\r\ntest: blah"}
|
53
|
+
curl.stub!(:response_code).and_return(200)
|
54
|
+
curl
|
55
|
+
end
|
56
|
+
zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
|
57
|
+
response = zendesk.get_user(13)
|
58
|
+
response.url.should =~ %r{/users/13.xml$}
|
59
|
+
response.status.should == 200
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be able to list all" do
|
63
|
+
curl_object = Curl::Easy.method(:new)
|
64
|
+
Curl::Easy.stub!(:new).and_return do |*args|
|
65
|
+
curl = curl_object.call(*args)
|
66
|
+
curl.stub!(:perform)
|
67
|
+
curl.stub!(:header_str) { "\r\ntest: blah"}
|
68
|
+
curl.stub!(:response_code).and_return(200)
|
69
|
+
curl
|
70
|
+
end
|
71
|
+
zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
|
72
|
+
response = zendesk.get_users
|
73
|
+
response.url.should =~ %r{/users.xml$}
|
74
|
+
response.status.should == 200
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be able to delete" do
|
78
|
+
curl_object = Curl::Easy.method(:new)
|
79
|
+
Curl::Easy.stub!(:new).and_return do |*args|
|
80
|
+
curl = curl_object.call(*args)
|
81
|
+
curl.stub!(:http_delete)
|
82
|
+
curl.stub!(:perform)
|
83
|
+
curl.stub!(:response_code).and_return(200)
|
84
|
+
curl.stub!(:header_str) { "\r\nadsf\r\ndsaf"}
|
85
|
+
curl
|
86
|
+
end
|
87
|
+
zendesk = Zendesk::Main.new('my_company', "some_login", "some_password")
|
88
|
+
response = zendesk.delete_user(12)
|
89
|
+
response.url.should =~ %r{/users/12.xml}
|
90
|
+
response.status.should == 200
|
91
|
+
end
|
92
|
+
end
|
data/zendesk-api.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{zendesk-api-naoya}
|
5
|
+
s.version = "0.3.3"
|
6
|
+
|
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}
|
10
|
+
s.description = %q{RubyGem wrapper for REST API to http://zendesk.com}
|
11
|
+
s.email = %q{pg.ericson@gmail.com}
|
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"]
|
13
|
+
s.files = ["Manifest", "README.markdown", "Rakefile", "geminstaller.yml", "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", "spec/zendesk/main_spec.rb", "spec/zendesk/user_spec.rb", "zendesk-api.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/pgericson/zendesk-api}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Zendesk-api", "--main", "README.markdown"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{zendesk-api}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{RubyGem wrapper for REST API to http://zendesk.com}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<crack>, [">= 0.1.8"])
|
27
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<crack>, [">= 0.1.8"])
|
30
|
+
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<crack>, [">= 0.1.8"])
|
34
|
+
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zendesk-api-naoya
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Peter Ericson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-27 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: crack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 1
|
32
|
+
- 8
|
33
|
+
version: 0.1.8
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
48
|
+
version: "2.3"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: RubyGem wrapper for REST API to http://zendesk.com
|
52
|
+
email: pg.ericson@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- README.markdown
|
59
|
+
- lib/console.rb
|
60
|
+
- lib/zendesk-api.rb
|
61
|
+
- lib/zendesk.rb
|
62
|
+
- lib/zendesk/attachment.rb
|
63
|
+
- lib/zendesk/entry.rb
|
64
|
+
- lib/zendesk/forum.rb
|
65
|
+
- lib/zendesk/group.rb
|
66
|
+
- lib/zendesk/main.rb
|
67
|
+
- lib/zendesk/organization.rb
|
68
|
+
- lib/zendesk/search.rb
|
69
|
+
- lib/zendesk/tag.rb
|
70
|
+
- lib/zendesk/ticket.rb
|
71
|
+
- lib/zendesk/user.rb
|
72
|
+
- lib/zendesk/user_identity.rb
|
73
|
+
files:
|
74
|
+
- Manifest
|
75
|
+
- README.markdown
|
76
|
+
- Rakefile
|
77
|
+
- geminstaller.yml
|
78
|
+
- lib/console.rb
|
79
|
+
- lib/zendesk-api.rb
|
80
|
+
- lib/zendesk.rb
|
81
|
+
- lib/zendesk/attachment.rb
|
82
|
+
- lib/zendesk/entry.rb
|
83
|
+
- lib/zendesk/forum.rb
|
84
|
+
- lib/zendesk/group.rb
|
85
|
+
- lib/zendesk/main.rb
|
86
|
+
- lib/zendesk/organization.rb
|
87
|
+
- lib/zendesk/search.rb
|
88
|
+
- lib/zendesk/tag.rb
|
89
|
+
- lib/zendesk/ticket.rb
|
90
|
+
- lib/zendesk/user.rb
|
91
|
+
- lib/zendesk/user_identity.rb
|
92
|
+
- spec/zendesk/main_spec.rb
|
93
|
+
- spec/zendesk/user_spec.rb
|
94
|
+
- zendesk-api.gemspec
|
95
|
+
homepage: http://github.com/pgericson/zendesk-api
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options:
|
100
|
+
- --line-numbers
|
101
|
+
- --inline-source
|
102
|
+
- --title
|
103
|
+
- Zendesk-api
|
104
|
+
- --main
|
105
|
+
- README.markdown
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 11
|
123
|
+
segments:
|
124
|
+
- 1
|
125
|
+
- 2
|
126
|
+
version: "1.2"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project: zendesk-api
|
130
|
+
rubygems_version: 1.8.10
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: RubyGem wrapper for REST API to http://zendesk.com
|
134
|
+
test_files: []
|
135
|
+
|