feat(clientLibs): add Ruby client library to Client Page (#16617)

* doc(clientLibs): add actual version of Java client

* feat(clientLibs): add Ruby client library

* feat(clientLibs): add Ruby client library

Co-authored-by: Russ Savage <russorat@users.noreply.github.com>
pull/16656/head
Jakub Bednář 2020-01-23 23:32:32 +01:00 committed by Russ Savage
parent 94b13f1532
commit ee85eec6a1
3 changed files with 171 additions and 2 deletions

View File

@ -0,0 +1,125 @@
// Libraries
import React, {FunctionComponent} from 'react'
import {connect} from 'react-redux'
// Components
import ClientLibraryOverlay from 'src/clientLibraries/components/ClientLibraryOverlay'
import TemplatedCodeSnippet from 'src/shared/components/TemplatedCodeSnippet'
// Constants
import {clientRubyLibrary} from 'src/clientLibraries/constants'
// Selectors
import {getOrg} from 'src/organizations/selectors'
// Types
import {AppState} from 'src/types'
interface StateProps {
org: string
}
type Props = StateProps
const ClientRubyOverlay: FunctionComponent<Props> = props => {
const {
name,
url,
initializeGemCodeSnippet,
initializeClientCodeSnippet,
writingDataLineProtocolCodeSnippet,
writingDataPointCodeSnippet,
writingDataHashCodeSnippet,
writingDataBatchCodeSnippet,
} = clientRubyLibrary
const {org} = props
const server = window.location.origin
return (
<ClientLibraryOverlay title={`${name} Client Library`}>
<p>
For more detailed and up to date information check out the{' '}
<a href={url} target="_blank">
GitHub Repository
</a>
</p>
<h5>Install the Gem</h5>
<TemplatedCodeSnippet template={initializeGemCodeSnippet} label="Code" />
<h5>Initialize the Client</h5>
<TemplatedCodeSnippet
template={initializeClientCodeSnippet}
label="Ruby Code"
defaults={{
server: 'serverUrl',
token: 'token',
}}
values={{
server,
}}
/>
<h5>Write Data</h5>
<p>Option 1: Use InfluxDB Line Protocol to write data</p>
<TemplatedCodeSnippet
template={writingDataLineProtocolCodeSnippet}
label="Ruby Code"
defaults={{
bucket: 'bucketID',
org: 'orgID',
}}
values={{
org,
}}
/>
<p>Option 2: Use a Data Point to write data</p>
<TemplatedCodeSnippet
template={writingDataPointCodeSnippet}
label="Ruby Code"
defaults={{
bucket: 'bucketID',
org: 'orgID',
}}
values={{
org,
}}
/>
<p>Option 3: Use a Hash to write data</p>
<TemplatedCodeSnippet
template={writingDataHashCodeSnippet}
label="Ruby Code"
defaults={{
bucket: 'bucketID',
org: 'orgID',
}}
values={{
org,
}}
/>
<p>Option 4: Use a Batch Sequence to write data</p>
<TemplatedCodeSnippet
template={writingDataBatchCodeSnippet}
label="Ruby Code"
defaults={{
bucket: 'bucketID',
org: 'orgID',
}}
values={{
org,
}}
/>
</ClientLibraryOverlay>
)
}
const mstp = (state: AppState): StateProps => {
const {id} = getOrg(state)
return {
org: id,
}
}
export {ClientRubyOverlay}
export default connect<StateProps, {}, Props>(
mstp,
null
)(ClientRubyOverlay)

View File

@ -4,6 +4,7 @@ import GoLogo from '../graphics/GoLogo'
import JavaLogo from '../graphics/JavaLogo'
import JSLogo from '../graphics/JSLogo'
import PythonLogo from '../graphics/PythonLogo'
import RubyLogo from '../graphics/RubyLogo'
export interface ClientLibrary {
id: string
@ -107,10 +108,10 @@ export const clientJavaLibrary = {
buildWithMavenCodeSnippet: `<dependency>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client-java</artifactId>
<version>1.1.0</version>
<version>1.4.0</version>
</dependency>`,
buildWithGradleCodeSnippet: `dependencies {
compile "com.influxdb:influxdb-client-java:1.1.0"
compile "com.influxdb:influxdb-client-java:1.4.0"
}`,
initializeClientCodeSnippet: `package example;
@ -198,10 +199,48 @@ write_client.write("<%= bucket %>", "<%= org %>", point)`,
write_client.write("<%= bucket %>", "<%= org %>", sequence)`,
}
export const clientRubyLibrary = {
id: 'ruby',
name: 'Ruby',
url: 'https://github.com/influxdata/influxdb-client-ruby',
image: RubyLogo,
initializeGemCodeSnippet: `gem install influxdb-client -v 1.0.0.beta`,
initializeClientCodeSnippet: `## You can generate a Token from the "Tokens Tab" in the UI
client = InfluxDB2::Client.new('<%= server %>', '<%= token %>')`,
writingDataLineProtocolCodeSnippet: `data = 'mem,host=host1 used_percent=23.43234543 1556896326'
write_client.write(data: data, bucket: '<%= bucket %>', org: '<%= org %>')`,
writingDataPointCodeSnippet: `point = InfluxDB2::Point.new(name: 'mem')
.add_tag('host', 'host1')
.add_field('used_percent', 23.43234543)
.time(1_556_896_326, WritePrecision.NS)
write_client.write(data: point, bucket: '<%= bucket %>', org: '<%= org %>')`,
writingDataHashCodeSnippet: `hash = { name: 'h2o',
tags: { host: 'aws', region: 'us' },
fields: { level: 5, saturation: '99%' },
time: 123 }
write_client.write(data: hash, bucket: '<%= bucket %>', org: '<%= org %>')`,
writingDataBatchCodeSnippet: `point = InfluxDB2::Point.new(name: 'mem')
.add_tag('host', 'host1')
.add_field('used_percent', 23.43234543)
.time(1_556_896_326, WritePrecision.NS)
hash = { name: 'h2o',
tags: { host: 'aws', region: 'us' },
fields: { level: 5, saturation: '99%' },
time: 123 }
data = 'mem,host=host1 used_percent=23.43234543 1556896326'
write_client.write(data: [point, hash, data], bucket: '<%= bucket %>', org: '<%= org %>')`,
}
export const clientLibraries: ClientLibrary[] = [
clientCSharpLibrary,
clientGoLibrary,
clientJavaLibrary,
clientJSLibrary,
clientPythonLibrary,
clientRubyLibrary,
]

View File

@ -52,6 +52,7 @@ import ClientGoOverlay from 'src/clientLibraries/components/ClientGoOverlay'
import ClientJavaOverlay from 'src/clientLibraries/components/ClientJavaOverlay'
import ClientJSOverlay from 'src/clientLibraries/components/ClientJSOverlay'
import ClientPythonOverlay from 'src/clientLibraries/components/ClientPythonOverlay'
import ClientRubyOverlay from 'src/clientLibraries/components/ClientRubyOverlay'
import TemplateImportOverlay from 'src/templates/components/TemplateImportOverlay'
import TemplateExportOverlay from 'src/templates/components/TemplateExportOverlay'
import VariablesIndex from 'src/variables/containers/VariablesIndex'
@ -349,6 +350,10 @@ class Root extends PureComponent {
path="python"
component={ClientPythonOverlay}
/>
<Route
path="ruby"
component={ClientRubyOverlay}
/>
</Route>
</Route>
<Route path="settings">