timely-app 1.0.2 → 1.0.3
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/bin/timely-app +177 -0
- data/lib/timely-app/version.rb +1 -1
- data/timely-app.gemspec +24 -15
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb007aeefb95161536612d0873a2af916979e63090722db4058ef085ea61b9d7
|
4
|
+
data.tar.gz: f635b0b3c8824b054230cc30e05511b6a52d79b1eaeb8d85312d7467717309e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21e914d28e5f658f279191910064353341efe89c461a74ab9d3243db7569dde398f085fed5497639164ac956c4bbabd2a6bcaabe5ae2e5997fe9c9b891216f3f
|
7
|
+
data.tar.gz: 2ebf7294e89b0dfde01076bd02c5dec9eee2272f1ae1b83c617f50f13a119b8e2a45704f3e7ff7735769cd05a6b1d905310c578bb12c4a6b16bd14566a5b3cfe
|
data/CHANGELOG.md
CHANGED
data/bin/timely-app
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "optparse"
|
5
|
+
require "timely-app"
|
6
|
+
|
7
|
+
module TimelyApp
|
8
|
+
class CLI
|
9
|
+
attr_reader :options, :client
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@options = options
|
13
|
+
@client = TimelyApp::Client.new(
|
14
|
+
access_token: options[:access_token] || fetch_access_token,
|
15
|
+
account_id: options[:account_id] || fetch_account_id,
|
16
|
+
verbose: options[:verbose]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_config(key)
|
21
|
+
read_config_file&.fetch(key, nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_config(key, value)
|
25
|
+
save_config_file(key => value)
|
26
|
+
end
|
27
|
+
|
28
|
+
def command_exists?(cmd)
|
29
|
+
client.respond_to?(cmd)
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(cmd, *args)
|
33
|
+
client.send(cmd, *args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def auth(client_id, client_secret)
|
37
|
+
if !client_id || !client_secret
|
38
|
+
puts "Usage: timely-app auth CLIENT_ID CLIENT_SECRET"
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
auth_client = TimelyApp::Client.new(verbose: options[:verbose])
|
43
|
+
auth_url = auth_client.get_oauth_authorize_url(
|
44
|
+
client_id: client_id,
|
45
|
+
redirect_uri: "urn:ietf:wg:oauth:2.0:oob"
|
46
|
+
)
|
47
|
+
puts "Visit this URL in your browser:"
|
48
|
+
puts auth_url
|
49
|
+
puts "\nEnter authorization code here:"
|
50
|
+
code = gets.chomp
|
51
|
+
begin
|
52
|
+
token = auth_client.post_oauth_token(
|
53
|
+
client_id: client_id,
|
54
|
+
client_secret: client_secret,
|
55
|
+
code: code,
|
56
|
+
redirect_uri: "urn:ietf:wg:oauth:2.0:oob",
|
57
|
+
grant_type: "authorization_code"
|
58
|
+
)
|
59
|
+
if options[:save]
|
60
|
+
save_config_file(
|
61
|
+
access_token: token.access_token,
|
62
|
+
refresh_token: token.refresh_token,
|
63
|
+
created_at: token.created_at
|
64
|
+
)
|
65
|
+
else
|
66
|
+
puts "\nAccess token:\n#{token.access_token}\n"
|
67
|
+
end
|
68
|
+
if options[:verbose]
|
69
|
+
puts "Token details: #{token.to_h}"
|
70
|
+
end
|
71
|
+
rescue TimelyApp::Error => e
|
72
|
+
puts "Authentication failed"
|
73
|
+
if options[:verbose]
|
74
|
+
puts "Code: #{code}"
|
75
|
+
puts "Response code: #{e.response.code}"
|
76
|
+
puts "Response: #{e.response.body}"
|
77
|
+
end
|
78
|
+
exit 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def config_file_path
|
85
|
+
Dir.home + "/.timelyrc"
|
86
|
+
end
|
87
|
+
|
88
|
+
def read_config_file
|
89
|
+
if File.exist?(config_file_path)
|
90
|
+
YAML.load_file(config_file_path)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def fetch_account_id
|
95
|
+
read_config_file&.fetch("account_id", nil)
|
96
|
+
end
|
97
|
+
|
98
|
+
def fetch_access_token
|
99
|
+
read_config_file&.fetch("access_token", nil)
|
100
|
+
end
|
101
|
+
|
102
|
+
def check_access_token
|
103
|
+
if !fetch_access_token
|
104
|
+
puts "No access token found. Run `timely-app auth` to get one."
|
105
|
+
exit 1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def save_config_file(**options)
|
110
|
+
config = read_config_file || {}
|
111
|
+
config.merge!(options)
|
112
|
+
File.open(config_file_path, "w") do |f|
|
113
|
+
f.write(config.to_yaml)
|
114
|
+
end
|
115
|
+
puts "Saved to #{config_file_path}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
options = {}
|
121
|
+
OptionParser.new do |opts|
|
122
|
+
opts.banner = "Usage: timely-app [command] [options]"
|
123
|
+
|
124
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
125
|
+
options[:verbose] = v
|
126
|
+
end
|
127
|
+
|
128
|
+
opts.on("-a", "--account ACCOUNT", "Account name") do |a|
|
129
|
+
options[:account] = a
|
130
|
+
end
|
131
|
+
|
132
|
+
opts.on("-s", "--save", "Save changes to file") do |s|
|
133
|
+
options[:save] = s
|
134
|
+
end
|
135
|
+
end.parse!
|
136
|
+
|
137
|
+
cli = TimelyApp::CLI.new(options)
|
138
|
+
|
139
|
+
cmd = ARGV.shift
|
140
|
+
case cmd
|
141
|
+
when "auth"
|
142
|
+
if ARGV.length == 0
|
143
|
+
cli.auth(ENV.fetch('TIMELY_CLIENT_ID'), ENV.fetch('TIMELY_CLIENT_SECRET'))
|
144
|
+
elsif ARGV.length == 2
|
145
|
+
cli.auth(ARGV.shift, ARGV.shift)
|
146
|
+
else
|
147
|
+
puts "Usage: timely-app auth CLIENT_ID CLIENT_SECRET"
|
148
|
+
exit 1
|
149
|
+
end
|
150
|
+
when "config"
|
151
|
+
if ARGV.length == 1
|
152
|
+
puts cli.get_config(ARGV.shift)
|
153
|
+
elsif ARGV.length == 2
|
154
|
+
cli.set_config(ARGV.shift, ARGV.shift)
|
155
|
+
else
|
156
|
+
puts "Usage: timely-app config [key] [value]"
|
157
|
+
exit 1
|
158
|
+
end
|
159
|
+
else
|
160
|
+
if cli.command_exists?(cmd)
|
161
|
+
response = cli.call(cmd, *ARGV)
|
162
|
+
ARGV.clear
|
163
|
+
case response
|
164
|
+
when Array
|
165
|
+
response.each do |r|
|
166
|
+
puts r.to_h
|
167
|
+
end
|
168
|
+
when TimelyApp::Record
|
169
|
+
puts response.to_h
|
170
|
+
else
|
171
|
+
puts response
|
172
|
+
end
|
173
|
+
else
|
174
|
+
puts "Unknown command: #{cmd}"
|
175
|
+
exit 1
|
176
|
+
end
|
177
|
+
end
|
data/lib/timely-app/version.rb
CHANGED
data/timely-app.gemspec
CHANGED
@@ -1,20 +1,29 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.version =
|
4
|
-
|
2
|
+
s.name = "timely-app"
|
3
|
+
s.version = "1.0.3"
|
4
|
+
|
5
|
+
s.license = "MIT"
|
6
|
+
|
5
7
|
s.platform = Gem::Platform::RUBY
|
6
|
-
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.required_ruby_version = '>= 1.9.3'
|
13
|
-
s.require_path = 'lib'
|
8
|
+
|
9
|
+
s.authors = ["Andrei Makarov"]
|
10
|
+
s.email = ["andrei@kiskolabs.com"]
|
11
|
+
s.homepage = "https://github.com/amkisko/timely-app"
|
12
|
+
s.description = "Ruby client for the Timely API"
|
13
|
+
s.summary = "See description"
|
14
14
|
s.metadata = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
"homepage" => "https://github.com/amkisko/timely-app",
|
16
|
+
"source_code_uri" => "https://github.com/amkisko/timely-app",
|
17
|
+
"bug_tracker_uri" => "https://github.com/amkisko/timely-app/issues",
|
18
|
+
"changelog_uri" => "https://github.com/amkisko/timely-app/blob/main/CHANGELOG.md",
|
19
|
+
"rubygems_mfa_required" => "true"
|
19
20
|
}
|
21
|
+
|
22
|
+
s.files = Dir.glob("lib/**/*.rb") + Dir.glob("bin/**/*") + %w(CHANGELOG.md LICENSE.md README.md timely-app.gemspec)
|
23
|
+
|
24
|
+
s.bindir = "bin"
|
25
|
+
s.executables = ["timely-app"]
|
26
|
+
|
27
|
+
s.required_ruby_version = ">= 1.9.3"
|
28
|
+
s.require_path = "lib"
|
20
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timely-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Makarov
|
@@ -13,13 +13,15 @@ dependencies: []
|
|
13
13
|
description: Ruby client for the Timely API
|
14
14
|
email:
|
15
15
|
- andrei@kiskolabs.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- timely-app
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
20
21
|
- CHANGELOG.md
|
21
22
|
- LICENSE.md
|
22
23
|
- README.md
|
24
|
+
- bin/timely-app
|
23
25
|
- lib/timely-app.rb
|
24
26
|
- lib/timely-app/client.rb
|
25
27
|
- lib/timely-app/client/accounts.rb
|
@@ -50,7 +52,8 @@ metadata:
|
|
50
52
|
homepage: https://github.com/amkisko/timely-app
|
51
53
|
source_code_uri: https://github.com/amkisko/timely-app
|
52
54
|
bug_tracker_uri: https://github.com/amkisko/timely-app/issues
|
53
|
-
changelog_uri: https://github.com/amkisko/timely-app/blob/main/
|
55
|
+
changelog_uri: https://github.com/amkisko/timely-app/blob/main/CHANGELOG.md
|
56
|
+
rubygems_mfa_required: 'true'
|
54
57
|
post_install_message:
|
55
58
|
rdoc_options: []
|
56
59
|
require_paths:
|