octoauth 1.0.1 → 1.0.2

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: 6e3c5f9de8d5d04c3da935d4bd4326a096751c5a
4
- data.tar.gz: b6282a33046a75bff72b9d5a95518618698dcbf5
3
+ metadata.gz: 9aa2e61a7ffe64cb1ca0a5c992a62afad06ba3f2
4
+ data.tar.gz: 3eea475acbea688c561c178afd6418f83695618a
5
5
  SHA512:
6
- metadata.gz: ad5f2c360831e28e24281234026d762b3ef6a680cf64ecab46c6b6e7e2b94dc6d2e588b2d3ed98f230cbab0aef254ddd37d183ec8ddc46f8fb2406e151b11a6a
7
- data.tar.gz: d96a4bf5d6e51f37365fcb67c42c58168634c146a0218886ffd4e2249b825bcc6445b694ecdbc3dd009b95f0233f2d19084b3ab7b295833012731c35b1ecf46a
6
+ metadata.gz: 34b473862aff7ce51daf7f2d3c17c2dfd98bd01bba08a521e9a93bac0fcbfa81ffa80b39f00baf17fb1fe56bbf024b80adc0017383aeea609ff60284745675ef
7
+ data.tar.gz: c9d43a74f10613864ec54a04382465f80772a5ecd463cb6277648fd44d6d0b0f46c866727757d46f2fb970a287bfcf1f76ab34bc5f0707794799f9fb3608e69a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- # 1.0.2 / Unreleased
1
+ # 1.0.2 / 2015-05-03
2
+
3
+ * [ENHANCEMENT] Fix option/param handling to be cleaner
2
4
 
3
5
  # 1.0.1 / 2015-02-20
4
6
 
data/lib/octoauth/auth.rb CHANGED
@@ -19,55 +19,68 @@ module Octoauth
19
19
  ##
20
20
  # Authentication object
21
21
  class Auth
22
- attr_reader :token
23
-
24
22
  def initialize(params = {})
25
- params[:config_note] = "#{params[:note]}"
26
- if params[:api_endpoint]
27
- params[:config_note] << "--#{params[:api_endpoint]}"
28
- end
29
- @config = ConfigFile.new file: params[:file], note: params[:config_note]
30
- @token = load_token params
31
- save if params[:autosave]
23
+ parse_params!(params)
24
+ @config = ConfigFile.new file: @options[:file], note: config_note
25
+ save if @options[:autosave]
32
26
  end
33
27
 
34
28
  def save
35
- fail 'No token to save' unless @token
29
+ fail 'No token to save' unless token
36
30
  fail 'No file given for config' unless @config.file
37
31
  @config.token = @token
38
32
  @config.write
39
33
  end
40
34
 
35
+ def token
36
+ @token ||= load_token
37
+ end
38
+
41
39
  private
42
40
 
43
- def load_token(params = {}) # rubocop:disable Metrics/AbcSize
41
+ def parse_params!(params)
42
+ @options = params.subset(
43
+ :file, :note, :autosave, :scopes,
44
+ :login, :password, :twofactor, :api_endpoint
45
+ )
46
+ end
47
+
48
+ def config_note
49
+ return @options[:note] unless @options[:api_endpoint]
50
+ "#{@options[:note]}--#{@options[:api_endpoint]}"
51
+ end
52
+
53
+ def prompt!(needs2fa = false)
54
+ @options[:login] ||= PROMPTS[:login].ask
55
+ @options[:password] ||= PROMPTS[:password].ask
56
+ @options[:scopes] ||= DEFAULT_SCOPES
57
+ return unless needs2fa
58
+ @options[:twofactor] ||= PROMPTS[:twofactor].ask
59
+ @options[:headers] = { 'X-GitHub-OTP' => @options[:twofactor] }
60
+ end
61
+
62
+ def load_token(needs2fa = false)
44
63
  return @config.token if @config.token
45
- params[:login] ||= PROMPTS[:login].ask
46
- params[:password] ||= PROMPTS[:password].ask
47
- params[:twofactor] ||= PROMPTS[:twofactor].ask if params[:needs2fa]
48
- params[:scopes] ||= DEFAULT_SCOPES
49
- if params[:twofactor]
50
- params[:headers] = { 'X-GitHub-OTP' => params[:twofactor] }
51
- end
52
- authenticate! params
64
+ prompt!(needs2fa)
65
+ authenticate
53
66
  end
54
67
 
55
- def authenticate!(params = {})
68
+ def authenticate
56
69
  client = Octokit::Client.new(
57
- params.subset(:login, :password, :api_endpoint)
70
+ @options.subset(:login, :password, :api_endpoint)
58
71
  )
59
72
  client.create_authorization(
60
- params.subset(:note, :scopes, :headers)
73
+ @options.subset(:note, :scopes, :headers)
61
74
  ).token
62
75
  rescue Octokit::OneTimePasswordRequired
63
- load_token params.merge(needs2fa: true)
76
+ load_token(true)
64
77
  rescue Octokit::UnprocessableEntity
65
- check_existing_token client, params
78
+ check_existing_token client
66
79
  end
67
80
 
68
- def check_existing_token(client, params = {})
69
- client.authorizations(params.subset(:headers))
70
- .find { |x| x[:note] == params[:note] }.token
81
+ def check_existing_token(client)
82
+ client.authorizations(@options.subset(:headers))
83
+ .find { |x| x[:note] == @options[:note] }.token
71
84
  end
72
85
  end
73
86
  end
data/octoauth.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'octoauth'
3
- s.version = '1.0.1'
3
+ s.version = '1.0.2'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
 
6
6
  s.summary = 'Auth token helper for GitHub API'
@@ -16,10 +16,10 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency 'octokit', '~> 3.8.0'
17
17
  s.add_dependency 'userinput', '~> 1.0.0'
18
18
 
19
- s.add_development_dependency 'rubocop', '~> 0.29.0'
19
+ s.add_development_dependency 'rubocop', '~> 0.30.0'
20
20
  s.add_development_dependency 'rake', '~> 10.4.0'
21
- s.add_development_dependency 'coveralls', '~> 0.7.1'
21
+ s.add_development_dependency 'coveralls', '~> 0.8.0'
22
22
  s.add_development_dependency 'rspec', '~> 3.2.0'
23
23
  s.add_development_dependency 'fuubar', '~> 2.0.0'
24
- s.add_development_dependency 'webmock', '~> 1.20.0'
24
+ s.add_development_dependency 'webmock', '~> 1.21.0'
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octoauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.29.0
47
+ version: 0.30.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.29.0
54
+ version: 0.30.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.7.1
75
+ version: 0.8.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.7.1
82
+ version: 0.8.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 1.20.0
117
+ version: 1.21.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 1.20.0
124
+ version: 1.21.0
125
125
  description: Lightweight wrapper to sanely handle OAuth tokens with Octokit
126
126
  email: me@lesaker.org
127
127
  executables: []