├── src ├── .openapi-generator │ ├── VERSION │ └── FILES ├── .rspec ├── Gemfile ├── Rakefile ├── .travis.yml ├── docs │ ├── State.md │ ├── ApiResponse.md │ ├── PushDataAttribute.md │ ├── PushData.md │ └── DefaultApi.md ├── lib │ ├── databox │ │ ├── version.rb │ │ ├── models │ │ │ ├── state.rb │ │ │ ├── push_data_attribute.rb │ │ │ ├── api_response.rb │ │ │ └── push_data.rb │ │ ├── api_error.rb │ │ ├── configuration.rb │ │ ├── api │ │ │ └── default_api.rb │ │ └── api_client.rb │ └── databox.rb ├── .gitlab-ci.yml ├── .gitignore ├── spec │ ├── models │ │ ├── state_spec.rb │ │ ├── api_response_spec.rb │ │ ├── push_data_attribute_spec.rb │ │ └── push_data_spec.rb │ ├── api │ │ └── default_api_spec.rb │ └── spec_helper.rb ├── .openapi-generator-ignore ├── databox.gemspec ├── git_push.sh ├── README.md └── .rubocop.yml ├── .github ├── sdk-gen-config.json ├── workflows │ ├── require-labels.yml │ ├── publish_sdk.yml │ └── generate_sdk_code.yml └── release-drafter.yml ├── LICENSE.txt └── README.md /src/.openapi-generator/VERSION: -------------------------------------------------------------------------------- 1 | 7.6.0 2 | -------------------------------------------------------------------------------- /src/.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --require spec_helper 3 | -------------------------------------------------------------------------------- /src/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :development, :test do 6 | gem 'rake', '~> 13.0.1' 7 | gem 'pry-byebug' 8 | gem 'rubocop', '~> 0.66.0' 9 | end 10 | -------------------------------------------------------------------------------- /src/Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | begin 4 | require 'rspec/core/rake_task' 5 | 6 | RSpec::Core::RakeTask.new(:spec) 7 | task default: :spec 8 | rescue LoadError 9 | # no rspec available 10 | end 11 | -------------------------------------------------------------------------------- /.github/sdk-gen-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "gemName": "databox", 3 | "gemVersion": "{VERSION}", 4 | "gemAuthor": "Databox", 5 | "gemDescription": "SDK Client for using Databox Push API feature", 6 | "gemHomepage": "https://databox.com/" 7 | } -------------------------------------------------------------------------------- /src/.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: bundler 3 | rvm: 4 | - 2.7 5 | - 3.0 6 | - 3.1 7 | script: 8 | - bundle install --path vendor/bundle 9 | - bundle exec rspec 10 | - gem build databox.gemspec 11 | - gem install ./databox-2.1.1.gem 12 | -------------------------------------------------------------------------------- /src/docs/State.md: -------------------------------------------------------------------------------- 1 | # Databox::State 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | 8 | ## Example 9 | 10 | ```ruby 11 | require 'databox' 12 | 13 | instance = Databox::State.new() 14 | ``` 15 | 16 | -------------------------------------------------------------------------------- /src/lib/databox/version.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | module Databox 14 | VERSION = '2.1.1' 15 | end 16 | -------------------------------------------------------------------------------- /src/docs/ApiResponse.md: -------------------------------------------------------------------------------- 1 | # Databox::ApiResponse 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **status** | **String** | | [optional] | 8 | | **message** | **String** | | [optional] | 9 | 10 | ## Example 11 | 12 | ```ruby 13 | require 'databox' 14 | 15 | instance = Databox::ApiResponse.new( 16 | status: null, 17 | message: null 18 | ) 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /src/docs/PushDataAttribute.md: -------------------------------------------------------------------------------- 1 | # Databox::PushDataAttribute 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **key** | **String** | | [optional] | 8 | | **value** | **String** | | [optional] | 9 | 10 | ## Example 11 | 12 | ```ruby 13 | require 'databox' 14 | 15 | instance = Databox::PushDataAttribute.new( 16 | key: null, 17 | value: null 18 | ) 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /.github/workflows/require-labels.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request Labels 2 | 3 | on: 4 | pull_request: 5 | types: [opened, reopened, labeled, unlabeled, edited, synchronize] 6 | branches: [master] 7 | 8 | jobs: 9 | label: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: mheap/github-action-required-labels@v5 13 | with: 14 | mode: exactly 15 | count: 1 16 | labels: "major,minor,patch" 17 | -------------------------------------------------------------------------------- /src/.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | .ruby: &ruby 2 | variables: 3 | LANG: "C.UTF-8" 4 | before_script: 5 | - ruby -v 6 | - bundle config set --local deployment true 7 | - bundle install -j $(nproc) 8 | parallel: 9 | matrix: 10 | - RUBY_VERSION: ['2.7', '3.0', '3.1'] 11 | image: "ruby:$RUBY_VERSION" 12 | cache: 13 | paths: 14 | - vendor/ruby 15 | key: 'ruby-$RUBY_VERSION' 16 | 17 | gem: 18 | extends: .ruby 19 | script: 20 | - bundle exec rspec 21 | - bundle exec rake build 22 | - bundle exec rake install 23 | artifacts: 24 | paths: 25 | - pkg/*.gem 26 | 27 | -------------------------------------------------------------------------------- /src/docs/PushData.md: -------------------------------------------------------------------------------- 1 | # Databox::PushData 2 | 3 | ## Properties 4 | 5 | | Name | Type | Description | Notes | 6 | | ---- | ---- | ----------- | ----- | 7 | | **attributes** | [**Array<PushDataAttribute>**](PushDataAttribute.md) | | [optional] | 8 | | **date** | **String** | | [optional] | 9 | | **key** | **String** | | [optional] | 10 | | **period_from** | **String** | | [optional] | 11 | | **period_to** | **String** | | [optional] | 12 | | **unit** | **String** | | [optional] | 13 | | **value** | **Float** | | [optional] | 14 | 15 | ## Example 16 | 17 | ```ruby 18 | require 'databox' 19 | 20 | instance = Databox::PushData.new( 21 | attributes: null, 22 | date: null, 23 | key: null, 24 | period_from: null, 25 | period_to: null, 26 | unit: null, 27 | value: null 28 | ) 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /src/.openapi-generator/FILES: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .gitlab-ci.yml 3 | .rspec 4 | .rubocop.yml 5 | .travis.yml 6 | Gemfile 7 | README.md 8 | Rakefile 9 | databox.gemspec 10 | docs/ApiResponse.md 11 | docs/DefaultApi.md 12 | docs/PushData.md 13 | docs/PushDataAttribute.md 14 | docs/State.md 15 | git_push.sh 16 | lib/databox.rb 17 | lib/databox/api/default_api.rb 18 | lib/databox/api_client.rb 19 | lib/databox/api_error.rb 20 | lib/databox/configuration.rb 21 | lib/databox/models/api_response.rb 22 | lib/databox/models/push_data.rb 23 | lib/databox/models/push_data_attribute.rb 24 | lib/databox/models/state.rb 25 | lib/databox/version.rb 26 | spec/api/default_api_spec.rb 27 | spec/models/api_response_spec.rb 28 | spec/models/push_data_attribute_spec.rb 29 | spec/models/push_data_spec.rb 30 | spec/models/state_spec.rb 31 | spec/spec_helper.rb 32 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by: https://openapi-generator.tech 2 | # 3 | 4 | *.gem 5 | *.rbc 6 | /.config 7 | /coverage/ 8 | /InstalledFiles 9 | /pkg/ 10 | /spec/reports/ 11 | /spec/examples.txt 12 | /test/tmp/ 13 | /test/version_tmp/ 14 | /tmp/ 15 | 16 | ## Specific to RubyMotion: 17 | .dat* 18 | .repl_history 19 | build/ 20 | 21 | ## Documentation cache and generated files: 22 | /.yardoc/ 23 | /_yardoc/ 24 | /doc/ 25 | /rdoc/ 26 | 27 | ## Environment normalization: 28 | /.bundle/ 29 | /vendor/bundle 30 | /lib/bundler/man/ 31 | 32 | # for a library or gem, you might want to ignore these files since the code is 33 | # intended to run in multiple environments; otherwise, check them in: 34 | # Gemfile.lock 35 | # .ruby-version 36 | # .ruby-gemset 37 | 38 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 39 | .rvmrc 40 | -------------------------------------------------------------------------------- /src/spec/models/state_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for Databox::State 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe Databox::State do 21 | let(:instance) { Databox::State.new } 22 | 23 | describe 'test an instance of State' do 24 | it 'should create an instance of State' do 25 | # uncomment below to test the instance creation 26 | #expect(instance).to be_instance_of(Databox::State) 27 | end 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: '$RESOLVED_VERSION' 2 | tag-template: '$RESOLVED_VERSION' 3 | categories: 4 | - title: 'Features' 5 | labels: 6 | - 'feature' 7 | - 'enhancement' 8 | - title: 'Fixes' 9 | labels: 10 | - 'fix' 11 | - 'bugfix' 12 | - 'bug' 13 | - title: 'Maintenance' 14 | label: 'chore' 15 | change-template: '- $TITLE @$AUTHOR (#$NUMBER)' 16 | change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. 17 | version-resolver: 18 | major: 19 | labels: 20 | - 'major' 21 | minor: 22 | labels: 23 | - 'minor' 24 | patch: 25 | labels: 26 | - 'patch' 27 | default: patch 28 | template: | 29 | ## Changes 30 | 31 | $CHANGES 32 | 33 | **Contributors**: $CONTRIBUTORS 34 | 35 | **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION 36 | -------------------------------------------------------------------------------- /src/lib/databox/models/state.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module Databox 17 | class State 18 | DOWN = "DOWN".freeze 19 | UP = "UP".freeze 20 | 21 | def self.all_vars 22 | @all_vars ||= [DOWN, UP].freeze 23 | end 24 | 25 | # Builds the enum from string 26 | # @param [String] The enum value in the form of the string 27 | # @return [String] The enum value 28 | def self.build_from_hash(value) 29 | new.build_from_hash(value) 30 | end 31 | 32 | # Builds the enum from string 33 | # @param [String] The enum value in the form of the string 34 | # @return [String] The enum value 35 | def build_from_hash(value) 36 | return value if State.all_vars.include?(value) 37 | raise "Invalid ENUM value #{value} for class #State" 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /src/.openapi-generator-ignore: -------------------------------------------------------------------------------- 1 | # OpenAPI Generator Ignore 2 | # Generated by openapi-generator https://github.com/openapitools/openapi-generator 3 | 4 | # Use this file to prevent files from being overwritten by the generator. 5 | # The patterns follow closely to .gitignore or .dockerignore. 6 | 7 | # As an example, the C# client generator defines ApiClient.cs. 8 | # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: 9 | #ApiClient.cs 10 | 11 | # You can match any string of characters against a directory, file or extension with a single asterisk (*): 12 | #foo/*/qux 13 | # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux 14 | 15 | # You can recursively match patterns against a directory, file or extension with a double asterisk (**): 16 | #foo/**/qux 17 | # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux 18 | 19 | # You can also negate patterns with an exclamation (!). 20 | # For example, you can ignore all files in a docs folder with the file extension .md: 21 | #docs/*.md 22 | # Then explicitly reverse the ignore rule for a single file: 23 | #!docs/README.md 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Oto Brglez 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/lib/databox.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | # Common files 14 | require 'databox/api_client' 15 | require 'databox/api_error' 16 | require 'databox/version' 17 | require 'databox/configuration' 18 | 19 | # Models 20 | require 'databox/models/api_response' 21 | require 'databox/models/push_data' 22 | require 'databox/models/push_data_attribute' 23 | require 'databox/models/state' 24 | 25 | # APIs 26 | require 'databox/api/default_api' 27 | 28 | module Databox 29 | class << self 30 | # Customize default settings for the SDK using block. 31 | # Databox.configure do |config| 32 | # config.username = "xxx" 33 | # config.password = "xxx" 34 | # end 35 | # If no block given, return the default Configuration object. 36 | def configure 37 | if block_given? 38 | yield(Configuration.default) 39 | else 40 | Configuration.default 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /src/databox.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | =begin 4 | #Static OpenAPI document of Push API resource 5 | 6 | #Push API resources Open API documentation 7 | 8 | The version of the OpenAPI document: 0.4.1 9 | 10 | Generated by: https://openapi-generator.tech 11 | Generator version: 7.6.0 12 | 13 | =end 14 | 15 | $:.push File.expand_path("../lib", __FILE__) 16 | require "databox/version" 17 | 18 | Gem::Specification.new do |s| 19 | s.name = "databox" 20 | s.version = Databox::VERSION 21 | s.platform = Gem::Platform::RUBY 22 | s.authors = ["Databox"] 23 | s.email = [""] 24 | s.homepage = "https://databox.com/" 25 | s.summary = "Static OpenAPI document of Push API resource Ruby Gem" 26 | s.description = "SDK Client for using Databox Push API feature" 27 | s.license = "Unlicense" 28 | s.required_ruby_version = ">= 2.7" 29 | s.metadata = {} 30 | 31 | s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' 32 | 33 | s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' 34 | 35 | s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } 36 | s.test_files = `find spec/*`.split("\n") 37 | s.executables = [] 38 | s.require_paths = ["lib"] 39 | end 40 | -------------------------------------------------------------------------------- /src/spec/models/api_response_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for Databox::ApiResponse 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe Databox::ApiResponse do 21 | let(:instance) { Databox::ApiResponse.new } 22 | 23 | describe 'test an instance of ApiResponse' do 24 | it 'should create an instance of ApiResponse' do 25 | # uncomment below to test the instance creation 26 | #expect(instance).to be_instance_of(Databox::ApiResponse) 27 | end 28 | end 29 | 30 | describe 'test attribute "status"' do 31 | it 'should work' do 32 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 33 | end 34 | end 35 | 36 | describe 'test attribute "message"' do 37 | it 'should work' do 38 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 39 | end 40 | end 41 | 42 | end 43 | -------------------------------------------------------------------------------- /src/spec/models/push_data_attribute_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for Databox::PushDataAttribute 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe Databox::PushDataAttribute do 21 | let(:instance) { Databox::PushDataAttribute.new } 22 | 23 | describe 'test an instance of PushDataAttribute' do 24 | it 'should create an instance of PushDataAttribute' do 25 | # uncomment below to test the instance creation 26 | #expect(instance).to be_instance_of(Databox::PushDataAttribute) 27 | end 28 | end 29 | 30 | describe 'test attribute "key"' do 31 | it 'should work' do 32 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 33 | end 34 | end 35 | 36 | describe 'test attribute "value"' do 37 | it 'should work' do 38 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 39 | end 40 | end 41 | 42 | end 43 | -------------------------------------------------------------------------------- /src/lib/databox/api_error.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | module Databox 14 | class ApiError < StandardError 15 | attr_reader :code, :response_headers, :response_body 16 | 17 | # Usage examples: 18 | # ApiError.new 19 | # ApiError.new("message") 20 | # ApiError.new(:code => 500, :response_headers => {}, :response_body => "") 21 | # ApiError.new(:code => 404, :message => "Not Found") 22 | def initialize(arg = nil) 23 | if arg.is_a? Hash 24 | if arg.key?(:message) || arg.key?('message') 25 | super(arg[:message] || arg['message']) 26 | else 27 | super arg 28 | end 29 | 30 | arg.each do |k, v| 31 | instance_variable_set "@#{k}", v 32 | end 33 | else 34 | super arg 35 | @message = arg 36 | end 37 | end 38 | 39 | # Override to_s to display a friendly error message 40 | def to_s 41 | message 42 | end 43 | 44 | def message 45 | if @message.nil? 46 | msg = "Error message: the server returns an error" 47 | else 48 | msg = @message 49 | end 50 | 51 | msg += "\nHTTP status code: #{code}" if code 52 | msg += "\nResponse headers: #{response_headers}" if response_headers 53 | msg += "\nResponse body: #{response_body}" if response_body 54 | 55 | msg 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /src/git_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ 3 | # 4 | # Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" 5 | 6 | git_user_id=$1 7 | git_repo_id=$2 8 | release_note=$3 9 | git_host=$4 10 | 11 | if [ "$git_host" = "" ]; then 12 | git_host="github.com" 13 | echo "[INFO] No command line input provided. Set \$git_host to $git_host" 14 | fi 15 | 16 | if [ "$git_user_id" = "" ]; then 17 | git_user_id="GIT_USER_ID" 18 | echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" 19 | fi 20 | 21 | if [ "$git_repo_id" = "" ]; then 22 | git_repo_id="GIT_REPO_ID" 23 | echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" 24 | fi 25 | 26 | if [ "$release_note" = "" ]; then 27 | release_note="Minor update" 28 | echo "[INFO] No command line input provided. Set \$release_note to $release_note" 29 | fi 30 | 31 | # Initialize the local directory as a Git repository 32 | git init 33 | 34 | # Adds the files in the local repository and stages them for commit. 35 | git add . 36 | 37 | # Commits the tracked changes and prepares them to be pushed to a remote repository. 38 | git commit -m "$release_note" 39 | 40 | # Sets the new remote 41 | git_remote=$(git remote) 42 | if [ "$git_remote" = "" ]; then # git remote not defined 43 | 44 | if [ "$GIT_TOKEN" = "" ]; then 45 | echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." 46 | git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git 47 | else 48 | git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git 49 | fi 50 | 51 | fi 52 | 53 | git pull origin master 54 | 55 | # Pushes (Forces) the changes in the local repository up to the remote repository 56 | echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" 57 | git push origin master 2>&1 | grep -v 'To https' 58 | -------------------------------------------------------------------------------- /src/spec/models/push_data_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | require 'date' 16 | 17 | # Unit tests for Databox::PushData 18 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 19 | # Please update as you see appropriate 20 | describe Databox::PushData do 21 | let(:instance) { Databox::PushData.new } 22 | 23 | describe 'test an instance of PushData' do 24 | it 'should create an instance of PushData' do 25 | # uncomment below to test the instance creation 26 | #expect(instance).to be_instance_of(Databox::PushData) 27 | end 28 | end 29 | 30 | describe 'test attribute "attributes"' do 31 | it 'should work' do 32 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 33 | end 34 | end 35 | 36 | describe 'test attribute "date"' do 37 | it 'should work' do 38 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 39 | end 40 | end 41 | 42 | describe 'test attribute "key"' do 43 | it 'should work' do 44 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 45 | end 46 | end 47 | 48 | describe 'test attribute "period_from"' do 49 | it 'should work' do 50 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 51 | end 52 | end 53 | 54 | describe 'test attribute "period_to"' do 55 | it 'should work' do 56 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 57 | end 58 | end 59 | 60 | describe 'test attribute "unit"' do 61 | it 'should work' do 62 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 63 | end 64 | end 65 | 66 | describe 'test attribute "value"' do 67 | it 'should work' do 68 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 69 | end 70 | end 71 | 72 | end 73 | -------------------------------------------------------------------------------- /src/spec/api/default_api_spec.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'spec_helper' 14 | require 'json' 15 | 16 | # Unit tests for Databox::DefaultApi 17 | # Automatically generated by openapi-generator (https://openapi-generator.tech) 18 | # Please update as you see appropriate 19 | describe 'DefaultApi' do 20 | before do 21 | # run before each test 22 | @api_instance = Databox::DefaultApi.new 23 | end 24 | 25 | after do 26 | # run after each test 27 | end 28 | 29 | describe 'test an instance of DefaultApi' do 30 | it 'should create an instance of DefaultApi' do 31 | expect(@api_instance).to be_instance_of(Databox::DefaultApi) 32 | end 33 | end 34 | 35 | # unit tests for data_delete 36 | # @param [Hash] opts the optional parameters 37 | # @return [nil] 38 | describe 'data_delete test' do 39 | it 'should work' do 40 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 41 | end 42 | end 43 | 44 | # unit tests for data_metric_key_delete 45 | # @param metric_key 46 | # @param [Hash] opts the optional parameters 47 | # @return [nil] 48 | describe 'data_metric_key_delete test' do 49 | it 'should work' do 50 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 51 | end 52 | end 53 | 54 | # unit tests for data_post 55 | # @param [Hash] opts the optional parameters 56 | # @option opts [Array] :push_data 57 | # @return [nil] 58 | describe 'data_post test' do 59 | it 'should work' do 60 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 61 | end 62 | end 63 | 64 | # unit tests for metrickeys_get 65 | # @param [Hash] opts the optional parameters 66 | # @return [nil] 67 | describe 'metrickeys_get test' do 68 | it 'should work' do 69 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 70 | end 71 | end 72 | 73 | # unit tests for metrickeys_post 74 | # @param [Hash] opts the optional parameters 75 | # @option opts [Object] :body 76 | # @return [nil] 77 | describe 'metrickeys_post test' do 78 | it 'should work' do 79 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 80 | end 81 | end 82 | 83 | # unit tests for ping_get 84 | # @param [Hash] opts the optional parameters 85 | # @return [nil] 86 | describe 'ping_get test' do 87 | it 'should work' do 88 | # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/ 89 | end 90 | end 91 | 92 | end 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # databox 2 | 3 | Databox - the Ruby gem for the Static OpenAPI document of Push API resource 4 | 5 | Push API resources Open API documentation 6 | 7 | This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: 8 | 9 | - API version: 0.4.1 10 | - Package version: 2.1.1 11 | - Generator version: 7.6.0 12 | - Build package: org.openapitools.codegen.languages.RubyClientCodegen 13 | 14 | ## Installation 15 | 16 | ### Build a gem 17 | 18 | To build the Ruby code into a gem: 19 | 20 | ```shell 21 | gem build databox.gemspec 22 | ``` 23 | 24 | Then either install the gem locally: 25 | 26 | ```shell 27 | gem install ./databox-2.1.1.gem 28 | ``` 29 | 30 | (for development, run `gem install --dev ./databox-2.1.1.gem` to install the development dependencies) 31 | 32 | or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/). 33 | 34 | Finally add this to the Gemfile: 35 | 36 | gem 'databox', '~> 2.1.1' 37 | 38 | ### Install from Git 39 | 40 | If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile: 41 | 42 | gem 'databox', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git' 43 | 44 | ### Include the Ruby code directly 45 | 46 | Include the Ruby code directly using `-I` as follows: 47 | 48 | ```shell 49 | ruby -Ilib script.rb 50 | ``` 51 | 52 | ## Getting Started 53 | 54 | Please follow the [installation](#installation) procedure and then run the following code: 55 | 56 | ```ruby 57 | # Load the gem 58 | require 'databox' 59 | 60 | # Setup authorization 61 | Databox.configure do |config| 62 | # Configure HTTP basic authorization: basicAuth 63 | config.username = 'YOUR_USERNAME' 64 | config.password = 'YOUR_PASSWORD' 65 | end 66 | 67 | api_instance = Databox::DefaultApi.new 68 | 69 | begin 70 | api_instance.data_delete 71 | rescue Databox::ApiError => e 72 | puts "Exception when calling DefaultApi->data_delete: #{e}" 73 | end 74 | 75 | ``` 76 | 77 | ## Documentation for API Endpoints 78 | 79 | All URIs are relative to *https://push.databox.com* 80 | 81 | Class | Method | HTTP request | Description 82 | ------------ | ------------- | ------------- | ------------- 83 | *Databox::DefaultApi* | [**data_delete**](docs/DefaultApi.md#data_delete) | **DELETE** /data | 84 | *Databox::DefaultApi* | [**data_metric_key_delete**](docs/DefaultApi.md#data_metric_key_delete) | **DELETE** /data/{metricKey} | 85 | *Databox::DefaultApi* | [**data_post**](docs/DefaultApi.md#data_post) | **POST** /data | 86 | *Databox::DefaultApi* | [**metrickeys_get**](docs/DefaultApi.md#metrickeys_get) | **GET** /metrickeys | 87 | *Databox::DefaultApi* | [**metrickeys_post**](docs/DefaultApi.md#metrickeys_post) | **POST** /metrickeys | 88 | *Databox::DefaultApi* | [**ping_get**](docs/DefaultApi.md#ping_get) | **GET** /ping | 89 | 90 | 91 | ## Documentation for Models 92 | 93 | - [Databox::ApiResponse](docs/ApiResponse.md) 94 | - [Databox::PushData](docs/PushData.md) 95 | - [Databox::PushDataAttribute](docs/PushDataAttribute.md) 96 | - [Databox::State](docs/State.md) 97 | 98 | 99 | ## Documentation for Authorization 100 | 101 | 102 | Authentication schemes defined for the API: 103 | ### basicAuth 104 | 105 | - **Type**: HTTP basic authentication 106 | 107 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # databox 2 | 3 | Databox - the Ruby gem for the Static OpenAPI document of Push API resource 4 | 5 | Push API resources Open API documentation 6 | 7 | This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: 8 | 9 | - API version: 0.4.1 10 | - Package version: 2.1.1 11 | - Generator version: 7.6.0 12 | - Build package: org.openapitools.codegen.languages.RubyClientCodegen 13 | 14 | ## Installation 15 | 16 | ### Build a gem 17 | 18 | To build the Ruby code into a gem: 19 | 20 | ```shell 21 | gem build databox.gemspec 22 | ``` 23 | 24 | Then either install the gem locally: 25 | 26 | ```shell 27 | gem install ./databox-2.1.1.gem 28 | ``` 29 | 30 | (for development, run `gem install --dev ./databox-2.1.1.gem` to install the development dependencies) 31 | 32 | or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/). 33 | 34 | Finally add this to the Gemfile: 35 | 36 | gem 'databox', '~> 2.1.1' 37 | 38 | ### Install from Git 39 | 40 | If the Ruby gem is hosted at a git repository: https://github.com/GIT_USER_ID/GIT_REPO_ID, then add the following in the Gemfile: 41 | 42 | gem 'databox', :git => 'https://github.com/GIT_USER_ID/GIT_REPO_ID.git' 43 | 44 | ### Include the Ruby code directly 45 | 46 | Include the Ruby code directly using `-I` as follows: 47 | 48 | ```shell 49 | ruby -Ilib script.rb 50 | ``` 51 | 52 | ## Getting Started 53 | 54 | Please follow the [installation](#installation) procedure and then run the following code: 55 | 56 | ```ruby 57 | # Load the gem 58 | require 'databox' 59 | 60 | # Setup authorization 61 | Databox.configure do |config| 62 | # Configure HTTP basic authorization: basicAuth 63 | config.username = 'YOUR_USERNAME' 64 | config.password = 'YOUR_PASSWORD' 65 | end 66 | 67 | api_instance = Databox::DefaultApi.new 68 | 69 | begin 70 | api_instance.data_delete 71 | rescue Databox::ApiError => e 72 | puts "Exception when calling DefaultApi->data_delete: #{e}" 73 | end 74 | 75 | ``` 76 | 77 | ## Documentation for API Endpoints 78 | 79 | All URIs are relative to *https://push.databox.com* 80 | 81 | Class | Method | HTTP request | Description 82 | ------------ | ------------- | ------------- | ------------- 83 | *Databox::DefaultApi* | [**data_delete**](docs/DefaultApi.md#data_delete) | **DELETE** /data | 84 | *Databox::DefaultApi* | [**data_metric_key_delete**](docs/DefaultApi.md#data_metric_key_delete) | **DELETE** /data/{metricKey} | 85 | *Databox::DefaultApi* | [**data_post**](docs/DefaultApi.md#data_post) | **POST** /data | 86 | *Databox::DefaultApi* | [**metrickeys_get**](docs/DefaultApi.md#metrickeys_get) | **GET** /metrickeys | 87 | *Databox::DefaultApi* | [**metrickeys_post**](docs/DefaultApi.md#metrickeys_post) | **POST** /metrickeys | 88 | *Databox::DefaultApi* | [**ping_get**](docs/DefaultApi.md#ping_get) | **GET** /ping | 89 | 90 | 91 | ## Documentation for Models 92 | 93 | - [Databox::ApiResponse](docs/ApiResponse.md) 94 | - [Databox::PushData](docs/PushData.md) 95 | - [Databox::PushDataAttribute](docs/PushDataAttribute.md) 96 | - [Databox::State](docs/State.md) 97 | 98 | 99 | ## Documentation for Authorization 100 | 101 | 102 | Authentication schemes defined for the API: 103 | ### basicAuth 104 | 105 | - **Type**: HTTP basic authentication 106 | 107 | -------------------------------------------------------------------------------- /.github/workflows/publish_sdk.yml: -------------------------------------------------------------------------------- 1 | name: Publish SDK 2 | on: 3 | push: 4 | branches: 5 | - master 6 | paths: 7 | - 'src/**' 8 | 9 | jobs: 10 | release_draft: 11 | name: Create release draft 12 | runs-on: ubuntu-latest 13 | outputs: 14 | release_body: ${{ steps.create_release_draft.outputs.body }} 15 | release_tag: ${{ steps.create_release_draft.outputs.tag_name }} 16 | release_html_url: ${{ steps.create_release_draft.outputs.html_url }} 17 | release_id: ${{ steps.create_release_draft.outputs.id }} 18 | steps: 19 | - name: "Create release draft" 20 | id: create_release_draft 21 | uses: release-drafter/release-drafter@v6 22 | with: 23 | commitish: master 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | 27 | build: 28 | runs-on: ubuntu-latest 29 | permissions: 30 | contents: write 31 | pull-requests: write 32 | id-token: write 33 | 34 | steps: 35 | 36 | - uses: actions/checkout@v4 37 | 38 | - name: Set up Ruby 39 | uses: ruby/setup-ruby@v1 40 | with: 41 | bundler-cache: true 42 | ruby-version: ruby 43 | working-directory: src 44 | 45 | - name: Set remote URL 46 | run: | 47 | # Attribute commits to the last committer on HEAD 48 | git config --global user.email "${{ github.actor }}@users.noreply.github.com" 49 | git config --global user.name "${{ github.actor }}" 50 | git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/$GITHUB_REPOSITORY" 51 | 52 | - name: Configure trusted publishing credentials 53 | uses: rubygems/configure-rubygems-credentials@v1.0.0 54 | 55 | - name: Run release rake task 56 | run: bundle exec rake release 57 | shell: bash 58 | working-directory: src 59 | 60 | release_publish: 61 | name: Publish release 62 | runs-on: ubuntu-latest 63 | needs: 64 | - release_draft 65 | - build 66 | steps: 67 | - name: "Publish release" 68 | uses: eregon/publish-release@v1 69 | env: 70 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 71 | with: 72 | release_id: ${{ needs.release_draft.outputs.release_id }} 73 | 74 | post_slack_job: 75 | name: Post info to Slack in #engeering-releases channel 76 | needs: 77 | - release_draft 78 | - release_publish 79 | runs-on: ubuntu-latest 80 | env: 81 | SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} 82 | steps: 83 | - name: Format to Slack msg 84 | uses: LoveToKnow/slackify-markdown-action@v1.0.0 85 | id: slack_msg_converter 86 | with: 87 | text: ${{needs.release_draft.outputs.release_body}} 88 | - name: Post to a Slack channel 89 | if: success() 90 | id: slack 91 | uses: slackapi/slack-github-action@v1.23.0 92 | with: 93 | channel-id: 'C027FC31SVD' 94 | payload: | 95 | { 96 | "text": "New version post", 97 | "blocks": [ 98 | { 99 | "type": "section", 100 | "text": { 101 | "type": "mrkdwn", 102 | "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:" 103 | } 104 | }, 105 | { 106 | "type": "section", 107 | "text": { 108 | "type": "mrkdwn", 109 | "text": ${{toJSON(steps.slack_msg_converter.outputs.text)}} 110 | } 111 | } 112 | ] 113 | } 114 | -------------------------------------------------------------------------------- /.github/workflows/generate_sdk_code.yml: -------------------------------------------------------------------------------- 1 | name: Generate SDK Code 2 | on: 3 | repository_dispatch: 4 | types: [publish_sdk] 5 | env: 6 | GENERATOR_VERISON: "7.6.0" 7 | CONFIG_FILE: "sdk-gen-config.json" 8 | jobs: 9 | sdk: 10 | name: Generate SDK code 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | 16 | - name: Get Latest Release 17 | id: latest-version 18 | uses: pozetroninc/github-action-get-latest-release@v0.7.0 19 | with: 20 | owner: ${{ github.repository_owner }} 21 | repo: databox-ruby 22 | excludes: prerelease, draft 23 | token: ${{ secrets.PAT_APPROVE_PR }} 24 | 25 | - name: Determine Version 26 | id: version 27 | uses: actions/github-script@v7 28 | with: 29 | script: | 30 | const version = '${{ steps.latest-version.outputs.release }}'; 31 | const parts = version.split('.'); 32 | switch('${{ github.event.client_payload.labels }}') { 33 | case 'patch': 34 | parts[2] = parseInt(parts[2]) + 1; 35 | break; 36 | case 'minor': 37 | parts[1] = parseInt(parts[1]) + 1; 38 | break; 39 | case 'major': 40 | parts[0] = parseInt(parts[0]) + 1; 41 | break; 42 | default: 43 | parts[2] = parseInt(parts[2]) + 1; 44 | break; 45 | } 46 | const newVersion = parts.join('.'); 47 | return newVersion; 48 | 49 | - name: Download OpenAPI Generator 50 | run: | 51 | 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 52 | 53 | - name: Download OpenAPI Specification 54 | uses: actions/download-artifact@v4 55 | with: 56 | name: ${{ github.event.client_payload.openapi_spec }} 57 | path: ${{ runner.temp }}/openapispec 58 | repository: databox/data-link 59 | github-token: ${{ secrets.PAT_APPROVE_PR }} 60 | run-id: ${{ github.event.client_payload.run_id }} 61 | 62 | - name: Remove old SDK 63 | run: | 64 | rm -rf src/* 65 | rm -rf docs/* 66 | 67 | - name: Set API and SDK versions 68 | run: | 69 | cp .github/${{ env.CONFIG_FILE }} ${{ runner.temp }}/${{ env.CONFIG_FILE }} 70 | 71 | #set SDK version 72 | sed -i "s/{VERSION}/${{ steps.version.outputs.result }}/g" ${{ runner.temp }}/${{ env.CONFIG_FILE }} 73 | 74 | #set API version 75 | sed -i 's/version: "1.0"/version: ${{ github.event.client_payload.version }}/g' ${{ runner.temp }}/openapispec/openapi.yml 76 | 77 | - name: Generate SDK 78 | run: | 79 | java --version 80 | 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 81 | cp ./src/README.md ./README.md 82 | cp -r ./src/docs ./docs 83 | 84 | - name: Create Pull Request 85 | id: cpr 86 | uses: peter-evans/create-pull-request@v6 87 | with: 88 | base: master 89 | token: ${{ secrets.GITHUB_TOKEN }} 90 | commit-message: 'chore: release data-link SDK' 91 | title: '[SDK release] Generated SDK code based on data-link ${{ github.event.client_payload.version }} API changes' 92 | branch: 'release/${{ github.event.client_payload.version }}/${{ github.event.client_payload.timestamp }}' 93 | body: > 94 | 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 }}). 95 | labels: | 96 | automated 97 | ${{ github.event.client_payload.labels || 'patch' }} -------------------------------------------------------------------------------- /src/.rubocop.yml: -------------------------------------------------------------------------------- 1 | # This file is based on https://github.com/rails/rails/blob/master/.rubocop.yml (MIT license) 2 | # Automatically generated by OpenAPI Generator (https://openapi-generator.tech) 3 | AllCops: 4 | TargetRubyVersion: 2.4 5 | # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop 6 | # to ignore them, so only the ones explicitly set in this file are enabled. 7 | DisabledByDefault: true 8 | Exclude: 9 | - '**/templates/**/*' 10 | - '**/vendor/**/*' 11 | - 'actionpack/lib/action_dispatch/journey/parser.rb' 12 | 13 | # Prefer &&/|| over and/or. 14 | Style/AndOr: 15 | Enabled: true 16 | 17 | # Align `when` with `case`. 18 | Layout/CaseIndentation: 19 | Enabled: true 20 | 21 | # Align comments with method definitions. 22 | Layout/CommentIndentation: 23 | Enabled: true 24 | 25 | Layout/ElseAlignment: 26 | Enabled: true 27 | 28 | Layout/EmptyLineAfterMagicComment: 29 | Enabled: true 30 | 31 | # In a regular class definition, no empty lines around the body. 32 | Layout/EmptyLinesAroundClassBody: 33 | Enabled: true 34 | 35 | # In a regular method definition, no empty lines around the body. 36 | Layout/EmptyLinesAroundMethodBody: 37 | Enabled: true 38 | 39 | # In a regular module definition, no empty lines around the body. 40 | Layout/EmptyLinesAroundModuleBody: 41 | Enabled: true 42 | 43 | Layout/FirstArgumentIndentation: 44 | Enabled: true 45 | 46 | # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. 47 | Style/HashSyntax: 48 | Enabled: false 49 | 50 | # Method definitions after `private` or `protected` isolated calls need one 51 | # extra level of indentation. 52 | Layout/IndentationConsistency: 53 | Enabled: true 54 | EnforcedStyle: indented_internal_methods 55 | 56 | # Two spaces, no tabs (for indentation). 57 | Layout/IndentationWidth: 58 | Enabled: true 59 | 60 | Layout/LeadingCommentSpace: 61 | Enabled: true 62 | 63 | Layout/SpaceAfterColon: 64 | Enabled: true 65 | 66 | Layout/SpaceAfterComma: 67 | Enabled: true 68 | 69 | Layout/SpaceAroundEqualsInParameterDefault: 70 | Enabled: true 71 | 72 | Layout/SpaceAroundKeyword: 73 | Enabled: true 74 | 75 | Layout/SpaceAroundOperators: 76 | Enabled: true 77 | 78 | Layout/SpaceBeforeComma: 79 | Enabled: true 80 | 81 | Layout/SpaceBeforeFirstArg: 82 | Enabled: true 83 | 84 | Style/DefWithParentheses: 85 | Enabled: true 86 | 87 | # Defining a method with parameters needs parentheses. 88 | Style/MethodDefParentheses: 89 | Enabled: true 90 | 91 | Style/FrozenStringLiteralComment: 92 | Enabled: false 93 | EnforcedStyle: always 94 | 95 | # Use `foo {}` not `foo{}`. 96 | Layout/SpaceBeforeBlockBraces: 97 | Enabled: true 98 | 99 | # Use `foo { bar }` not `foo {bar}`. 100 | Layout/SpaceInsideBlockBraces: 101 | Enabled: true 102 | 103 | # Use `{ a: 1 }` not `{a:1}`. 104 | Layout/SpaceInsideHashLiteralBraces: 105 | Enabled: true 106 | 107 | Layout/SpaceInsideParens: 108 | Enabled: true 109 | 110 | # Check quotes usage according to lint rule below. 111 | #Style/StringLiterals: 112 | # Enabled: true 113 | # EnforcedStyle: single_quotes 114 | 115 | # Detect hard tabs, no hard tabs. 116 | Layout/IndentationStyle: 117 | Enabled: true 118 | 119 | # Blank lines should not have any spaces. 120 | Layout/TrailingEmptyLines: 121 | Enabled: true 122 | 123 | # No trailing whitespace. 124 | Layout/TrailingWhitespace: 125 | Enabled: false 126 | 127 | # Use quotes for string literals when they are enough. 128 | Style/RedundantPercentQ: 129 | Enabled: true 130 | 131 | # Align `end` with the matching keyword or starting expression except for 132 | # assignments, where it should be aligned with the LHS. 133 | Layout/EndAlignment: 134 | Enabled: true 135 | EnforcedStyleAlignWith: variable 136 | AutoCorrect: true 137 | 138 | # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. 139 | Lint/RequireParentheses: 140 | Enabled: true 141 | 142 | Style/RedundantReturn: 143 | Enabled: true 144 | AllowMultipleReturnValues: true 145 | 146 | Style/Semicolon: 147 | Enabled: true 148 | AllowAsExpressionSeparator: true 149 | -------------------------------------------------------------------------------- /src/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | # load the gem 14 | require 'databox' 15 | 16 | # The following was generated by the `rspec --init` command. Conventionally, all 17 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 18 | # The generated `.rspec` file contains `--require spec_helper` which will cause 19 | # this file to always be loaded, without a need to explicitly require it in any 20 | # files. 21 | # 22 | # Given that it is always loaded, you are encouraged to keep this file as 23 | # light-weight as possible. Requiring heavyweight dependencies from this file 24 | # will add to the boot time of your test suite on EVERY test run, even for an 25 | # individual file that may not need all of that loaded. Instead, consider making 26 | # a separate helper file that requires the additional dependencies and performs 27 | # the additional setup, and require it from the spec files that actually need 28 | # it. 29 | # 30 | # The `.rspec` file also contains a few flags that are not defaults but that 31 | # users commonly want. 32 | # 33 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 34 | RSpec.configure do |config| 35 | # rspec-expectations config goes here. You can use an alternate 36 | # assertion/expectation library such as wrong or the stdlib/minitest 37 | # assertions if you prefer. 38 | config.expect_with :rspec do |expectations| 39 | # This option will default to `true` in RSpec 4. It makes the `description` 40 | # and `failure_message` of custom matchers include text for helper methods 41 | # defined using `chain`, e.g.: 42 | # be_bigger_than(2).and_smaller_than(4).description 43 | # # => "be bigger than 2 and smaller than 4" 44 | # ...rather than: 45 | # # => "be bigger than 2" 46 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 47 | end 48 | 49 | # rspec-mocks config goes here. You can use an alternate test double 50 | # library (such as bogus or mocha) by changing the `mock_with` option here. 51 | config.mock_with :rspec do |mocks| 52 | # Prevents you from mocking or stubbing a method that does not exist on 53 | # a real object. This is generally recommended, and will default to 54 | # `true` in RSpec 4. 55 | mocks.verify_partial_doubles = true 56 | end 57 | 58 | # The settings below are suggested to provide a good initial experience 59 | # with RSpec, but feel free to customize to your heart's content. 60 | =begin 61 | # These two settings work together to allow you to limit a spec run 62 | # to individual examples or groups you care about by tagging them with 63 | # `:focus` metadata. When nothing is tagged with `:focus`, all examples 64 | # get run. 65 | config.filter_run :focus 66 | config.run_all_when_everything_filtered = true 67 | 68 | # Allows RSpec to persist some state between runs in order to support 69 | # the `--only-failures` and `--next-failure` CLI options. We recommend 70 | # you configure your source control system to ignore this file. 71 | config.example_status_persistence_file_path = "spec/examples.txt" 72 | 73 | # Limits the available syntax to the non-monkey patched syntax that is 74 | # recommended. For more details, see: 75 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 76 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 77 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 78 | config.disable_monkey_patching! 79 | 80 | # This setting enables warnings. It's recommended, but in some cases may 81 | # be too noisy due to issues in dependencies. 82 | config.warnings = true 83 | 84 | # Many RSpec users commonly either run the entire suite or an individual 85 | # file, and it's useful to allow more verbose output when running an 86 | # individual spec file. 87 | if config.files_to_run.one? 88 | # Use the documentation formatter for detailed output, 89 | # unless a formatter has already been configured 90 | # (e.g. via a command-line flag). 91 | config.default_formatter = 'doc' 92 | end 93 | 94 | # Print the 10 slowest examples and example groups at the 95 | # end of the spec run, to help surface which specs are running 96 | # particularly slow. 97 | config.profile_examples = 10 98 | 99 | # Run specs in random order to surface order dependencies. If you find an 100 | # order dependency and want to debug it, you can fix the order by providing 101 | # the seed, which is printed after each run. 102 | # --seed 1234 103 | config.order = :random 104 | 105 | # Seed global randomization in this process using the `--seed` CLI option. 106 | # Setting this allows you to use `--seed` to deterministically reproduce 107 | # test failures related to randomization by passing the same `--seed` value 108 | # as the one that triggered the failure. 109 | Kernel.srand config.seed 110 | =end 111 | end 112 | -------------------------------------------------------------------------------- /src/lib/databox/models/push_data_attribute.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module Databox 17 | class PushDataAttribute 18 | attr_accessor :key 19 | 20 | attr_accessor :value 21 | 22 | # Attribute mapping from ruby-style variable name to JSON key. 23 | def self.attribute_map 24 | { 25 | :'key' => :'key', 26 | :'value' => :'value' 27 | } 28 | end 29 | 30 | # Returns all the JSON keys this model knows about 31 | def self.acceptable_attributes 32 | attribute_map.values 33 | end 34 | 35 | # Attribute type mapping. 36 | def self.openapi_types 37 | { 38 | :'key' => :'String', 39 | :'value' => :'String' 40 | } 41 | end 42 | 43 | # List of attributes with nullable: true 44 | def self.openapi_nullable 45 | Set.new([ 46 | ]) 47 | end 48 | 49 | # Initializes the object 50 | # @param [Hash] attributes Model attributes in the form of hash 51 | def initialize(attributes = {}) 52 | if (!attributes.is_a?(Hash)) 53 | fail ArgumentError, "The input argument (attributes) must be a hash in `Databox::PushDataAttribute` initialize method" 54 | end 55 | 56 | # check to see if the attribute exists and convert string to symbol for hash key 57 | attributes = attributes.each_with_object({}) { |(k, v), h| 58 | if (!self.class.attribute_map.key?(k.to_sym)) 59 | fail ArgumentError, "`#{k}` is not a valid attribute in `Databox::PushDataAttribute`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect 60 | end 61 | h[k.to_sym] = v 62 | } 63 | 64 | if attributes.key?(:'key') 65 | self.key = attributes[:'key'] 66 | end 67 | 68 | if attributes.key?(:'value') 69 | self.value = attributes[:'value'] 70 | end 71 | end 72 | 73 | # Show invalid properties with the reasons. Usually used together with valid? 74 | # @return Array for valid properties with the reasons 75 | def list_invalid_properties 76 | warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' 77 | invalid_properties = Array.new 78 | invalid_properties 79 | end 80 | 81 | # Check to see if the all the properties in the model are valid 82 | # @return true if the model is valid 83 | def valid? 84 | warn '[DEPRECATED] the `valid?` method is obsolete' 85 | true 86 | end 87 | 88 | # Checks equality by comparing each attribute. 89 | # @param [Object] Object to be compared 90 | def ==(o) 91 | return true if self.equal?(o) 92 | self.class == o.class && 93 | key == o.key && 94 | value == o.value 95 | end 96 | 97 | # @see the `==` method 98 | # @param [Object] Object to be compared 99 | def eql?(o) 100 | self == o 101 | end 102 | 103 | # Calculates hash code according to all attributes. 104 | # @return [Integer] Hash code 105 | def hash 106 | [key, value].hash 107 | end 108 | 109 | # Builds the object from hash 110 | # @param [Hash] attributes Model attributes in the form of hash 111 | # @return [Object] Returns the model itself 112 | def self.build_from_hash(attributes) 113 | return nil unless attributes.is_a?(Hash) 114 | attributes = attributes.transform_keys(&:to_sym) 115 | transformed_hash = {} 116 | openapi_types.each_pair do |key, type| 117 | if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? 118 | transformed_hash["#{key}"] = nil 119 | elsif type =~ /\AArray<(.*)>/i 120 | # check to ensure the input is an array given that the attribute 121 | # is documented as an array but the input is not 122 | if attributes[attribute_map[key]].is_a?(Array) 123 | transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } 124 | end 125 | elsif !attributes[attribute_map[key]].nil? 126 | transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) 127 | end 128 | end 129 | new(transformed_hash) 130 | end 131 | 132 | # Deserializes the data based on type 133 | # @param string type Data type 134 | # @param string value Value to be deserialized 135 | # @return [Object] Deserialized data 136 | def self._deserialize(type, value) 137 | case type.to_sym 138 | when :Time 139 | Time.parse(value) 140 | when :Date 141 | Date.parse(value) 142 | when :String 143 | value.to_s 144 | when :Integer 145 | value.to_i 146 | when :Float 147 | value.to_f 148 | when :Boolean 149 | if value.to_s =~ /\A(true|t|yes|y|1)\z/i 150 | true 151 | else 152 | false 153 | end 154 | when :Object 155 | # generic object (usually a Hash), return directly 156 | value 157 | when /\AArray<(?.+)>\z/ 158 | inner_type = Regexp.last_match[:inner_type] 159 | value.map { |v| _deserialize(inner_type, v) } 160 | when /\AHash<(?.+?), (?.+)>\z/ 161 | k_type = Regexp.last_match[:k_type] 162 | v_type = Regexp.last_match[:v_type] 163 | {}.tap do |hash| 164 | value.each do |k, v| 165 | hash[_deserialize(k_type, k)] = _deserialize(v_type, v) 166 | end 167 | end 168 | else # model 169 | # models (e.g. Pet) or oneOf 170 | klass = Databox.const_get(type) 171 | klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) 172 | end 173 | end 174 | 175 | # Returns the string representation of the object 176 | # @return [String] String presentation of the object 177 | def to_s 178 | to_hash.to_s 179 | end 180 | 181 | # to_body is an alias to to_hash (backward compatibility) 182 | # @return [Hash] Returns the object in the form of hash 183 | def to_body 184 | to_hash 185 | end 186 | 187 | # Returns the object in the form of hash 188 | # @return [Hash] Returns the object in the form of hash 189 | def to_hash 190 | hash = {} 191 | self.class.attribute_map.each_pair do |attr, param| 192 | value = self.send(attr) 193 | if value.nil? 194 | is_nullable = self.class.openapi_nullable.include?(attr) 195 | next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) 196 | end 197 | 198 | hash[param] = _to_hash(value) 199 | end 200 | hash 201 | end 202 | 203 | # Outputs non-array value in the form of hash 204 | # For object, use to_hash. Otherwise, just return the value 205 | # @param [Object] value Any valid value 206 | # @return [Hash] Returns the value in the form of hash 207 | def _to_hash(value) 208 | if value.is_a?(Array) 209 | value.compact.map { |v| _to_hash(v) } 210 | elsif value.is_a?(Hash) 211 | {}.tap do |hash| 212 | value.each { |k, v| hash[k] = _to_hash(v) } 213 | end 214 | elsif value.respond_to? :to_hash 215 | value.to_hash 216 | else 217 | value 218 | end 219 | end 220 | 221 | end 222 | 223 | end 224 | -------------------------------------------------------------------------------- /src/lib/databox/models/api_response.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module Databox 17 | class ApiResponse 18 | attr_accessor :status 19 | 20 | attr_accessor :message 21 | 22 | # Attribute mapping from ruby-style variable name to JSON key. 23 | def self.attribute_map 24 | { 25 | :'status' => :'status', 26 | :'message' => :'message' 27 | } 28 | end 29 | 30 | # Returns all the JSON keys this model knows about 31 | def self.acceptable_attributes 32 | attribute_map.values 33 | end 34 | 35 | # Attribute type mapping. 36 | def self.openapi_types 37 | { 38 | :'status' => :'String', 39 | :'message' => :'String' 40 | } 41 | end 42 | 43 | # List of attributes with nullable: true 44 | def self.openapi_nullable 45 | Set.new([ 46 | ]) 47 | end 48 | 49 | # Initializes the object 50 | # @param [Hash] attributes Model attributes in the form of hash 51 | def initialize(attributes = {}) 52 | if (!attributes.is_a?(Hash)) 53 | fail ArgumentError, "The input argument (attributes) must be a hash in `Databox::ApiResponse` initialize method" 54 | end 55 | 56 | # check to see if the attribute exists and convert string to symbol for hash key 57 | attributes = attributes.each_with_object({}) { |(k, v), h| 58 | if (!self.class.attribute_map.key?(k.to_sym)) 59 | fail ArgumentError, "`#{k}` is not a valid attribute in `Databox::ApiResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect 60 | end 61 | h[k.to_sym] = v 62 | } 63 | 64 | if attributes.key?(:'status') 65 | self.status = attributes[:'status'] 66 | end 67 | 68 | if attributes.key?(:'message') 69 | self.message = attributes[:'message'] 70 | end 71 | end 72 | 73 | # Show invalid properties with the reasons. Usually used together with valid? 74 | # @return Array for valid properties with the reasons 75 | def list_invalid_properties 76 | warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' 77 | invalid_properties = Array.new 78 | invalid_properties 79 | end 80 | 81 | # Check to see if the all the properties in the model are valid 82 | # @return true if the model is valid 83 | def valid? 84 | warn '[DEPRECATED] the `valid?` method is obsolete' 85 | true 86 | end 87 | 88 | # Checks equality by comparing each attribute. 89 | # @param [Object] Object to be compared 90 | def ==(o) 91 | return true if self.equal?(o) 92 | self.class == o.class && 93 | status == o.status && 94 | message == o.message 95 | end 96 | 97 | # @see the `==` method 98 | # @param [Object] Object to be compared 99 | def eql?(o) 100 | self == o 101 | end 102 | 103 | # Calculates hash code according to all attributes. 104 | # @return [Integer] Hash code 105 | def hash 106 | [status, message].hash 107 | end 108 | 109 | # Builds the object from hash 110 | # @param [Hash] attributes Model attributes in the form of hash 111 | # @return [Object] Returns the model itself 112 | def self.build_from_hash(attributes) 113 | return nil unless attributes.is_a?(Hash) 114 | attributes = attributes.transform_keys(&:to_sym) 115 | transformed_hash = {} 116 | openapi_types.each_pair do |key, type| 117 | if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? 118 | transformed_hash["#{key}"] = nil 119 | elsif type =~ /\AArray<(.*)>/i 120 | # check to ensure the input is an array given that the attribute 121 | # is documented as an array but the input is not 122 | if attributes[attribute_map[key]].is_a?(Array) 123 | transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } 124 | end 125 | elsif !attributes[attribute_map[key]].nil? 126 | transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) 127 | end 128 | end 129 | new(transformed_hash) 130 | end 131 | 132 | # Deserializes the data based on type 133 | # @param string type Data type 134 | # @param string value Value to be deserialized 135 | # @return [Object] Deserialized data 136 | def self._deserialize(type, value) 137 | case type.to_sym 138 | when :Time 139 | Time.parse(value) 140 | when :Date 141 | Date.parse(value) 142 | when :String 143 | value.to_s 144 | when :Integer 145 | value.to_i 146 | when :Float 147 | value.to_f 148 | when :Boolean 149 | if value.to_s =~ /\A(true|t|yes|y|1)\z/i 150 | true 151 | else 152 | false 153 | end 154 | when :Object 155 | # generic object (usually a Hash), return directly 156 | value 157 | when /\AArray<(?.+)>\z/ 158 | inner_type = Regexp.last_match[:inner_type] 159 | value.map { |v| _deserialize(inner_type, v) } 160 | when /\AHash<(?.+?), (?.+)>\z/ 161 | k_type = Regexp.last_match[:k_type] 162 | v_type = Regexp.last_match[:v_type] 163 | {}.tap do |hash| 164 | value.each do |k, v| 165 | hash[_deserialize(k_type, k)] = _deserialize(v_type, v) 166 | end 167 | end 168 | else # model 169 | # models (e.g. Pet) or oneOf 170 | klass = Databox.const_get(type) 171 | klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) 172 | end 173 | end 174 | 175 | # Returns the string representation of the object 176 | # @return [String] String presentation of the object 177 | def to_s 178 | to_hash.to_s 179 | end 180 | 181 | # to_body is an alias to to_hash (backward compatibility) 182 | # @return [Hash] Returns the object in the form of hash 183 | def to_body 184 | to_hash 185 | end 186 | 187 | # Returns the object in the form of hash 188 | # @return [Hash] Returns the object in the form of hash 189 | def to_hash 190 | hash = {} 191 | self.class.attribute_map.each_pair do |attr, param| 192 | value = self.send(attr) 193 | if value.nil? 194 | is_nullable = self.class.openapi_nullable.include?(attr) 195 | next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) 196 | end 197 | 198 | hash[param] = _to_hash(value) 199 | end 200 | hash 201 | end 202 | 203 | # Outputs non-array value in the form of hash 204 | # For object, use to_hash. Otherwise, just return the value 205 | # @param [Object] value Any valid value 206 | # @return [Hash] Returns the value in the form of hash 207 | def _to_hash(value) 208 | if value.is_a?(Array) 209 | value.compact.map { |v| _to_hash(v) } 210 | elsif value.is_a?(Hash) 211 | {}.tap do |hash| 212 | value.each { |k, v| hash[k] = _to_hash(v) } 213 | end 214 | elsif value.respond_to? :to_hash 215 | value.to_hash 216 | else 217 | value 218 | end 219 | end 220 | 221 | end 222 | 223 | end 224 | -------------------------------------------------------------------------------- /src/lib/databox/models/push_data.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'time' 15 | 16 | module Databox 17 | class PushData 18 | attr_accessor :attributes 19 | 20 | attr_accessor :date 21 | 22 | attr_accessor :key 23 | 24 | attr_accessor :period_from 25 | 26 | attr_accessor :period_to 27 | 28 | attr_accessor :unit 29 | 30 | attr_accessor :value 31 | 32 | # Attribute mapping from ruby-style variable name to JSON key. 33 | def self.attribute_map 34 | { 35 | :'attributes' => :'attributes', 36 | :'date' => :'date', 37 | :'key' => :'key', 38 | :'period_from' => :'periodFrom', 39 | :'period_to' => :'periodTo', 40 | :'unit' => :'unit', 41 | :'value' => :'value' 42 | } 43 | end 44 | 45 | # Returns all the JSON keys this model knows about 46 | def self.acceptable_attributes 47 | attribute_map.values 48 | end 49 | 50 | # Attribute type mapping. 51 | def self.openapi_types 52 | { 53 | :'attributes' => :'Array', 54 | :'date' => :'String', 55 | :'key' => :'String', 56 | :'period_from' => :'String', 57 | :'period_to' => :'String', 58 | :'unit' => :'String', 59 | :'value' => :'Float' 60 | } 61 | end 62 | 63 | # List of attributes with nullable: true 64 | def self.openapi_nullable 65 | Set.new([ 66 | ]) 67 | end 68 | 69 | # Initializes the object 70 | # @param [Hash] attributes Model attributes in the form of hash 71 | def initialize(attributes = {}) 72 | if (!attributes.is_a?(Hash)) 73 | fail ArgumentError, "The input argument (attributes) must be a hash in `Databox::PushData` initialize method" 74 | end 75 | 76 | # check to see if the attribute exists and convert string to symbol for hash key 77 | attributes = attributes.each_with_object({}) { |(k, v), h| 78 | if (!self.class.attribute_map.key?(k.to_sym)) 79 | fail ArgumentError, "`#{k}` is not a valid attribute in `Databox::PushData`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect 80 | end 81 | h[k.to_sym] = v 82 | } 83 | 84 | if attributes.key?(:'attributes') 85 | if (value = attributes[:'attributes']).is_a?(Array) 86 | self.attributes = value 87 | end 88 | end 89 | 90 | if attributes.key?(:'date') 91 | self.date = attributes[:'date'] 92 | end 93 | 94 | if attributes.key?(:'key') 95 | self.key = attributes[:'key'] 96 | end 97 | 98 | if attributes.key?(:'period_from') 99 | self.period_from = attributes[:'period_from'] 100 | end 101 | 102 | if attributes.key?(:'period_to') 103 | self.period_to = attributes[:'period_to'] 104 | end 105 | 106 | if attributes.key?(:'unit') 107 | self.unit = attributes[:'unit'] 108 | end 109 | 110 | if attributes.key?(:'value') 111 | self.value = attributes[:'value'] 112 | end 113 | end 114 | 115 | # Show invalid properties with the reasons. Usually used together with valid? 116 | # @return Array for valid properties with the reasons 117 | def list_invalid_properties 118 | warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' 119 | invalid_properties = Array.new 120 | invalid_properties 121 | end 122 | 123 | # Check to see if the all the properties in the model are valid 124 | # @return true if the model is valid 125 | def valid? 126 | warn '[DEPRECATED] the `valid?` method is obsolete' 127 | true 128 | end 129 | 130 | # Checks equality by comparing each attribute. 131 | # @param [Object] Object to be compared 132 | def ==(o) 133 | return true if self.equal?(o) 134 | self.class == o.class && 135 | attributes == o.attributes && 136 | date == o.date && 137 | key == o.key && 138 | period_from == o.period_from && 139 | period_to == o.period_to && 140 | unit == o.unit && 141 | value == o.value 142 | end 143 | 144 | # @see the `==` method 145 | # @param [Object] Object to be compared 146 | def eql?(o) 147 | self == o 148 | end 149 | 150 | # Calculates hash code according to all attributes. 151 | # @return [Integer] Hash code 152 | def hash 153 | [attributes, date, key, period_from, period_to, unit, value].hash 154 | end 155 | 156 | # Builds the object from hash 157 | # @param [Hash] attributes Model attributes in the form of hash 158 | # @return [Object] Returns the model itself 159 | def self.build_from_hash(attributes) 160 | return nil unless attributes.is_a?(Hash) 161 | attributes = attributes.transform_keys(&:to_sym) 162 | transformed_hash = {} 163 | openapi_types.each_pair do |key, type| 164 | if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? 165 | transformed_hash["#{key}"] = nil 166 | elsif type =~ /\AArray<(.*)>/i 167 | # check to ensure the input is an array given that the attribute 168 | # is documented as an array but the input is not 169 | if attributes[attribute_map[key]].is_a?(Array) 170 | transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } 171 | end 172 | elsif !attributes[attribute_map[key]].nil? 173 | transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) 174 | end 175 | end 176 | new(transformed_hash) 177 | end 178 | 179 | # Deserializes the data based on type 180 | # @param string type Data type 181 | # @param string value Value to be deserialized 182 | # @return [Object] Deserialized data 183 | def self._deserialize(type, value) 184 | case type.to_sym 185 | when :Time 186 | Time.parse(value) 187 | when :Date 188 | Date.parse(value) 189 | when :String 190 | value.to_s 191 | when :Integer 192 | value.to_i 193 | when :Float 194 | value.to_f 195 | when :Boolean 196 | if value.to_s =~ /\A(true|t|yes|y|1)\z/i 197 | true 198 | else 199 | false 200 | end 201 | when :Object 202 | # generic object (usually a Hash), return directly 203 | value 204 | when /\AArray<(?.+)>\z/ 205 | inner_type = Regexp.last_match[:inner_type] 206 | value.map { |v| _deserialize(inner_type, v) } 207 | when /\AHash<(?.+?), (?.+)>\z/ 208 | k_type = Regexp.last_match[:k_type] 209 | v_type = Regexp.last_match[:v_type] 210 | {}.tap do |hash| 211 | value.each do |k, v| 212 | hash[_deserialize(k_type, k)] = _deserialize(v_type, v) 213 | end 214 | end 215 | else # model 216 | # models (e.g. Pet) or oneOf 217 | klass = Databox.const_get(type) 218 | klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) 219 | end 220 | end 221 | 222 | # Returns the string representation of the object 223 | # @return [String] String presentation of the object 224 | def to_s 225 | to_hash.to_s 226 | end 227 | 228 | # to_body is an alias to to_hash (backward compatibility) 229 | # @return [Hash] Returns the object in the form of hash 230 | def to_body 231 | to_hash 232 | end 233 | 234 | # Returns the object in the form of hash 235 | # @return [Hash] Returns the object in the form of hash 236 | def to_hash 237 | hash = {} 238 | self.class.attribute_map.each_pair do |attr, param| 239 | value = self.send(attr) 240 | if value.nil? 241 | is_nullable = self.class.openapi_nullable.include?(attr) 242 | next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) 243 | end 244 | 245 | hash[param] = _to_hash(value) 246 | end 247 | hash 248 | end 249 | 250 | # Outputs non-array value in the form of hash 251 | # For object, use to_hash. Otherwise, just return the value 252 | # @param [Object] value Any valid value 253 | # @return [Hash] Returns the value in the form of hash 254 | def _to_hash(value) 255 | if value.is_a?(Array) 256 | value.compact.map { |v| _to_hash(v) } 257 | elsif value.is_a?(Hash) 258 | {}.tap do |hash| 259 | value.each { |k, v| hash[k] = _to_hash(v) } 260 | end 261 | elsif value.respond_to? :to_hash 262 | value.to_hash 263 | else 264 | value 265 | end 266 | end 267 | 268 | end 269 | 270 | end 271 | -------------------------------------------------------------------------------- /src/docs/DefaultApi.md: -------------------------------------------------------------------------------- 1 | # Databox::DefaultApi 2 | 3 | All URIs are relative to *https://push.databox.com* 4 | 5 | | Method | HTTP request | Description | 6 | | ------ | ------------ | ----------- | 7 | | [**data_delete**](DefaultApi.md#data_delete) | **DELETE** /data | | 8 | | [**data_metric_key_delete**](DefaultApi.md#data_metric_key_delete) | **DELETE** /data/{metricKey} | | 9 | | [**data_post**](DefaultApi.md#data_post) | **POST** /data | | 10 | | [**metrickeys_get**](DefaultApi.md#metrickeys_get) | **GET** /metrickeys | | 11 | | [**metrickeys_post**](DefaultApi.md#metrickeys_post) | **POST** /metrickeys | | 12 | | [**ping_get**](DefaultApi.md#ping_get) | **GET** /ping | | 13 | 14 | 15 | ## data_delete 16 | 17 | > data_delete 18 | 19 | 20 | 21 | ### Examples 22 | 23 | ```ruby 24 | require 'time' 25 | require 'databox' 26 | # setup authorization 27 | Databox.configure do |config| 28 | # Configure HTTP basic authorization: basicAuth 29 | config.username = 'YOUR USERNAME' 30 | config.password = 'YOUR PASSWORD' 31 | end 32 | 33 | api_instance = Databox::DefaultApi.new 34 | 35 | begin 36 | 37 | api_instance.data_delete 38 | rescue Databox::ApiError => e 39 | puts "Error when calling DefaultApi->data_delete: #{e}" 40 | end 41 | ``` 42 | 43 | #### Using the data_delete_with_http_info variant 44 | 45 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 46 | 47 | > data_delete_with_http_info 48 | 49 | ```ruby 50 | begin 51 | 52 | data, status_code, headers = api_instance.data_delete_with_http_info 53 | p status_code # => 2xx 54 | p headers # => { ... } 55 | p data # => nil 56 | rescue Databox::ApiError => e 57 | puts "Error when calling DefaultApi->data_delete_with_http_info: #{e}" 58 | end 59 | ``` 60 | 61 | ### Parameters 62 | 63 | This endpoint does not need any parameter. 64 | 65 | ### Return type 66 | 67 | nil (empty response body) 68 | 69 | ### Authorization 70 | 71 | [basicAuth](../README.md#basicAuth) 72 | 73 | ### HTTP request headers 74 | 75 | - **Content-Type**: Not defined 76 | - **Accept**: Not defined 77 | 78 | 79 | ## data_metric_key_delete 80 | 81 | > data_metric_key_delete(metric_key) 82 | 83 | 84 | 85 | ### Examples 86 | 87 | ```ruby 88 | require 'time' 89 | require 'databox' 90 | # setup authorization 91 | Databox.configure do |config| 92 | # Configure HTTP basic authorization: basicAuth 93 | config.username = 'YOUR USERNAME' 94 | config.password = 'YOUR PASSWORD' 95 | end 96 | 97 | api_instance = Databox::DefaultApi.new 98 | metric_key = 'metric_key_example' # String | 99 | 100 | begin 101 | 102 | api_instance.data_metric_key_delete(metric_key) 103 | rescue Databox::ApiError => e 104 | puts "Error when calling DefaultApi->data_metric_key_delete: #{e}" 105 | end 106 | ``` 107 | 108 | #### Using the data_metric_key_delete_with_http_info variant 109 | 110 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 111 | 112 | > data_metric_key_delete_with_http_info(metric_key) 113 | 114 | ```ruby 115 | begin 116 | 117 | data, status_code, headers = api_instance.data_metric_key_delete_with_http_info(metric_key) 118 | p status_code # => 2xx 119 | p headers # => { ... } 120 | p data # => nil 121 | rescue Databox::ApiError => e 122 | puts "Error when calling DefaultApi->data_metric_key_delete_with_http_info: #{e}" 123 | end 124 | ``` 125 | 126 | ### Parameters 127 | 128 | | Name | Type | Description | Notes | 129 | | ---- | ---- | ----------- | ----- | 130 | | **metric_key** | **String** | | | 131 | 132 | ### Return type 133 | 134 | nil (empty response body) 135 | 136 | ### Authorization 137 | 138 | [basicAuth](../README.md#basicAuth) 139 | 140 | ### HTTP request headers 141 | 142 | - **Content-Type**: Not defined 143 | - **Accept**: Not defined 144 | 145 | 146 | ## data_post 147 | 148 | > data_post(opts) 149 | 150 | 151 | 152 | ### Examples 153 | 154 | ```ruby 155 | require 'time' 156 | require 'databox' 157 | # setup authorization 158 | Databox.configure do |config| 159 | # Configure HTTP basic authorization: basicAuth 160 | config.username = 'YOUR USERNAME' 161 | config.password = 'YOUR PASSWORD' 162 | end 163 | 164 | api_instance = Databox::DefaultApi.new 165 | opts = { 166 | push_data: [Databox::PushData.new] # Array | 167 | } 168 | 169 | begin 170 | 171 | api_instance.data_post(opts) 172 | rescue Databox::ApiError => e 173 | puts "Error when calling DefaultApi->data_post: #{e}" 174 | end 175 | ``` 176 | 177 | #### Using the data_post_with_http_info variant 178 | 179 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 180 | 181 | > data_post_with_http_info(opts) 182 | 183 | ```ruby 184 | begin 185 | 186 | data, status_code, headers = api_instance.data_post_with_http_info(opts) 187 | p status_code # => 2xx 188 | p headers # => { ... } 189 | p data # => nil 190 | rescue Databox::ApiError => e 191 | puts "Error when calling DefaultApi->data_post_with_http_info: #{e}" 192 | end 193 | ``` 194 | 195 | ### Parameters 196 | 197 | | Name | Type | Description | Notes | 198 | | ---- | ---- | ----------- | ----- | 199 | | **push_data** | [**Array<PushData>**](PushData.md) | | [optional] | 200 | 201 | ### Return type 202 | 203 | nil (empty response body) 204 | 205 | ### Authorization 206 | 207 | [basicAuth](../README.md#basicAuth) 208 | 209 | ### HTTP request headers 210 | 211 | - **Content-Type**: application/json, application/vnd.databox.v2+json 212 | - **Accept**: Not defined 213 | 214 | 215 | ## metrickeys_get 216 | 217 | > metrickeys_get 218 | 219 | 220 | 221 | ### Examples 222 | 223 | ```ruby 224 | require 'time' 225 | require 'databox' 226 | # setup authorization 227 | Databox.configure do |config| 228 | # Configure HTTP basic authorization: basicAuth 229 | config.username = 'YOUR USERNAME' 230 | config.password = 'YOUR PASSWORD' 231 | end 232 | 233 | api_instance = Databox::DefaultApi.new 234 | 235 | begin 236 | 237 | api_instance.metrickeys_get 238 | rescue Databox::ApiError => e 239 | puts "Error when calling DefaultApi->metrickeys_get: #{e}" 240 | end 241 | ``` 242 | 243 | #### Using the metrickeys_get_with_http_info variant 244 | 245 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 246 | 247 | > metrickeys_get_with_http_info 248 | 249 | ```ruby 250 | begin 251 | 252 | data, status_code, headers = api_instance.metrickeys_get_with_http_info 253 | p status_code # => 2xx 254 | p headers # => { ... } 255 | p data # => nil 256 | rescue Databox::ApiError => e 257 | puts "Error when calling DefaultApi->metrickeys_get_with_http_info: #{e}" 258 | end 259 | ``` 260 | 261 | ### Parameters 262 | 263 | This endpoint does not need any parameter. 264 | 265 | ### Return type 266 | 267 | nil (empty response body) 268 | 269 | ### Authorization 270 | 271 | [basicAuth](../README.md#basicAuth) 272 | 273 | ### HTTP request headers 274 | 275 | - **Content-Type**: Not defined 276 | - **Accept**: Not defined 277 | 278 | 279 | ## metrickeys_post 280 | 281 | > metrickeys_post(opts) 282 | 283 | 284 | 285 | ### Examples 286 | 287 | ```ruby 288 | require 'time' 289 | require 'databox' 290 | # setup authorization 291 | Databox.configure do |config| 292 | # Configure HTTP basic authorization: basicAuth 293 | config.username = 'YOUR USERNAME' 294 | config.password = 'YOUR PASSWORD' 295 | end 296 | 297 | api_instance = Databox::DefaultApi.new 298 | opts = { 299 | body: { ... } # Object | 300 | } 301 | 302 | begin 303 | 304 | api_instance.metrickeys_post(opts) 305 | rescue Databox::ApiError => e 306 | puts "Error when calling DefaultApi->metrickeys_post: #{e}" 307 | end 308 | ``` 309 | 310 | #### Using the metrickeys_post_with_http_info variant 311 | 312 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 313 | 314 | > metrickeys_post_with_http_info(opts) 315 | 316 | ```ruby 317 | begin 318 | 319 | data, status_code, headers = api_instance.metrickeys_post_with_http_info(opts) 320 | p status_code # => 2xx 321 | p headers # => { ... } 322 | p data # => nil 323 | rescue Databox::ApiError => e 324 | puts "Error when calling DefaultApi->metrickeys_post_with_http_info: #{e}" 325 | end 326 | ``` 327 | 328 | ### Parameters 329 | 330 | | Name | Type | Description | Notes | 331 | | ---- | ---- | ----------- | ----- | 332 | | **body** | **Object** | | [optional] | 333 | 334 | ### Return type 335 | 336 | nil (empty response body) 337 | 338 | ### Authorization 339 | 340 | [basicAuth](../README.md#basicAuth) 341 | 342 | ### HTTP request headers 343 | 344 | - **Content-Type**: application/json, application/vnd.databox.v2+json 345 | - **Accept**: Not defined 346 | 347 | 348 | ## ping_get 349 | 350 | > ping_get 351 | 352 | 353 | 354 | ### Examples 355 | 356 | ```ruby 357 | require 'time' 358 | require 'databox' 359 | # setup authorization 360 | Databox.configure do |config| 361 | # Configure HTTP basic authorization: basicAuth 362 | config.username = 'YOUR USERNAME' 363 | config.password = 'YOUR PASSWORD' 364 | end 365 | 366 | api_instance = Databox::DefaultApi.new 367 | 368 | begin 369 | 370 | api_instance.ping_get 371 | rescue Databox::ApiError => e 372 | puts "Error when calling DefaultApi->ping_get: #{e}" 373 | end 374 | ``` 375 | 376 | #### Using the ping_get_with_http_info variant 377 | 378 | This returns an Array which contains the response data (`nil` in this case), status code and headers. 379 | 380 | > ping_get_with_http_info 381 | 382 | ```ruby 383 | begin 384 | 385 | data, status_code, headers = api_instance.ping_get_with_http_info 386 | p status_code # => 2xx 387 | p headers # => { ... } 388 | p data # => nil 389 | rescue Databox::ApiError => e 390 | puts "Error when calling DefaultApi->ping_get_with_http_info: #{e}" 391 | end 392 | ``` 393 | 394 | ### Parameters 395 | 396 | This endpoint does not need any parameter. 397 | 398 | ### Return type 399 | 400 | nil (empty response body) 401 | 402 | ### Authorization 403 | 404 | [basicAuth](../README.md#basicAuth) 405 | 406 | ### HTTP request headers 407 | 408 | - **Content-Type**: Not defined 409 | - **Accept**: Not defined 410 | 411 | -------------------------------------------------------------------------------- /src/lib/databox/configuration.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | module Databox 14 | class Configuration 15 | # Defines url scheme 16 | attr_accessor :scheme 17 | 18 | # Defines url host 19 | attr_accessor :host 20 | 21 | # Defines url base path 22 | attr_accessor :base_path 23 | 24 | # Define server configuration index 25 | attr_accessor :server_index 26 | 27 | # Define server operation configuration index 28 | attr_accessor :server_operation_index 29 | 30 | # Default server variables 31 | attr_accessor :server_variables 32 | 33 | # Default server operation variables 34 | attr_accessor :server_operation_variables 35 | 36 | # Defines API keys used with API Key authentications. 37 | # 38 | # @return [Hash] key: parameter name, value: parameter value (API key) 39 | # 40 | # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string) 41 | # config.api_key['api_key'] = 'xxx' 42 | attr_accessor :api_key 43 | 44 | # Defines API key prefixes used with API Key authentications. 45 | # 46 | # @return [Hash] key: parameter name, value: API key prefix 47 | # 48 | # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers) 49 | # config.api_key_prefix['api_key'] = 'Token' 50 | attr_accessor :api_key_prefix 51 | 52 | # Defines the username used with HTTP basic authentication. 53 | # 54 | # @return [String] 55 | attr_accessor :username 56 | 57 | # Defines the password used with HTTP basic authentication. 58 | # 59 | # @return [String] 60 | attr_accessor :password 61 | 62 | # Defines the access token (Bearer) used with OAuth2. 63 | attr_accessor :access_token 64 | 65 | # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2. 66 | # Overrides the access_token if set 67 | # @return [Proc] 68 | attr_accessor :access_token_getter 69 | 70 | # Set this to return data as binary instead of downloading a temp file. When enabled (set to true) 71 | # HTTP responses with return type `File` will be returned as a stream of binary data. 72 | # Default to false. 73 | attr_accessor :return_binary_data 74 | 75 | # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response 76 | # details will be logged with `logger.debug` (see the `logger` attribute). 77 | # Default to false. 78 | # 79 | # @return [true, false] 80 | attr_accessor :debugging 81 | 82 | # Defines the logger used for debugging. 83 | # Default to `Rails.logger` (when in Rails) or logging to STDOUT. 84 | # 85 | # @return [#debug] 86 | attr_accessor :logger 87 | 88 | # Defines the temporary folder to store downloaded files 89 | # (for API endpoints that have file response). 90 | # Default to use `Tempfile`. 91 | # 92 | # @return [String] 93 | attr_accessor :temp_folder_path 94 | 95 | # The time limit for HTTP request in seconds. 96 | # Default to 0 (never times out). 97 | attr_accessor :timeout 98 | 99 | # Set this to false to skip client side validation in the operation. 100 | # Default to true. 101 | # @return [true, false] 102 | attr_accessor :client_side_validation 103 | 104 | ### TLS/SSL setting 105 | # Set this to false to skip verifying SSL certificate when calling API from https server. 106 | # Default to true. 107 | # 108 | # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. 109 | # 110 | # @return [true, false] 111 | attr_accessor :verify_ssl 112 | 113 | ### TLS/SSL setting 114 | # Set this to false to skip verifying SSL host name 115 | # Default to true. 116 | # 117 | # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. 118 | # 119 | # @return [true, false] 120 | attr_accessor :verify_ssl_host 121 | 122 | ### TLS/SSL setting 123 | # Set this to customize the certificate file to verify the peer. 124 | # 125 | # @return [String] the path to the certificate file 126 | # 127 | # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: 128 | # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 129 | attr_accessor :ssl_ca_cert 130 | 131 | ### TLS/SSL setting 132 | # Client certificate file (for client certificate) 133 | attr_accessor :cert_file 134 | 135 | ### TLS/SSL setting 136 | # Client private key file (for client certificate) 137 | attr_accessor :key_file 138 | 139 | # Set this to customize parameters encoding of array parameter with multi collectionFormat. 140 | # Default to nil. 141 | # 142 | # @see The params_encoding option of Ethon. Related source code: 143 | # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 144 | attr_accessor :params_encoding 145 | 146 | 147 | attr_accessor :inject_format 148 | 149 | attr_accessor :force_ending_format 150 | 151 | def initialize 152 | @scheme = 'https' 153 | @host = 'push.databox.com' 154 | @base_path = '' 155 | @server_index = nil 156 | @server_operation_index = {} 157 | @server_variables = {} 158 | @server_operation_variables = {} 159 | @api_key = {} 160 | @api_key_prefix = {} 161 | @client_side_validation = true 162 | @verify_ssl = true 163 | @verify_ssl_host = true 164 | @cert_file = nil 165 | @key_file = nil 166 | @timeout = 0 167 | @params_encoding = nil 168 | @debugging = false 169 | @inject_format = false 170 | @force_ending_format = false 171 | @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) 172 | 173 | yield(self) if block_given? 174 | end 175 | 176 | # The default Configuration object. 177 | def self.default 178 | @@default ||= Configuration.new 179 | end 180 | 181 | def configure 182 | yield(self) if block_given? 183 | end 184 | 185 | def scheme=(scheme) 186 | # remove :// from scheme 187 | @scheme = scheme.sub(/:\/\//, '') 188 | end 189 | 190 | def host=(host) 191 | # remove http(s):// and anything after a slash 192 | @host = host.sub(/https?:\/\//, '').split('/').first 193 | end 194 | 195 | def base_path=(base_path) 196 | # Add leading and trailing slashes to base_path 197 | @base_path = "/#{base_path}".gsub(/\/+/, '/') 198 | @base_path = '' if @base_path == '/' 199 | end 200 | 201 | # Returns base URL for specified operation based on server settings 202 | def base_url(operation = nil) 203 | if operation_server_settings.key?(operation) then 204 | index = server_operation_index.fetch(operation, server_index) 205 | server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation]) 206 | else 207 | server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil) 208 | end 209 | end 210 | 211 | # Gets API key (with prefix if set). 212 | # @param [String] param_name the parameter name of API key auth 213 | def api_key_with_prefix(param_name, param_alias = nil) 214 | key = @api_key[param_name] 215 | key = @api_key.fetch(param_alias, key) unless param_alias.nil? 216 | if @api_key_prefix[param_name] 217 | "#{@api_key_prefix[param_name]} #{key}" 218 | else 219 | key 220 | end 221 | end 222 | 223 | # Gets access_token using access_token_getter or uses the static access_token 224 | def access_token_with_refresh 225 | return access_token if access_token_getter.nil? 226 | access_token_getter.call 227 | end 228 | 229 | # Gets Basic Auth token string 230 | def basic_auth_token 231 | 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n") 232 | end 233 | 234 | # Returns Auth Settings hash for api client. 235 | def auth_settings 236 | { 237 | 'basicAuth' => 238 | { 239 | type: 'basic', 240 | in: 'header', 241 | key: 'Authorization', 242 | value: basic_auth_token 243 | }, 244 | } 245 | end 246 | 247 | # Returns an array of Server setting 248 | def server_settings 249 | [ 250 | { 251 | url: "https://push.databox.com", 252 | description: "Dev mode server description", 253 | } 254 | ] 255 | end 256 | 257 | def operation_server_settings 258 | { 259 | } 260 | end 261 | 262 | # Returns URL based on server settings 263 | # 264 | # @param index array index of the server settings 265 | # @param variables hash of variable and the corresponding value 266 | def server_url(index, variables = {}, servers = nil) 267 | servers = server_settings if servers == nil 268 | 269 | # check array index out of bound 270 | if (index.nil? || index < 0 || index >= servers.size) 271 | fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}" 272 | end 273 | 274 | server = servers[index] 275 | url = server[:url] 276 | 277 | return url unless server.key? :variables 278 | 279 | # go through variable and assign a value 280 | server[:variables].each do |name, variable| 281 | if variables.key?(name) 282 | if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])) 283 | url.gsub! "{" + name.to_s + "}", variables[name] 284 | else 285 | fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}." 286 | end 287 | else 288 | # use default value 289 | url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value] 290 | end 291 | end 292 | 293 | url 294 | end 295 | 296 | 297 | end 298 | end 299 | -------------------------------------------------------------------------------- /src/lib/databox/api/default_api.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'cgi' 14 | 15 | module Databox 16 | class DefaultApi 17 | attr_accessor :api_client 18 | 19 | def initialize(api_client = ApiClient.default) 20 | @api_client = api_client 21 | end 22 | # @param [Hash] opts the optional parameters 23 | # @return [nil] 24 | def data_delete(opts = {}) 25 | data_delete_with_http_info(opts) 26 | nil 27 | end 28 | 29 | # @param [Hash] opts the optional parameters 30 | # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers 31 | def data_delete_with_http_info(opts = {}) 32 | if @api_client.config.debugging 33 | @api_client.config.logger.debug 'Calling API: DefaultApi.data_delete ...' 34 | end 35 | # resource path 36 | local_var_path = '/data' 37 | 38 | # query parameters 39 | query_params = opts[:query_params] || {} 40 | 41 | # header parameters 42 | header_params = opts[:header_params] || {} 43 | 44 | # form parameters 45 | form_params = opts[:form_params] || {} 46 | 47 | # http body (model) 48 | post_body = opts[:debug_body] 49 | 50 | # return_type 51 | return_type = opts[:debug_return_type] 52 | 53 | # auth_names 54 | auth_names = opts[:debug_auth_names] || ['basicAuth'] 55 | 56 | new_options = opts.merge( 57 | :operation => :"DefaultApi.data_delete", 58 | :header_params => header_params, 59 | :query_params => query_params, 60 | :form_params => form_params, 61 | :body => post_body, 62 | :auth_names => auth_names, 63 | :return_type => return_type 64 | ) 65 | 66 | data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options) 67 | if @api_client.config.debugging 68 | @api_client.config.logger.debug "API called: DefaultApi#data_delete\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" 69 | end 70 | return data, status_code, headers 71 | end 72 | 73 | # @param metric_key [String] 74 | # @param [Hash] opts the optional parameters 75 | # @return [nil] 76 | def data_metric_key_delete(metric_key, opts = {}) 77 | data_metric_key_delete_with_http_info(metric_key, opts) 78 | nil 79 | end 80 | 81 | # @param metric_key [String] 82 | # @param [Hash] opts the optional parameters 83 | # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers 84 | def data_metric_key_delete_with_http_info(metric_key, opts = {}) 85 | if @api_client.config.debugging 86 | @api_client.config.logger.debug 'Calling API: DefaultApi.data_metric_key_delete ...' 87 | end 88 | # verify the required parameter 'metric_key' is set 89 | if @api_client.config.client_side_validation && metric_key.nil? 90 | fail ArgumentError, "Missing the required parameter 'metric_key' when calling DefaultApi.data_metric_key_delete" 91 | end 92 | # resource path 93 | local_var_path = '/data/{metricKey}'.sub('{' + 'metricKey' + '}', CGI.escape(metric_key.to_s)) 94 | 95 | # query parameters 96 | query_params = opts[:query_params] || {} 97 | 98 | # header parameters 99 | header_params = opts[:header_params] || {} 100 | 101 | # form parameters 102 | form_params = opts[:form_params] || {} 103 | 104 | # http body (model) 105 | post_body = opts[:debug_body] 106 | 107 | # return_type 108 | return_type = opts[:debug_return_type] 109 | 110 | # auth_names 111 | auth_names = opts[:debug_auth_names] || ['basicAuth'] 112 | 113 | new_options = opts.merge( 114 | :operation => :"DefaultApi.data_metric_key_delete", 115 | :header_params => header_params, 116 | :query_params => query_params, 117 | :form_params => form_params, 118 | :body => post_body, 119 | :auth_names => auth_names, 120 | :return_type => return_type 121 | ) 122 | 123 | data, status_code, headers = @api_client.call_api(:DELETE, local_var_path, new_options) 124 | if @api_client.config.debugging 125 | @api_client.config.logger.debug "API called: DefaultApi#data_metric_key_delete\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" 126 | end 127 | return data, status_code, headers 128 | end 129 | 130 | # @param [Hash] opts the optional parameters 131 | # @option opts [Array] :push_data 132 | # @return [nil] 133 | def data_post(opts = {}) 134 | data_post_with_http_info(opts) 135 | nil 136 | end 137 | 138 | # @param [Hash] opts the optional parameters 139 | # @option opts [Array] :push_data 140 | # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers 141 | def data_post_with_http_info(opts = {}) 142 | if @api_client.config.debugging 143 | @api_client.config.logger.debug 'Calling API: DefaultApi.data_post ...' 144 | end 145 | # resource path 146 | local_var_path = '/data' 147 | 148 | # query parameters 149 | query_params = opts[:query_params] || {} 150 | 151 | # header parameters 152 | header_params = opts[:header_params] || {} 153 | # HTTP header 'Content-Type' 154 | content_type = @api_client.select_header_content_type(['application/json', 'application/vnd.databox.v2+json']) 155 | if !content_type.nil? 156 | header_params['Content-Type'] = content_type 157 | end 158 | 159 | # form parameters 160 | form_params = opts[:form_params] || {} 161 | 162 | # http body (model) 163 | post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'push_data']) 164 | 165 | # return_type 166 | return_type = opts[:debug_return_type] 167 | 168 | # auth_names 169 | auth_names = opts[:debug_auth_names] || ['basicAuth'] 170 | 171 | new_options = opts.merge( 172 | :operation => :"DefaultApi.data_post", 173 | :header_params => header_params, 174 | :query_params => query_params, 175 | :form_params => form_params, 176 | :body => post_body, 177 | :auth_names => auth_names, 178 | :return_type => return_type 179 | ) 180 | 181 | data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) 182 | if @api_client.config.debugging 183 | @api_client.config.logger.debug "API called: DefaultApi#data_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" 184 | end 185 | return data, status_code, headers 186 | end 187 | 188 | # @param [Hash] opts the optional parameters 189 | # @return [nil] 190 | def metrickeys_get(opts = {}) 191 | metrickeys_get_with_http_info(opts) 192 | nil 193 | end 194 | 195 | # @param [Hash] opts the optional parameters 196 | # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers 197 | def metrickeys_get_with_http_info(opts = {}) 198 | if @api_client.config.debugging 199 | @api_client.config.logger.debug 'Calling API: DefaultApi.metrickeys_get ...' 200 | end 201 | # resource path 202 | local_var_path = '/metrickeys' 203 | 204 | # query parameters 205 | query_params = opts[:query_params] || {} 206 | 207 | # header parameters 208 | header_params = opts[:header_params] || {} 209 | 210 | # form parameters 211 | form_params = opts[:form_params] || {} 212 | 213 | # http body (model) 214 | post_body = opts[:debug_body] 215 | 216 | # return_type 217 | return_type = opts[:debug_return_type] 218 | 219 | # auth_names 220 | auth_names = opts[:debug_auth_names] || ['basicAuth'] 221 | 222 | new_options = opts.merge( 223 | :operation => :"DefaultApi.metrickeys_get", 224 | :header_params => header_params, 225 | :query_params => query_params, 226 | :form_params => form_params, 227 | :body => post_body, 228 | :auth_names => auth_names, 229 | :return_type => return_type 230 | ) 231 | 232 | data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) 233 | if @api_client.config.debugging 234 | @api_client.config.logger.debug "API called: DefaultApi#metrickeys_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" 235 | end 236 | return data, status_code, headers 237 | end 238 | 239 | # @param [Hash] opts the optional parameters 240 | # @option opts [Object] :body 241 | # @return [nil] 242 | def metrickeys_post(opts = {}) 243 | metrickeys_post_with_http_info(opts) 244 | nil 245 | end 246 | 247 | # @param [Hash] opts the optional parameters 248 | # @option opts [Object] :body 249 | # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers 250 | def metrickeys_post_with_http_info(opts = {}) 251 | if @api_client.config.debugging 252 | @api_client.config.logger.debug 'Calling API: DefaultApi.metrickeys_post ...' 253 | end 254 | # resource path 255 | local_var_path = '/metrickeys' 256 | 257 | # query parameters 258 | query_params = opts[:query_params] || {} 259 | 260 | # header parameters 261 | header_params = opts[:header_params] || {} 262 | # HTTP header 'Content-Type' 263 | content_type = @api_client.select_header_content_type(['application/json', 'application/vnd.databox.v2+json']) 264 | if !content_type.nil? 265 | header_params['Content-Type'] = content_type 266 | end 267 | 268 | # form parameters 269 | form_params = opts[:form_params] || {} 270 | 271 | # http body (model) 272 | post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'body']) 273 | 274 | # return_type 275 | return_type = opts[:debug_return_type] 276 | 277 | # auth_names 278 | auth_names = opts[:debug_auth_names] || ['basicAuth'] 279 | 280 | new_options = opts.merge( 281 | :operation => :"DefaultApi.metrickeys_post", 282 | :header_params => header_params, 283 | :query_params => query_params, 284 | :form_params => form_params, 285 | :body => post_body, 286 | :auth_names => auth_names, 287 | :return_type => return_type 288 | ) 289 | 290 | data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options) 291 | if @api_client.config.debugging 292 | @api_client.config.logger.debug "API called: DefaultApi#metrickeys_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" 293 | end 294 | return data, status_code, headers 295 | end 296 | 297 | # @param [Hash] opts the optional parameters 298 | # @return [nil] 299 | def ping_get(opts = {}) 300 | ping_get_with_http_info(opts) 301 | nil 302 | end 303 | 304 | # @param [Hash] opts the optional parameters 305 | # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers 306 | def ping_get_with_http_info(opts = {}) 307 | if @api_client.config.debugging 308 | @api_client.config.logger.debug 'Calling API: DefaultApi.ping_get ...' 309 | end 310 | # resource path 311 | local_var_path = '/ping' 312 | 313 | # query parameters 314 | query_params = opts[:query_params] || {} 315 | 316 | # header parameters 317 | header_params = opts[:header_params] || {} 318 | 319 | # form parameters 320 | form_params = opts[:form_params] || {} 321 | 322 | # http body (model) 323 | post_body = opts[:debug_body] 324 | 325 | # return_type 326 | return_type = opts[:debug_return_type] 327 | 328 | # auth_names 329 | auth_names = opts[:debug_auth_names] || ['basicAuth'] 330 | 331 | new_options = opts.merge( 332 | :operation => :"DefaultApi.ping_get", 333 | :header_params => header_params, 334 | :query_params => query_params, 335 | :form_params => form_params, 336 | :body => post_body, 337 | :auth_names => auth_names, 338 | :return_type => return_type 339 | ) 340 | 341 | data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options) 342 | if @api_client.config.debugging 343 | @api_client.config.logger.debug "API called: DefaultApi#ping_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" 344 | end 345 | return data, status_code, headers 346 | end 347 | end 348 | end 349 | -------------------------------------------------------------------------------- /src/lib/databox/api_client.rb: -------------------------------------------------------------------------------- 1 | =begin 2 | #Static OpenAPI document of Push API resource 3 | 4 | #Push API resources Open API documentation 5 | 6 | The version of the OpenAPI document: 0.4.1 7 | 8 | Generated by: https://openapi-generator.tech 9 | Generator version: 7.6.0 10 | 11 | =end 12 | 13 | require 'date' 14 | require 'json' 15 | require 'logger' 16 | require 'tempfile' 17 | require 'time' 18 | require 'typhoeus' 19 | 20 | 21 | module Databox 22 | class ApiClient 23 | # The Configuration object holding settings to be used in the API client. 24 | attr_accessor :config 25 | 26 | # Defines the headers to be used in HTTP requests of all API calls by default. 27 | # 28 | # @return [Hash] 29 | attr_accessor :default_headers 30 | 31 | # Initializes the ApiClient 32 | # @option config [Configuration] Configuration for initializing the object, default to Configuration.default 33 | def initialize(config = Configuration.default) 34 | @config = config 35 | @user_agent = "OpenAPI-Generator/#{VERSION}/ruby" 36 | @default_headers = { 37 | 'Content-Type' => 'application/json', 38 | 'User-Agent' => @user_agent 39 | } 40 | end 41 | 42 | def self.default 43 | @@default ||= ApiClient.new 44 | end 45 | 46 | # Call an API with given options. 47 | # 48 | # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: 49 | # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers. 50 | def call_api(http_method, path, opts = {}) 51 | request = build_request(http_method, path, opts) 52 | tempfile = download_file(request) if opts[:return_type] == 'File' 53 | response = request.run 54 | 55 | if @config.debugging 56 | @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" 57 | end 58 | 59 | unless response.success? 60 | if response.timed_out? 61 | fail ApiError.new('Connection timed out') 62 | elsif response.code == 0 63 | # Errors from libcurl will be made visible here 64 | fail ApiError.new(:code => 0, 65 | :message => response.return_message) 66 | else 67 | fail ApiError.new(:code => response.code, 68 | :response_headers => response.headers, 69 | :response_body => response.body), 70 | response.status_message 71 | end 72 | end 73 | 74 | if opts[:return_type] == 'File' 75 | data = tempfile 76 | elsif opts[:return_type] 77 | data = deserialize(response, opts[:return_type]) 78 | else 79 | data = nil 80 | end 81 | return data, response.code, response.headers 82 | end 83 | 84 | # Builds the HTTP request 85 | # 86 | # @param [String] http_method HTTP method/verb (e.g. POST) 87 | # @param [String] path URL path (e.g. /account/new) 88 | # @option opts [Hash] :header_params Header parameters 89 | # @option opts [Hash] :query_params Query parameters 90 | # @option opts [Hash] :form_params Query parameters 91 | # @option opts [Object] :body HTTP body (JSON/XML) 92 | # @return [Typhoeus::Request] A Typhoeus Request 93 | def build_request(http_method, path, opts = {}) 94 | url = build_request_url(path, opts) 95 | http_method = http_method.to_sym.downcase 96 | 97 | header_params = @default_headers.merge(opts[:header_params] || {}) 98 | query_params = opts[:query_params] || {} 99 | form_params = opts[:form_params] || {} 100 | follow_location = opts[:follow_location] || true 101 | 102 | update_params_for_auth! header_params, query_params, opts[:auth_names] 103 | 104 | # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) 105 | _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 106 | 107 | req_opts = { 108 | :method => http_method, 109 | :headers => header_params, 110 | :params => query_params, 111 | :params_encoding => @config.params_encoding, 112 | :timeout => @config.timeout, 113 | :ssl_verifypeer => @config.verify_ssl, 114 | :ssl_verifyhost => _verify_ssl_host, 115 | :sslcert => @config.cert_file, 116 | :sslkey => @config.key_file, 117 | :verbose => @config.debugging, 118 | :followlocation => follow_location 119 | } 120 | 121 | # set custom cert, if provided 122 | req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert 123 | 124 | if [:post, :patch, :put, :delete].include?(http_method) 125 | req_body = build_request_body(header_params, form_params, opts[:body]) 126 | req_opts.update :body => req_body 127 | if @config.debugging 128 | @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" 129 | end 130 | end 131 | 132 | Typhoeus::Request.new(url, req_opts) 133 | end 134 | 135 | # Builds the HTTP request body 136 | # 137 | # @param [Hash] header_params Header parameters 138 | # @param [Hash] form_params Query parameters 139 | # @param [Object] body HTTP body (JSON/XML) 140 | # @return [String] HTTP body data in the form of string 141 | def build_request_body(header_params, form_params, body) 142 | # http form 143 | if header_params['Content-Type'] == 'application/x-www-form-urlencoded' || 144 | header_params['Content-Type'] == 'multipart/form-data' 145 | data = {} 146 | form_params.each do |key, value| 147 | case value 148 | when ::File, ::Array, nil 149 | # let typhoeus handle File, Array and nil parameters 150 | data[key] = value 151 | else 152 | data[key] = value.to_s 153 | end 154 | end 155 | elsif body 156 | data = body.is_a?(String) ? body : body.to_json 157 | else 158 | data = nil 159 | end 160 | data 161 | end 162 | 163 | # Save response body into a file in (the defined) temporary folder, using the filename 164 | # from the "Content-Disposition" header if provided, otherwise a random filename. 165 | # The response body is written to the file in chunks in order to handle files which 166 | # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby 167 | # process can use. 168 | # 169 | # @see Configuration#temp_folder_path 170 | # 171 | # @return [Tempfile] the tempfile generated 172 | def download_file(request) 173 | tempfile = nil 174 | encoding = nil 175 | request.on_headers do |response| 176 | content_disposition = response.headers['Content-Disposition'] 177 | if content_disposition && content_disposition =~ /filename=/i 178 | filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] 179 | prefix = sanitize_filename(filename) 180 | else 181 | prefix = 'download-' 182 | end 183 | prefix = prefix + '-' unless prefix.end_with?('-') 184 | encoding = response.body.encoding 185 | tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) 186 | end 187 | request.on_body do |chunk| 188 | chunk.force_encoding(encoding) 189 | tempfile.write(chunk) 190 | end 191 | # run the request to ensure the tempfile is created successfully before returning it 192 | request.run 193 | if tempfile 194 | tempfile.close 195 | @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\ 196 | "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\ 197 | "will be deleted automatically with GC. It's also recommended to delete the temp file "\ 198 | "explicitly with `tempfile.delete`" 199 | else 200 | fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}") 201 | end 202 | 203 | tempfile 204 | end 205 | 206 | # Check if the given MIME is a JSON MIME. 207 | # JSON MIME examples: 208 | # application/json 209 | # application/json; charset=UTF8 210 | # APPLICATION/JSON 211 | # */* 212 | # @param [String] mime MIME 213 | # @return [Boolean] True if the MIME is application/json 214 | def json_mime?(mime) 215 | (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil? 216 | end 217 | 218 | # Deserialize the response to the given return type. 219 | # 220 | # @param [Response] response HTTP response 221 | # @param [String] return_type some examples: "User", "Array", "Hash" 222 | def deserialize(response, return_type) 223 | body = response.body 224 | return nil if body.nil? || body.empty? 225 | 226 | # return response body directly for String return type 227 | return body.to_s if return_type == 'String' 228 | 229 | # ensuring a default content type 230 | content_type = response.headers['Content-Type'] || 'application/json' 231 | 232 | fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) 233 | 234 | begin 235 | data = JSON.parse("[#{body}]", :symbolize_names => true)[0] 236 | rescue JSON::ParserError => e 237 | if %w(String Date Time).include?(return_type) 238 | data = body 239 | else 240 | raise e 241 | end 242 | end 243 | 244 | convert_to_type data, return_type 245 | end 246 | 247 | # Convert data to the given return type. 248 | # @param [Object] data Data to be converted 249 | # @param [String] return_type Return type 250 | # @return [Mixed] Data in a particular type 251 | def convert_to_type(data, return_type) 252 | return nil if data.nil? 253 | case return_type 254 | when 'String' 255 | data.to_s 256 | when 'Integer' 257 | data.to_i 258 | when 'Float' 259 | data.to_f 260 | when 'Boolean' 261 | data == true 262 | when 'Time' 263 | # parse date time (expecting ISO 8601 format) 264 | Time.parse data 265 | when 'Date' 266 | # parse date time (expecting ISO 8601 format) 267 | Date.parse data 268 | when 'Object' 269 | # generic object (usually a Hash), return directly 270 | data 271 | when /\AArray<(.+)>\z/ 272 | # e.g. Array 273 | sub_type = $1 274 | data.map { |item| convert_to_type(item, sub_type) } 275 | when /\AHash\\z/ 276 | # e.g. Hash 277 | sub_type = $1 278 | {}.tap do |hash| 279 | data.each { |k, v| hash[k] = convert_to_type(v, sub_type) } 280 | end 281 | else 282 | # models (e.g. Pet) or oneOf 283 | klass = Databox.const_get(return_type) 284 | klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data) 285 | end 286 | end 287 | 288 | # Sanitize filename by removing path. 289 | # e.g. ../../sun.gif becomes sun.gif 290 | # 291 | # @param [String] filename the filename to be sanitized 292 | # @return [String] the sanitized filename 293 | def sanitize_filename(filename) 294 | filename.split(/[\/\\]/).last 295 | end 296 | 297 | def build_request_url(path, opts = {}) 298 | # Add leading and trailing slashes to path 299 | path = "/#{path}".gsub(/\/+/, '/') 300 | @config.base_url(opts[:operation]) + path 301 | end 302 | 303 | # Update header and query params based on authentication settings. 304 | # 305 | # @param [Hash] header_params Header parameters 306 | # @param [Hash] query_params Query parameters 307 | # @param [String] auth_names Authentication scheme name 308 | def update_params_for_auth!(header_params, query_params, auth_names) 309 | Array(auth_names).each do |auth_name| 310 | auth_setting = @config.auth_settings[auth_name] 311 | next unless auth_setting 312 | case auth_setting[:in] 313 | when 'header' then header_params[auth_setting[:key]] = auth_setting[:value] 314 | when 'query' then query_params[auth_setting[:key]] = auth_setting[:value] 315 | else fail ArgumentError, 'Authentication token must be in `query` or `header`' 316 | end 317 | end 318 | end 319 | 320 | # Sets user agent in HTTP header 321 | # 322 | # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0) 323 | def user_agent=(user_agent) 324 | @user_agent = user_agent 325 | @default_headers['User-Agent'] = @user_agent 326 | end 327 | 328 | # Return Accept header based on an array of accepts provided. 329 | # @param [Array] accepts array for Accept 330 | # @return [String] the Accept header (e.g. application/json) 331 | def select_header_accept(accepts) 332 | return nil if accepts.nil? || accepts.empty? 333 | # use JSON when present, otherwise use all of the provided 334 | json_accept = accepts.find { |s| json_mime?(s) } 335 | json_accept || accepts.join(',') 336 | end 337 | 338 | # Return Content-Type header based on an array of content types provided. 339 | # @param [Array] content_types array for Content-Type 340 | # @return [String] the Content-Type header (e.g. application/json) 341 | def select_header_content_type(content_types) 342 | # return nil by default 343 | return if content_types.nil? || content_types.empty? 344 | # use JSON when present, otherwise use the first one 345 | json_content_type = content_types.find { |s| json_mime?(s) } 346 | json_content_type || content_types.first 347 | end 348 | 349 | # Convert object (array, hash, object, etc) to JSON string. 350 | # @param [Object] model object to be converted into JSON string 351 | # @return [String] JSON string representation of the object 352 | def object_to_http_body(model) 353 | return model if model.nil? || model.is_a?(String) 354 | local_body = nil 355 | if model.is_a?(Array) 356 | local_body = model.map { |m| object_to_hash(m) } 357 | else 358 | local_body = object_to_hash(model) 359 | end 360 | local_body.to_json 361 | end 362 | 363 | # Convert object(non-array) to hash. 364 | # @param [Object] obj object to be converted into JSON string 365 | # @return [String] JSON string representation of the object 366 | def object_to_hash(obj) 367 | if obj.respond_to?(:to_hash) 368 | obj.to_hash 369 | else 370 | obj 371 | end 372 | end 373 | 374 | # Build parameter value according to the given collection format. 375 | # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi 376 | def build_collection_param(param, collection_format) 377 | case collection_format 378 | when :csv 379 | param.join(',') 380 | when :ssv 381 | param.join(' ') 382 | when :tsv 383 | param.join("\t") 384 | when :pipes 385 | param.join('|') 386 | when :multi 387 | # return the array directly as typhoeus will handle it as expected 388 | param 389 | else 390 | fail "unknown collection format: #{collection_format.inspect}" 391 | end 392 | end 393 | end 394 | end 395 | --------------------------------------------------------------------------------