awesomekit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/awesomekit.rb +1 -3
- data/lib/awesomekit/authenticator.rb +13 -13
- data/lib/awesomekit/cli.rb +8 -42
- data/lib/awesomekit/client.rb +19 -11
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9597254f6ceaeca2ee78fcdc52e3dc892c1b2dd9
|
4
|
+
data.tar.gz: 20db737d66db06ae670145a815c38560ee9376a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5f1abe2c5414d763a9e3a4171a57ad5ae26579729c697a7e194bada92d28d3c71122cbe8cd10d07d7987ad687186d14c15e2d5065c80f590dcdc0562da24d82
|
7
|
+
data.tar.gz: f56aaeea1d803ff507725753a7a2d45ed10a4287d3a9ce1ab04b305af0539cd1cad6f78d0a11f5c99229d48e1b4b184692d690140b816400980b57cd58b6a16e
|
data/lib/awesomekit.rb
CHANGED
@@ -2,33 +2,33 @@ module Awesomekit
|
|
2
2
|
class Authenticator
|
3
3
|
CONFIG_FILE = '.typekit'
|
4
4
|
|
5
|
-
# PUBLIC: Return the current saved
|
6
|
-
# If no
|
7
|
-
def self.
|
5
|
+
# PUBLIC: Return the current saved api_token
|
6
|
+
# If no token exists, prompt user for token
|
7
|
+
def self.api_token
|
8
8
|
if File.exist?(config)
|
9
9
|
File.open(config, 'r').gets
|
10
10
|
else
|
11
|
-
|
11
|
+
prompt_user_for_token
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
# PUBLIC: Delete any existing
|
16
|
-
def self.
|
15
|
+
# PUBLIC: Delete any existing api_token config file
|
16
|
+
def self.clear_api_token
|
17
17
|
File.unlink(config) if File.exist?(config)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def self.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def self.prompt_user_for_token
|
23
|
+
ap('Enter your Adobe Typekit API token: ', color: { string: :yellow })
|
24
|
+
api_token = STDIN.gets.chomp
|
25
|
+
save_token_to_config(api_token)
|
26
|
+
api_token
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.
|
29
|
+
def self.save_token_to_config(api_token)
|
30
30
|
File.open(config, 'w') do |file|
|
31
|
-
file.write(
|
31
|
+
file.write(api_token)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
data/lib/awesomekit/cli.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'awesome_print'
|
2
3
|
|
3
4
|
module Awesomekit
|
4
5
|
class CLI < Thor
|
5
6
|
include Thor::Actions
|
6
7
|
|
7
|
-
desc 'logout', 'Remove your Adobe Typekit API
|
8
|
+
desc 'logout', 'Remove your Adobe Typekit API token'
|
8
9
|
def logout
|
9
|
-
Awesomekit::Authenticator.
|
10
|
-
|
10
|
+
Awesomekit::Authenticator.clear_api_token
|
11
|
+
ap('Successfully logged out', color: { string: :yellow })
|
11
12
|
end
|
12
13
|
|
13
14
|
desc 'list', 'List available kits'
|
@@ -17,14 +18,13 @@ module Awesomekit
|
|
17
18
|
published version of the kit. Defaults to false, or draft kit version.'
|
18
19
|
def list
|
19
20
|
kits = typekit_client.get_kits
|
20
|
-
return not_found if kits.empty?
|
21
21
|
|
22
|
-
|
22
|
+
ap(kits) if kits
|
23
23
|
|
24
24
|
if options[:verbose]
|
25
25
|
kits.each do |kit|
|
26
26
|
kit = typekit_client.get_kit(kit['id'], options[:published])
|
27
|
-
|
27
|
+
ap(kit) if kit
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -37,47 +37,13 @@ module Awesomekit
|
|
37
37
|
def show
|
38
38
|
kit = typekit_client.get_kit(options[:id], options[:published])
|
39
39
|
|
40
|
-
|
40
|
+
ap(kit) if kit
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
def display_kits(kits)
|
46
|
-
Formatador.display_line("[bold]Your Kits:[/]")
|
47
|
-
Formatador.display_table(kits)
|
48
|
-
end
|
49
|
-
|
50
|
-
def display_kit_detail(kit)
|
51
|
-
Formatador.display_line("[blue]Kit: #{kit['name']}[/]")
|
52
|
-
kit_data = [{
|
53
|
-
id: kit['id'],
|
54
|
-
domains: kit['domains'].join(','),
|
55
|
-
analytics: kit['analytics'].to_s
|
56
|
-
}]
|
57
|
-
Formatador.display_table(kit_data, [:id, :domains, :analytics])
|
58
|
-
|
59
|
-
Formatador.display_line("[bold]#{kit['name']} Families:[/]")
|
60
|
-
kit['families'].each do |family|
|
61
|
-
display_family_detail(family)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def display_family_detail(family)
|
66
|
-
family_data = [{
|
67
|
-
name: family['name'],
|
68
|
-
id: family['id'],
|
69
|
-
slug: family['slug'],
|
70
|
-
css_names: family['css_names'].join(',')
|
71
|
-
}]
|
72
|
-
Formatador.display_table(family_data, [:name, :id, :slug, :css_names])
|
73
|
-
end
|
74
|
-
|
75
|
-
def not_found
|
76
|
-
Formatador.display_line('[red]No kits found[/]')
|
77
|
-
end
|
78
|
-
|
79
45
|
def typekit_client
|
80
|
-
@client ||= Awesomekit::Client.new(Awesomekit::Authenticator.
|
46
|
+
@client ||= Awesomekit::Client.new(Awesomekit::Authenticator.api_token)
|
81
47
|
end
|
82
48
|
end
|
83
49
|
end
|
data/lib/awesomekit/client.rb
CHANGED
@@ -6,8 +6,8 @@ module Awesomekit
|
|
6
6
|
|
7
7
|
base_uri 'https://typekit.com/api/v1/json'
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
self.class.headers('X-Typekit-Token' =>
|
9
|
+
def initialize(api_token)
|
10
|
+
self.class.headers('X-Typekit-Token' => api_token)
|
11
11
|
end
|
12
12
|
|
13
13
|
# PUBLIC: Returns a list of kits owned by the authenticating user
|
@@ -15,9 +15,13 @@ module Awesomekit
|
|
15
15
|
def get_kits
|
16
16
|
response = self.class.get("/kits")
|
17
17
|
|
18
|
-
process_errors(response)
|
18
|
+
return if process_errors(response)
|
19
19
|
|
20
|
-
|
20
|
+
# If no kits are found, an empty array is returned (not a Not Found error)
|
21
|
+
kits = response['kits']
|
22
|
+
return not_found if kits.nil? || kits.empty?
|
23
|
+
|
24
|
+
kits
|
21
25
|
end
|
22
26
|
|
23
27
|
# PUBLIC: Returns information about a kit found by kit_id
|
@@ -32,7 +36,7 @@ module Awesomekit
|
|
32
36
|
response = self.class.get("/kits/#{kit_id}")
|
33
37
|
end
|
34
38
|
|
35
|
-
process_errors(response)
|
39
|
+
return if process_errors(response)
|
36
40
|
|
37
41
|
response['kit']
|
38
42
|
end
|
@@ -41,21 +45,25 @@ module Awesomekit
|
|
41
45
|
|
42
46
|
# PRIVATE: Display any error messages returned by Typekit.
|
43
47
|
#
|
44
|
-
# Automatically removes an invalid
|
45
|
-
# so the user will be prompted to enter a new
|
48
|
+
# Automatically removes an invalid api_token if error is a 401 not authorized,
|
49
|
+
# so the user will be prompted to enter a new token on their next request.
|
46
50
|
def process_errors(response)
|
47
51
|
if response['errors']
|
48
|
-
errors = '
|
52
|
+
errors = 'The server responded with the following error(s): '
|
49
53
|
errors << response['errors'].join(',')
|
50
54
|
|
51
55
|
if errors.include?('Not authorized')
|
52
|
-
Awesomekit::Authenticator.
|
56
|
+
Awesomekit::Authenticator.clear_api_token
|
53
57
|
end
|
54
58
|
|
55
|
-
|
59
|
+
puts(errors)
|
56
60
|
|
57
|
-
|
61
|
+
return true
|
58
62
|
end
|
59
63
|
end
|
64
|
+
|
65
|
+
def not_found
|
66
|
+
puts('No kits found')
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesomekit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liz Hubertz
|
@@ -39,19 +39,25 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.14.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: awesome_print
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '1.7'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.7.0
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
57
|
+
version: '1.7'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.7.0
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rspec
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|