firespring_dev_commands 2.1.14 → 2.1.15.pre.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/firespring_dev_commands/bloom_growth/rock.rb +40 -0
- data/lib/firespring_dev_commands/bloom_growth/user.rb +15 -0
- data/lib/firespring_dev_commands/bloom_growth.rb +150 -0
- data/lib/firespring_dev_commands/target_process.rb +1 -1
- data/lib/firespring_dev_commands/version.rb +1 -1
- data/lib/firespring_dev_commands.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e1efc782df39d178d2de0412f8fd65927b7e1f1b64ecfafa622e613976701e7
|
4
|
+
data.tar.gz: '091547f390ce8ca3174c2f7dc94bea7aaf5bac290aa98e276477ba0d05bac3b8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a04dbb7d2bd7bf1e83a8453bc0fa9b4b0022d01915c6c3c9e6dbffda213eb3b6cad05ae533e6b32c5f1cd6c32b54e37fb5408b27281d28310906cb4e576d392f
|
7
|
+
data.tar.gz: f8e472631337d4a366542842e3e87cb5493bbd11fb68cfe4ad30d6f7fa4f8dcb3c5e64a8c5dbda0463dd662e475391ba3de10374772a63701bf4e58ae4089c51
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Dev
|
2
|
+
class BloomGrowth
|
3
|
+
# Class containing rock information
|
4
|
+
class Rock
|
5
|
+
attr_accessor :data, :id, :type, :name, :owner, :complete, :state, :created, :due
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@data = data
|
9
|
+
@id = data['Id']
|
10
|
+
@type = data['Type']
|
11
|
+
@name = data['Name'].to_s.strip
|
12
|
+
@owner = User.new(data['Owner']) if data['Owner']
|
13
|
+
@complete = data['Complete']
|
14
|
+
@state = completion_to_state(data['Completion'])
|
15
|
+
@created = Time.parse(data['CreateTime']) if data['CreateTime']
|
16
|
+
@due = Time.parse(data['DueDate']) if data['DueDate']
|
17
|
+
@archived = data['Archived']
|
18
|
+
end
|
19
|
+
|
20
|
+
def completion_to_state(completion_id)
|
21
|
+
case completion_id
|
22
|
+
when 0
|
23
|
+
'Off Track'
|
24
|
+
when 1
|
25
|
+
'On Track'
|
26
|
+
when 2
|
27
|
+
'Complete'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def colorized_state
|
32
|
+
return unless state
|
33
|
+
return state.light_red if state.downcase.include?('off track')
|
34
|
+
return state.light_green if state.downcase.include?('complete')
|
35
|
+
|
36
|
+
state.light_white
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Dev
|
2
|
+
class BloomGrowth
|
3
|
+
# Class containing user information
|
4
|
+
class User
|
5
|
+
attr_accessor :data, :id, :type, :name
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@data = data
|
9
|
+
@id = data['Id']
|
10
|
+
@type = data['Type']
|
11
|
+
@name = data['Name'].to_s.strip
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Dev
|
4
|
+
class BloomGrowth
|
5
|
+
# The config file to try to load credentials from
|
6
|
+
CONFIG_FILE = "#{Dir.home}/.env.bloom".freeze
|
7
|
+
|
8
|
+
# The text of the username variable key
|
9
|
+
BLOOM_USERNAME = 'BLOOM_USERNAME'.freeze
|
10
|
+
|
11
|
+
# The text of the password variable key
|
12
|
+
BLOOM_PASSWORD = 'BLOOM_PASSWORD'.freeze
|
13
|
+
|
14
|
+
BLOOM_TOKEN = 'BLOOM_TOKEN'.freeze
|
15
|
+
|
16
|
+
# The text of the url variable key
|
17
|
+
BLOOM_URL = 'BLOOM_URL'.freeze
|
18
|
+
|
19
|
+
# Config object for setting top level bloom growth config options
|
20
|
+
Config = Struct.new(:username, :password, :url, :http_debug) do
|
21
|
+
def initialize
|
22
|
+
Dotenv.load(CONFIG_FILE) if File.exist?(CONFIG_FILE)
|
23
|
+
|
24
|
+
self.username = ENV.fetch(BLOOM_USERNAME, nil)
|
25
|
+
self.password = ENV.fetch(BLOOM_PASSWORD, nil)
|
26
|
+
self.url = ENV.fetch(BLOOM_URL, 'https://app.bloomgrowth.com')
|
27
|
+
self.http_debug = false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
# Instantiates a new top level config object if one hasn't already been created
|
33
|
+
# Yields that config object to any given block
|
34
|
+
# Returns the resulting config object
|
35
|
+
def config
|
36
|
+
@config ||= Config.new
|
37
|
+
yield(@config) if block_given?
|
38
|
+
@config
|
39
|
+
end
|
40
|
+
|
41
|
+
# Alias the config method to configure for a slightly clearer access syntax
|
42
|
+
alias_method :configure, :config
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_accessor :username, :password, :url, :token, :client, :default_headers
|
46
|
+
|
47
|
+
# Initialize a new target process client using the given inputs
|
48
|
+
def initialize(username: self.class.config.username, password: self.class.config.password, url: self.class.config.url)
|
49
|
+
raise 'username is required' if username.to_s.strip.empty?
|
50
|
+
raise 'password is required' if password.to_s.strip.empty?
|
51
|
+
raise 'url is required' if url.to_s.strip.empty?
|
52
|
+
|
53
|
+
@username = username
|
54
|
+
@password = password
|
55
|
+
@url = url
|
56
|
+
uri = URI.parse(@url)
|
57
|
+
@client = Net::HTTP.new(uri.host, uri.port)
|
58
|
+
@client.use_ssl = true
|
59
|
+
@client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
60
|
+
@client.set_debug_output(LOG) if self.class.config.http_debug
|
61
|
+
@default_headers = {
|
62
|
+
'authorization' => "Bearer #{token}",
|
63
|
+
'content-type' => 'application/json',
|
64
|
+
'accept' => 'application/json'
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
# TODO: Should we look at https://github.com/DannyBen/lightly for caching the token?
|
69
|
+
def token
|
70
|
+
@token ||= ENV.fetch(BLOOM_TOKEN, nil)
|
71
|
+
|
72
|
+
unless @token
|
73
|
+
response = post(
|
74
|
+
'/Token',
|
75
|
+
{
|
76
|
+
grant_type: 'password',
|
77
|
+
userName: username,
|
78
|
+
password:
|
79
|
+
},
|
80
|
+
headers: {
|
81
|
+
'content-type' => 'application/json',
|
82
|
+
'accept' => 'application/json'
|
83
|
+
}
|
84
|
+
)
|
85
|
+
@token = response['access_token']
|
86
|
+
LOG.info("Retrieved BloomGrowth token. Expires on #{Time.now + response['expires_in']}")
|
87
|
+
end
|
88
|
+
|
89
|
+
@token
|
90
|
+
end
|
91
|
+
|
92
|
+
def visible_user_rocks(&)
|
93
|
+
{}.tap do |hsh|
|
94
|
+
visible_users.each do |user|
|
95
|
+
hsh[user] = user_rocks(user.id)
|
96
|
+
end
|
97
|
+
hsh.each(&)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def visible_users(&)
|
102
|
+
[].tap do |ary|
|
103
|
+
get('/api/v1/users/mineviewable') do |user_data|
|
104
|
+
ary << User.new(user_data)
|
105
|
+
end
|
106
|
+
ary.each(&)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def user_rocks(user_id, &)
|
111
|
+
[].tap do |ary|
|
112
|
+
get("/api/v1/rocks/user/#{user_id}") do |rock_data|
|
113
|
+
ary << Rock.new(rock_data)
|
114
|
+
end
|
115
|
+
ary.each(&)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def user_direct_reports(user_id, &)
|
120
|
+
[].tap do |ary|
|
121
|
+
get("/api/v1/users/#{user_id}/directreports") do |user_data|
|
122
|
+
ary << User.new(user_data)
|
123
|
+
end
|
124
|
+
ary.each(&)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Perform a get request to the given path using the given query
|
129
|
+
# Call the given block (if present) with each piece of data
|
130
|
+
# Return all pieces of data
|
131
|
+
def get(path, query_string: nil, headers: default_headers, &)
|
132
|
+
url = path
|
133
|
+
url << "?#{URI.encode_www_form(query_string)}" unless query_string.to_s.strip.empty?
|
134
|
+
|
135
|
+
response = client.request_get(url, headers)
|
136
|
+
raise "Error querying #{url} [#{query_string}]: #{response.inspect}" unless response.response.is_a?(Net::HTTPSuccess)
|
137
|
+
|
138
|
+
JSON.parse(response.body).each(&)
|
139
|
+
nil
|
140
|
+
end
|
141
|
+
|
142
|
+
def post(path, data, headers: default_headers)
|
143
|
+
data = data.to_json unless data.is_a?(String)
|
144
|
+
response = client.request_post(path, data, headers)
|
145
|
+
raise "Error querying #{url}/#{path}: #{response.inspect}" unless response.response.is_a?(Net::HTTPSuccess)
|
146
|
+
|
147
|
+
JSON.parse(response.body)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -15,7 +15,7 @@ module Dev
|
|
15
15
|
# The text of the url variable key
|
16
16
|
TP_URL = 'TP_URL'.freeze
|
17
17
|
|
18
|
-
# Config object for setting top level
|
18
|
+
# Config object for setting top level target process config options
|
19
19
|
Config = Struct.new(:username, :password, :url, :http_debug) do
|
20
20
|
def initialize
|
21
21
|
Dotenv.load(CONFIG_FILE) if File.exist?(CONFIG_FILE)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firespring_dev_commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.15.pre.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Firespring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -327,6 +327,9 @@ files:
|
|
327
327
|
- lib/firespring_dev_commands/aws/parameter.rb
|
328
328
|
- lib/firespring_dev_commands/aws/profile.rb
|
329
329
|
- lib/firespring_dev_commands/aws/s3.rb
|
330
|
+
- lib/firespring_dev_commands/bloom_growth.rb
|
331
|
+
- lib/firespring_dev_commands/bloom_growth/rock.rb
|
332
|
+
- lib/firespring_dev_commands/bloom_growth/user.rb
|
330
333
|
- lib/firespring_dev_commands/boolean.rb
|
331
334
|
- lib/firespring_dev_commands/common.rb
|
332
335
|
- lib/firespring_dev_commands/daterange.rb
|
@@ -399,9 +402,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
399
402
|
version: '3.1'
|
400
403
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
401
404
|
requirements:
|
402
|
-
- - "
|
405
|
+
- - ">"
|
403
406
|
- !ruby/object:Gem::Version
|
404
|
-
version:
|
407
|
+
version: 1.3.1
|
405
408
|
requirements: []
|
406
409
|
rubygems_version: 3.4.10
|
407
410
|
signing_key:
|