ghkeys 1.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: 493771f5b0a7c7fcac0a45d73af3253aaade61aa
4
- data.tar.gz: 354689ef309b1823190a4f60130efcb324d2b11c
3
+ metadata.gz: 2b96a1df80d832753a10798c758f2718117c2c74
4
+ data.tar.gz: 4534718ba71425d75f3da84ffe86033f56abf34d
5
5
  SHA512:
6
- metadata.gz: dff8f8a01a0f399ecf39fcdb5048a82365b77fb3632ba10fe5d927a6e867691ae6dd35689af80f4f7b00857f8ccb986f4102f152e5365e093257204e195bc3c6
7
- data.tar.gz: 7d013df99c15248eda8ebd099c4e66811b752e47afb98a400a79ef1ef8331fcf7492560824277bb99ca4100055a67fc7e8ea2fc1077c830e720774a9f2f34b87
6
+ metadata.gz: 205fd042fcde45ad2c131eea6e669f30c7b8f1b7bd76d8fd9b711bd75ccf5a3e3c4a5b8d751c576bed6c59fea4300748b1201dddf5d89c95c137cf9d9bdfca38
7
+ data.tar.gz: 7760232838783003009e1aa9f3a46dc8970ab4a9f38c6e63c89214d45e68797ee1a33ce730f75474383d9600dad8fd976deae05daa5f48e57aa837d80b299cf1
data/.gitignore CHANGED
@@ -1,9 +1,2 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ /bin
2
+ /pkg
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ghkeys (1.0)
5
+ httparty (~> 0.13.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.1)
11
+ diff-lcs (1.2.5)
12
+ httparty (0.13.7)
13
+ json (~> 1.8)
14
+ multi_xml (>= 0.5.2)
15
+ json (1.8.3)
16
+ method_source (0.8.2)
17
+ multi_xml (0.5.5)
18
+ pry (0.10.3)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.8.1)
21
+ slop (~> 3.4)
22
+ rake (10.5.0)
23
+ rspec (3.4.0)
24
+ rspec-core (~> 3.4.0)
25
+ rspec-expectations (~> 3.4.0)
26
+ rspec-mocks (~> 3.4.0)
27
+ rspec-core (3.4.4)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-expectations (3.4.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-mocks (3.4.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-support (3.4.1)
36
+ slop (3.6.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.12)
43
+ ghkeys!
44
+ pry
45
+ rake (~> 10.0)
46
+ rspec (~> 3.0)
47
+
48
+ BUNDLED WITH
49
+ 1.12.5
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ghkeys
1
+ # GHKeys - GitHub Keys
2
2
 
3
3
  GitHub Keys gem allows you to fetch users keys in the simplest way. It uses web scraping because of GH API limits.
4
4
 
@@ -27,6 +27,8 @@ GHKeys('axvm')
27
27
  => #array of strings
28
28
  ```
29
29
 
30
+ Each key will be wrapped into SSHKey class. It gives you ability to calculate md5\sha1\sha256 fingerprints. If key is corrupted or invalid, `IncorrectOrCorruptedKey` exception will be raised.
31
+
30
32
  ## Contributing
31
33
 
32
34
  Bug reports and pull requests are welcome on GitHub at https://github.com/axvm/ghkeys.
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
24
  spec.add_development_dependency "pry"
25
25
  spec.add_dependency "httparty", "~> 0.13.7"
26
+ spec.add_dependency "sshkey", "~> 1.8.0"
26
27
  end
@@ -1,28 +1,32 @@
1
1
  require "ghkeys/version"
2
+ require 'ghkeys/exceptions'
3
+ require "ghkeys/ssh_key"
4
+ require "sshkey"
2
5
  require "httparty"
3
- require 'pry'
4
6
 
5
7
  module GHKeys
6
8
  extend self
7
9
 
8
10
  def fetch(username)
9
11
  response = HTTParty.get("https://github.com/#{username}.keys")
10
- raise UserNotFound.new(username) if response.code == 404
12
+ raise UserNotFound if response.code == 404
11
13
 
12
14
  response.split("\n")
13
15
  end
14
16
 
15
- class UserNotFound < StandardError
16
- attr_reader :user
17
- def initialize(user, msg="Incorrect username or user not exists.")
18
- @user = user
19
- super(msg)
17
+ def parse(keys)
18
+ keys.inject [] do |a, k|
19
+ a << SSHKey.new(k)
20
20
  end
21
21
  end
22
+
23
+ def by_username(username)
24
+ parse(fetch(username))
25
+ end
22
26
  end
23
27
 
24
28
  module Kernel
25
29
  def GHKeys(username)
26
- GHKeys.fetch(username)
30
+ by_username(username)
27
31
  end
28
32
  end
@@ -0,0 +1,4 @@
1
+ module GHKeys
2
+ class UserNotFound < StandardError; end
3
+ class IncorrectOrCorruptedKey < StandardError; end
4
+ end
@@ -0,0 +1,39 @@
1
+ module GHKeys
2
+ class SSHKey
3
+ attr_accessor :key
4
+
5
+ def initialize(base64_key)
6
+ @key = base64_key
7
+
8
+ raise IncorrectOrCorruptedKey unless valid?
9
+ end
10
+
11
+ def valid?
12
+ ::SSHKey.valid_ssh_public_key? @key
13
+ end
14
+
15
+ def bits
16
+ ::SSHKey.ssh_public_key_bits @key
17
+ end
18
+
19
+ def md5_fingerprint
20
+ ::SSHKey.fingerprint @key
21
+ end
22
+
23
+ def sha1_fingerprint
24
+ ::SSHKey.sha1_fingerprint @key
25
+ end
26
+
27
+ def sha256_fingerprint
28
+ ::SSHKey.sha256_fingerprint @key
29
+ end
30
+
31
+ def to_s
32
+ @key
33
+ end
34
+
35
+ def inspect
36
+ to_s
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module GHKeys
2
- VERSION = "1.0"
2
+ VERSION = "2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghkeys
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - axvm
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.13.7
83
+ - !ruby/object:Gem::Dependency
84
+ name: sshkey
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.0
83
97
  description: Simple gem might be useful when you need to fetch users public keys
84
98
  email:
85
99
  - axvmindaweb@gmail.com
@@ -91,12 +105,15 @@ files:
91
105
  - ".rspec"
92
106
  - ".travis.yml"
93
107
  - Gemfile
108
+ - Gemfile.lock
94
109
  - README.md
95
110
  - Rakefile
96
111
  - bin/console
97
112
  - bin/setup
98
113
  - ghkeys.gemspec
99
114
  - lib/ghkeys.rb
115
+ - lib/ghkeys/exceptions.rb
116
+ - lib/ghkeys/ssh_key.rb
100
117
  - lib/ghkeys/version.rb
101
118
  homepage: https://github.com/axvm/ghkeys
102
119
  licenses: []