Skip to content

Commit

Permalink
Class structure (influxdata#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar authored Dec 9, 2019
1 parent a4cd75b commit 6fd7a4d
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ commands:
- restore_cache:
name: Restoring Gem Cache
keys:
- &cache-key gem-cache-{{ checksum "influxdb_client.gemspec" }}
- &cache-key gem-cache-{{ checksum "influxdb.gemspec" }}
- gem-cache-
- run:
name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Metrics/LineLength:
Max: 120
22 changes: 21 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

source 'https://rubygems.org'

# Specify your gem's dependencies in influxdb_client.gemspec
# Specify your gem's dependencies in influxdb-client.gemspec
gemspec
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@ This repository contains the reference Ruby client for the InfluxDB 2.0.

## Installation

Add this line to your application's Gemfile:
The InfluxDB 2 client is bundled as a gem and is hosted on [Rubygems](https://rubygems.org/gems/mongo).

```ruby
gem 'influxdb_client'
```

And then execute:
### Install the Gem

$ bundle
The client can be installed manually or with bundler.

Or install it yourself as:
To install the client gem manually:

$ gem install influxdb_client
```
gem install influxdb_client -v 1.0.0.alpha
```

## Usage

TODO: Write usage instructions here
### Creating a client

Use **InfluxDB::Client** to create a client connected to a running InfluxDB 2 instance.

```ruby
client = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')
```

## Contributing

Expand Down
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'bundler/gem_tasks'
require 'rake/testtask'
require 'rubocop/rake_task'
Expand Down
26 changes: 23 additions & 3 deletions influxdb_client.gemspec → influxdb-client.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'influxdb_client/version'
require 'influxdb/client/version'

Gem::Specification.new do |spec|
spec.name = 'influxdb_client'
spec.version = InfluxDBClient::VERSION
spec.name = 'influxdb-client'
spec.version = InfluxDB::VERSION
spec.authors = ['Jakub Bednar']
spec.email = ['jakub.bednar@gmail.com']

Expand Down
23 changes: 23 additions & 0 deletions lib/influxdb/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'influxdb/client/version'
require 'influxdb/client/client'
require 'influxdb/client/write_api'
59 changes: 59 additions & 0 deletions lib/influxdb/client/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module InfluxDB
# The client is the entry point to HTTP API defined
# in https://github.com/influxdata/influxdb/blob/master/http/swagger.yml.
class Client
# @return [ Hash ] options The configuration options.
attr_reader :options

# Instantiate a new InfluxDB client.
#
# @example Instantiate a client.
# InfluxDBClient::Client.new(url: 'http://localhost:9999', token: 'my-token')
#
# @param [String] url InfluxDB server API url (ex. http://localhost:9999).
# @param [String] token authentication token
def initialize(options = nil, url:, token:)
@options = options ? options.dup : {}
@options[:url] = url if url.is_a? String
@options[:token] = token if token.is_a? String
@closed = false

at_exit { close }
end

# Write time series data into InfluxDB thought WriteApi.
#
# @return [WriteApi] New instance of WriteApi.
def create_write_api
WriteApi.new
end

# Close all connections into InfluxDB 2.
#
# @return [ true ] Always true.
def close
@closed = true
true
end
end
end
23 changes: 23 additions & 0 deletions lib/influxdb/client/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module InfluxDB
VERSION = '1.0.0.alpha'.freeze
end
26 changes: 26 additions & 0 deletions lib/influxdb/client/write_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

module InfluxDB
# Write time series data into InfluxDB.
#
class WriteApi
end
end
6 changes: 0 additions & 6 deletions lib/influxdb_client.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/influxdb_client/version.rb

This file was deleted.

11 changes: 0 additions & 11 deletions test/influx_db_client_test.rb

This file was deleted.

70 changes: 70 additions & 0 deletions test/influxdb/client_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'test_helper'

class ClientTest < Minitest::Test
def test_defined_version_number
refute_nil ::InfluxDB::VERSION
end

def test_client_new
refute_nil InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')
end

def test_client_hash
client1 = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')
client2 = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token-diff')

refute_equal client1.hash, client2.hash
assert_equal client1.hash, client1.hash
end

def test_client_eq
client1 = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')
client2 = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token-diff')

refute_equal client1, client2
assert_equal client1, client1
end

def test_client_options
client = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')

assert_equal 'http://localhost:9999', client.options[:url]
assert_equal 'my-token', client.options[:token]
end

def test_close
client = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')

assert_equal true, client.close
assert_equal true, client.close
end

def test_get_write_api
client = InfluxDB::Client.new(url: 'http://localhost:9999', token: 'my-token')

write_api = client.create_write_api

refute_nil write_api
assert_instance_of InfluxDB::WriteApi, write_api
end
end
22 changes: 21 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# The MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

require 'simplecov'
SimpleCov.start

Expand All @@ -7,7 +27,7 @@
end

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'influxdb_client'
require 'influxdb/client'

require 'minitest/autorun'
require 'minitest/reporters'
Expand Down

0 comments on commit 6fd7a4d

Please sign in to comment.