diff --git a/.env b/.env deleted file mode 100644 index 2197004..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -DATABOX_MODE="development" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..5017ca3 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,35 @@ +name-template: '$RESOLVED_VERSION' +tag-template: '$RESOLVED_VERSION' +categories: + - title: 'Features' + labels: + - 'feature' + - 'enhancement' + - title: 'Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: 'Maintenance' + label: 'chore' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +template: | + ## Changes + + $CHANGES + + **Contributors**: $CONTRIBUTORS + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION diff --git a/.github/sdk-gen-config.json b/.github/sdk-gen-config.json new file mode 100644 index 0000000..385e4fc --- /dev/null +++ b/.github/sdk-gen-config.json @@ -0,0 +1,7 @@ +{ + "gemName": "databox", + "gemVersion": "{VERSION}", + "gemAuthor": "Databox", + "gemDescription": "SDK Client for using Databox Push API feature", + "gemHomepage": "https://databox.com/" +} \ No newline at end of file diff --git a/.github/workflows/generate_sdk_code.yml b/.github/workflows/generate_sdk_code.yml new file mode 100644 index 0000000..e336fb1 --- /dev/null +++ b/.github/workflows/generate_sdk_code.yml @@ -0,0 +1,94 @@ +name: Generate SDK Code +on: + repository_dispatch: + types: [publish_sdk] +env: + GENERATOR_VERISON: "7.6.0" + CONFIG_FILE: "sdk-gen-config.json" +jobs: + sdk: + name: Generate SDK code + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get Latest Release + id: latest-version + uses: pozetroninc/github-action-get-latest-release@v0.7.0 + with: + owner: ${{ github.repository_owner }} + repo: databox-ruby + excludes: prerelease, draft + token: ${{ secrets.PAT_APPROVE_PR }} + + - name: Determine Version + id: version + uses: actions/github-script@v7 + with: + script: | + const version = '${{ steps.latest-version.outputs.release }}'; + const parts = version.split('.'); + switch('${{ github.event.client_payload.labels }}') { + case 'patch': + parts[2] = parseInt(parts[2]) + 1; + break; + case 'minor': + parts[1] = parseInt(parts[1]) + 1; + break; + case 'major': + parts[0] = parseInt(parts[0]) + 1; + break; + default: + parts[2] = parseInt(parts[2]) + 1; + break; + } + const newVersion = parts.join('.'); + return newVersion; + + - name: Download OpenAPI Generator + run: | + curl https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${{ env.GENERATOR_VERISON }}/openapi-generator-cli-${{ env.GENERATOR_VERISON }}.jar -o ${{ runner.temp }}/openapi-generator-cli.jar + + - name: Download OpenAPI Specification + uses: actions/download-artifact@v4 + with: + name: ${{ github.event.client_payload.openapi_spec }} + path: ${{ runner.temp }}/openapispec + repository: databox/data-link + github-token: ${{ secrets.PAT_APPROVE_PR }} + run-id: ${{ github.event.client_payload.run_id }} + + - name: Remove old SDK + run: rm -rf src/* + + - name: Set API and SDK versions + run: | + cp .github/${{ env.CONFIG_FILE }} ${{ runner.temp }}/${{ env.CONFIG_FILE }} + + #set SDK version + sed -i "s/{VERSION}/${{ steps.version.outputs.result }}/g" ${{ runner.temp }}/${{ env.CONFIG_FILE }} + + #set API version + sed -i 's/version: "1.0"/version: ${{ github.event.client_payload.version }}/g' ${{ runner.temp }}/openapispec/openapi.yml + + - name: Generate SDK + run: | + java --version + java -jar ${{ runner.temp }}/openapi-generator-cli.jar generate -i ${{ runner.temp }}/openapispec/openapi.yml -g ruby -o ./src -c ${{ runner.temp }}/${{ env.CONFIG_FILE }} --skip-validate-spec + cp ./src/README.md ./README.md + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v6 + with: + base: master + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: 'chore: release data-link SDK' + title: '[SDK release] Generated SDK code based on data-link ${{ github.event.client_payload.version }} API changes' + branch: 'release/${{ github.event.client_payload.version }}/${{ github.event.client_payload.timestamp }}' + body: > + This is a release of the SDK based on the API changes for `data-link` [${{ github.event.client_payload.version }}](${{ github.event.client_payload.release_url }}). + labels: | + automated + ${{ github.event.client_payload.labels || 'patch' }} \ No newline at end of file diff --git a/.github/workflows/publish_sdk.yml b/.github/workflows/publish_sdk.yml new file mode 100644 index 0000000..b58dcd8 --- /dev/null +++ b/.github/workflows/publish_sdk.yml @@ -0,0 +1,95 @@ +name: Publish SDK +on: + push: + branches: + - master + paths: + - 'src/**' +jobs: + release_draft: + name: Create release draft + runs-on: ubuntu-latest + outputs: + release_body: ${{ steps.create_release_draft.outputs.body }} + release_tag: ${{ steps.create_release_draft.outputs.tag_name }} + release_html_url: ${{ steps.create_release_draft.outputs.html_url }} + release_id: ${{ steps.create_release_draft.outputs.id }} + steps: + - name: "Create release draft" + id: create_release_draft + uses: release-drafter/release-drafter@v6 + with: + commitish: master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Release Gem + if: contains(github.ref, 'refs/tags/v') + uses: cadwallion/publish-rubygems-action@master + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_TOKEN}} + RELEASE_COMMAND: rake release + WORKDIR: src + + release_publish: + name: Publish release + runs-on: ubuntu-latest + needs: + - release_draft + - build + steps: + - name: "Publish release" + uses: eregon/publish-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ needs.release_draft.outputs.release_id }} + + post_slack_job: + name: Post info to Slack in #engeering-releases channel + needs: + - release_draft + - release_publish + runs-on: ubuntu-latest + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + steps: + - name: Format to Slack msg + uses: LoveToKnow/slackify-markdown-action@v1.0.0 + id: slack_msg_converter + with: + text: ${{needs.release_draft.outputs.release_body}} + - name: Post to a Slack channel + if: success() + id: slack + uses: slackapi/slack-github-action@v1.23.0 + with: + channel-id: 'C027FC31SVD' + payload: | + { + "text": "New version post", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "New <${{ github.server_url }}/${{ github.repository }}|`${{ github.repository }}`> release <${{ github.server_url }}/${{ github.repository }}/releases/${{ needs.create_release_draft_job.outputs.release_tag }}|${{ needs.create_release_draft_job.outputs.release_tag }}> is available! :tada:" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ${{toJSON(steps.slack_msg_converter.outputs.text)}} + } + } + ] + } + \ No newline at end of file diff --git a/.github/workflows/require-labels.yml b/.github/workflows/require-labels.yml new file mode 100644 index 0000000..be13e16 --- /dev/null +++ b/.github/workflows/require-labels.yml @@ -0,0 +1,16 @@ +name: Pull Request Labels + +on: + pull_request: + types: [opened, reopened, labeled, unlabeled, edited, synchronize] + branches: [master] + +jobs: + label: + runs-on: ubuntu-latest + steps: + - uses: mheap/github-action-required-labels@v5 + with: + mode: exactly + count: 1 + labels: "major,minor,patch" diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d4458e1..0000000 --- a/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -.idea/ -*.sh -!*test_*sh -*.gem -*.rbc -.bundle -.config -.yardoc -Gemfile.lock -InstalledFiles -_yardoc -coverage -doc/ -lib/bundler/man -pkg -rdoc -spec/reports -test/tmp -test/version_tmp -tmp diff --git a/.pryrc b/.pryrc deleted file mode 100644 index 04276cf..0000000 --- a/.pryrc +++ /dev/null @@ -1,7 +0,0 @@ -require 'databox' - -Databox.configure do |c| - c.push_token = ENV["DATABOX_PUSH_TOKEN"] -end - -client = Databox::Client.new \ No newline at end of file diff --git a/.rspec b/.rspec deleted file mode 100644 index f449dae..0000000 --- a/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---format doc ---color diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 0a42ccd..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -databox diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index a831048..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-2.3.0 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0e80bb5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -install: - - "travis_retry bundle install" -script: - - "bundle exec rspec --format doc --color" diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 5b56b18..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,27 +0,0 @@ -# Change Log -Following guidelines of http://keepachangelog.com/ - -## [Unreleased] - -## [2.0.1] - Sep 26, 2016 -- update README -- (bugfix) fix missing date in push payload if provided as a root key - -## [2.0.0] - Aug 30, 2016 -- update request headers -- update GET /lastpushes -- handle new response - -## [0.2.2] - Jan 24, 2016 -Databox API has changed a bit in part dedicated for retrieving last pushes. This SDK was updated accordingly. - -## [0.2.1] - Jul 22, 2015 -Support for additional attributes -Test for additional attributes support -Updated README.md example - -[Unreleased]: https://github.com/databox/databox-ruby/compare/2.0.1...master -[2.0.1]: https://github.com/databox/databox-ruby/compare/2.0.0...2.0.1 -[2.0.0]: https://github.com/databox/databox-ruby/compare/0.2.2...2.0.0 -[0.2.2]: https://github.com/databox/databox-ruby/compare/0.2.1...0.2.2 -[0.2.1]: https://github.com/databox/databox-ruby/tree/0.2.1 diff --git a/Gemfile b/Gemfile deleted file mode 100644 index c43d95f..0000000 --- a/Gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in databox.gemspec -gemspec diff --git a/Guardfile b/Guardfile deleted file mode 100644 index 6a4de5b..0000000 --- a/Guardfile +++ /dev/null @@ -1,9 +0,0 @@ -guard :rspec, all_on_start: false, all_after_pass: false, parallel: false do - watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } - watch(%r{^lib/databox/(.+)\.rb$}) { |m| "spec/databox/#{m[1]}_spec.rb" } - - watch('spec/spec_helper.rb') { "spec" } - watch('lib/databox.rb') { "spec" } - -end diff --git a/Rakefile b/Rakefile deleted file mode 100644 index e2325af..0000000 --- a/Rakefile +++ /dev/null @@ -1,10 +0,0 @@ -require "bundler/gem_tasks" - -task :console do - require 'irb' - require 'irb/completion' - require 'databox' # You know what to do. - ARGV.clear - IRB.start -end - diff --git a/databox.gemspec b/databox.gemspec deleted file mode 100644 index 0af62bb..0000000 --- a/databox.gemspec +++ /dev/null @@ -1,28 +0,0 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'databox/version' - -Gem::Specification.new do |spec| - spec.name = 'databox' - spec.version = Databox::VERSION - spec.authors = ['Oto Brglez'] - spec.email = ['otobrglez@gmail.com'] - spec.description = %q{Ruby Gem for Databox - Mobile Executive Dashboard.} - spec.summary = %q{API wrapper for Databox} - spec.homepage = 'https://github.com/databox/databox-ruby' - spec.license = 'MIT' - - spec.files = `git ls-files`.split($/) - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.require_paths = ['lib'] - - spec.add_dependency 'httparty' - - spec.add_development_dependency "bundler", "~> 1.3" - spec.add_development_dependency "rake" - spec.add_development_dependency "rspec" - spec.add_development_dependency "shoulda-matchers" - spec.add_development_dependency "pry" -end diff --git a/example.rb b/example.rb deleted file mode 100755 index ce32b2e..0000000 --- a/example.rb +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env ruby -require 'pp' -require 'bundler/setup' -require 'databox' - -Databox.configure do |c| - c.push_token = ENV["DATABOX_PUSH_TOKEN"] -end - -client = Databox::Client.new() - -3.times do |t| - client.push(key: "example.ruby", value: t*100, date:(DateTime.now - t).strftime('%Y-%m-%d')) -end - -client.push(key: "example.ruby.unit", value: 100, unit: "USD") - -pp client.last_push(3) diff --git a/lib/databox.rb b/lib/databox.rb deleted file mode 100644 index d9f355a..0000000 --- a/lib/databox.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Databox - autoload :VERSION, 'databox/version' - autoload :Client, 'databox/client' - autoload :Configuration, 'databox/configuration' - - class << self - attr_accessor :configuration - - def configured? - return false if configuration.nil? - [ - configuration.push_host, - configuration.push_token - ].compact.size == 2 - end - - def client - @client ||= ::Client.new - end - end - - def self.configure - self.configuration ||= Configuration.new - yield configuration if block_given? - end -end diff --git a/lib/databox/client.rb b/lib/databox/client.rb deleted file mode 100644 index cb4fabc..0000000 --- a/lib/databox/client.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'httparty' -require 'json' - -class Databox::Client - include HTTParty - format :json - headers 'User-Agent' => "databox-ruby/#{Databox::VERSION}" - headers 'Accept' => "application/vnd.databox.v#{Databox::VERSION.split('.')[0]}+json" - debug_output if [1, "1"].include?(ENV["HTTPARTY_DEBUG"]) - default_timeout 1 if ENV["DATABOX_MODE"] == "test" - - attr_accessor :last_push_content - - def initialize - Databox.configure unless Databox.configured? - - self.class.base_uri push_host - self.class.basic_auth push_token, '' - self.class.headers 'Content-Type' => 'application/json' - self - end - - def push_host - Databox.configuration.push_host - end - - def push_token - Databox.configuration.push_token - end - - # Sends data to actual end-point. - def raw_push(path='/', data=nil) - handle self.class.post(path, data.nil? ? {} : {body: JSON.dump({data: data})}) - end - - def handle(response) - response.parsed_response - end - - def process_kpi(options={}) - - %i{key value}.each do |k| - raise("Missing '#{k}'") if (options[k] || options[k.to_s]).nil? - end - - options["$#{(options['key'] || options[:key])}"] = options['value'] || options[:value] - options.delete_if { |k, _| [:key, 'key', :value, 'value'].include?(k) } - - attributes = options[:attributes] || options['attributes'] - unless attributes.nil? - [:attributes, 'attributes'].each {|k| options.delete(k) } - attributes.each { |k,v| options[k] = v } - end - - options - end - - def push(kpi={}) - self.last_push_content = raw_push('/', [process_kpi(kpi)]) - self.last_push_content.key?('id') - end - - def insert_all(rows=[]) - self.last_push_content = raw_push('/', rows.map {|r| process_kpi(r) }) - self.last_push_content.key?('id') - end - - def last_push(n=1) - handle self.class.get("/lastpushes?limit=#{n}") - end -end diff --git a/lib/databox/configuration.rb b/lib/databox/configuration.rb deleted file mode 100644 index f6f46eb..0000000 --- a/lib/databox/configuration.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Databox::Configuration - attr_accessor :push_token, :push_host - - def initialize - @push_host ||= 'https://push.databox.com' - @push_token ||= ENV['DATABOX_PUSH_TOKEN'] - end -end diff --git a/lib/databox/version.rb b/lib/databox/version.rb deleted file mode 100644 index c9c2b86..0000000 --- a/lib/databox/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module Databox - VERSION = '2.0.1' -end diff --git a/spec/databox/client_spec.rb b/spec/databox/client_spec.rb deleted file mode 100644 index 1c5f60c..0000000 --- a/spec/databox/client_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' -require 'pp' - -describe Databox::Client do - before do - Databox.configure do |c| - c.push_token = 'adxg1kq5a4g04k0wk0s4wkssow8osw84' - end - - allow_any_instance_of(Databox::Client).to receive(:raw_push)\ - .and_return({'id' => '147251'}) - end - - let!(:client) { Databox::Client.new } - - context 'push' do - it { expect { client.push(nil) }.to raise_exception } - it { expect { client.push(key: 'sales.total', value: nil) }.to raise_exception } - it { expect { client.push(key: nil, value: 3000) }.to raise_exception } - it { expect(client.push(key: 'sales.total', value: 2000)).to eq true } - end - - # context 'push w/ attributes' do - # it { - # payload = { - # key: 'test', - # value: 200, - # attributes: { - # 'me': 'Oto' - # } - # } - # - # expect(client).to receive(:raw_push) - # .with('/', [ - # {"$test" => 200, :me => "Oto"} - # ]) - # .once.and_call_original - # expect(client.push(payload)).to eq true - # } - # end - - context 'insert_all' do - it { expect { client.insert_all([ - {key: 'temp.lj'}, - {key: 'temp.ljx', value: 60.3}, - ]) }.to raise_exception } - - it { expect(client.insert_all([ - {key: 'temp.ljx', value: 4.3}, - {key: 'temp.ljx', value: 1.3, date: '2015-01-01 09:00:00'}, - ])).to eq true } - end -end diff --git a/spec/databox_spec.rb b/spec/databox_spec.rb deleted file mode 100644 index 017e747..0000000 --- a/spec/databox_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe Databox do - - context "VERSION" do - it { expect(Databox::VERSION).to match /^\d+.\d+.\d+/ } - end - - context "DATABOX_MODE" do - it { expect(ENV["DATABOX_MODE"]).to eq "test" } - end - - context 'configuration' do - before do - Databox.configure do |c| - c.push_token = '' - end - end - - it { expect(Databox.configuration.push_host).to match /push/ } - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index dce0ce7..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'bundler/setup' -require 'databox' - -ENV["DATABOX_MODE"] = "test" - -RSpec.configure do |config| - config.fail_fast = ENV['RSPEC_FAIL_FAST'] == "1" - config.mock_framework = :rspec - config.run_all_when_everything_filtered = true - - config.expect_with :rspec do |c| - c.syntax = :expect - end -end -