Skip to content

Commit e6f9480

Browse files
Initial commit
0 parents  commit e6f9480

25 files changed

+622
-0
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @betterup/developer-experience

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Please see the documentation for all configuration options:
2+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
3+
4+
version: 2
5+
updates:
6+
- package-ecosystem: "bundler"
7+
directory: "/" # Location of package manifests
8+
schedule:
9+
interval: "weekly"

.github/workflows/main.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Ruby
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
name: Ruby ${{ matrix.ruby }}
14+
strategy:
15+
matrix:
16+
ruby:
17+
- '3.3.4'
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Set up Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby }}
25+
bundler-cache: true
26+
- name: Run the default task
27+
run: bundle exec rake

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/
9+
.DS_Store
10+
11+
# rspec failure tracking
12+
.rspec_status

.rspec

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--format documentation
2+
--color
3+
--require spec_helper

.rubocop.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AllCops:
2+
TargetRubyVersion: 3.0
3+
4+
Style/Documentation:
5+
Enabled: false
6+
7+
Metrics/BlockLength:
8+
Enabled: false

.simplecov

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require 'simplecov'
4+
5+
SimpleCov.start 'rails' do
6+
add_filter %w[version.rb initializer.rb]
7+
end

Gemfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
# Specify your gem's dependencies in cortex.gemspec
6+
gemspec
7+
8+
group :test, :development do
9+
gem 'rake', '~> 13.0'
10+
gem 'rspec', '~> 3.0'
11+
gem 'rubocop', '~> 1.21'
12+
end
13+
14+
group :development do
15+
gem 'yard', '~> 0.9', require: false
16+
end
17+
18+
group :test do
19+
gem 'simplecov', '~> 0.22', require: false
20+
gem 'vcr', '~> 6.3', require: false
21+
gem 'webmock', '~> 3.23', require: false
22+
end

Gemfile.lock

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
PATH
2+
remote: .
3+
specs:
4+
cortex_app (0.1.0)
5+
httparty (~> 0.22)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
addressable (2.8.7)
11+
public_suffix (>= 2.0.2, < 7.0)
12+
ast (2.4.2)
13+
base64 (0.2.0)
14+
bigdecimal (3.1.8)
15+
crack (1.0.0)
16+
bigdecimal
17+
rexml
18+
csv (3.3.0)
19+
diff-lcs (1.5.1)
20+
docile (1.4.1)
21+
hashdiff (1.1.1)
22+
httparty (0.22.0)
23+
csv
24+
mini_mime (>= 1.0.0)
25+
multi_xml (>= 0.5.2)
26+
json (2.7.2)
27+
language_server-protocol (3.17.0.3)
28+
mini_mime (1.1.5)
29+
multi_xml (0.7.1)
30+
bigdecimal (~> 3.1)
31+
parallel (1.26.3)
32+
parser (3.3.5.0)
33+
ast (~> 2.4.1)
34+
racc
35+
public_suffix (6.0.1)
36+
racc (1.8.1)
37+
rainbow (3.1.1)
38+
rake (13.2.1)
39+
regexp_parser (2.9.2)
40+
rexml (3.3.7)
41+
rspec (3.13.0)
42+
rspec-core (~> 3.13.0)
43+
rspec-expectations (~> 3.13.0)
44+
rspec-mocks (~> 3.13.0)
45+
rspec-core (3.13.1)
46+
rspec-support (~> 3.13.0)
47+
rspec-expectations (3.13.3)
48+
diff-lcs (>= 1.2.0, < 2.0)
49+
rspec-support (~> 3.13.0)
50+
rspec-mocks (3.13.1)
51+
diff-lcs (>= 1.2.0, < 2.0)
52+
rspec-support (~> 3.13.0)
53+
rspec-support (3.13.1)
54+
rubocop (1.66.1)
55+
json (~> 2.3)
56+
language_server-protocol (>= 3.17.0)
57+
parallel (~> 1.10)
58+
parser (>= 3.3.0.2)
59+
rainbow (>= 2.2.2, < 4.0)
60+
regexp_parser (>= 2.4, < 3.0)
61+
rubocop-ast (>= 1.32.2, < 2.0)
62+
ruby-progressbar (~> 1.7)
63+
unicode-display_width (>= 2.4.0, < 3.0)
64+
rubocop-ast (1.32.3)
65+
parser (>= 3.3.1.0)
66+
ruby-progressbar (1.13.0)
67+
simplecov (0.22.0)
68+
docile (~> 1.1)
69+
simplecov-html (~> 0.11)
70+
simplecov_json_formatter (~> 0.1)
71+
simplecov-html (0.13.1)
72+
simplecov_json_formatter (0.1.4)
73+
unicode-display_width (2.6.0)
74+
vcr (6.3.1)
75+
base64
76+
webmock (3.23.1)
77+
addressable (>= 2.8.0)
78+
crack (>= 0.3.2)
79+
hashdiff (>= 0.4.0, < 2.0.0)
80+
yard (0.9.37)
81+
82+
PLATFORMS
83+
arm64-darwin-23
84+
ruby
85+
86+
DEPENDENCIES
87+
cortex_app!
88+
rake (~> 13.0)
89+
rspec (~> 3.0)
90+
rubocop (~> 1.21)
91+
simplecov (~> 0.22)
92+
vcr (~> 6.3)
93+
webmock (~> 3.23)
94+
yard (~> 0.9)
95+
96+
BUNDLED WITH
97+
2.5.17

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Bryan Hickerson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Cortex App API Integration
2+
3+
[Cortex](https://www.cortex.io/) is a platform for cataloging and tracking software platforms.
4+
5+
This gem adds a Ruby integration for Cortex's API.
6+
7+
## Installation
8+
9+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10+
11+
Install the gem and add to the application's Gemfile by executing:
12+
13+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14+
15+
If bundler is not being used to manage dependencies, install the gem by executing:
16+
17+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18+
19+
## Usage
20+
21+
TODO: Write usage instructions here
22+
23+
## Development
24+
25+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26+
27+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28+
29+
## Contributing
30+
31+
Bug reports and pull requests are welcome on GitHub at https://github.com/betterup/cortex_app.
32+
33+
## License
34+
35+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
5+
6+
RSpec::Core::RakeTask.new(:spec)
7+
8+
require 'rubocop/rake_task'
9+
10+
RuboCop::RakeTask.new
11+
12+
task default: %i[spec rubocop]

bin/console

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'bundler/setup'
5+
require 'cortex_app'
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require 'irb'
11+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

cortex_app.gemspec

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'lib/cortex_app/version'
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = 'cortex_app'
7+
spec.version = CortexApp::VERSION
8+
spec.authors = ['BetterUp Developers']
9+
10+
spec.summary = 'Ruby client for Cortex API'
11+
spec.license = 'MIT'
12+
spec.required_ruby_version = '>= 3.0.0'
13+
14+
# Specify which files should be added to the gem when it is released.
15+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16+
gemspec = File.basename(__FILE__)
17+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
18+
ls.readlines("\x0", chomp: true).reject do |f|
19+
(f == gemspec) ||
20+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
21+
end
22+
end
23+
spec.bindir = 'exe'
24+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25+
spec.require_paths = ['lib']
26+
27+
spec.add_dependency 'httparty', '~> 0.22'
28+
29+
# For more information and examples about making a new gem, check out our
30+
# guide at: https://bundler.io/guides/creating_gem.html
31+
end

lib/cortex_app.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
require_relative 'cortex_app/version'
4+
require_relative 'cortex_app/api'
5+
require_relative 'cortex_app/custom_data'
6+
7+
module CortexApp
8+
end

lib/cortex_app/api.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require 'httparty'
4+
5+
module CortexApp
6+
# Base class for Cortex API classes
7+
class Api
8+
API_URL = 'https://api.getcortexapp.com/api/v1'
9+
10+
# @param bearer_token [String] the bearer token to authenticate with Cortex
11+
def initialize(bearer_token:) = @bearer_token = bearer_token
12+
13+
private
14+
15+
def http_post(path:, data:)
16+
HTTParty.post("#{API_URL}/#{path}", headers: headers, body: data.to_json)
17+
end
18+
19+
def http_put(path:, data:)
20+
HTTParty.put("#{API_URL}/#{path}", headers: headers, body: data.to_json)
21+
end
22+
23+
def headers
24+
@headers ||= { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@bearer_token}" }
25+
end
26+
end
27+
end

lib/cortex_app/custom_data.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module CortexApp
4+
# API client to interact with Cortex {https://docs.cortex.io/docs/reference/basics/custom-data custom data}
5+
class CustomData < Api
6+
# POSTs custom data to Cortex for a specific entity
7+
#
8+
# @param entity_tag [String] the entity tag in Cortex
9+
# @param data [Hash] the custom data to POST
10+
def post(entity_tag:, data:)
11+
http_post(path: post_path(entity_tag), data: data)
12+
end
13+
14+
# Bulk PUTs custom data to Cortex for multiple entities
15+
#
16+
# @param data [Hash] the custom data to PUT
17+
def put_bulk(data:)
18+
http_put(path: 'catalog/custom-data', data: data)
19+
end
20+
21+
private
22+
23+
def post_path(entity_tag)
24+
"catalog/#{entity_tag}/custom-data"
25+
end
26+
end
27+
end

lib/cortex_app/version.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
module CortexApp
4+
VERSION = '0.1.0'
5+
end

sig/cortex_app.rbs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CortexApp
2+
VERSION: String
3+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
4+
end

0 commit comments

Comments
 (0)