typekitty 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37f1473e0e6dc13f43d93bab6283c84472103bc5
4
- data.tar.gz: dff794e1045ed9f7668c97084587e07707fa606b
3
+ metadata.gz: 12ef796ef4d8ac7424248dd866bd7e17f88b20c9
4
+ data.tar.gz: 16cafcb320a5ece2d40497b23c2b03c2c536eacf
5
5
  SHA512:
6
- metadata.gz: 3a7c7d933691099a642105f2b095000cb98b9ab173f688a165de05bfaef77029329549028ff3c09b5373637e46a95ee5ae2d8a65ee5fa8eca378b4a683a71310
7
- data.tar.gz: a56beae61fe572674225564439b993a843a72c6884841bc76cabad16a4fe7dfe63cb899246b657539de230414bb8c2c06b266396f977f986b0da52d9f0cecb19
6
+ metadata.gz: c7897142ca94c94d167ce415cc9cf1431c1cc8d83c09b7329344b30a9608a9b1d8bd8e028af48e1cbc0d53e2cc6019ecdda079c2199d150b0e925605c1500044
7
+ data.tar.gz: cd747e7611e8e3a46fea3e69389ae2d37592fad9f2cc0d44445005b94259529bb176354ad3430cbe6f3a2a4acbea6eedfc63f06b8f0f389f9bc05a52af9b9d88
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # Add the lib to the load path
4
- $:.unshift File.dirname(__FILE__) + '/../lib'
5
-
6
3
  # Require the CLI
7
- require 'typekitty'
4
+ require_relative '../lib/typekitty'
8
5
 
9
6
  # Start the CLI
10
7
  Typekitty::CLI.start ARGV
@@ -3,4 +3,5 @@ $:.unshift File.dirname(__FILE__)
3
3
 
4
4
  # Load the libraries
5
5
  require 'typekitty/api'
6
+ require 'typekitty/kit'
6
7
  require 'typekitty/cli'
@@ -1,16 +1,35 @@
1
1
  require 'httparty'
2
+ require 'typekitty/kit'
2
3
 
3
4
  module Typekitty
4
5
  module API
5
- include ::HTTParty
6
+ include HTTParty
6
7
 
7
8
  format :json
8
9
  base_uri 'https://typekit.com/api/v1/json'
9
10
  default_params :token => ENV['TYPEKIT_TOKEN']
10
11
 
11
- # Lists kits by their `id`
12
12
  def self.kits
13
- [*get('/kits')['kits']].map { |kit| kit['id'] }
13
+ response = handle_response get '/kits'
14
+
15
+ response['kits'].inject([]) do |kits, kit|
16
+ kits << self.kit(kit['id'])
17
+ end
18
+ end
19
+
20
+ def self.kit id
21
+ response = handle_response get "/kits/#{id}"
22
+
23
+ Typekitty::Kit.new response['kit']
14
24
  end
25
+
26
+ def self.handle_response response
27
+ case response.code
28
+ when 200 then response
29
+ when 401 then raise UnauthorizedError
30
+ end
31
+ end
32
+
33
+ class UnauthorizedError < StandardError; end
15
34
  end
16
35
  end
@@ -3,13 +3,18 @@ require 'typekitty/api'
3
3
 
4
4
  module Typekitty
5
5
  class CLI < Thor
6
+ desc 'kits', 'Lists your kits'
6
7
  option :token, :required => true
7
-
8
- desc 'kits', 'Lists your kits by their `id`'
9
8
  def kits
10
9
  puts api.kits
11
10
  end
12
11
 
12
+ desc 'kit KIT_ID', 'Get information about a kit'
13
+ option :token, :required => true
14
+ def kit id
15
+ puts api.kit id
16
+ end
17
+
13
18
  no_commands do
14
19
  def api
15
20
  Typekitty::API.default_params :token => options[:token]
@@ -0,0 +1,22 @@
1
+ require 'hashie'
2
+ require 'typekitty/api'
3
+
4
+ module Typekitty
5
+ class Kit < Hashie::Dash
6
+ property :id, :required => true
7
+ property :link
8
+ property :name, :required => true
9
+ property :analytics, :required => true
10
+ property :badge, :required => true
11
+ property :domains, :required => true
12
+ property :families, :required => true
13
+
14
+ def self.all
15
+ Typekitty::API.kits
16
+ end
17
+
18
+ def self.find id
19
+ Typekitty::API.kit id
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typekitty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Adam Kaplan
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.13.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -105,6 +119,7 @@ files:
105
119
  - lib/typekitty.rb
106
120
  - lib/typekitty/api.rb
107
121
  - lib/typekitty/cli.rb
122
+ - lib/typekitty/kit.rb
108
123
  homepage: https://github.com/razic/typekitty
109
124
  licenses:
110
125
  - MIT