awesomekit 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa7ab5dc29d8d9f285b380e00960d32c61bb26bc
4
- data.tar.gz: 4f64ed4474f314e6087f6e4fbb220d515ee9bd71
3
+ metadata.gz: 9597254f6ceaeca2ee78fcdc52e3dc892c1b2dd9
4
+ data.tar.gz: 20db737d66db06ae670145a815c38560ee9376a0
5
5
  SHA512:
6
- metadata.gz: 159a13a507dc51481402214e5588446cd0fe2f6c5ffcd229735d271a63736014018636f0bf2be4cd22c317454eac07e35f76e53fe4d7d5289ced052415151d63
7
- data.tar.gz: f0ebc1288b930eafb1576c7168f2bdae1435d715fcd69e232d14bc2616792ad8231dd89d4786e989aa2a65ca6749034a8e07aa724e9d9acd154555d98dce31a5
6
+ metadata.gz: a5f1abe2c5414d763a9e3a4171a57ad5ae26579729c697a7e194bada92d28d3c71122cbe8cd10d07d7987ad687186d14c15e2d5065c80f590dcdc0562da24d82
7
+ data.tar.gz: f56aaeea1d803ff507725753a7a2d45ed10a4287d3a9ce1ab04b305af0539cd1cad6f78d0a11f5c99229d48e1b4b184692d690140b816400980b57cd58b6a16e
@@ -1,10 +1,8 @@
1
1
  module Awesomekit
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  NAME = 'awesomekit'
4
4
  end
5
5
 
6
- require 'formatador'
7
-
8
6
  require 'awesomekit/authenticator'
9
7
  require 'awesomekit/client'
10
8
  require 'awesomekit/cli'
@@ -2,33 +2,33 @@ module Awesomekit
2
2
  class Authenticator
3
3
  CONFIG_FILE = '.typekit'
4
4
 
5
- # PUBLIC: Return the current saved api_key
6
- # If no key exists, prompt user for key
7
- def self.api_key
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
- prompt_user_for_key
11
+ prompt_user_for_token
12
12
  end
13
13
  end
14
14
 
15
- # PUBLIC: Delete any existing api_key config file
16
- def self.clear_api_key
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.prompt_user_for_key
23
- Formatador.display('[yellow]Please enter your Adobe Typekit API key: [/]')
24
- api_key = STDIN.gets.chomp
25
- save_key_to_config(api_key)
26
- api_key
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.save_key_to_config(api_key)
29
+ def self.save_token_to_config(api_token)
30
30
  File.open(config, 'w') do |file|
31
- file.write(api_key)
31
+ file.write(api_token)
32
32
  end
33
33
  end
34
34
 
@@ -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 key'
8
+ desc 'logout', 'Remove your Adobe Typekit API token'
8
9
  def logout
9
- Awesomekit::Authenticator.clear_api_key
10
- Formatador.display_line('[yellow]Successfully logged out[/]')
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
- display_kits(kits)
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
- display_kit_detail(kit)
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
- display_kit_detail(kit)
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.api_key)
46
+ @client ||= Awesomekit::Client.new(Awesomekit::Authenticator.api_token)
81
47
  end
82
48
  end
83
49
  end
@@ -6,8 +6,8 @@ module Awesomekit
6
6
 
7
7
  base_uri 'https://typekit.com/api/v1/json'
8
8
 
9
- def initialize(api_key)
10
- self.class.headers('X-Typekit-Token' => api_key)
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
- response['kits']
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 api_key if error is a 401 not authorized,
45
- # so the user will be prompted to enter a new key on their next request.
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 = '[red]The server responded with the following error(s):[/] '
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.clear_api_key
56
+ Awesomekit::Authenticator.clear_api_token
53
57
  end
54
58
 
55
- Formatador.display_line(errors)
59
+ puts(errors)
56
60
 
57
- exit
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.1
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: formatador
42
+ name: awesome_print
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.5
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: 0.2.5
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