sutra 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.ruby-version +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +39 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/sutra +6 -0
- data/lib/sutra.rb +8 -0
- data/lib/sutra/api.rb +37 -0
- data/lib/sutra/cli.rb +41 -0
- data/lib/sutra/macro.rb +117 -0
- data/lib/sutra/version.rb +3 -0
- data/sutra.gemspec +26 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd5caa3dcf1a68ac2ed8565fd113bc30d51384e739bd1c5c2aa32e31e95420b8
|
4
|
+
data.tar.gz: 1e798d64e0c593c204276e6c9e8187ff56cf29847fa7d142e8eb4c28fd1e9d0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 473b3f9649a1b514a2fa07cf89bf59cff248355026b375320851eb0c04d4da8f7e96242bf081af00dbb35ddbfab0036956ff5ccfbf4ffe5cea8a7dda33cecfe0
|
7
|
+
data.tar.gz: 3bc26c61df25689ebdc1de6f1ce12d05f1cfc5f0f9ef1e27c72da913560a3cb90053526215920bc5a3ace0610216fcaf436447f045f710243ca415800c297e24
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sutra (0.1.0)
|
5
|
+
toml
|
6
|
+
zendesk_api
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
faraday (0.17.3)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
hashie (3.6.0)
|
14
|
+
inflection (1.0.0)
|
15
|
+
mime-types (3.3.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2019.1009)
|
18
|
+
multipart-post (2.1.1)
|
19
|
+
parslet (1.8.2)
|
20
|
+
rake (13.0.1)
|
21
|
+
toml (0.2.0)
|
22
|
+
parslet (~> 1.8.0)
|
23
|
+
zendesk_api (1.24.0)
|
24
|
+
faraday (>= 0.9.0, < 1.0.0)
|
25
|
+
hashie (>= 3.5.2, < 4.0.0)
|
26
|
+
inflection
|
27
|
+
mime-types
|
28
|
+
multipart-post (~> 2.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler
|
35
|
+
rake
|
36
|
+
sutra!
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Sutra
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sutra`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sutra'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sutra
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/udzura/sutra.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sutra"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/sutra
ADDED
data/lib/sutra.rb
ADDED
data/lib/sutra/api.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "zendesk_api"
|
2
|
+
require "toml"
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module Sutra
|
6
|
+
class API
|
7
|
+
def initialize(local_conf)
|
8
|
+
@client = ZendeskAPI::Client.new do |config|
|
9
|
+
config.url = local_conf.url
|
10
|
+
config.username = local_conf.username
|
11
|
+
config.token = local_conf.token
|
12
|
+
|
13
|
+
if local_conf.log_file
|
14
|
+
config.logger = Logger.new(local_conf.log_file)
|
15
|
+
else
|
16
|
+
config.logger = Logger.new(STDOUT)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
attr_reader :client
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def current
|
24
|
+
@current ||= API.new(local_config)
|
25
|
+
end
|
26
|
+
|
27
|
+
def local_config
|
28
|
+
v = TOML.load_file(ENV['SUTRA_CONFIG_PATH'] || "#{ENV['HOME']}/.sutra/config.toml")
|
29
|
+
if nestv = v["sutra"] || v["zendesk"]
|
30
|
+
Hashie::Mash.new(nestv)
|
31
|
+
else
|
32
|
+
Hashie::Mash.new(v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/sutra/cli.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Sutra
|
4
|
+
class Help
|
5
|
+
def initialize(*)
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
$stderr.puts <<~USAGE
|
10
|
+
#{File.basename $0} version: #{VERSION}
|
11
|
+
Available commands:
|
12
|
+
\tmacro - manage Zendesk macros
|
13
|
+
\thelp - show this message
|
14
|
+
USAGE
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Cli
|
19
|
+
def initialize(argv)
|
20
|
+
@subcommand = argv.shift
|
21
|
+
@argv = argv
|
22
|
+
end
|
23
|
+
|
24
|
+
COMMANDS = {
|
25
|
+
"help" => Help,
|
26
|
+
"--help" => Help,
|
27
|
+
"-h" => Help,
|
28
|
+
"macro" => Macro
|
29
|
+
}
|
30
|
+
|
31
|
+
def run
|
32
|
+
if klass = COMMANDS[@subcommand]
|
33
|
+
klass.new(@argv).run
|
34
|
+
else
|
35
|
+
$stderr.puts "subcommand not found: #{@subcommand.inspect}"
|
36
|
+
Help.new(nil).run
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/sutra/macro.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Sutra
|
5
|
+
class Macro
|
6
|
+
def initialize(argv)
|
7
|
+
@action = argv.shift
|
8
|
+
@argv = argv
|
9
|
+
end
|
10
|
+
|
11
|
+
def usage
|
12
|
+
<<~USAGE
|
13
|
+
#{File.basename $0} macro
|
14
|
+
Available actions:
|
15
|
+
\tdump [-c|--category CATEGORY_NAME] [-o|--out OUTFILE]
|
16
|
+
\t`- dump current existing macro into YAML
|
17
|
+
\tcategories [-f|--filter FILTER_RE] [-q]
|
18
|
+
\t`- show current existing categories
|
19
|
+
USAGE
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
case @action
|
24
|
+
when /^d/
|
25
|
+
do_dump
|
26
|
+
when /^c/
|
27
|
+
do_list_categories
|
28
|
+
else
|
29
|
+
raise OptionParser::ParseError
|
30
|
+
end
|
31
|
+
rescue OptionParser::ParseError
|
32
|
+
$stderr.puts usage
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def do_dump
|
37
|
+
@options = OptionParser.getopts(@argv, 'c:o:', 'category:', 'out:')
|
38
|
+
|
39
|
+
category = @options['category'] || @options['c']
|
40
|
+
yaml = YAML.dump find_all_by_category(category).map(&:to_h)
|
41
|
+
|
42
|
+
out = @options['out'] || @options['o']
|
43
|
+
io = if !out
|
44
|
+
$stdout
|
45
|
+
else
|
46
|
+
File.open(out, 'w')
|
47
|
+
end
|
48
|
+
io.write yaml + "\n"
|
49
|
+
puts "Dump int #{out} successfully" if out
|
50
|
+
end
|
51
|
+
|
52
|
+
def do_list_categories
|
53
|
+
@options = OptionParser.getopts(@argv, 'qf:', 'filter:')
|
54
|
+
filter = @options['filter'] || @options['f']
|
55
|
+
quiet = !!@options['q']
|
56
|
+
|
57
|
+
cats = Sutra::API.current.client.connection.get("macros/categories.json").body
|
58
|
+
cats["categories"].select! {|c| c =~ Regexp.compile(filter) } if filter
|
59
|
+
|
60
|
+
if quiet || !$stdout.tty?
|
61
|
+
cats["categories"].each {|c| puts "#{c}" }
|
62
|
+
else
|
63
|
+
puts "Available categories:"
|
64
|
+
cats["categories"].each {|c| puts "\t#{c}" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_all_by_category(category)
|
69
|
+
ms = Sutra::API.current.client.macros(category: category)
|
70
|
+
ms.to_a.map{|m| Entity.new(m) }
|
71
|
+
end
|
72
|
+
|
73
|
+
class Entity
|
74
|
+
def initialize(data)
|
75
|
+
@_data = data
|
76
|
+
end
|
77
|
+
|
78
|
+
def [](key)
|
79
|
+
@_data[key]
|
80
|
+
end
|
81
|
+
|
82
|
+
def key
|
83
|
+
self["title"]
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_h
|
87
|
+
h = @_data.to_hash
|
88
|
+
{
|
89
|
+
"title" => h["title"],
|
90
|
+
"active" => h["active"],
|
91
|
+
"position" => h["position"],
|
92
|
+
"description" => h["description"],
|
93
|
+
"actions" => h["actions"],
|
94
|
+
"restriction" => readable_restriction,
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_yaml
|
99
|
+
YAML.dump to_h
|
100
|
+
end
|
101
|
+
|
102
|
+
def readable_restriction
|
103
|
+
case @_data.dig("restriction", "type")
|
104
|
+
when "Group"
|
105
|
+
@_restriction_group ||= Sutra::API.current.client.groups.find(id: @_data.dig("restriction", "id"))
|
106
|
+
ret = self["restriction"].merge({"name" => @_restriction_group.name}).to_hash
|
107
|
+
if ret["ids"] && ret["ids"].size <= 1
|
108
|
+
ret.delete "ids"
|
109
|
+
end
|
110
|
+
ret
|
111
|
+
else
|
112
|
+
self["restriction"].to_hash
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/sutra.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "sutra/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sutra"
|
7
|
+
spec.version = Sutra::VERSION
|
8
|
+
spec.authors = ["Uchio Kondo"]
|
9
|
+
spec.email = ["udzura@udzura.jp"]
|
10
|
+
|
11
|
+
spec.summary = %q{Zendesk as Code}
|
12
|
+
spec.description = %q{Zendesk as Code}
|
13
|
+
spec.homepage = "https://github.com/udzura/sutra"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "zendesk_api"
|
25
|
+
spec.add_dependency "toml"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sutra
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Uchio Kondo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-10 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: toml
|
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
|
+
description: Zendesk as Code
|
42
|
+
email:
|
43
|
+
- udzura@udzura.jp
|
44
|
+
executables:
|
45
|
+
- sutra
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".ruby-version"
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- exe/sutra
|
58
|
+
- lib/sutra.rb
|
59
|
+
- lib/sutra/api.rb
|
60
|
+
- lib/sutra/cli.rb
|
61
|
+
- lib/sutra/macro.rb
|
62
|
+
- lib/sutra/version.rb
|
63
|
+
- sutra.gemspec
|
64
|
+
homepage: https://github.com/udzura/sutra
|
65
|
+
licenses: []
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.1.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Zendesk as Code
|
86
|
+
test_files: []
|