zend 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 06d8a9f8dfc7a58be94400d7f2895ae4414b6c82
4
+ data.tar.gz: 510f86a5312ce14fc1aabfc679061dc24cdb1ebb
5
+ SHA512:
6
+ metadata.gz: 503627f9466251962d5999cebc51452592036c556cb204cb3027015b1d59b69bfd9c76b6a55fb368d646e1214eefef01906f350b7806abee03d72a659b1ca20e
7
+ data.tar.gz: 7a14d6722f3878d64960822113b2e291c002c0b302d273119d698b917808ebc6faf2d4f065a19a0626811ddbaa3905af9b26f114251f8a294643c81c64e23ac0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## 0.1.0 (September 7, 2013)
2
+
3
+ Features:
4
+
5
+ - `zend login` to log in to your Zendesk account
6
+ - `zend logout` to remove local Zendesk credentials
7
+ - `zend show <ticket id>` to show basic ticket information
8
+ - set `ZEND_ACCOUNT` environment variable to skip account detail
9
+ requests for each command
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zend.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jean Mertz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Zend
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'zend'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install zend
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/zend ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'zend'
5
+ Zend::CLI.start
data/lib/zend/auth.rb ADDED
@@ -0,0 +1,138 @@
1
+ require 'zendesk_api'
2
+ require 'netrc'
3
+ require 'highline/import'
4
+
5
+ module Zend
6
+ class Auth
7
+ class << self
8
+ def api
9
+ unless @api
10
+ @api = ZendeskAPI::Client.new do |config|
11
+ config.url = "https://#{domain}/api/v2"
12
+ config.username = user
13
+ config.token = password
14
+ end
15
+ unauthorized_callback(@api)
16
+ end
17
+
18
+ @api
19
+ end
20
+
21
+ def login
22
+ delete_credentials
23
+ get_credentials
24
+ end
25
+
26
+ def logout
27
+ delete_credentials
28
+ end
29
+
30
+ def domain
31
+ "#{get_account}.zendesk.com"
32
+ end
33
+
34
+ def user
35
+ get_credentials[0]
36
+ end
37
+
38
+ def password
39
+ get_credentials[1]
40
+ end
41
+
42
+ private
43
+
44
+ def get_account
45
+ @account ||= (ENV['ZEND_ACCOUNT'] || ask_for_account)
46
+ end
47
+
48
+ def unauthorized_callback(api)
49
+ api.insert_callback do |response|
50
+ if response[:status] == 401
51
+ Kernel.abort 'Incorrect Zendesk API authentication credentials'
52
+ end
53
+ end
54
+ end
55
+
56
+ def verify
57
+ api.users.first
58
+ end
59
+
60
+ def netrc_path
61
+ default = Netrc.default_path
62
+ encrypted = default + '.gpg'
63
+ if File.exists?(encrypted)
64
+ encrypted
65
+ else
66
+ default
67
+ end
68
+ end
69
+
70
+ def netrc
71
+ @netrc ||= begin
72
+ File.exists?(netrc_path) && Netrc.read(netrc_path)
73
+ rescue => error
74
+ if error.message =~ /^Permission bits for/
75
+ perm = File.stat(netrc_path).mode & 0777
76
+ Kernel.abort "Permissions #{perm} for '#{netrc_path}' are too
77
+ open. You should run `chmod 0600 #{netrc_path}` so that your
78
+ credentials are NOT accessible by others."
79
+ else
80
+ raise error
81
+ end
82
+ end
83
+ end
84
+
85
+ def get_credentials
86
+ @credentials ||= (read_credentials || ask_for_and_save_credentials)
87
+ end
88
+
89
+ def delete_credentials
90
+ if netrc
91
+ netrc.delete(domain)
92
+ netrc.save
93
+ end
94
+ @email, @token = nil
95
+ end
96
+
97
+ def read_credentials
98
+ netrc[domain] if netrc
99
+ end
100
+
101
+ def write_credentials
102
+ FileUtils.mkdir_p(File.dirname(netrc_path))
103
+ FileUtils.touch(netrc_path)
104
+ FileUtils.chmod(0600, netrc_path)
105
+ netrc[domain] = @credentials
106
+ netrc.save
107
+ end
108
+
109
+ def ask_for_account
110
+ say "Enter your Zendesk account (subdomain). Set a ZEND_ACCOUNT environment variable to skip this step.\n\n"
111
+ @account = ask 'Zendesk subdomain: '
112
+ end
113
+
114
+ def ask_for_credentials
115
+ say 'Enter your Zendesk credentials.' if ENV['ZEND_ACCOUNT']
116
+
117
+ email = ask 'E-mail address: '
118
+ token = ask_token 'Secret token (typing will be hidden): '
119
+
120
+ [email, token]
121
+ end
122
+
123
+ def ask_for_and_save_credentials
124
+ @credentials = ask_for_credentials
125
+ write_credentials
126
+ verify
127
+
128
+ @credentials
129
+ end
130
+
131
+ def ask_token(message)
132
+ HighLine.new.ask(message) do |q|
133
+ q.echo = false
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
data/lib/zend/cli.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Zend
2
+ class CLI < Thor
3
+
4
+ desc 'login', 'Starts prompt to login to your Zendesk account'
5
+ def login
6
+ Zend::Auth.login
7
+ end
8
+
9
+ desc 'logout', 'Remove credentials from local machine'
10
+ def logout
11
+ Zend::Auth.logout
12
+ end
13
+
14
+ desc 'ticket details', 'Get details of a Zendesk ticket'
15
+ def show(ticket_id)
16
+ puts Zend::Command::Ticket.new(ticket_id).print
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ class Zend::Command::Base
2
+ def api
3
+ Zend::Auth.api
4
+ end
5
+
6
+ def terminal_width
7
+ result = unix? ? dynamic_width : 80
8
+ (result < 10) ? 80 : result
9
+ rescue
10
+ 80
11
+ end
12
+
13
+ private
14
+
15
+ def unix?
16
+ RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
17
+ end
18
+
19
+ def dynamic_width
20
+ @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
21
+ end
22
+
23
+ def dynamic_width_stty
24
+ %x{stty size 2>/dev/null}.split[1].to_i
25
+ end
26
+
27
+ def dynamic_width_tput
28
+ %x{tput cols 2>/dev/null}.to_i
29
+ end
30
+
31
+ end
@@ -0,0 +1,56 @@
1
+ module Zend
2
+ module Command
3
+ class Ticket < Base
4
+ attr_reader :ticket
5
+
6
+ def initialize(ticket_id)
7
+ @ticket = api.tickets.find(id: ticket_id, include: :users)
8
+ end
9
+
10
+ def print
11
+ rows = Array.new
12
+ rows << [value: col_subject, colspan: 3]
13
+ rows << :separator
14
+ rows << [col_requester, col_created, col_updated]
15
+
16
+ puts Terminal::Table.new(
17
+ style: {
18
+ width: terminal_width,
19
+ padding_left: 3
20
+ },
21
+ rows: rows
22
+ )
23
+
24
+ puts col_description
25
+ end
26
+
27
+ private
28
+
29
+ def col_subject
30
+ "##{ticket.id}: #{ticket.subject}"
31
+ end
32
+
33
+ def col_requester
34
+ "By: #{requester}"
35
+ end
36
+
37
+ def col_created
38
+ %Q{Created: #{ticket.created_at.getlocal.strftime("%-d %B, %H:%M")}}
39
+ end
40
+
41
+ def col_updated
42
+ %Q{Updated: #{ticket.updated_at.getlocal.strftime("%-d %B, %H:%M")}}
43
+ end
44
+
45
+ def col_description
46
+ "\n#{ticket.description}"
47
+ #.scan(/.{1,80}/m).join("\n")
48
+ end
49
+
50
+ def requester
51
+ ticket.requester.name
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module Zend
2
+ module Command
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Zend
2
+ VERSION = '0.1.0'
3
+ end
data/lib/zend.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'thor'
2
+ require 'highline'
3
+ require 'terminal-table'
4
+
5
+ require 'zend/version'
6
+ require 'zend/auth'
7
+ require 'zend/cli'
8
+ require 'zend/command'
9
+ require 'zend/command/base'
10
+ require 'zend/command/ticket'
11
+
12
+ module Zend
13
+ end
data/zend.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zend/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'zend'
8
+ spec.version = Zend::VERSION
9
+ spec.authors = ['Jean Mertz']
10
+ spec.email = ['jean@mertz.fm']
11
+ spec.description = %q{Interact with Zendesk through your terminal.}
12
+ spec.summary = %q{A command line interface to everything Zendesk}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'zendesk_api', '~> 1.0.3'
22
+ spec.add_dependency 'thor'
23
+ spec.add_dependency 'highline'
24
+ spec.add_dependency 'terminal-table'
25
+ spec.add_dependency 'netrc'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.3'
28
+ spec.add_development_dependency 'rake'
29
+ spec.add_development_dependency 'rspec', '~> 2.14'
30
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jean Mertz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zendesk_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: terminal-table
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: netrc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '2.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '2.14'
125
+ description: Interact with Zendesk through your terminal.
126
+ email:
127
+ - jean@mertz.fm
128
+ executables:
129
+ - zend
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - CHANGELOG.md
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/zend
140
+ - lib/zend.rb
141
+ - lib/zend/auth.rb
142
+ - lib/zend/cli.rb
143
+ - lib/zend/command.rb
144
+ - lib/zend/command/base.rb
145
+ - lib/zend/command/ticket.rb
146
+ - lib/zend/version.rb
147
+ - zend.gemspec
148
+ homepage: ''
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.0.3
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: A command line interface to everything Zendesk
172
+ test_files: []
173
+ has_rdoc: