Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanhickerson committed Sep 24, 2024
0 parents commit e6f9480
Show file tree
Hide file tree
Showing 25 changed files with 622 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @betterup/developer-experience
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "bundler"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruby

on:
push:
branches:
- main

pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.3.4'

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
.DS_Store

# rspec failure tracking
.rspec_status
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AllCops:
TargetRubyVersion: 3.0

Style/Documentation:
Enabled: false

Metrics/BlockLength:
Enabled: false
7 changes: 7 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

require 'simplecov'

SimpleCov.start 'rails' do
add_filter %w[version.rb initializer.rb]
end
22 changes: 22 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in cortex.gemspec
gemspec

group :test, :development do
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 1.21'
end

group :development do
gem 'yard', '~> 0.9', require: false
end

group :test do
gem 'simplecov', '~> 0.22', require: false
gem 'vcr', '~> 6.3', require: false
gem 'webmock', '~> 3.23', require: false
end
97 changes: 97 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
PATH
remote: .
specs:
cortex_app (0.1.0)
httparty (~> 0.22)

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
crack (1.0.0)
bigdecimal
rexml
csv (3.3.0)
diff-lcs (1.5.1)
docile (1.4.1)
hashdiff (1.1.1)
httparty (0.22.0)
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
mini_mime (1.1.5)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
public_suffix (6.0.1)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.3.7)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
unicode-display_width (2.6.0)
vcr (6.3.1)
base64
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
yard (0.9.37)

PLATFORMS
arm64-darwin-23
ruby

DEPENDENCIES
cortex_app!
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.21)
simplecov (~> 0.22)
vcr (~> 6.3)
webmock (~> 3.23)
yard (~> 0.9)

BUNDLED WITH
2.5.17
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024 Bryan Hickerson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Cortex App API Integration

[Cortex](https://www.cortex.io/) is a platform for cataloging and tracking software platforms.

This gem adds a Ruby integration for Cortex's API.

## Installation

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.

Install the gem and add to the application's Gemfile by executing:

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG

## Usage

TODO: Write usage instructions here

## Development

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.

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).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/betterup/cortex_app.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

require 'rubocop/rake_task'

RuboCop::RakeTask.new

task default: %i[spec rubocop]
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'cortex_app'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
31 changes: 31 additions & 0 deletions cortex_app.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative 'lib/cortex_app/version'

Gem::Specification.new do |spec|
spec.name = 'cortex_app'
spec.version = CortexApp::VERSION
spec.authors = ['BetterUp Developers']

spec.summary = 'Ruby client for Cortex API'
spec.license = 'MIT'
spec.required_ruby_version = '>= 3.0.0'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
gemspec = File.basename(__FILE__)
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
ls.readlines("\x0", chomp: true).reject do |f|
(f == gemspec) ||
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
end
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'httparty', '~> 0.22'

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
end
8 changes: 8 additions & 0 deletions lib/cortex_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require_relative 'cortex_app/version'
require_relative 'cortex_app/api'
require_relative 'cortex_app/custom_data'

module CortexApp
end
27 changes: 27 additions & 0 deletions lib/cortex_app/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'httparty'

module CortexApp
# Base class for Cortex API classes
class Api
API_URL = 'https://api.getcortexapp.com/api/v1'

# @param bearer_token [String] the bearer token to authenticate with Cortex
def initialize(bearer_token:) = @bearer_token = bearer_token

private

def http_post(path:, data:)
HTTParty.post("#{API_URL}/#{path}", headers: headers, body: data.to_json)
end

def http_put(path:, data:)
HTTParty.put("#{API_URL}/#{path}", headers: headers, body: data.to_json)
end

def headers
@headers ||= { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@bearer_token}" }
end
end
end
27 changes: 27 additions & 0 deletions lib/cortex_app/custom_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module CortexApp
# API client to interact with Cortex {https://docs.cortex.io/docs/reference/basics/custom-data custom data}
class CustomData < Api
# POSTs custom data to Cortex for a specific entity
#
# @param entity_tag [String] the entity tag in Cortex
# @param data [Hash] the custom data to POST
def post(entity_tag:, data:)
http_post(path: post_path(entity_tag), data: data)
end

# Bulk PUTs custom data to Cortex for multiple entities
#
# @param data [Hash] the custom data to PUT
def put_bulk(data:)
http_put(path: 'catalog/custom-data', data: data)
end

private

def post_path(entity_tag)
"catalog/#{entity_tag}/custom-data"
end
end
end
5 changes: 5 additions & 0 deletions lib/cortex_app/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module CortexApp
VERSION = '0.1.0'
end
4 changes: 4 additions & 0 deletions sig/cortex_app.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CortexApp
VERSION: String
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
end
Loading

0 comments on commit e6f9480

Please sign in to comment.