firespring_dev_commands 2.1.14.pre.alpha.3 → 2.1.15.pre.alpha.1
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 +141 -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 +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ab90393842f466166db3eed2197d5682d206dd9c493cb30a82d6a7a80ab056f
|
4
|
+
data.tar.gz: 948d2a597c1ecdee4ccd4fd5c00b1d4c7eb7c6cf674eb42146ff6b0a3ff4ffe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c551b5ce4522f8d1d6e42ab9496f20782be9012b2bd332993215444584a22da8ad4c88eb74ace2a2b936b1f16c9a12dffb27c3ba6acff9f337496bfc3710d58
|
7
|
+
data.tar.gz: e267f88702182c29c21c66428d4dd472c19bef1120ad36fe55c08574193affaf79baedb65cea94ac06721e7b6626f5684fd28342c1433e50caa0d55c4d15aaa3
|
@@ -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'])
|
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,141 @@
|
|
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
|
+
# Perform a get request to the given path using the given query
|
120
|
+
# Call the given block (if present) with each piece of data
|
121
|
+
# Return all pieces of data
|
122
|
+
def get(path, query_string: nil, headers: default_headers, &)
|
123
|
+
url = path
|
124
|
+
url << "?#{URI.encode_www_form(query_string)}" unless query_string.to_s.strip.empty?
|
125
|
+
|
126
|
+
response = client.request_get(url, headers)
|
127
|
+
raise "Error querying #{url} [#{query_string}]: #{response.inspect}" unless response.response.is_a?(Net::HTTPSuccess)
|
128
|
+
|
129
|
+
JSON.parse(response.body).each(&)
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
|
133
|
+
def post(path, data, headers: default_headers)
|
134
|
+
data = data.to_json unless data.is_a?(String)
|
135
|
+
response = client.request_post(path, data, headers)
|
136
|
+
raise "Error querying #{url}/#{path}: #{response.inspect}" unless response.response.is_a?(Net::HTTPSuccess)
|
137
|
+
|
138
|
+
JSON.parse(response.body)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
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.1
|
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-28 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
|