firespring_dev_commands 2.1.14 → 2.1.15.pre.alpha.1

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
2
  SHA256:
3
- metadata.gz: ab405907618e9d8d58ff0e045ee3808e7bafdd9102ea13cb90449e01ed429e6d
4
- data.tar.gz: 9d7115d8d8860a34b5bf4aea4fca0768defcd886a3ea47031bced230b4a569f8
3
+ metadata.gz: 0ab90393842f466166db3eed2197d5682d206dd9c493cb30a82d6a7a80ab056f
4
+ data.tar.gz: 948d2a597c1ecdee4ccd4fd5c00b1d4c7eb7c6cf674eb42146ff6b0a3ff4ffe8
5
5
  SHA512:
6
- metadata.gz: 488975ad6a49e2ae5cd4a0fc6fe05884746193fd35755fa7149713d56c54ea955c733d5c0f73fdd3e50eadb120c0d40312d2272a36e70d0ee8b1e4b31392aad8
7
- data.tar.gz: 790d7efa6fd46c1e2bf894531a6a5a5780c4a78aa8354a6538f424a6e016aeabf665e935c0a847f71e60b8c06b5cd1df5d89f21dbecda969f0374e6382c3d712
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 jira config options
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)
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.14'.freeze
9
+ VERSION = '2.1.15.pre.alpha.1'.freeze
10
10
  end
11
11
  end
@@ -11,7 +11,7 @@ DEV_COMMANDS_TOP_LEVEL = self
11
11
 
12
12
  # Load all gems referenced in the Gemfile
13
13
  require 'bundler'
14
- Bundler.require
14
+ Bundler.require(:default)
15
15
 
16
16
  # Add libdir to the default ruby path
17
17
  libdir = File.realpath(File.dirname(__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.14
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-21 00:00:00.000000000 Z
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
@@ -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: '0'
407
+ version: 1.3.1
405
408
  requirements: []
406
409
  rubygems_version: 3.4.10
407
410
  signing_key: