zendesk-api 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,13 @@
1
+ README.markdown
2
+ Rakefile
3
+ lib/console.rb
4
+ lib/zendesk-api.rb
5
+ lib/zendesk.rb
6
+ lib/zendesk/attachment.rb
7
+ lib/zendesk/group.rb
8
+ lib/zendesk/main.rb
9
+ lib/zendesk/organization.rb
10
+ lib/zendesk/ticket.rb
11
+ lib/zendesk/user.rb
12
+ zendesk-api.gemspec
13
+ Manifest
data/README.markdown ADDED
@@ -0,0 +1,63 @@
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
+ gem install zendesk-api
17
+
18
+ Bundler install:
19
+ gem "zendesk-api", "latestversion"
20
+
21
+ ## How to use it
22
+ ### Basic
23
+ Below outputs xml
24
+ z = Zendesk::Main.new('subdomain', 'username', 'password')
25
+ and outputs json
26
+ z = Zendesk::Main.new('subdomain', 'username', 'password', :format => 'json')
27
+
28
+ For the most part all functions is based on the following functions
29
+ REST function_names = %{user, organization, group, ticket,attachement, tag, forum, entries, search}
30
+
31
+ ### Show
32
+ z.get_function_name(user_id)
33
+ e.g.
34
+ z.get_user(121)
35
+ ### List
36
+ z.get_function_names #with a s in the end, for plural
37
+ e.g.
38
+ z.get_users
39
+
40
+ ### Create
41
+ with string
42
+ z.create_function_name("<user><email>email@company.com</email><name>John Doe</name></user>")
43
+ with hash(array is not supported yet)
44
+ z.create_function_name({:email => 'email@company.com', :name => 'John Doe'})
45
+
46
+ ### Update
47
+ Not supported yet
48
+
49
+ ### Destroy
50
+ z.destroy_function_name(id)
51
+ e.g.
52
+ z.destroy_user(234)
53
+
54
+
55
+ ## Using The Zendesk Console
56
+
57
+ The Zendesk library comes with a convenient console for testing and quick commands (or whatever else you want to use it for).
58
+
59
+ From /
60
+
61
+ irb -r lib/zendesk/console
62
+ z = Zendesk::Main.new('accountname', 'username', 'password')
63
+ z.get_users
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('zendesk-api', '0.1.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
+ end
13
+
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/lib/console.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'lib/zendesk-api'
2
+ puts <<-TXT
3
+ Stuff here to explain what it does
4
+ TXT
5
+
6
+ include Zendesk
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'curb'
3
+ require 'activeresource'
4
+
5
+ module Zendesk
6
+ class Error < StandardError; end
7
+ class CouldNotAuthenticateYou < StandardError; end
8
+ end
9
+
10
+ require 'zendesk/ticket'
11
+ require 'zendesk/user'
12
+ require 'zendesk/organization'
13
+ require 'zendesk/group'
14
+ require 'zendesk/attachment'
15
+ require 'zendesk/main'
data/lib/zendesk.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/zendesk"
@@ -0,0 +1,5 @@
1
+ module Zendesk
2
+ module Attachment
3
+
4
+ end
5
+ 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", :destroy => true)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,71 @@
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
+ if options[:format] && ['xml','json'].any?{|f| f == options[:format]}
11
+ @format = options[:format]
12
+ else
13
+ @format = 'xml'
14
+ end
15
+ end
16
+
17
+ def main_url
18
+ url_prefix = "http://"
19
+ url_postfix = ".zendesk.com/"
20
+ url = url_prefix + @account + url_postfix
21
+ end
22
+
23
+ def self.to_xml(function_name, input)
24
+ if input.is_a?(String)
25
+ input
26
+ else
27
+ input.to_xml({:root => function_name})
28
+ end
29
+ end
30
+
31
+ def make_request(end_url, body = {})
32
+ curl = Curl::Easy.new(main_url + end_url + ".#{@format}")
33
+ curl.userpwd = "#{@username}:#{@password}"
34
+ unless body.empty?
35
+ if body.values.first.is_a?(Hash)
36
+ final_body = body.values.first.to_xml
37
+ elsif body.values.first.is_a?(String)
38
+ final_body = body.values.first
39
+ end
40
+
41
+ if body[:create]
42
+ curl.headers = "Content-Type: application/xml"
43
+ curl.http_post(final_body)
44
+ elsif body[:update]
45
+ curl.headers = "Content-Type: application/xml"
46
+ curl.http_put(final_body)
47
+ elsif body[:destroy]
48
+ curl.http_delete(final_body)
49
+ elsif body[:list]
50
+ params = "?" + body[:list].to_a.map do |p|
51
+ "#{p[0]}=#{p[1]}"
52
+ end.join("&")
53
+ curl.url = curl.url + params
54
+ end
55
+ else
56
+ curl.perform
57
+ end
58
+
59
+ if curl.body_str == "<error>Couldn't authenticate you</error>"
60
+ return "string" #raise CouldNotAuthenticateYou
61
+ end
62
+ curl.body_str
63
+ end
64
+
65
+ include Zendesk::Ticket
66
+ include Zendesk::User
67
+ include Zendesk::Organization
68
+ include Zendesk::Group
69
+ include Zendesk::Attachment
70
+ end
71
+ 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", :destroy => true)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ module Zendesk
2
+ module Ticket
3
+
4
+ def get_tickets(rule_id)
5
+ make_request("tickets")
6
+ end
7
+
8
+ def get_ticket(id)
9
+ make_request("tickets/#{id}")
10
+ end
11
+
12
+ def create_ticket(input)
13
+ make_request("tickets", :create => Zendesk::Main.to_xml('ticket', input))
14
+ end
15
+
16
+ def update_ticket(input)
17
+ make_request("tickets", :update => Zendesk::Main.to_xml('ticket', input))
18
+ end
19
+
20
+ def delete_ticket(id)
21
+ make_request("tickets", :destroy => true)
22
+ end
23
+ end
24
+ end
@@ -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(input)
21
+ make_request("users", :update => Zendesk::Main.to_xml('user', input))
22
+ end
23
+
24
+ def delete_user(id)
25
+ make_request("users", :destroy => true)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{zendesk-api}
5
+ s.version = "0.1.2"
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-03-11}
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/group.rb", "lib/zendesk/main.rb", "lib/zendesk/organization.rb", "lib/zendesk/ticket.rb", "lib/zendesk/user.rb"]
13
+ s.files = ["README.markdown", "Rakefile", "lib/console.rb", "lib/zendesk-api.rb", "lib/zendesk.rb", "lib/zendesk/attachment.rb", "lib/zendesk/group.rb", "lib/zendesk/main.rb", "lib/zendesk/organization.rb", "lib/zendesk/ticket.rb", "lib/zendesk/user.rb", "zendesk-api.gemspec", "Manifest"]
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.6}
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::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zendesk-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 2
9
+ version: 0.1.2
10
+ platform: ruby
11
+ authors:
12
+ - Peter Ericson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-11 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: RubyGem wrapper for REST API to http://zendesk.com
22
+ email: pg.ericson@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.markdown
29
+ - lib/console.rb
30
+ - lib/zendesk-api.rb
31
+ - lib/zendesk.rb
32
+ - lib/zendesk/attachment.rb
33
+ - lib/zendesk/group.rb
34
+ - lib/zendesk/main.rb
35
+ - lib/zendesk/organization.rb
36
+ - lib/zendesk/ticket.rb
37
+ - lib/zendesk/user.rb
38
+ files:
39
+ - README.markdown
40
+ - Rakefile
41
+ - lib/console.rb
42
+ - lib/zendesk-api.rb
43
+ - lib/zendesk.rb
44
+ - lib/zendesk/attachment.rb
45
+ - lib/zendesk/group.rb
46
+ - lib/zendesk/main.rb
47
+ - lib/zendesk/organization.rb
48
+ - lib/zendesk/ticket.rb
49
+ - lib/zendesk/user.rb
50
+ - zendesk-api.gemspec
51
+ - Manifest
52
+ has_rdoc: true
53
+ homepage: http://github.com/pgericson/zendesk-api
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --line-numbers
59
+ - --inline-source
60
+ - --title
61
+ - Zendesk-api
62
+ - --main
63
+ - README.markdown
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 1
79
+ - 2
80
+ version: "1.2"
81
+ requirements: []
82
+
83
+ rubyforge_project: zendesk-api
84
+ rubygems_version: 1.3.6
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: RubyGem wrapper for REST API to http://zendesk.com
88
+ test_files: []
89
+