clian 0.4.1 → 0.5.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
- SHA1:
3
- metadata.gz: f129bb5f94439abf0cd13b8f0d84725a651f1d0f
4
- data.tar.gz: e82d6c81a348849d58c10c684368997d24320e9c
2
+ SHA256:
3
+ metadata.gz: b65d588a5fe3b0124bab9fcf6b5eeb2c754e7172fa5c2bb41af3d2fbb973a5b7
4
+ data.tar.gz: fa79302cdf627d030e079459800b726b1a41d476a1011c668917b70f684eb714
5
5
  SHA512:
6
- metadata.gz: 97b6f721b07df9332464eab4e16e5c25fcc64d1babd16533f49ad55ed7192f195916ef99490e81d7ddb32d19e99d3f1b56bf78d981969e157da11581e8debfd0
7
- data.tar.gz: bb50f21d1dfc734348ca3b0013acd0d4550644fb5c87d45b42f4915432b30030e5a7f14664dd0d909b14bac85e7c8cda9b6eaf05f77fc1dbcb55b398d7c676d5
6
+ metadata.gz: c60178e38a33066ea9f06e582f25c20096aade63150b46dc64abcb388bd3487dcc49b449710d23fd5f7332c09a069e295d2b307a93a37d1be51ea9e003bb42d1
7
+ data.tar.gz: 3e98ea8037ac8408cffeda18b201de4e5499a50c7ababc857ec4af6499d2fbaea7dc8679206bb780d4c0e1a1342e2339c11ffd2d454e87d68c360af69ae5b190
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Yoshinari Nomura
3
+ Copyright (c) 2016-2025 Yoshinari Nomura
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/clian.gemspec CHANGED
@@ -25,13 +25,12 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_runtime_dependency "thor", ">= 0.19.1"
29
- spec.add_runtime_dependency "google-api-client", "~> 0.13"
30
- spec.add_runtime_dependency "googleauth", "~> 0.6.0"
31
- spec.add_runtime_dependency "launchy"
32
- spec.add_runtime_dependency "mail"
28
+ spec.add_runtime_dependency "thor", '~> 1.3', '>= 1.3.2'
29
+ spec.add_runtime_dependency "googleauth", '~> 1.14'
30
+ spec.add_runtime_dependency "launchy", '~> 3.1', '>= 3.1.1'
31
+ spec.add_runtime_dependency 'webrick', '~> 1.9', '>= 1.9.1'
33
32
 
34
- spec.add_development_dependency "bundler", "~> 1.11"
35
- spec.add_development_dependency "rake", "~> 10.0"
36
- spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "rake"
35
+ spec.add_development_dependency "rspec"
37
36
  end
@@ -1,4 +1,3 @@
1
- require 'google/apis/gmail_v1'
2
1
  require 'googleauth'
3
2
  require 'googleauth/stores/file_token_store'
4
3
  require 'launchy'
@@ -23,22 +22,62 @@ module Clian
23
22
  end
24
23
 
25
24
  def auth_interactively(user_id = "default", shell = Thor.new.shell)
26
- oob_uri = "urn:ietf:wg:oauth:2.0:oob"
25
+ callback_uri = "http://localhost:8000"
27
26
 
28
- url = @authorizer.get_authorization_url(base_url: oob_uri)
27
+ url = @authorizer.get_authorization_url(base_url: callback_uri)
29
28
  begin
30
29
  Launchy.open(url)
31
30
  rescue
32
31
  puts "Open URL in your browser:\n #{url}"
33
32
  end
34
33
 
35
- code = shell.ask "Enter the resulting code:"
34
+ puts "Waiting OAuth code at #{callback_uri} ..."
35
+
36
+ code = get_oauth_code_by_webserver(8000) ||
37
+ shell.ask("Enter the resulting code:")
38
+ puts "Done."
36
39
 
37
40
  @authorizer.get_and_store_credentials_from_code(
38
41
  user_id: user_id,
39
42
  code: code,
40
- base_url: oob_uri
43
+ base_url: callback_uri
44
+ )
45
+ end
46
+
47
+ private
48
+
49
+ def get_oauth_code_by_webserver(port = 8000)
50
+ require 'webrick'
51
+ require 'uri'
52
+
53
+ code = nil
54
+ server = WEBrick::HTTPServer.new(
55
+ Port: port,
56
+ Logger: WEBrick::Log.new(File.open(File::NULL, "w")),
57
+ AccessLog: []
41
58
  )
59
+
60
+ server.mount_proc '/' do |req, res|
61
+ query = URI.decode_www_form(req.query_string || "").to_h
62
+ code = query["code"]
63
+
64
+ if code
65
+ res.status = 200
66
+ res.content_type = "text/plain"
67
+ res.body = "Got OAuth code: #{code}\nYou can close this browser and back to CLI."
68
+
69
+ # shutdown server in another thread to avoid blocking current request
70
+ Thread.new { server.shutdown }
71
+ else
72
+ res.status = 400
73
+ res.body = "Failed to get OAuth code"
74
+ end
75
+ end
76
+
77
+ # block until shutdown is called in another thread
78
+ server.start
79
+ return code
42
80
  end
81
+
43
82
  end # Authorizer
44
83
  end # Clian
data/lib/clian/cli.rb CHANGED
@@ -32,7 +32,7 @@ module Clian
32
32
 
33
33
  gemfile = File.expand_path("../../Gemfile", command_path)
34
34
 
35
- if File.exists?(gemfile + ".lock")
35
+ if File.exist?(gemfile + ".lock")
36
36
  ENV["BUNDLE_GEMFILE"] = gemfile
37
37
  require "bundler/setup"
38
38
  end
data/lib/clian/config.rb CHANGED
@@ -53,7 +53,7 @@ module Clian
53
53
  end
54
54
 
55
55
  def self.create_from_yaml_string(yaml_string, filename = nil)
56
- hash = YAML.load(yaml_string, filename) || {}
56
+ hash = YAML.load(yaml_string, filename: filename) || {}
57
57
  return new(hash)
58
58
  end
59
59
 
@@ -191,7 +191,7 @@ module Clian
191
191
  end
192
192
 
193
193
  def self.create_from_file(file_name = self.default_path)
194
- unless File.exists?(File.expand_path(file_name))
194
+ unless File.exist?(File.expand_path(file_name))
195
195
  raise ConfigurationError, "config file '#{file_name}' not found"
196
196
  end
197
197
  begin
data/lib/clian/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Clian
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,127 +1,131 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clian
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshinari Nomura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-22 00:00:00.000000000 Z
11
+ date: 2025-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.19.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
19
+ version: '1.3'
24
20
  - - ">="
25
21
  - !ruby/object:Gem::Version
26
- version: 0.19.1
27
- - !ruby/object:Gem::Dependency
28
- name: google-api-client
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.13'
22
+ version: 1.3.2
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
27
  - - "~>"
39
28
  - !ruby/object:Gem::Version
40
- version: '0.13'
29
+ version: '1.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.2
41
33
  - !ruby/object:Gem::Dependency
42
34
  name: googleauth
43
35
  requirement: !ruby/object:Gem::Requirement
44
36
  requirements:
45
37
  - - "~>"
46
38
  - !ruby/object:Gem::Version
47
- version: 0.6.0
39
+ version: '1.14'
48
40
  type: :runtime
49
41
  prerelease: false
50
42
  version_requirements: !ruby/object:Gem::Requirement
51
43
  requirements:
52
44
  - - "~>"
53
45
  - !ruby/object:Gem::Version
54
- version: 0.6.0
46
+ version: '1.14'
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: launchy
57
49
  requirement: !ruby/object:Gem::Requirement
58
50
  requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
59
54
  - - ">="
60
55
  - !ruby/object:Gem::Version
61
- version: '0'
56
+ version: 3.1.1
62
57
  type: :runtime
63
58
  prerelease: false
64
59
  version_requirements: !ruby/object:Gem::Requirement
65
60
  requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.1'
66
64
  - - ">="
67
65
  - !ruby/object:Gem::Version
68
- version: '0'
66
+ version: 3.1.1
69
67
  - !ruby/object:Gem::Dependency
70
- name: mail
68
+ name: webrick
71
69
  requirement: !ruby/object:Gem::Requirement
72
70
  requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.9'
73
74
  - - ">="
74
75
  - !ruby/object:Gem::Version
75
- version: '0'
76
+ version: 1.9.1
76
77
  type: :runtime
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.9'
80
84
  - - ">="
81
85
  - !ruby/object:Gem::Version
82
- version: '0'
86
+ version: 1.9.1
83
87
  - !ruby/object:Gem::Dependency
84
88
  name: bundler
85
89
  requirement: !ruby/object:Gem::Requirement
86
90
  requirements:
87
- - - "~>"
91
+ - - ">="
88
92
  - !ruby/object:Gem::Version
89
- version: '1.11'
93
+ version: '0'
90
94
  type: :development
91
95
  prerelease: false
92
96
  version_requirements: !ruby/object:Gem::Requirement
93
97
  requirements:
94
- - - "~>"
98
+ - - ">="
95
99
  - !ruby/object:Gem::Version
96
- version: '1.11'
100
+ version: '0'
97
101
  - !ruby/object:Gem::Dependency
98
102
  name: rake
99
103
  requirement: !ruby/object:Gem::Requirement
100
104
  requirements:
101
- - - "~>"
105
+ - - ">="
102
106
  - !ruby/object:Gem::Version
103
- version: '10.0'
107
+ version: '0'
104
108
  type: :development
105
109
  prerelease: false
106
110
  version_requirements: !ruby/object:Gem::Requirement
107
111
  requirements:
108
- - - "~>"
112
+ - - ">="
109
113
  - !ruby/object:Gem::Version
110
- version: '10.0'
114
+ version: '0'
111
115
  - !ruby/object:Gem::Dependency
112
116
  name: rspec
113
117
  requirement: !ruby/object:Gem::Requirement
114
118
  requirements:
115
- - - "~>"
119
+ - - ">="
116
120
  - !ruby/object:Gem::Version
117
- version: '3.0'
121
+ version: '0'
118
122
  type: :development
119
123
  prerelease: false
120
124
  version_requirements: !ruby/object:Gem::Requirement
121
125
  requirements:
122
- - - "~>"
126
+ - - ">="
123
127
  - !ruby/object:Gem::Version
124
- version: '3.0'
128
+ version: '0'
125
129
  description: Small set of Ruby classes helpful for creation of CLI tools.
126
130
  email:
127
131
  - nom@quickhack.net
@@ -164,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
168
  - !ruby/object:Gem::Version
165
169
  version: '0'
166
170
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.6.14
171
+ rubygems_version: 3.5.22
169
172
  signing_key:
170
173
  specification_version: 4
171
174
  summary: Small set of Ruby classes helpful for creation of CLI tools.