kittastrophe 0.2.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/kittastrophe +74 -0
- data/bin/setup +8 -0
- data/kittastrophe.gemspec +31 -0
- data/lib/kittastrophe.rb +2 -0
- data/lib/kittastrophe/client.rb +86 -0
- data/lib/kittastrophe/version.rb +3 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c48767a21015b87f2888bd77282a758e87f4c3f7ab3a919bed4025912342f70a
|
4
|
+
data.tar.gz: b1c0002c206b071feafdde93588e4f4f61515781d80bddee2750d7d789073001
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e62934f4e8335d7527a53952261d6026851849a8d1abb9bf58b2df73d641746f29d4aeb74600e2f3cd91c5aaedb73ea59660a76c8fba803cdcecd43b11e3049
|
7
|
+
data.tar.gz: 62db2fd43e71a4694e90ec3f4ad51c9beb829669ce6bb2c6d62f54dc8906fe57d6455c9a5c12de77a194e8282ad5bf2923b3c87e37e926560ffafa15145d76e3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kittastrophe (0.2.0)
|
5
|
+
curb (~> 0.9.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.4.0)
|
11
|
+
crack (0.4.3)
|
12
|
+
safe_yaml (~> 1.0.0)
|
13
|
+
curb (0.9.6)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
hashdiff (0.3.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.7.0)
|
18
|
+
rspec-core (~> 3.7.0)
|
19
|
+
rspec-expectations (~> 3.7.0)
|
20
|
+
rspec-mocks (~> 3.7.0)
|
21
|
+
rspec-core (3.7.1)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-expectations (3.7.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-mocks (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-support (3.7.1)
|
30
|
+
safe_yaml (1.0.4)
|
31
|
+
webmock (3.4.2)
|
32
|
+
addressable (>= 2.3.6)
|
33
|
+
crack (>= 0.3.2)
|
34
|
+
hashdiff
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.16)
|
41
|
+
kittastrophe!
|
42
|
+
rake (~> 10.0)
|
43
|
+
rspec (~> 3.0)
|
44
|
+
webmock (~> 3.4.2)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 David Schainker
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Kittastrophe
|
2
|
+
|
3
|
+
This Ruby Gem is a CLI client for Adobe's original [TypeKit API](https://typekit.com/docs/api/v1/:format/kits).
|
4
|
+
|
5
|
+
It can be used both as a gem or as it's intended CLI tool.
|
6
|
+
|
7
|
+
## Installation and dependencies
|
8
|
+
|
9
|
+
This gem assumes you have `liburl` installed.
|
10
|
+
|
11
|
+
Mac OS installation of `libcurl` can be handled vie installing [Homebrew](https://brew.sh/), and then running `$ brew install curl`.
|
12
|
+
|
13
|
+
Most modern Linuxes ensure libcurl is installed or make it very easy to do so.
|
14
|
+
|
15
|
+
Install `kittastrophe` via
|
16
|
+
|
17
|
+
$ gem install kittastrophe
|
18
|
+
|
19
|
+
Or add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'kittastrophe'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
- [ ] Prettier printing of output
|
32
|
+
- [ ] Better encapsulation of functionality
|
33
|
+
- [ ] Use proper exit codes for client
|
34
|
+
- [ ] Refactor test suite to better encapsulate stubbed API responses
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
```bash
|
39
|
+
Options:
|
40
|
+
-c, --configure Configure your TypeKit API key
|
41
|
+
so you don't have to always remember it.
|
42
|
+
-l, --list List kits owned by the authenticating user.
|
43
|
+
-s, --show ID Show information for kit with the given ID
|
44
|
+
-h, --help Shows help
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
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).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/schainker/kittastrophe.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "kittastrophe"
|
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/kittastrophe
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path('../../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'kittastrophe'
|
7
|
+
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
if ARGV.empty?
|
11
|
+
ARGV[0] = '-h'
|
12
|
+
end
|
13
|
+
|
14
|
+
options = {}
|
15
|
+
|
16
|
+
parser = OptionParser.new do |opts|
|
17
|
+
opts.banner = "A command line interface in Ruby to fetch information about your kits using the public Typekit APIs"
|
18
|
+
opts.separator ""
|
19
|
+
opts.separator "Options:"
|
20
|
+
|
21
|
+
opts.on("-c", "--configure", "You will be prompted for configuration values of your TypeKit API key.") do |c|
|
22
|
+
options[:cmd] = "config"
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-l", "--list", "List kits owned by the authenticating user") do |l|
|
26
|
+
options[:cmd] = "list"
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-s", "--show ID", "Show information for kit with the given ID") do |id|
|
30
|
+
options[:cmd] = "show"
|
31
|
+
options[:id] = id || ''
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("-z", "") do |id|
|
35
|
+
options[:cmd] = "zoid"
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on_tail("-h", "--help", "Shows help") do |help|
|
39
|
+
puts opts
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
## OptionParser will throw exception upon parsing if you aren't ready for it
|
46
|
+
begin
|
47
|
+
parser.parse!
|
48
|
+
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument # Alphabetical reordering is not only soothing but also makes this program work better for reasons that aren't obvious to me.
|
49
|
+
puts "Invalid option or missing argument!"
|
50
|
+
puts ""
|
51
|
+
ARGV[0] = '-h'
|
52
|
+
parser.parse!
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
# Slightly more sophisticated error checking
|
57
|
+
if options[:cmd] == "show" and options[:id].nil?
|
58
|
+
abort(optparse.help)
|
59
|
+
end
|
60
|
+
|
61
|
+
client = Kittastrophe::Client.new()
|
62
|
+
case options[:cmd]
|
63
|
+
when "config"
|
64
|
+
client.configure
|
65
|
+
when "list"
|
66
|
+
pp client.list
|
67
|
+
when "show"
|
68
|
+
pp client.show(options[:id])
|
69
|
+
when "zoid"
|
70
|
+
pp client.zoidberg
|
71
|
+
else
|
72
|
+
abort(optparse.help) # don't particularly dig that this has to be here, but it's ok
|
73
|
+
end
|
74
|
+
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "kittastrophe/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kittastrophe"
|
8
|
+
spec.version = Kittastrophe::VERSION
|
9
|
+
spec.authors = ["David Schainker"]
|
10
|
+
spec.email = ["david@schainker.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{This Typekit client will change the way you think about typekit clients}
|
13
|
+
spec.description = %q{This client does what you want, when you want it, on your CLI}
|
14
|
+
spec.homepage = "https://www.github.com/schainker/kittastrophe"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.executables = ["kittastrophe"]
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "curb", "~> 0.9.6"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "webmock", "~> 3.4.2"
|
31
|
+
end
|
data/lib/kittastrophe.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require 'optparse'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Kittastrophe
|
6
|
+
class Client
|
7
|
+
|
8
|
+
@@KEY_PATH = File.join(Dir.home, ".typekit")
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@api_key = read_api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def key_path
|
16
|
+
@@KEY_PATH
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def zoidberg
|
21
|
+
"Hooray, I'm useful!"
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def list
|
26
|
+
http = Curl.get("https://typekit.com/api/v1/json/kits") do |http|
|
27
|
+
http.headers['X-Typekit-Token'] = @api_key
|
28
|
+
end
|
29
|
+
|
30
|
+
body = JSON.parse(http.body_str)
|
31
|
+
|
32
|
+
if http.response_code != 200
|
33
|
+
process_error(body)
|
34
|
+
else
|
35
|
+
body
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def show(id)
|
40
|
+
http = Curl.get("https://typekit.com/api/v1/json/kits/#{id}") do |http|
|
41
|
+
http.headers['X-Typekit-Token'] = @api_key
|
42
|
+
end
|
43
|
+
|
44
|
+
body = JSON.parse(http.body_str)
|
45
|
+
|
46
|
+
if http.response_code != 200
|
47
|
+
process_error(body)
|
48
|
+
else
|
49
|
+
body
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def process_error(body)
|
55
|
+
body["errors"]
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def configure
|
60
|
+
api_key = prompt "Please enter your TypeKit API key: "
|
61
|
+
|
62
|
+
open(@@KEY_PATH, 'w') do |f|
|
63
|
+
f.puts "#{api_key}".strip
|
64
|
+
f.close
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def prompt(*args)
|
70
|
+
print(*args)
|
71
|
+
gets
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def read_api_key
|
76
|
+
if File.exists?(@@KEY_PATH)
|
77
|
+
file = File.open(@@KEY_PATH, "rb")
|
78
|
+
contents = file.read
|
79
|
+
file.close
|
80
|
+
key = contents.strip
|
81
|
+
end
|
82
|
+
|
83
|
+
ENV['TYPEKIT_API_KEY'] || key
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kittastrophe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Schainker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.4.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.4.2
|
83
|
+
description: This client does what you want, when you want it, on your CLI
|
84
|
+
email:
|
85
|
+
- david@schainker.net
|
86
|
+
executables:
|
87
|
+
- kittastrophe
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/kittastrophe
|
101
|
+
- bin/setup
|
102
|
+
- kittastrophe.gemspec
|
103
|
+
- lib/kittastrophe.rb
|
104
|
+
- lib/kittastrophe/client.rb
|
105
|
+
- lib/kittastrophe/version.rb
|
106
|
+
homepage: https://www.github.com/schainker/kittastrophe
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.7.6
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: This Typekit client will change the way you think about typekit clients
|
130
|
+
test_files: []
|