gripst 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 380652abb4dbc428aa05221d26c7d1f1fc10a310
4
- data.tar.gz: 941e5560a575c5692a8b8ed9cfee3017d6abc77d
3
+ metadata.gz: dc4166725366d8376ffac640f2790bcb1e3815f9
4
+ data.tar.gz: 59d3c347ee3e7577f468b1b75ed41ecf89b34058
5
5
  SHA512:
6
- metadata.gz: e76a6efdf94bbe15a5322bda54e968ccab81b4b37da4dceb47e46d2d4c4ea09850dd5c242e6410debef5ff6eca011ce5fb1f5ad4038aed7609d378be2a9937c2
7
- data.tar.gz: c3a9585f58ef11be7a9adc97e358e4bb9499316c3ac2b4b42f9a0e5d96412abdd507843259e62e0fc265b5ab861f0009c5eca8f338c9bffa97dbd8c9f599e3f5
6
+ metadata.gz: 17cb2a9747fd9417a5fb63e5b2cb0cdd4b28e7ee767574f8e99fb1b711f73861e19f7df7d7234e3e15133a3e5dcbc3b7e118e2048bd1651f925ba705528a5b36
7
+ data.tar.gz: afc395c8f85de986767019f6c4d5c42347cf20b3be8d6dc697ad73131e9df2fe8fec1232691c7f7d47c6ff17175ce099203e226f0f746fd7cd8119f00633c522
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .ruby-version
2
2
  .ruby-gemset
3
+ .rbenv-gemsets
3
4
  .rpsec
4
5
  *.gem
5
6
  *.rbc
@@ -0,0 +1,92 @@
1
+ require 'octokit'
2
+ require 'pry'
3
+
4
+ class Client
5
+ PATH = ENV['HOME'] + '/.gripst'
6
+
7
+ class << self
8
+ def get_auth_token
9
+ return oauth_from_file if oauth_from_file
10
+ authorizer = Client.new
11
+ authorizer.authorize
12
+ end
13
+
14
+ private
15
+
16
+ def oauth_from_file
17
+ File.open PATH, &:readline if File.exists? PATH
18
+ end
19
+ end
20
+
21
+ attr_reader :username,
22
+ :password
23
+
24
+ def initialize
25
+ @username = get_username
26
+ @password = get_password
27
+ end
28
+
29
+ def authorize
30
+
31
+ begin
32
+ auth_token = client.create_authorization :scopes => ['gists'], :note => 'gripst'
33
+ rescue Octokit::OneTimePasswordRequired
34
+ otp = get_otp
35
+ auth_token = authorize_with_otp otp
36
+ end
37
+
38
+ write_auth_token auth_token
39
+ login_with_oauth auth_token
40
+ end
41
+
42
+ private
43
+ def get_username
44
+ puts 'Enter your GitHub username'
45
+ STDIN.gets.chomp
46
+ end
47
+
48
+ def get_password
49
+ begin
50
+ system "stty -echo"
51
+ puts 'Enter your GitHub password'
52
+ puts '(the input will be hidden)'
53
+ STDIN.gets.chomp
54
+ ensure
55
+ system "stty echo"
56
+ end
57
+ end
58
+
59
+ def get_otp
60
+ puts 'Looks like you have 2FA. Smart move.'
61
+ puts 'Enter the OTP from GitHub'
62
+ STDIN.gets.chomp
63
+ end
64
+
65
+ def client
66
+ @client ||= Octokit::Client.new :login => username,
67
+ :password => password
68
+ end
69
+
70
+ def authorize_with_otp(token)
71
+ response = client.create_authorization :scopes => ['gist'],
72
+ :note => 'gripst',
73
+ :headers => { 'X-GitHub-OTP' => token }
74
+ response[:token]
75
+ rescue Octokit::UnprocessableEntity => e
76
+ raise "422 error: #{e}"
77
+ end
78
+
79
+ def login_with_oauth(oauth_token)
80
+ client = Octokit::Client.new :access_token => oauth_token
81
+ client.user.login
82
+ client
83
+ end
84
+
85
+ def write_auth_token(oauth_token)
86
+ File.new PATH, 'w+' unless File.exists? PATH
87
+ file = File.open PATH, 'w+'
88
+ file << oauth_token
89
+ ensure
90
+ file.close
91
+ end
92
+ end
data/lib/gripst/gripst.rb CHANGED
@@ -3,6 +3,7 @@ require 'tmpdir'
3
3
  require 'octokit'
4
4
  require 'git'
5
5
  require_relative 'string'
6
+ require_relative 'client'
6
7
  require_relative 'version'
7
8
 
8
9
  module Gripst
@@ -11,7 +12,7 @@ module Gripst
11
12
  ParamObj = Struct.new(:id, :path)
12
13
 
13
14
  def initialize
14
- @auth_token = ENV['GITHUB_USER_ACCESS_TOKEN']
15
+ @auth_token = retrieve_auth_token
15
16
  @tmpdir = Dir.mktmpdir
16
17
  end
17
18
 
@@ -23,10 +24,6 @@ module Gripst
23
24
  client.gists.map(&:id)
24
25
  end
25
26
 
26
- def client
27
- @client ||= create_client
28
- end
29
-
30
27
  def clone(id)
31
28
  Git.clone "https://#{auth_token}@gist.github.com/#{id}.git", id, :path => "#{tmpdir}"
32
29
  true
@@ -46,6 +43,10 @@ module Gripst
46
43
 
47
44
  private
48
45
 
46
+ def client
47
+ @client ||= create_client
48
+ end
49
+
49
50
  def create_client
50
51
  client = Octokit::Client.new :access_token => "#{auth_token}"
51
52
  client.user.login
@@ -78,5 +79,10 @@ module Gripst
78
79
  def extract_gistfile_name(path)
79
80
  path.split('/')[-1].yellow
80
81
  end
82
+
83
+ def retrieve_auth_token
84
+ return ENV['GITHUB_USER_ACCESS_TOKEN'] if ENV['GITHUB_USER_ACCESS_TOKEN']
85
+ Client.get_auth_token
86
+ end
81
87
  end
82
88
  end
@@ -1,3 +1,3 @@
1
1
  module Gripst
2
- VERSION = '0.0.6'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,109 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gripst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Beizer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.3'
20
- - - '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 3.3.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.3'
30
- - - '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.3.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: git
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '1.2'
40
- - - '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: 1.2.8
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.2'
50
- - - '>='
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.2.8
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: bundler
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ~>
57
+ - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '1.3'
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ~>
64
+ - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '1.3'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rspec
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ~>
71
+ - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: '3.0'
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ~>
78
+ - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '3.0'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rake
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ~>
85
+ - - "~>"
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ~>
92
+ - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: pry
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - ~>
99
+ - - "~>"
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - ~>
106
+ - - "~>"
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  description: Brute-force grep your gists
@@ -114,8 +114,8 @@ executables:
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
- - .gitignore
118
- - .rspec
117
+ - ".gitignore"
118
+ - ".rspec"
119
119
  - Gemfile
120
120
  - LICENSE.txt
121
121
  - README.md
@@ -125,6 +125,7 @@ files:
125
125
  - contributing.md
126
126
  - gripst.gemspec
127
127
  - lib/gripst.rb
128
+ - lib/gripst/client.rb
128
129
  - lib/gripst/gripst.rb
129
130
  - lib/gripst/string.rb
130
131
  - lib/gripst/version.rb
@@ -141,17 +142,17 @@ require_paths:
141
142
  - lib
142
143
  required_ruby_version: !ruby/object:Gem::Requirement
143
144
  requirements:
144
- - - '>='
145
+ - - ">="
145
146
  - !ruby/object:Gem::Version
146
147
  version: '2.0'
147
148
  required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  requirements:
149
- - - '>='
150
+ - - ">="
150
151
  - !ruby/object:Gem::Version
151
152
  version: '0'
152
153
  requirements: []
153
154
  rubyforge_project:
154
- rubygems_version: 2.2.2
155
+ rubygems_version: 2.4.8
155
156
  signing_key:
156
157
  specification_version: 4
157
158
  summary: Brute-force grep your gists for when the search tool is not enough