├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ └── lintest.yml ├── .gitignore ├── .golangci.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Earthfile ├── LICENSE ├── README.md ├── administration ├── administration.go └── administration_test.go ├── client.go ├── client_options.go ├── common └── random │ └── random.go ├── datasources ├── data_sources.go └── data_sources_test.go ├── doc.go ├── docs └── static │ └── img │ ├── api-key-0.png │ └── api-key-1.png ├── gen ├── client │ ├── administration │ │ ├── administration_client.go │ │ ├── get_ping_parameters.go │ │ └── get_ping_responses.go │ ├── data_sources │ │ ├── data_sources_client.go │ │ ├── delete_data_sources_id_parameters.go │ │ ├── delete_data_sources_id_responses.go │ │ ├── get_data_sources_id_parameters.go │ │ ├── get_data_sources_id_responses.go │ │ ├── list_parameters.go │ │ ├── list_responses.go │ │ ├── post_data_sources_id_parameters.go │ │ ├── post_data_sources_id_responses.go │ │ ├── post_data_sources_parameters.go │ │ └── post_data_sources_responses.go │ ├── queries │ │ ├── delete_queries_id_parameters.go │ │ ├── delete_queries_id_responses.go │ │ ├── get_queries_id_parameters.go │ │ ├── get_queries_id_responses.go │ │ ├── get_queries_id_results_parameters.go │ │ ├── get_queries_id_results_responses.go │ │ ├── get_queries_parameters.go │ │ ├── get_queries_responses.go │ │ ├── post_queries_id_parameters.go │ │ ├── post_queries_id_regenerate_api_key_parameters.go │ │ ├── post_queries_id_regenerate_api_key_responses.go │ │ ├── post_queries_id_responses.go │ │ ├── post_queries_id_results_parameters.go │ │ ├── post_queries_id_results_responses.go │ │ ├── post_queries_parameters.go │ │ ├── post_queries_responses.go │ │ └── queries_client.go │ ├── redashclient_client.go │ ├── users │ │ ├── get_users_id_parameters.go │ │ ├── get_users_id_responses.go │ │ └── users_client.go │ └── visualizations │ │ ├── delete_visualizations_id_parameters.go │ │ ├── delete_visualizations_id_responses.go │ │ ├── post_visualizations_parameters.go │ │ ├── post_visualizations_responses.go │ │ └── visualizations_client.go └── models │ ├── data_source.go │ ├── error.go │ ├── job_result.go │ ├── query.go │ ├── query_list.go │ ├── query_result.go │ ├── schedule.go │ ├── user.go │ └── visualization.go ├── go.mod ├── go.sum ├── mocks ├── administration │ ├── ClientOption.go │ └── ClientService.go ├── data_sources │ ├── ClientOption.go │ └── ClientService.go ├── queries │ ├── ClientOption.go │ └── ClientService.go ├── users │ ├── ClientOption.go │ └── ClientService.go └── visualizations │ ├── ClientOption.go │ └── ClientService.go ├── options ├── options.go └── options_test.go ├── queries ├── queries.go └── queries_test.go ├── scripts └── generate_client.sh ├── swagger.yaml ├── users ├── users.go └── users_test.go └── visualizations ├── visualizations.go └── visualizations_test.go /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve. 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Describe the bug 11 | A clear and concise description of what the bug is. 12 | 13 | ## To Reproduce 14 | 15 | Steps to reproduce the behavior: 16 | 17 | 1. Go to '...' 18 | 2. Click on '....' 19 | 3. Scroll down to '....' 20 | 4. See error 21 | 22 | ## Expected behavior 23 | 24 | A clear and concise description of what you expected to happen. 25 | 26 | ## 27 | 28 | If applicable, add screenshots to help explain your problem. 29 | 30 | ## Environment data (please complete the following information) 31 | - Redash Version: [e.g. `10.1.0`] 32 | 33 | ## Additional context 34 | 35 | Add any other context about the problem here. 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | Fixes #. 4 | 5 | ## Proposed Changes 6 | 7 | PUT THE PROPOSED CHANGE HERE. 8 | 9 | ## Checklist 10 | 11 | - [ ] Does it work? Share logs/screenshots if relevant. 12 | - [ ] Does CI pass? 13 | - [ ] Have you read the contribution guide? 14 | -------------------------------------------------------------------------------- /.github/workflows/lintest.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | 11 | lintest: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Download latest earthly 17 | run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.6.4/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" 18 | 19 | - name: Earthly version 20 | run: earthly --version 21 | 22 | - name: Run lintest 23 | run: earthly --strict +lintest # Can't use --ci because we want output 24 | 25 | - name: Check Earthly local output 26 | run: ls -la . 27 | 28 | - uses: codecov/codecov-action@v2 29 | with: 30 | fail_ci_if_error: true 31 | verbose: true 32 | 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | coverage.xml 14 | 15 | # Dependency directories (remove the comment below to include it) 16 | # vendor/ 17 | 18 | .idea/ 19 | *.swp 20 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | linters-settings: 2 | dupl: 3 | threshold: 100 4 | funlen: 5 | lines: 100 6 | statements: 50 7 | gci: 8 | local-prefixes: github.com/golangci/golangci-lint 9 | goconst: 10 | min-len: 2 11 | min-occurrences: 2 12 | gocritic: 13 | enabled-tags: 14 | - diagnostic 15 | - experimental 16 | - opinionated 17 | - performance 18 | - style 19 | gocyclo: 20 | min-complexity: 15 21 | goimports: 22 | local-prefixes: github.com/golangci/golangci-lint 23 | gomnd: 24 | settings: 25 | mnd: 26 | # don't include the "operation" and "assign" 27 | checks: 28 | - argument 29 | - case 30 | - condition 31 | - return 32 | govet: 33 | check-shadowing: true 34 | settings: 35 | printf: 36 | funcs: 37 | - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof 38 | - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf 39 | - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf 40 | - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf 41 | lll: 42 | line-length: 140 43 | maligned: 44 | suggest-new: true 45 | misspell: 46 | locale: US 47 | nolintlint: 48 | allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) 49 | allow-unused: false # report any unused nolint directives 50 | require-explanation: false # don't require an explanation for nolint directives 51 | require-specific: false # don't require nolint directives to be specific about which linter is being skipped 52 | revive: 53 | ignoreGeneratedHeader: false 54 | severity: warning 55 | confidence: 0.8 56 | errorCode: 0 57 | warningCode: 0 58 | 59 | linters: 60 | # please, do not use `enable-all`: it's deprecated and will be removed soon. 61 | # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint 62 | disable-all: true 63 | enable: 64 | - bodyclose 65 | - deadcode 66 | - depguard 67 | - dogsled 68 | - dupl 69 | - errcheck 70 | - exportloopref 71 | - exhaustive 72 | - funlen 73 | - gochecknoinits 74 | - goconst 75 | - gocritic 76 | - gocyclo 77 | - gofmt 78 | - goimports 79 | - gomnd 80 | - goprintffuncname 81 | - gosec 82 | - gosimple 83 | - govet 84 | - ineffassign 85 | - lll 86 | - misspell 87 | - nakedret 88 | - noctx 89 | - nolintlint 90 | - revive 91 | - rowserrcheck 92 | - staticcheck 93 | - structcheck 94 | - stylecheck 95 | - typecheck 96 | - unconvert 97 | - unparam 98 | - unused 99 | - varcheck 100 | - whitespace 101 | 102 | # don't enable: 103 | # - asciicheck 104 | # - scopelint 105 | # - gochecknoglobals 106 | # - gocognit 107 | # - godot 108 | # - godox 109 | # - goerr113 110 | # - interfacer 111 | # - maligned 112 | # - nestif 113 | # - prealloc 114 | # - testpackage 115 | # - revive 116 | # - wsl 117 | 118 | issues: 119 | # Excluding configuration per-path, per-linter, per-text and per-source 120 | exclude-rules: 121 | - path: _test\.go 122 | linters: 123 | - gomnd 124 | exclude-use-default: false 125 | exclude: 126 | # Uncomment checks you want to INCLUDE, comment checks you want to IGNORE 127 | # EXC0001 errcheck: Almost all programs ignore errors on these functions and in most cases it's ok 128 | # - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked 129 | 130 | # EXC0002 golint: Annoying issue about not having a comment. The rare codebase has such comments 131 | # - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form) 132 | 133 | # EXC0003 golint: False positive when tests are defined in package 'test' 134 | - func name will be used as test\.Test.* by other packages, and that stutters; consider calling this 135 | 136 | # EXC0004 govet: Common false positives 137 | - (possible misuse of unsafe.Pointer|should have signature) 138 | 139 | # EXC0005 staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore 140 | # - ineffective break statement. Did you mean to break out of the outer loop 141 | 142 | # EXC0006 gosec: Too many false-positives on 'unsafe' usage 143 | # - Use of unsafe calls should be audited 144 | - (G107) 145 | # EXC0007 gosec: Too many false-positives for parametrized shell calls 146 | # - Subprocess launch(ed with variable|ing should be audited) 147 | 148 | # EXC0008 gosec: Duplicated errcheck checks 149 | - (G104|G307) 150 | 151 | # EXC0009 gosec: Too many issues in popular repos 152 | # - (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less) 153 | 154 | # EXC0010 gosec: False positive is triggered by 'src, err := ioutil.ReadFile(filename)' 155 | # - Potential file inclusion via variable 156 | 157 | # EXC0011 stylecheck: Annoying issue about not having a comment. The rare codebase has such comments 158 | - (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form) 159 | 160 | # EXC0012 errcheck: ignore errors on log 161 | - Error return value of (.*Log.*|.*\`\`.*) is not checked 162 | 163 | run: 164 | skip-dirs-use-default: true 165 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to RecoLabs.ai Open Source 2 | 3 | Hello! Thanks for reading this. We'd love your input! 4 | 5 | We want to make contributing to this project as easy and transparent as possible, whether it's: 6 | 7 | - Reporting a bug 8 | - Discussing the current state of the code 9 | - Submitting a fix 10 | - Proposing new features 11 | 12 | ## How to contribute? 13 | 14 | 1. Create an issue. 15 | 1. Fork the repo and create your branch from `main`. 16 | 1. Issue your pull request! 17 | 18 | ## Report bugs using Github's issues 19 | 20 | We use GitHub issues to track public bugs. Report a bug by opening a new issue. 21 | 22 | ## License 23 | 24 | By contributing, you agree that your contributions will be licensed under this 25 | repository's license. 26 | -------------------------------------------------------------------------------- /Earthfile: -------------------------------------------------------------------------------- 1 | VERSION 0.6 2 | 3 | 4 | ARG GO_VERSION=1.16 5 | ARG GOLANGCI_VERSION=1.40.1 6 | 7 | base-go: 8 | FROM golang:$GO_VERSION 9 | 10 | RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg/mod -- \ 11 | go install github.com/axw/gocov/gocov@latest \ 12 | && go install github.com/AlekSi/gocov-xml@latest \ 13 | && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v${GOLANGCI_VERSION} 14 | 15 | ENV CGO_ENABLED=0 16 | ENV GOOS=linux 17 | ENV GOARCH=amd64 18 | 19 | WORKDIR /build 20 | 21 | copy-code: 22 | FROM +base-go 23 | COPY --dir */. *go* .golangci.yml ./ 24 | 25 | deps: 26 | FROM +copy-code 27 | COPY go.mod go.sum . 28 | RUN go mod download 29 | SAVE ARTIFACT go.mod AS LOCAL go.mod 30 | SAVE ARTIFACT go.sum AS LOCAL go.sum 31 | 32 | lint: ## Lints the go code with various linters 33 | FROM +deps 34 | ## This linter is controlled via a config file, and is super-strict 35 | RUN --mount=type=cache,target=/root/.cache/golangci-lint \ 36 | --mount=type=cache,target=/root/.cache/go-build -- \ 37 | golangci-lint run -v --print-resources-usage \ 38 | --modules-download-mode=readonly --timeout=10m 39 | 40 | test: ## Run tests and save coverage 41 | FROM +deps 42 | RUN --mount=type=cache,target=/root/.cache/go-build -- \ 43 | go test -v -mod=readonly -coverprofile=cover.out ./... \ 44 | && gocov convert cover.out | gocov-xml > coverage.xml 45 | SAVE ARTIFACT coverage.xml AS LOCAL coverage.xml 46 | 47 | 48 | lintest: ## One step for lint and test 49 | BUILD +lint 50 | BUILD +test 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2022, RecoLabs 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /administration/administration.go: -------------------------------------------------------------------------------- 1 | package administration 2 | 3 | import ( 4 | "github.com/recolabs/redash-go-sdk/gen/client" 5 | admin "github.com/recolabs/redash-go-sdk/gen/client/administration" 6 | ) 7 | 8 | type RequestWrapper struct { 9 | httpClient *client.Redashclient 10 | host string 11 | opts []admin.ClientOption 12 | } 13 | 14 | func NewRequestWrapper(httpClient *client.Redashclient, opts ...admin.ClientOption) *RequestWrapper { 15 | return &RequestWrapper{httpClient: httpClient, opts: opts} 16 | } 17 | 18 | // Ping verify connection initialized 19 | func (requestWrapper *RequestWrapper) Ping() (err error) { 20 | params := admin.NewGetPingParams() 21 | _, err = requestWrapper.httpClient.Administration.GetPing(params, nil, requestWrapper.opts...) 22 | return err 23 | } 24 | -------------------------------------------------------------------------------- /administration/administration_test.go: -------------------------------------------------------------------------------- 1 | package administration 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/recolabs/redash-go-sdk/gen/client" 8 | admin "github.com/recolabs/redash-go-sdk/gen/client/administration" 9 | mock_administration "github.com/recolabs/redash-go-sdk/mocks/administration" 10 | ) 11 | 12 | const ( 13 | testAddress = "localhost:5005" 14 | ) 15 | 16 | func TestPingFunction(t *testing.T) { 17 | pingParams := admin.NewGetPingParams() 18 | happyFlowClient := client.NewHTTPClientWithConfig(nil, 19 | &client.TransportConfig{Host: testAddress, BasePath: "/api"}) 20 | 21 | successfullyAdministrationMock := mock_administration.ClientService{} 22 | happyFlowClient.Administration = &successfullyAdministrationMock 23 | successfullyAdministrationMock.On("GetPing", pingParams, nil).Return(admin.NewGetPingOK(), nil) 24 | 25 | serverErrorClient := client.NewHTTPClientWithConfig(nil, 26 | &client.TransportConfig{Host: testAddress, BasePath: "/api"}) 27 | serverErrAdministrationMock := mock_administration.ClientService{} 28 | serverErrorClient.Administration = &serverErrAdministrationMock 29 | serverErrAdministrationMock.On("GetPing", pingParams, nil). 30 | Return(admin.NewGetPingOK(), fmt.Errorf("Internal Server Error")) 31 | 32 | type fields struct { 33 | httpClient *client.Redashclient 34 | host string 35 | } 36 | tests := []struct { 37 | name string 38 | fields fields 39 | wantErr bool 40 | }{ 41 | { 42 | name: "Successfully ping", 43 | fields: fields{httpClient: happyFlowClient, host: testAddress}, 44 | wantErr: false, 45 | }, 46 | { 47 | name: "Ping fails on a server error", 48 | fields: fields{httpClient: serverErrorClient, host: testAddress}, 49 | wantErr: true, 50 | }, 51 | } 52 | for _, tt := range tests { 53 | t.Run(tt.name, func(t *testing.T) { 54 | administration := &RequestWrapper{ 55 | httpClient: tt.fields.httpClient, 56 | host: tt.fields.host, 57 | } 58 | err := administration.Ping() 59 | if (err != nil) != tt.wantErr { 60 | t.Errorf("RequestWrapper.Add() error = %v, wantErr %v", err, tt.wantErr) 61 | return 62 | } 63 | }) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | // A simple go client for Redash, wraps some Redash's REST API in go methods. 2 | // Client Initialization 3 | // 4 | // import ( 5 | // redashclient "github.com/recolabs/redash-go-sdk/redashClient" 6 | // "github.com/recolabs/redash-go-sdk/gen/client" 7 | // ) 8 | // redashClient := redashclient.NewClient( 9 | // "{API_KEY}", 10 | // &client.TransportConfig{ 11 | // Host: "{HOST_ADDRESS}", 12 | // }) 13 | // 14 | // Usage 15 | // 16 | // Calls in the client are of the form: 17 | // client..(...) 18 | // 19 | // For example: 20 | // List the current queries in Redash 21 | // redashClient.Queries.List() 22 | // 23 | // 24 | // Add a query to Redash 25 | // queryString := "SELECT email, count(*) public.table GROUP BY name" 26 | // redashClient.Queries.Add(1, "Example Query", queryString, []queries.Parameters{})) 27 | 28 | package redashclient 29 | 30 | import ( 31 | httptransport "github.com/go-openapi/runtime/client" 32 | "github.com/recolabs/redash-go-sdk/administration" 33 | "github.com/recolabs/redash-go-sdk/datasources" 34 | "github.com/recolabs/redash-go-sdk/gen/client" 35 | "github.com/recolabs/redash-go-sdk/queries" 36 | "github.com/recolabs/redash-go-sdk/users" 37 | "github.com/recolabs/redash-go-sdk/visualizations" 38 | ) 39 | 40 | // Client wrapping ReDash's rest API 41 | type Client struct { 42 | Queries *queries.RequestWrapper 43 | Visualizations *visualizations.RequestWrapper 44 | Users *users.RequestWrapper 45 | DataSources *datasources.RequestWrapper 46 | Administration *administration.RequestWrapper 47 | apiKey string 48 | } 49 | 50 | // Build A new client object with every RequestWrapper using the provided configuration 51 | func NewClient(apiKey string, cfg *client.TransportConfig, opts ...ClientOption) Client { 52 | if cfg == nil { 53 | cfg = client.DefaultTransportConfig() 54 | } 55 | if cfg.Host == "" { 56 | cfg.Host = client.DefaultHost 57 | } 58 | if cfg.BasePath == "" { 59 | cfg.BasePath = client.DefaultBasePath 60 | } 61 | if cfg.Schemes == nil { 62 | cfg.Schemes = client.DefaultSchemes 63 | } 64 | 65 | // create transport and client 66 | transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes) 67 | scheme := selectScheme(cfg.Schemes) 68 | 69 | return NewClientWithTransport(apiKey, transport, scheme, opts...) 70 | } 71 | 72 | // Build A new client object with every RequestWrapper using the provided transport 73 | func NewClientWithTransport(apiKey string, transport *httptransport.Runtime, scheme string, opts ...ClientOption) Client { 74 | // auto authorize every api call 75 | transport.DefaultAuthentication = httptransport.APIKeyAuth("Authorization", "header", apiKey) 76 | 77 | var optsArray ClientOptions = opts 78 | dsClientOption := optsArray.toDataSourcesClientOptions() 79 | usersClientOption := optsArray.toUsersClientOptions() 80 | vizClientOption := optsArray.toVizClientOptions() 81 | queriesClientOption := optsArray.toQueryClientOptions() 82 | administrationClientOption := optsArray.toAdministrationClientOptions() 83 | 84 | httpClient := client.New(transport, nil) 85 | return Client{ 86 | Queries: queries.NewRequestWrapper(httpClient, queriesClientOption...), 87 | Visualizations: visualizations.NewRequestWrapper(httpClient, transport.Host, scheme, apiKey, vizClientOption...), 88 | Users: users.NewRequestWrapper(httpClient, usersClientOption...), 89 | DataSources: datasources.NewRequestWrapper(httpClient, dsClientOption...), 90 | Administration: administration.NewRequestWrapper(httpClient, administrationClientOption...), 91 | apiKey: apiKey, 92 | } 93 | } 94 | 95 | // GetAPIKey return the apiKey that used to initialize the client 96 | func GetAPIKey(clientRef *Client) string { 97 | return clientRef.apiKey 98 | } 99 | 100 | const https = "https" 101 | 102 | // Select the scheme to use based on the provided schemes - this function is a duplicate of the "runtime" package 103 | // due to the fact that the "runtime" package function is not exported 104 | func selectScheme(schemes []string) string { 105 | schLen := len(schemes) 106 | if schLen == 0 { 107 | return "" 108 | } 109 | 110 | scheme := schemes[0] 111 | // prefer https, but skip when not possible 112 | if scheme != https && schLen > 1 { 113 | for _, sch := range schemes { 114 | if sch == https { 115 | scheme = sch 116 | break 117 | } 118 | } 119 | } 120 | return scheme 121 | } 122 | -------------------------------------------------------------------------------- /client_options.go: -------------------------------------------------------------------------------- 1 | package redashclient 2 | 3 | import ( 4 | "github.com/go-openapi/runtime" 5 | gen_admin "github.com/recolabs/redash-go-sdk/gen/client/administration" 6 | gen_ds "github.com/recolabs/redash-go-sdk/gen/client/data_sources" 7 | gen_queries "github.com/recolabs/redash-go-sdk/gen/client/queries" 8 | gen_users "github.com/recolabs/redash-go-sdk/gen/client/users" 9 | gen_viz "github.com/recolabs/redash-go-sdk/gen/client/visualizations" 10 | ) 11 | 12 | // ClientOption is the option for Client methods. 13 | // It is used to configure the client just before execution and thus overwrite any default behavior 14 | type ClientOption func(*runtime.ClientOperation) 15 | type ClientOptions []ClientOption 16 | 17 | func (opts ClientOptions) toDataSourcesClientOptions() []gen_ds.ClientOption { 18 | if opts == nil { 19 | return nil 20 | } 21 | 22 | result := make([]gen_ds.ClientOption, len(opts)) 23 | for i, opt := range opts { 24 | result[i] = func(co *runtime.ClientOperation) { 25 | opt(co) 26 | } 27 | } 28 | return result 29 | } 30 | 31 | func (opts ClientOptions) toUsersClientOptions() []gen_users.ClientOption { 32 | if opts == nil { 33 | return nil 34 | } 35 | 36 | result := make([]gen_users.ClientOption, len(opts)) 37 | for i, opt := range opts { 38 | result[i] = func(co *runtime.ClientOperation) { 39 | opt(co) 40 | } 41 | } 42 | return result 43 | } 44 | 45 | func (opts ClientOptions) toVizClientOptions() []gen_viz.ClientOption { 46 | if opts == nil { 47 | return nil 48 | } 49 | 50 | result := make([]gen_viz.ClientOption, len(opts)) 51 | for i, opt := range opts { 52 | result[i] = func(co *runtime.ClientOperation) { 53 | opt(co) 54 | } 55 | } 56 | return result 57 | } 58 | 59 | func (opts ClientOptions) toQueryClientOptions() []gen_queries.ClientOption { 60 | if opts == nil { 61 | return nil 62 | } 63 | 64 | result := make([]gen_queries.ClientOption, len(opts)) 65 | for i, opt := range opts { 66 | result[i] = func(co *runtime.ClientOperation) { 67 | opt(co) 68 | } 69 | } 70 | return result 71 | } 72 | 73 | func (opts ClientOptions) toAdministrationClientOptions() []gen_admin.ClientOption { 74 | if opts == nil { 75 | return nil 76 | } 77 | 78 | result := make([]gen_admin.ClientOption, len(opts)) 79 | for i, opt := range opts { 80 | result[i] = func(co *runtime.ClientOperation) { 81 | opt(co) 82 | } 83 | } 84 | return result 85 | } 86 | -------------------------------------------------------------------------------- /common/random/random.go: -------------------------------------------------------------------------------- 1 | // Package random provides utilities for creating random things 2 | package random 3 | 4 | import ( 5 | cryptorand "crypto/rand" 6 | "math/big" 7 | "math/rand" 8 | ) 9 | 10 | const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 11 | 12 | // WeakRandString - returns a random string of the given length 13 | func WeakRandString(length int) string { 14 | b := make([]byte, length) 15 | for i := range b { 16 | b[i] = letterBytes[rand.Intn(len(letterBytes))] //nolint:gosec //reason: don't need strong crypto here 17 | } 18 | return string(b) 19 | } 20 | 21 | // SecureRandStringFromChars - returns a crypto safe random string of the given length with the given chars 22 | func SecureRandStringFromChars(n int, letters string) (string, error) { 23 | ret := make([]byte, n) 24 | for i := 0; i < n; i++ { 25 | num, err := cryptorand.Int(cryptorand.Reader, big.NewInt(int64(len(letters)))) 26 | if err != nil { 27 | return "", err 28 | } 29 | ret[i] = letters[num.Int64()] 30 | } 31 | 32 | return string(ret), nil 33 | } 34 | 35 | // SecureRandString - returns a crypto safe random string of the given length with the default chars 36 | func SecureRandString(n int) (string, error) { 37 | return SecureRandStringFromChars(n, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-") 38 | } 39 | -------------------------------------------------------------------------------- /datasources/data_sources.go: -------------------------------------------------------------------------------- 1 | // Package datasources provides methods of adding, removing and listing Data Sources 2 | package datasources 3 | 4 | import ( 5 | "github.com/recolabs/redash-go-sdk/gen/client" 6 | ds "github.com/recolabs/redash-go-sdk/gen/client/data_sources" 7 | "github.com/recolabs/redash-go-sdk/gen/models" 8 | "github.com/recolabs/redash-go-sdk/options" 9 | ) 10 | 11 | // RequestWrapper is the struct holding the configuration for the DataSource manipulation code 12 | type RequestWrapper struct { 13 | httpClient *client.Redashclient 14 | opts []ds.ClientOption 15 | } 16 | 17 | // NewDataSourceRequest builds a DataSourceRequest object. The only validation this 18 | // methods provides is that options argument is a valid json string 19 | // This method builds a new data source to be added to redash, thus the ID and Syntax members will be uninitialized. 20 | // Note - valid type and name can be found in `gen/models/data_source.go` - DataSourceName*, DataSourceType* 21 | func NewDataSource(dataSourceType, name, optionsJSON string) (*models.DataSource, error) { 22 | optionsMap, err := options.MapFromString(optionsJSON) 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | dataSource := &models.DataSource{ 28 | Type: &dataSourceType, 29 | Name: &name, 30 | Options: optionsMap, 31 | } 32 | err = dataSource.Validate(nil) 33 | if err != nil { 34 | return nil, err 35 | } 36 | 37 | return dataSource, nil 38 | } 39 | 40 | // NewRequestWrapper returns a simple RequestWrapper object with the provided configuration 41 | func NewRequestWrapper(httpClient *client.Redashclient, opts ...ds.ClientOption) *RequestWrapper { 42 | return &RequestWrapper{httpClient: httpClient, opts: opts} 43 | } 44 | 45 | // Add a the provided DataSource to Redash, 46 | // only the DataSource's name, type and options string are used other struct members hjy be ignored 47 | // Its best to use the NewDataSource method to build the data source from string variables 48 | func (requestWrapper *RequestWrapper) Add(dataSource *models.DataSource) (*models.DataSource, error) { 49 | err := dataSource.Validate(nil) 50 | if err != nil { 51 | return nil, err 52 | } 53 | 54 | addParams := ds.NewPostDataSourcesParams().WithBody(ds.PostDataSourcesBody{ 55 | Name: *dataSource.Name, 56 | Options: dataSource.Options, 57 | Type: *dataSource.Type, 58 | }) 59 | 60 | response, err := requestWrapper.httpClient.DataSources.PostDataSources(addParams, nil, requestWrapper.opts...) 61 | if err != nil { 62 | return nil, err 63 | } 64 | return response.GetPayload(), nil 65 | } 66 | 67 | // Update the provided DataSource in Redash, 68 | func (requestWrapper *RequestWrapper) Update(dataSource *models.DataSource) (*models.DataSource, error) { 69 | err := dataSource.Validate(nil) 70 | if err != nil { 71 | return nil, err 72 | } 73 | 74 | addParams := ds.NewPostDataSourcesIDParams().WithID(dataSource.ID).WithBody(ds.PostDataSourcesIDBody{ 75 | Name: *dataSource.Name, 76 | Options: dataSource.Options, 77 | Type: *dataSource.Type, 78 | }) 79 | 80 | response, err := requestWrapper.httpClient.DataSources.PostDataSourcesID(addParams, nil, requestWrapper.opts...) 81 | if err != nil { 82 | return nil, err 83 | } 84 | return response.GetPayload(), nil 85 | } 86 | 87 | // GetUser gets the details admin's user details 88 | func (requestWrapper *RequestWrapper) Get(dsID int64) (*models.DataSource, error) { 89 | getDSParams := ds.NewGetDataSourcesIDParams() 90 | getDSParams.ID = dsID 91 | response, err := requestWrapper.httpClient.DataSources.GetDataSourcesID(getDSParams, nil, requestWrapper.opts...) 92 | if err != nil { 93 | return nil, err 94 | } 95 | 96 | return response.GetPayload(), nil 97 | } 98 | 99 | // List existing data sources, if the user api key is has admin permission 100 | // all data sources are listed. Otherwise, only data souces that belong to the user group the user whose api 101 | // key the client uses will be displayed 102 | // 103 | // see relvant redash implemntation: 104 | // https://github.com/getredash/redash/blob/965db26cabfc0de83f65c91439092ed94db4de4a/redash/handlers/data_sources.py#L118 105 | func (requestWrapper *RequestWrapper) List() (resultDataSource []*models.DataSource, err error) { 106 | response, err := requestWrapper.httpClient.DataSources.List(nil, nil, requestWrapper.opts...) 107 | if err != nil { 108 | return nil, err 109 | } 110 | 111 | return response.GetPayload(), nil 112 | } 113 | 114 | // Remove deletes an existing data sources from Redash, it does not return the data source, 115 | // only an error if the deletion has failed 116 | func (requestWrapper *RequestWrapper) Delete(dataSourceID int64) error { 117 | deleteParams := ds.NewDeleteDataSourcesIDParams().WithID(dataSourceID) 118 | _, err := requestWrapper.httpClient.DataSources.DeleteDataSourcesID(deleteParams, nil, requestWrapper.opts...) 119 | if err != nil { 120 | return err 121 | } 122 | return nil 123 | } 124 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // redashclient is a go wrapper to Redash's REST API 2 | 3 | // redashclient provides a go API to set up and manager a remote redash client programmatically 4 | // 5 | // # Setting Up the configuration structure 6 | // 7 | // redashclient uses a configuration structure to hold data that changes between deploymnets to build such configuration structure run 8 | // 9 | // configuration := config.Config{Host: "0.0.0.0:5005", APIKey: ""} 10 | // 11 | // # Initilizting the client 12 | // 13 | // redashclient uses a configuration structure to hold data that changes between deploymnets to build such configuration structure run 14 | // 15 | // redashClient := redashclient.NewClient(&config.Config{Host: redashAddr, APIKey: apiKey}) 16 | package redashclient 17 | -------------------------------------------------------------------------------- /docs/static/img/api-key-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RecoLabs/redash-go-sdk/2c7c3359a55d6d53596107f09200d04f4c99e4ef/docs/static/img/api-key-0.png -------------------------------------------------------------------------------- /docs/static/img/api-key-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RecoLabs/redash-go-sdk/2c7c3359a55d6d53596107f09200d04f4c99e4ef/docs/static/img/api-key-1.png -------------------------------------------------------------------------------- /gen/client/administration/administration_client.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package administration 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | "github.com/go-openapi/strfmt" 13 | ) 14 | 15 | // New creates a new administration API client. 16 | func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { 17 | return &Client{transport: transport, formats: formats} 18 | } 19 | 20 | /* 21 | Client for administration API 22 | */ 23 | type Client struct { 24 | transport runtime.ClientTransport 25 | formats strfmt.Registry 26 | } 27 | 28 | // ClientOption is the option for Client methods 29 | type ClientOption func(*runtime.ClientOperation) 30 | 31 | // ClientService is the interface for Client methods 32 | type ClientService interface { 33 | GetPing(params *GetPingParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetPingOK, error) 34 | 35 | SetTransport(transport runtime.ClientTransport) 36 | } 37 | 38 | /* 39 | GetPing get ping API 40 | */ 41 | func (a *Client) GetPing(params *GetPingParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetPingOK, error) { 42 | // TODO: Validate the params before sending 43 | if params == nil { 44 | params = NewGetPingParams() 45 | } 46 | op := &runtime.ClientOperation{ 47 | ID: "GetPing", 48 | Method: "GET", 49 | PathPattern: "/ping", 50 | ProducesMediaTypes: []string{"application/json"}, 51 | ConsumesMediaTypes: []string{"application/json"}, 52 | Schemes: []string{"http", "https"}, 53 | Params: params, 54 | Reader: &GetPingReader{formats: a.formats}, 55 | AuthInfo: authInfo, 56 | Context: params.Context, 57 | Client: params.HTTPClient, 58 | } 59 | for _, opt := range opts { 60 | opt(op) 61 | } 62 | 63 | result, err := a.transport.Submit(op) 64 | if err != nil { 65 | return nil, err 66 | } 67 | success, ok := result.(*GetPingOK) 68 | if ok { 69 | return success, nil 70 | } 71 | // unexpected success response 72 | // safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue 73 | msg := fmt.Sprintf("unexpected success response for GetPing: API contract not enforced by server. Client expected to get an error, but got: %T", result) 74 | panic(msg) 75 | } 76 | 77 | // SetTransport changes the transport on the client 78 | func (a *Client) SetTransport(transport runtime.ClientTransport) { 79 | a.transport = transport 80 | } 81 | -------------------------------------------------------------------------------- /gen/client/administration/get_ping_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package administration 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | ) 18 | 19 | // NewGetPingParams creates a new GetPingParams object, 20 | // with the default timeout for this client. 21 | // 22 | // Default values are not hydrated, since defaults are normally applied by the API server side. 23 | // 24 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 25 | func NewGetPingParams() *GetPingParams { 26 | return &GetPingParams{ 27 | timeout: cr.DefaultTimeout, 28 | } 29 | } 30 | 31 | // NewGetPingParamsWithTimeout creates a new GetPingParams object 32 | // with the ability to set a timeout on a request. 33 | func NewGetPingParamsWithTimeout(timeout time.Duration) *GetPingParams { 34 | return &GetPingParams{ 35 | timeout: timeout, 36 | } 37 | } 38 | 39 | // NewGetPingParamsWithContext creates a new GetPingParams object 40 | // with the ability to set a context for a request. 41 | func NewGetPingParamsWithContext(ctx context.Context) *GetPingParams { 42 | return &GetPingParams{ 43 | Context: ctx, 44 | } 45 | } 46 | 47 | // NewGetPingParamsWithHTTPClient creates a new GetPingParams object 48 | // with the ability to set a custom HTTPClient for a request. 49 | func NewGetPingParamsWithHTTPClient(client *http.Client) *GetPingParams { 50 | return &GetPingParams{ 51 | HTTPClient: client, 52 | } 53 | } 54 | 55 | /* GetPingParams contains all the parameters to send to the API endpoint 56 | for the get ping operation. 57 | 58 | Typically these are written to a http.Request. 59 | */ 60 | type GetPingParams struct { 61 | timeout time.Duration 62 | Context context.Context 63 | HTTPClient *http.Client 64 | } 65 | 66 | // WithDefaults hydrates default values in the get ping params (not the query body). 67 | // 68 | // All values with no default are reset to their zero value. 69 | func (o *GetPingParams) WithDefaults() *GetPingParams { 70 | o.SetDefaults() 71 | return o 72 | } 73 | 74 | // SetDefaults hydrates default values in the get ping params (not the query body). 75 | // 76 | // All values with no default are reset to their zero value. 77 | func (o *GetPingParams) SetDefaults() { 78 | // no default values defined for this parameter 79 | } 80 | 81 | // WithTimeout adds the timeout to the get ping params 82 | func (o *GetPingParams) WithTimeout(timeout time.Duration) *GetPingParams { 83 | o.SetTimeout(timeout) 84 | return o 85 | } 86 | 87 | // SetTimeout adds the timeout to the get ping params 88 | func (o *GetPingParams) SetTimeout(timeout time.Duration) { 89 | o.timeout = timeout 90 | } 91 | 92 | // WithContext adds the context to the get ping params 93 | func (o *GetPingParams) WithContext(ctx context.Context) *GetPingParams { 94 | o.SetContext(ctx) 95 | return o 96 | } 97 | 98 | // SetContext adds the context to the get ping params 99 | func (o *GetPingParams) SetContext(ctx context.Context) { 100 | o.Context = ctx 101 | } 102 | 103 | // WithHTTPClient adds the HTTPClient to the get ping params 104 | func (o *GetPingParams) WithHTTPClient(client *http.Client) *GetPingParams { 105 | o.SetHTTPClient(client) 106 | return o 107 | } 108 | 109 | // SetHTTPClient adds the HTTPClient to the get ping params 110 | func (o *GetPingParams) SetHTTPClient(client *http.Client) { 111 | o.HTTPClient = client 112 | } 113 | 114 | // WriteToRequest writes these params to a swagger request 115 | func (o *GetPingParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 116 | 117 | if err := r.SetTimeout(o.timeout); err != nil { 118 | return err 119 | } 120 | var res []error 121 | 122 | if len(res) > 0 { 123 | return errors.CompositeValidationError(res...) 124 | } 125 | return nil 126 | } 127 | -------------------------------------------------------------------------------- /gen/client/administration/get_ping_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package administration 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // GetPingReader is a Reader for the GetPing structure. 17 | type GetPingReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *GetPingReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewGetPingOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | default: 31 | return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code()) 32 | } 33 | } 34 | 35 | // NewGetPingOK creates a GetPingOK with default headers values 36 | func NewGetPingOK() *GetPingOK { 37 | return &GetPingOK{} 38 | } 39 | 40 | /* GetPingOK describes a response with status code 200, with default header values. 41 | 42 | OK 43 | */ 44 | type GetPingOK struct { 45 | Payload string 46 | } 47 | 48 | func (o *GetPingOK) Error() string { 49 | return fmt.Sprintf("[GET /ping][%d] getPingOK %+v", 200, o.Payload) 50 | } 51 | func (o *GetPingOK) GetPayload() string { 52 | return o.Payload 53 | } 54 | 55 | func (o *GetPingOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 56 | 57 | // response payload 58 | if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { 59 | return err 60 | } 61 | 62 | return nil 63 | } 64 | -------------------------------------------------------------------------------- /gen/client/data_sources/delete_data_sources_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewDeleteDataSourcesIDParams creates a new DeleteDataSourcesIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewDeleteDataSourcesIDParams() *DeleteDataSourcesIDParams { 27 | return &DeleteDataSourcesIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewDeleteDataSourcesIDParamsWithTimeout creates a new DeleteDataSourcesIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewDeleteDataSourcesIDParamsWithTimeout(timeout time.Duration) *DeleteDataSourcesIDParams { 35 | return &DeleteDataSourcesIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewDeleteDataSourcesIDParamsWithContext creates a new DeleteDataSourcesIDParams object 41 | // with the ability to set a context for a request. 42 | func NewDeleteDataSourcesIDParamsWithContext(ctx context.Context) *DeleteDataSourcesIDParams { 43 | return &DeleteDataSourcesIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewDeleteDataSourcesIDParamsWithHTTPClient creates a new DeleteDataSourcesIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewDeleteDataSourcesIDParamsWithHTTPClient(client *http.Client) *DeleteDataSourcesIDParams { 51 | return &DeleteDataSourcesIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* DeleteDataSourcesIDParams contains all the parameters to send to the API endpoint 57 | for the delete data sources ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type DeleteDataSourcesIDParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the delete data sources ID params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *DeleteDataSourcesIDParams) WithDefaults() *DeleteDataSourcesIDParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the delete data sources ID params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *DeleteDataSourcesIDParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the delete data sources ID params 87 | func (o *DeleteDataSourcesIDParams) WithTimeout(timeout time.Duration) *DeleteDataSourcesIDParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the delete data sources ID params 93 | func (o *DeleteDataSourcesIDParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the delete data sources ID params 98 | func (o *DeleteDataSourcesIDParams) WithContext(ctx context.Context) *DeleteDataSourcesIDParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the delete data sources ID params 104 | func (o *DeleteDataSourcesIDParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the delete data sources ID params 109 | func (o *DeleteDataSourcesIDParams) WithHTTPClient(client *http.Client) *DeleteDataSourcesIDParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the delete data sources ID params 115 | func (o *DeleteDataSourcesIDParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the delete data sources ID params 120 | func (o *DeleteDataSourcesIDParams) WithID(id int64) *DeleteDataSourcesIDParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the delete data sources ID params 126 | func (o *DeleteDataSourcesIDParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *DeleteDataSourcesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/data_sources/delete_data_sources_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // DeleteDataSourcesIDReader is a Reader for the DeleteDataSourcesID structure. 19 | type DeleteDataSourcesIDReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *DeleteDataSourcesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 204: 27 | result := NewDeleteDataSourcesIDNoContent() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewDeleteDataSourcesIDDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewDeleteDataSourcesIDNoContent creates a DeleteDataSourcesIDNoContent with default headers values 45 | func NewDeleteDataSourcesIDNoContent() *DeleteDataSourcesIDNoContent { 46 | return &DeleteDataSourcesIDNoContent{} 47 | } 48 | 49 | /* DeleteDataSourcesIDNoContent describes a response with status code 204, with default header values. 50 | 51 | Data Source was deleted 52 | */ 53 | type DeleteDataSourcesIDNoContent struct { 54 | } 55 | 56 | func (o *DeleteDataSourcesIDNoContent) Error() string { 57 | return fmt.Sprintf("[DELETE /data_sources/{id}][%d] deleteDataSourcesIdNoContent ", 204) 58 | } 59 | 60 | func (o *DeleteDataSourcesIDNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 61 | 62 | return nil 63 | } 64 | 65 | // NewDeleteDataSourcesIDDefault creates a DeleteDataSourcesIDDefault with default headers values 66 | func NewDeleteDataSourcesIDDefault(code int) *DeleteDataSourcesIDDefault { 67 | return &DeleteDataSourcesIDDefault{ 68 | _statusCode: code, 69 | } 70 | } 71 | 72 | /* DeleteDataSourcesIDDefault describes a response with status code -1, with default header values. 73 | 74 | error 75 | */ 76 | type DeleteDataSourcesIDDefault struct { 77 | _statusCode int 78 | 79 | Payload *models.Error 80 | } 81 | 82 | // Code gets the status code for the delete data sources ID default response 83 | func (o *DeleteDataSourcesIDDefault) Code() int { 84 | return o._statusCode 85 | } 86 | 87 | func (o *DeleteDataSourcesIDDefault) Error() string { 88 | return fmt.Sprintf("[DELETE /data_sources/{id}][%d] DeleteDataSourcesID default %+v", o._statusCode, o.Payload) 89 | } 90 | func (o *DeleteDataSourcesIDDefault) GetPayload() *models.Error { 91 | return o.Payload 92 | } 93 | 94 | func (o *DeleteDataSourcesIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 95 | 96 | o.Payload = new(models.Error) 97 | 98 | // response payload 99 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 100 | return err 101 | } 102 | 103 | return nil 104 | } 105 | -------------------------------------------------------------------------------- /gen/client/data_sources/get_data_sources_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewGetDataSourcesIDParams creates a new GetDataSourcesIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewGetDataSourcesIDParams() *GetDataSourcesIDParams { 27 | return &GetDataSourcesIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewGetDataSourcesIDParamsWithTimeout creates a new GetDataSourcesIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewGetDataSourcesIDParamsWithTimeout(timeout time.Duration) *GetDataSourcesIDParams { 35 | return &GetDataSourcesIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetDataSourcesIDParamsWithContext creates a new GetDataSourcesIDParams object 41 | // with the ability to set a context for a request. 42 | func NewGetDataSourcesIDParamsWithContext(ctx context.Context) *GetDataSourcesIDParams { 43 | return &GetDataSourcesIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewGetDataSourcesIDParamsWithHTTPClient creates a new GetDataSourcesIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewGetDataSourcesIDParamsWithHTTPClient(client *http.Client) *GetDataSourcesIDParams { 51 | return &GetDataSourcesIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* GetDataSourcesIDParams contains all the parameters to send to the API endpoint 57 | for the get data sources ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type GetDataSourcesIDParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the get data sources ID params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *GetDataSourcesIDParams) WithDefaults() *GetDataSourcesIDParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the get data sources ID params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *GetDataSourcesIDParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the get data sources ID params 87 | func (o *GetDataSourcesIDParams) WithTimeout(timeout time.Duration) *GetDataSourcesIDParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the get data sources ID params 93 | func (o *GetDataSourcesIDParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the get data sources ID params 98 | func (o *GetDataSourcesIDParams) WithContext(ctx context.Context) *GetDataSourcesIDParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the get data sources ID params 104 | func (o *GetDataSourcesIDParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the get data sources ID params 109 | func (o *GetDataSourcesIDParams) WithHTTPClient(client *http.Client) *GetDataSourcesIDParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the get data sources ID params 115 | func (o *GetDataSourcesIDParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the get data sources ID params 120 | func (o *GetDataSourcesIDParams) WithID(id int64) *GetDataSourcesIDParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the get data sources ID params 126 | func (o *GetDataSourcesIDParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *GetDataSourcesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/data_sources/get_data_sources_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // GetDataSourcesIDReader is a Reader for the GetDataSourcesID structure. 19 | type GetDataSourcesIDReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *GetDataSourcesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewGetDataSourcesIDOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewGetDataSourcesIDDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewGetDataSourcesIDOK creates a GetDataSourcesIDOK with default headers values 45 | func NewGetDataSourcesIDOK() *GetDataSourcesIDOK { 46 | return &GetDataSourcesIDOK{} 47 | } 48 | 49 | /* GetDataSourcesIDOK describes a response with status code 200, with default header values. 50 | 51 | Get data source by ID 52 | */ 53 | type GetDataSourcesIDOK struct { 54 | Payload *models.DataSource 55 | } 56 | 57 | func (o *GetDataSourcesIDOK) Error() string { 58 | return fmt.Sprintf("[GET /data_sources/{id}][%d] getDataSourcesIdOK %+v", 200, o.Payload) 59 | } 60 | func (o *GetDataSourcesIDOK) GetPayload() *models.DataSource { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetDataSourcesIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | o.Payload = new(models.DataSource) 67 | 68 | // response payload 69 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 70 | return err 71 | } 72 | 73 | return nil 74 | } 75 | 76 | // NewGetDataSourcesIDDefault creates a GetDataSourcesIDDefault with default headers values 77 | func NewGetDataSourcesIDDefault(code int) *GetDataSourcesIDDefault { 78 | return &GetDataSourcesIDDefault{ 79 | _statusCode: code, 80 | } 81 | } 82 | 83 | /* GetDataSourcesIDDefault describes a response with status code -1, with default header values. 84 | 85 | error 86 | */ 87 | type GetDataSourcesIDDefault struct { 88 | _statusCode int 89 | 90 | Payload *models.Error 91 | } 92 | 93 | // Code gets the status code for the get data sources ID default response 94 | func (o *GetDataSourcesIDDefault) Code() int { 95 | return o._statusCode 96 | } 97 | 98 | func (o *GetDataSourcesIDDefault) Error() string { 99 | return fmt.Sprintf("[GET /data_sources/{id}][%d] GetDataSourcesID default %+v", o._statusCode, o.Payload) 100 | } 101 | func (o *GetDataSourcesIDDefault) GetPayload() *models.Error { 102 | return o.Payload 103 | } 104 | 105 | func (o *GetDataSourcesIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 106 | 107 | o.Payload = new(models.Error) 108 | 109 | // response payload 110 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 111 | return err 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /gen/client/data_sources/list_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | ) 18 | 19 | // NewListParams creates a new ListParams object, 20 | // with the default timeout for this client. 21 | // 22 | // Default values are not hydrated, since defaults are normally applied by the API server side. 23 | // 24 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 25 | func NewListParams() *ListParams { 26 | return &ListParams{ 27 | timeout: cr.DefaultTimeout, 28 | } 29 | } 30 | 31 | // NewListParamsWithTimeout creates a new ListParams object 32 | // with the ability to set a timeout on a request. 33 | func NewListParamsWithTimeout(timeout time.Duration) *ListParams { 34 | return &ListParams{ 35 | timeout: timeout, 36 | } 37 | } 38 | 39 | // NewListParamsWithContext creates a new ListParams object 40 | // with the ability to set a context for a request. 41 | func NewListParamsWithContext(ctx context.Context) *ListParams { 42 | return &ListParams{ 43 | Context: ctx, 44 | } 45 | } 46 | 47 | // NewListParamsWithHTTPClient creates a new ListParams object 48 | // with the ability to set a custom HTTPClient for a request. 49 | func NewListParamsWithHTTPClient(client *http.Client) *ListParams { 50 | return &ListParams{ 51 | HTTPClient: client, 52 | } 53 | } 54 | 55 | /* ListParams contains all the parameters to send to the API endpoint 56 | for the list operation. 57 | 58 | Typically these are written to a http.Request. 59 | */ 60 | type ListParams struct { 61 | timeout time.Duration 62 | Context context.Context 63 | HTTPClient *http.Client 64 | } 65 | 66 | // WithDefaults hydrates default values in the list params (not the query body). 67 | // 68 | // All values with no default are reset to their zero value. 69 | func (o *ListParams) WithDefaults() *ListParams { 70 | o.SetDefaults() 71 | return o 72 | } 73 | 74 | // SetDefaults hydrates default values in the list params (not the query body). 75 | // 76 | // All values with no default are reset to their zero value. 77 | func (o *ListParams) SetDefaults() { 78 | // no default values defined for this parameter 79 | } 80 | 81 | // WithTimeout adds the timeout to the list params 82 | func (o *ListParams) WithTimeout(timeout time.Duration) *ListParams { 83 | o.SetTimeout(timeout) 84 | return o 85 | } 86 | 87 | // SetTimeout adds the timeout to the list params 88 | func (o *ListParams) SetTimeout(timeout time.Duration) { 89 | o.timeout = timeout 90 | } 91 | 92 | // WithContext adds the context to the list params 93 | func (o *ListParams) WithContext(ctx context.Context) *ListParams { 94 | o.SetContext(ctx) 95 | return o 96 | } 97 | 98 | // SetContext adds the context to the list params 99 | func (o *ListParams) SetContext(ctx context.Context) { 100 | o.Context = ctx 101 | } 102 | 103 | // WithHTTPClient adds the HTTPClient to the list params 104 | func (o *ListParams) WithHTTPClient(client *http.Client) *ListParams { 105 | o.SetHTTPClient(client) 106 | return o 107 | } 108 | 109 | // SetHTTPClient adds the HTTPClient to the list params 110 | func (o *ListParams) SetHTTPClient(client *http.Client) { 111 | o.HTTPClient = client 112 | } 113 | 114 | // WriteToRequest writes these params to a swagger request 115 | func (o *ListParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 116 | 117 | if err := r.SetTimeout(o.timeout); err != nil { 118 | return err 119 | } 120 | var res []error 121 | 122 | if len(res) > 0 { 123 | return errors.CompositeValidationError(res...) 124 | } 125 | return nil 126 | } 127 | -------------------------------------------------------------------------------- /gen/client/data_sources/list_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // ListReader is a Reader for the List structure. 19 | type ListReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *ListReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewListOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewListDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewListOK creates a ListOK with default headers values 45 | func NewListOK() *ListOK { 46 | return &ListOK{} 47 | } 48 | 49 | /* ListOK describes a response with status code 200, with default header values. 50 | 51 | OK 52 | */ 53 | type ListOK struct { 54 | Payload []*models.DataSource 55 | } 56 | 57 | func (o *ListOK) Error() string { 58 | return fmt.Sprintf("[GET /data_sources][%d] listOK %+v", 200, o.Payload) 59 | } 60 | func (o *ListOK) GetPayload() []*models.DataSource { 61 | return o.Payload 62 | } 63 | 64 | func (o *ListOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | // response payload 67 | if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { 68 | return err 69 | } 70 | 71 | return nil 72 | } 73 | 74 | // NewListDefault creates a ListDefault with default headers values 75 | func NewListDefault(code int) *ListDefault { 76 | return &ListDefault{ 77 | _statusCode: code, 78 | } 79 | } 80 | 81 | /* ListDefault describes a response with status code -1, with default header values. 82 | 83 | error 84 | */ 85 | type ListDefault struct { 86 | _statusCode int 87 | 88 | Payload *models.Error 89 | } 90 | 91 | // Code gets the status code for the list default response 92 | func (o *ListDefault) Code() int { 93 | return o._statusCode 94 | } 95 | 96 | func (o *ListDefault) Error() string { 97 | return fmt.Sprintf("[GET /data_sources][%d] list default %+v", o._statusCode, o.Payload) 98 | } 99 | func (o *ListDefault) GetPayload() *models.Error { 100 | return o.Payload 101 | } 102 | 103 | func (o *ListDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 104 | 105 | o.Payload = new(models.Error) 106 | 107 | // response payload 108 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 109 | return err 110 | } 111 | 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /gen/client/data_sources/post_data_sources_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewPostDataSourcesIDParams creates a new PostDataSourcesIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewPostDataSourcesIDParams() *PostDataSourcesIDParams { 27 | return &PostDataSourcesIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewPostDataSourcesIDParamsWithTimeout creates a new PostDataSourcesIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewPostDataSourcesIDParamsWithTimeout(timeout time.Duration) *PostDataSourcesIDParams { 35 | return &PostDataSourcesIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewPostDataSourcesIDParamsWithContext creates a new PostDataSourcesIDParams object 41 | // with the ability to set a context for a request. 42 | func NewPostDataSourcesIDParamsWithContext(ctx context.Context) *PostDataSourcesIDParams { 43 | return &PostDataSourcesIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewPostDataSourcesIDParamsWithHTTPClient creates a new PostDataSourcesIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewPostDataSourcesIDParamsWithHTTPClient(client *http.Client) *PostDataSourcesIDParams { 51 | return &PostDataSourcesIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* PostDataSourcesIDParams contains all the parameters to send to the API endpoint 57 | for the post data sources ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type PostDataSourcesIDParams struct { 62 | 63 | // Body. 64 | Body PostDataSourcesIDBody 65 | 66 | // ID. 67 | ID int64 68 | 69 | timeout time.Duration 70 | Context context.Context 71 | HTTPClient *http.Client 72 | } 73 | 74 | // WithDefaults hydrates default values in the post data sources ID params (not the query body). 75 | // 76 | // All values with no default are reset to their zero value. 77 | func (o *PostDataSourcesIDParams) WithDefaults() *PostDataSourcesIDParams { 78 | o.SetDefaults() 79 | return o 80 | } 81 | 82 | // SetDefaults hydrates default values in the post data sources ID params (not the query body). 83 | // 84 | // All values with no default are reset to their zero value. 85 | func (o *PostDataSourcesIDParams) SetDefaults() { 86 | // no default values defined for this parameter 87 | } 88 | 89 | // WithTimeout adds the timeout to the post data sources ID params 90 | func (o *PostDataSourcesIDParams) WithTimeout(timeout time.Duration) *PostDataSourcesIDParams { 91 | o.SetTimeout(timeout) 92 | return o 93 | } 94 | 95 | // SetTimeout adds the timeout to the post data sources ID params 96 | func (o *PostDataSourcesIDParams) SetTimeout(timeout time.Duration) { 97 | o.timeout = timeout 98 | } 99 | 100 | // WithContext adds the context to the post data sources ID params 101 | func (o *PostDataSourcesIDParams) WithContext(ctx context.Context) *PostDataSourcesIDParams { 102 | o.SetContext(ctx) 103 | return o 104 | } 105 | 106 | // SetContext adds the context to the post data sources ID params 107 | func (o *PostDataSourcesIDParams) SetContext(ctx context.Context) { 108 | o.Context = ctx 109 | } 110 | 111 | // WithHTTPClient adds the HTTPClient to the post data sources ID params 112 | func (o *PostDataSourcesIDParams) WithHTTPClient(client *http.Client) *PostDataSourcesIDParams { 113 | o.SetHTTPClient(client) 114 | return o 115 | } 116 | 117 | // SetHTTPClient adds the HTTPClient to the post data sources ID params 118 | func (o *PostDataSourcesIDParams) SetHTTPClient(client *http.Client) { 119 | o.HTTPClient = client 120 | } 121 | 122 | // WithBody adds the body to the post data sources ID params 123 | func (o *PostDataSourcesIDParams) WithBody(body PostDataSourcesIDBody) *PostDataSourcesIDParams { 124 | o.SetBody(body) 125 | return o 126 | } 127 | 128 | // SetBody adds the body to the post data sources ID params 129 | func (o *PostDataSourcesIDParams) SetBody(body PostDataSourcesIDBody) { 130 | o.Body = body 131 | } 132 | 133 | // WithID adds the id to the post data sources ID params 134 | func (o *PostDataSourcesIDParams) WithID(id int64) *PostDataSourcesIDParams { 135 | o.SetID(id) 136 | return o 137 | } 138 | 139 | // SetID adds the id to the post data sources ID params 140 | func (o *PostDataSourcesIDParams) SetID(id int64) { 141 | o.ID = id 142 | } 143 | 144 | // WriteToRequest writes these params to a swagger request 145 | func (o *PostDataSourcesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 146 | 147 | if err := r.SetTimeout(o.timeout); err != nil { 148 | return err 149 | } 150 | var res []error 151 | if err := r.SetBodyParam(o.Body); err != nil { 152 | return err 153 | } 154 | 155 | // path param id 156 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 157 | return err 158 | } 159 | 160 | if len(res) > 0 { 161 | return errors.CompositeValidationError(res...) 162 | } 163 | return nil 164 | } 165 | -------------------------------------------------------------------------------- /gen/client/data_sources/post_data_sources_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "io" 12 | 13 | "github.com/go-openapi/runtime" 14 | "github.com/go-openapi/strfmt" 15 | "github.com/go-openapi/swag" 16 | 17 | "github.com/recolabs/redash-go-sdk/gen/models" 18 | ) 19 | 20 | // PostDataSourcesIDReader is a Reader for the PostDataSourcesID structure. 21 | type PostDataSourcesIDReader struct { 22 | formats strfmt.Registry 23 | } 24 | 25 | // ReadResponse reads a server response into the received o. 26 | func (o *PostDataSourcesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 27 | switch response.Code() { 28 | case 200: 29 | result := NewPostDataSourcesIDOK() 30 | if err := result.readResponse(response, consumer, o.formats); err != nil { 31 | return nil, err 32 | } 33 | return result, nil 34 | default: 35 | result := NewPostDataSourcesIDDefault(response.Code()) 36 | if err := result.readResponse(response, consumer, o.formats); err != nil { 37 | return nil, err 38 | } 39 | if response.Code()/100 == 2 { 40 | return result, nil 41 | } 42 | return nil, result 43 | } 44 | } 45 | 46 | // NewPostDataSourcesIDOK creates a PostDataSourcesIDOK with default headers values 47 | func NewPostDataSourcesIDOK() *PostDataSourcesIDOK { 48 | return &PostDataSourcesIDOK{} 49 | } 50 | 51 | /* PostDataSourcesIDOK describes a response with status code 200, with default header values. 52 | 53 | OK 54 | */ 55 | type PostDataSourcesIDOK struct { 56 | Payload *models.DataSource 57 | } 58 | 59 | func (o *PostDataSourcesIDOK) Error() string { 60 | return fmt.Sprintf("[POST /data_sources/{id}][%d] postDataSourcesIdOK %+v", 200, o.Payload) 61 | } 62 | func (o *PostDataSourcesIDOK) GetPayload() *models.DataSource { 63 | return o.Payload 64 | } 65 | 66 | func (o *PostDataSourcesIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 67 | 68 | o.Payload = new(models.DataSource) 69 | 70 | // response payload 71 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 72 | return err 73 | } 74 | 75 | return nil 76 | } 77 | 78 | // NewPostDataSourcesIDDefault creates a PostDataSourcesIDDefault with default headers values 79 | func NewPostDataSourcesIDDefault(code int) *PostDataSourcesIDDefault { 80 | return &PostDataSourcesIDDefault{ 81 | _statusCode: code, 82 | } 83 | } 84 | 85 | /* PostDataSourcesIDDefault describes a response with status code -1, with default header values. 86 | 87 | error 88 | */ 89 | type PostDataSourcesIDDefault struct { 90 | _statusCode int 91 | 92 | Payload *models.Error 93 | } 94 | 95 | // Code gets the status code for the post data sources ID default response 96 | func (o *PostDataSourcesIDDefault) Code() int { 97 | return o._statusCode 98 | } 99 | 100 | func (o *PostDataSourcesIDDefault) Error() string { 101 | return fmt.Sprintf("[POST /data_sources/{id}][%d] PostDataSourcesID default %+v", o._statusCode, o.Payload) 102 | } 103 | func (o *PostDataSourcesIDDefault) GetPayload() *models.Error { 104 | return o.Payload 105 | } 106 | 107 | func (o *PostDataSourcesIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 108 | 109 | o.Payload = new(models.Error) 110 | 111 | // response payload 112 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 113 | return err 114 | } 115 | 116 | return nil 117 | } 118 | 119 | /*PostDataSourcesIDBody post data sources ID body 120 | swagger:model PostDataSourcesIDBody 121 | */ 122 | type PostDataSourcesIDBody struct { 123 | 124 | // name 125 | Name string `json:"name,omitempty"` 126 | 127 | // options 128 | Options interface{} `json:"options,omitempty"` 129 | 130 | // type 131 | Type string `json:"type,omitempty"` 132 | } 133 | 134 | // Validate validates this post data sources ID body 135 | func (o *PostDataSourcesIDBody) Validate(formats strfmt.Registry) error { 136 | return nil 137 | } 138 | 139 | // ContextValidate validates this post data sources ID body based on context it is used 140 | func (o *PostDataSourcesIDBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 141 | return nil 142 | } 143 | 144 | // MarshalBinary interface implementation 145 | func (o *PostDataSourcesIDBody) MarshalBinary() ([]byte, error) { 146 | if o == nil { 147 | return nil, nil 148 | } 149 | return swag.WriteJSON(o) 150 | } 151 | 152 | // UnmarshalBinary interface implementation 153 | func (o *PostDataSourcesIDBody) UnmarshalBinary(b []byte) error { 154 | var res PostDataSourcesIDBody 155 | if err := swag.ReadJSON(b, &res); err != nil { 156 | return err 157 | } 158 | *o = res 159 | return nil 160 | } 161 | -------------------------------------------------------------------------------- /gen/client/data_sources/post_data_sources_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | ) 18 | 19 | // NewPostDataSourcesParams creates a new PostDataSourcesParams object, 20 | // with the default timeout for this client. 21 | // 22 | // Default values are not hydrated, since defaults are normally applied by the API server side. 23 | // 24 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 25 | func NewPostDataSourcesParams() *PostDataSourcesParams { 26 | return &PostDataSourcesParams{ 27 | timeout: cr.DefaultTimeout, 28 | } 29 | } 30 | 31 | // NewPostDataSourcesParamsWithTimeout creates a new PostDataSourcesParams object 32 | // with the ability to set a timeout on a request. 33 | func NewPostDataSourcesParamsWithTimeout(timeout time.Duration) *PostDataSourcesParams { 34 | return &PostDataSourcesParams{ 35 | timeout: timeout, 36 | } 37 | } 38 | 39 | // NewPostDataSourcesParamsWithContext creates a new PostDataSourcesParams object 40 | // with the ability to set a context for a request. 41 | func NewPostDataSourcesParamsWithContext(ctx context.Context) *PostDataSourcesParams { 42 | return &PostDataSourcesParams{ 43 | Context: ctx, 44 | } 45 | } 46 | 47 | // NewPostDataSourcesParamsWithHTTPClient creates a new PostDataSourcesParams object 48 | // with the ability to set a custom HTTPClient for a request. 49 | func NewPostDataSourcesParamsWithHTTPClient(client *http.Client) *PostDataSourcesParams { 50 | return &PostDataSourcesParams{ 51 | HTTPClient: client, 52 | } 53 | } 54 | 55 | /* PostDataSourcesParams contains all the parameters to send to the API endpoint 56 | for the post data sources operation. 57 | 58 | Typically these are written to a http.Request. 59 | */ 60 | type PostDataSourcesParams struct { 61 | 62 | // Body. 63 | Body PostDataSourcesBody 64 | 65 | timeout time.Duration 66 | Context context.Context 67 | HTTPClient *http.Client 68 | } 69 | 70 | // WithDefaults hydrates default values in the post data sources params (not the query body). 71 | // 72 | // All values with no default are reset to their zero value. 73 | func (o *PostDataSourcesParams) WithDefaults() *PostDataSourcesParams { 74 | o.SetDefaults() 75 | return o 76 | } 77 | 78 | // SetDefaults hydrates default values in the post data sources params (not the query body). 79 | // 80 | // All values with no default are reset to their zero value. 81 | func (o *PostDataSourcesParams) SetDefaults() { 82 | // no default values defined for this parameter 83 | } 84 | 85 | // WithTimeout adds the timeout to the post data sources params 86 | func (o *PostDataSourcesParams) WithTimeout(timeout time.Duration) *PostDataSourcesParams { 87 | o.SetTimeout(timeout) 88 | return o 89 | } 90 | 91 | // SetTimeout adds the timeout to the post data sources params 92 | func (o *PostDataSourcesParams) SetTimeout(timeout time.Duration) { 93 | o.timeout = timeout 94 | } 95 | 96 | // WithContext adds the context to the post data sources params 97 | func (o *PostDataSourcesParams) WithContext(ctx context.Context) *PostDataSourcesParams { 98 | o.SetContext(ctx) 99 | return o 100 | } 101 | 102 | // SetContext adds the context to the post data sources params 103 | func (o *PostDataSourcesParams) SetContext(ctx context.Context) { 104 | o.Context = ctx 105 | } 106 | 107 | // WithHTTPClient adds the HTTPClient to the post data sources params 108 | func (o *PostDataSourcesParams) WithHTTPClient(client *http.Client) *PostDataSourcesParams { 109 | o.SetHTTPClient(client) 110 | return o 111 | } 112 | 113 | // SetHTTPClient adds the HTTPClient to the post data sources params 114 | func (o *PostDataSourcesParams) SetHTTPClient(client *http.Client) { 115 | o.HTTPClient = client 116 | } 117 | 118 | // WithBody adds the body to the post data sources params 119 | func (o *PostDataSourcesParams) WithBody(body PostDataSourcesBody) *PostDataSourcesParams { 120 | o.SetBody(body) 121 | return o 122 | } 123 | 124 | // SetBody adds the body to the post data sources params 125 | func (o *PostDataSourcesParams) SetBody(body PostDataSourcesBody) { 126 | o.Body = body 127 | } 128 | 129 | // WriteToRequest writes these params to a swagger request 130 | func (o *PostDataSourcesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 131 | 132 | if err := r.SetTimeout(o.timeout); err != nil { 133 | return err 134 | } 135 | var res []error 136 | if err := r.SetBodyParam(o.Body); err != nil { 137 | return err 138 | } 139 | 140 | if len(res) > 0 { 141 | return errors.CompositeValidationError(res...) 142 | } 143 | return nil 144 | } 145 | -------------------------------------------------------------------------------- /gen/client/data_sources/post_data_sources_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package data_sources 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "io" 12 | 13 | "github.com/go-openapi/runtime" 14 | "github.com/go-openapi/strfmt" 15 | "github.com/go-openapi/swag" 16 | 17 | "github.com/recolabs/redash-go-sdk/gen/models" 18 | ) 19 | 20 | // PostDataSourcesReader is a Reader for the PostDataSources structure. 21 | type PostDataSourcesReader struct { 22 | formats strfmt.Registry 23 | } 24 | 25 | // ReadResponse reads a server response into the received o. 26 | func (o *PostDataSourcesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 27 | switch response.Code() { 28 | case 200: 29 | result := NewPostDataSourcesOK() 30 | if err := result.readResponse(response, consumer, o.formats); err != nil { 31 | return nil, err 32 | } 33 | return result, nil 34 | default: 35 | result := NewPostDataSourcesDefault(response.Code()) 36 | if err := result.readResponse(response, consumer, o.formats); err != nil { 37 | return nil, err 38 | } 39 | if response.Code()/100 == 2 { 40 | return result, nil 41 | } 42 | return nil, result 43 | } 44 | } 45 | 46 | // NewPostDataSourcesOK creates a PostDataSourcesOK with default headers values 47 | func NewPostDataSourcesOK() *PostDataSourcesOK { 48 | return &PostDataSourcesOK{} 49 | } 50 | 51 | /* PostDataSourcesOK describes a response with status code 200, with default header values. 52 | 53 | OK 54 | */ 55 | type PostDataSourcesOK struct { 56 | Payload *models.DataSource 57 | } 58 | 59 | func (o *PostDataSourcesOK) Error() string { 60 | return fmt.Sprintf("[POST /data_sources][%d] postDataSourcesOK %+v", 200, o.Payload) 61 | } 62 | func (o *PostDataSourcesOK) GetPayload() *models.DataSource { 63 | return o.Payload 64 | } 65 | 66 | func (o *PostDataSourcesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 67 | 68 | o.Payload = new(models.DataSource) 69 | 70 | // response payload 71 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 72 | return err 73 | } 74 | 75 | return nil 76 | } 77 | 78 | // NewPostDataSourcesDefault creates a PostDataSourcesDefault with default headers values 79 | func NewPostDataSourcesDefault(code int) *PostDataSourcesDefault { 80 | return &PostDataSourcesDefault{ 81 | _statusCode: code, 82 | } 83 | } 84 | 85 | /* PostDataSourcesDefault describes a response with status code -1, with default header values. 86 | 87 | error 88 | */ 89 | type PostDataSourcesDefault struct { 90 | _statusCode int 91 | 92 | Payload *models.Error 93 | } 94 | 95 | // Code gets the status code for the post data sources default response 96 | func (o *PostDataSourcesDefault) Code() int { 97 | return o._statusCode 98 | } 99 | 100 | func (o *PostDataSourcesDefault) Error() string { 101 | return fmt.Sprintf("[POST /data_sources][%d] PostDataSources default %+v", o._statusCode, o.Payload) 102 | } 103 | func (o *PostDataSourcesDefault) GetPayload() *models.Error { 104 | return o.Payload 105 | } 106 | 107 | func (o *PostDataSourcesDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 108 | 109 | o.Payload = new(models.Error) 110 | 111 | // response payload 112 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 113 | return err 114 | } 115 | 116 | return nil 117 | } 118 | 119 | /*PostDataSourcesBody post data sources body 120 | swagger:model PostDataSourcesBody 121 | */ 122 | type PostDataSourcesBody struct { 123 | 124 | // name 125 | Name string `json:"name,omitempty"` 126 | 127 | // options 128 | Options interface{} `json:"options,omitempty"` 129 | 130 | // type 131 | Type string `json:"type,omitempty"` 132 | } 133 | 134 | // Validate validates this post data sources body 135 | func (o *PostDataSourcesBody) Validate(formats strfmt.Registry) error { 136 | return nil 137 | } 138 | 139 | // ContextValidate validates this post data sources body based on context it is used 140 | func (o *PostDataSourcesBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 141 | return nil 142 | } 143 | 144 | // MarshalBinary interface implementation 145 | func (o *PostDataSourcesBody) MarshalBinary() ([]byte, error) { 146 | if o == nil { 147 | return nil, nil 148 | } 149 | return swag.WriteJSON(o) 150 | } 151 | 152 | // UnmarshalBinary interface implementation 153 | func (o *PostDataSourcesBody) UnmarshalBinary(b []byte) error { 154 | var res PostDataSourcesBody 155 | if err := swag.ReadJSON(b, &res); err != nil { 156 | return err 157 | } 158 | *o = res 159 | return nil 160 | } 161 | -------------------------------------------------------------------------------- /gen/client/queries/delete_queries_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewDeleteQueriesIDParams creates a new DeleteQueriesIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewDeleteQueriesIDParams() *DeleteQueriesIDParams { 27 | return &DeleteQueriesIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewDeleteQueriesIDParamsWithTimeout creates a new DeleteQueriesIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewDeleteQueriesIDParamsWithTimeout(timeout time.Duration) *DeleteQueriesIDParams { 35 | return &DeleteQueriesIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewDeleteQueriesIDParamsWithContext creates a new DeleteQueriesIDParams object 41 | // with the ability to set a context for a request. 42 | func NewDeleteQueriesIDParamsWithContext(ctx context.Context) *DeleteQueriesIDParams { 43 | return &DeleteQueriesIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewDeleteQueriesIDParamsWithHTTPClient creates a new DeleteQueriesIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewDeleteQueriesIDParamsWithHTTPClient(client *http.Client) *DeleteQueriesIDParams { 51 | return &DeleteQueriesIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* DeleteQueriesIDParams contains all the parameters to send to the API endpoint 57 | for the delete queries ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type DeleteQueriesIDParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the delete queries ID params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *DeleteQueriesIDParams) WithDefaults() *DeleteQueriesIDParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the delete queries ID params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *DeleteQueriesIDParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the delete queries ID params 87 | func (o *DeleteQueriesIDParams) WithTimeout(timeout time.Duration) *DeleteQueriesIDParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the delete queries ID params 93 | func (o *DeleteQueriesIDParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the delete queries ID params 98 | func (o *DeleteQueriesIDParams) WithContext(ctx context.Context) *DeleteQueriesIDParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the delete queries ID params 104 | func (o *DeleteQueriesIDParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the delete queries ID params 109 | func (o *DeleteQueriesIDParams) WithHTTPClient(client *http.Client) *DeleteQueriesIDParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the delete queries ID params 115 | func (o *DeleteQueriesIDParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the delete queries ID params 120 | func (o *DeleteQueriesIDParams) WithID(id int64) *DeleteQueriesIDParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the delete queries ID params 126 | func (o *DeleteQueriesIDParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *DeleteQueriesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/queries/delete_queries_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // DeleteQueriesIDReader is a Reader for the DeleteQueriesID structure. 19 | type DeleteQueriesIDReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *DeleteQueriesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewDeleteQueriesIDOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewDeleteQueriesIDDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewDeleteQueriesIDOK creates a DeleteQueriesIDOK with default headers values 45 | func NewDeleteQueriesIDOK() *DeleteQueriesIDOK { 46 | return &DeleteQueriesIDOK{} 47 | } 48 | 49 | /* DeleteQueriesIDOK describes a response with status code 200, with default header values. 50 | 51 | Query is archived 52 | */ 53 | type DeleteQueriesIDOK struct { 54 | } 55 | 56 | func (o *DeleteQueriesIDOK) Error() string { 57 | return fmt.Sprintf("[DELETE /queries/{id}][%d] deleteQueriesIdOK ", 200) 58 | } 59 | 60 | func (o *DeleteQueriesIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 61 | 62 | return nil 63 | } 64 | 65 | // NewDeleteQueriesIDDefault creates a DeleteQueriesIDDefault with default headers values 66 | func NewDeleteQueriesIDDefault(code int) *DeleteQueriesIDDefault { 67 | return &DeleteQueriesIDDefault{ 68 | _statusCode: code, 69 | } 70 | } 71 | 72 | /* DeleteQueriesIDDefault describes a response with status code -1, with default header values. 73 | 74 | error 75 | */ 76 | type DeleteQueriesIDDefault struct { 77 | _statusCode int 78 | 79 | Payload *models.Error 80 | } 81 | 82 | // Code gets the status code for the delete queries ID default response 83 | func (o *DeleteQueriesIDDefault) Code() int { 84 | return o._statusCode 85 | } 86 | 87 | func (o *DeleteQueriesIDDefault) Error() string { 88 | return fmt.Sprintf("[DELETE /queries/{id}][%d] DeleteQueriesID default %+v", o._statusCode, o.Payload) 89 | } 90 | func (o *DeleteQueriesIDDefault) GetPayload() *models.Error { 91 | return o.Payload 92 | } 93 | 94 | func (o *DeleteQueriesIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 95 | 96 | o.Payload = new(models.Error) 97 | 98 | // response payload 99 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 100 | return err 101 | } 102 | 103 | return nil 104 | } 105 | -------------------------------------------------------------------------------- /gen/client/queries/get_queries_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewGetQueriesIDParams creates a new GetQueriesIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewGetQueriesIDParams() *GetQueriesIDParams { 27 | return &GetQueriesIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewGetQueriesIDParamsWithTimeout creates a new GetQueriesIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewGetQueriesIDParamsWithTimeout(timeout time.Duration) *GetQueriesIDParams { 35 | return &GetQueriesIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetQueriesIDParamsWithContext creates a new GetQueriesIDParams object 41 | // with the ability to set a context for a request. 42 | func NewGetQueriesIDParamsWithContext(ctx context.Context) *GetQueriesIDParams { 43 | return &GetQueriesIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewGetQueriesIDParamsWithHTTPClient creates a new GetQueriesIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewGetQueriesIDParamsWithHTTPClient(client *http.Client) *GetQueriesIDParams { 51 | return &GetQueriesIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* GetQueriesIDParams contains all the parameters to send to the API endpoint 57 | for the get queries ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type GetQueriesIDParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the get queries ID params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *GetQueriesIDParams) WithDefaults() *GetQueriesIDParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the get queries ID params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *GetQueriesIDParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the get queries ID params 87 | func (o *GetQueriesIDParams) WithTimeout(timeout time.Duration) *GetQueriesIDParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the get queries ID params 93 | func (o *GetQueriesIDParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the get queries ID params 98 | func (o *GetQueriesIDParams) WithContext(ctx context.Context) *GetQueriesIDParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the get queries ID params 104 | func (o *GetQueriesIDParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the get queries ID params 109 | func (o *GetQueriesIDParams) WithHTTPClient(client *http.Client) *GetQueriesIDParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the get queries ID params 115 | func (o *GetQueriesIDParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the get queries ID params 120 | func (o *GetQueriesIDParams) WithID(id int64) *GetQueriesIDParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the get queries ID params 126 | func (o *GetQueriesIDParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *GetQueriesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/queries/get_queries_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // GetQueriesIDReader is a Reader for the GetQueriesID structure. 19 | type GetQueriesIDReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *GetQueriesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewGetQueriesIDOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewGetQueriesIDDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewGetQueriesIDOK creates a GetQueriesIDOK with default headers values 45 | func NewGetQueriesIDOK() *GetQueriesIDOK { 46 | return &GetQueriesIDOK{} 47 | } 48 | 49 | /* GetQueriesIDOK describes a response with status code 200, with default header values. 50 | 51 | Returned query object 52 | */ 53 | type GetQueriesIDOK struct { 54 | Payload *models.Query 55 | } 56 | 57 | func (o *GetQueriesIDOK) Error() string { 58 | return fmt.Sprintf("[GET /queries/{id}][%d] getQueriesIdOK %+v", 200, o.Payload) 59 | } 60 | func (o *GetQueriesIDOK) GetPayload() *models.Query { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetQueriesIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | o.Payload = new(models.Query) 67 | 68 | // response payload 69 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 70 | return err 71 | } 72 | 73 | return nil 74 | } 75 | 76 | // NewGetQueriesIDDefault creates a GetQueriesIDDefault with default headers values 77 | func NewGetQueriesIDDefault(code int) *GetQueriesIDDefault { 78 | return &GetQueriesIDDefault{ 79 | _statusCode: code, 80 | } 81 | } 82 | 83 | /* GetQueriesIDDefault describes a response with status code -1, with default header values. 84 | 85 | error 86 | */ 87 | type GetQueriesIDDefault struct { 88 | _statusCode int 89 | 90 | Payload *models.Error 91 | } 92 | 93 | // Code gets the status code for the get queries ID default response 94 | func (o *GetQueriesIDDefault) Code() int { 95 | return o._statusCode 96 | } 97 | 98 | func (o *GetQueriesIDDefault) Error() string { 99 | return fmt.Sprintf("[GET /queries/{id}][%d] GetQueriesID default %+v", o._statusCode, o.Payload) 100 | } 101 | func (o *GetQueriesIDDefault) GetPayload() *models.Error { 102 | return o.Payload 103 | } 104 | 105 | func (o *GetQueriesIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 106 | 107 | o.Payload = new(models.Error) 108 | 109 | // response payload 110 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 111 | return err 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /gen/client/queries/get_queries_id_results_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewGetQueriesIDResultsParams creates a new GetQueriesIDResultsParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewGetQueriesIDResultsParams() *GetQueriesIDResultsParams { 27 | return &GetQueriesIDResultsParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewGetQueriesIDResultsParamsWithTimeout creates a new GetQueriesIDResultsParams object 33 | // with the ability to set a timeout on a request. 34 | func NewGetQueriesIDResultsParamsWithTimeout(timeout time.Duration) *GetQueriesIDResultsParams { 35 | return &GetQueriesIDResultsParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetQueriesIDResultsParamsWithContext creates a new GetQueriesIDResultsParams object 41 | // with the ability to set a context for a request. 42 | func NewGetQueriesIDResultsParamsWithContext(ctx context.Context) *GetQueriesIDResultsParams { 43 | return &GetQueriesIDResultsParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewGetQueriesIDResultsParamsWithHTTPClient creates a new GetQueriesIDResultsParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewGetQueriesIDResultsParamsWithHTTPClient(client *http.Client) *GetQueriesIDResultsParams { 51 | return &GetQueriesIDResultsParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* GetQueriesIDResultsParams contains all the parameters to send to the API endpoint 57 | for the get queries ID results operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type GetQueriesIDResultsParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the get queries ID results params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *GetQueriesIDResultsParams) WithDefaults() *GetQueriesIDResultsParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the get queries ID results params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *GetQueriesIDResultsParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the get queries ID results params 87 | func (o *GetQueriesIDResultsParams) WithTimeout(timeout time.Duration) *GetQueriesIDResultsParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the get queries ID results params 93 | func (o *GetQueriesIDResultsParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the get queries ID results params 98 | func (o *GetQueriesIDResultsParams) WithContext(ctx context.Context) *GetQueriesIDResultsParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the get queries ID results params 104 | func (o *GetQueriesIDResultsParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the get queries ID results params 109 | func (o *GetQueriesIDResultsParams) WithHTTPClient(client *http.Client) *GetQueriesIDResultsParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the get queries ID results params 115 | func (o *GetQueriesIDResultsParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the get queries ID results params 120 | func (o *GetQueriesIDResultsParams) WithID(id int64) *GetQueriesIDResultsParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the get queries ID results params 126 | func (o *GetQueriesIDResultsParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *GetQueriesIDResultsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/queries/get_queries_id_results_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // GetQueriesIDResultsReader is a Reader for the GetQueriesIDResults structure. 19 | type GetQueriesIDResultsReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *GetQueriesIDResultsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewGetQueriesIDResultsOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewGetQueriesIDResultsDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewGetQueriesIDResultsOK creates a GetQueriesIDResultsOK with default headers values 45 | func NewGetQueriesIDResultsOK() *GetQueriesIDResultsOK { 46 | return &GetQueriesIDResultsOK{} 47 | } 48 | 49 | /* GetQueriesIDResultsOK describes a response with status code 200, with default header values. 50 | 51 | Query is executed 52 | */ 53 | type GetQueriesIDResultsOK struct { 54 | Payload *models.QueryResult 55 | } 56 | 57 | func (o *GetQueriesIDResultsOK) Error() string { 58 | return fmt.Sprintf("[GET /queries/{id}/results][%d] getQueriesIdResultsOK %+v", 200, o.Payload) 59 | } 60 | func (o *GetQueriesIDResultsOK) GetPayload() *models.QueryResult { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetQueriesIDResultsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | o.Payload = new(models.QueryResult) 67 | 68 | // response payload 69 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 70 | return err 71 | } 72 | 73 | return nil 74 | } 75 | 76 | // NewGetQueriesIDResultsDefault creates a GetQueriesIDResultsDefault with default headers values 77 | func NewGetQueriesIDResultsDefault(code int) *GetQueriesIDResultsDefault { 78 | return &GetQueriesIDResultsDefault{ 79 | _statusCode: code, 80 | } 81 | } 82 | 83 | /* GetQueriesIDResultsDefault describes a response with status code -1, with default header values. 84 | 85 | error 86 | */ 87 | type GetQueriesIDResultsDefault struct { 88 | _statusCode int 89 | 90 | Payload *models.Error 91 | } 92 | 93 | // Code gets the status code for the get queries ID results default response 94 | func (o *GetQueriesIDResultsDefault) Code() int { 95 | return o._statusCode 96 | } 97 | 98 | func (o *GetQueriesIDResultsDefault) Error() string { 99 | return fmt.Sprintf("[GET /queries/{id}/results][%d] GetQueriesIDResults default %+v", o._statusCode, o.Payload) 100 | } 101 | func (o *GetQueriesIDResultsDefault) GetPayload() *models.Error { 102 | return o.Payload 103 | } 104 | 105 | func (o *GetQueriesIDResultsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 106 | 107 | o.Payload = new(models.Error) 108 | 109 | // response payload 110 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 111 | return err 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /gen/client/queries/get_queries_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewGetQueriesParams creates a new GetQueriesParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewGetQueriesParams() *GetQueriesParams { 27 | return &GetQueriesParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewGetQueriesParamsWithTimeout creates a new GetQueriesParams object 33 | // with the ability to set a timeout on a request. 34 | func NewGetQueriesParamsWithTimeout(timeout time.Duration) *GetQueriesParams { 35 | return &GetQueriesParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetQueriesParamsWithContext creates a new GetQueriesParams object 41 | // with the ability to set a context for a request. 42 | func NewGetQueriesParamsWithContext(ctx context.Context) *GetQueriesParams { 43 | return &GetQueriesParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewGetQueriesParamsWithHTTPClient creates a new GetQueriesParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewGetQueriesParamsWithHTTPClient(client *http.Client) *GetQueriesParams { 51 | return &GetQueriesParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* GetQueriesParams contains all the parameters to send to the API endpoint 57 | for the get queries operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type GetQueriesParams struct { 62 | 63 | /* PageSize. 64 | 65 | Numeric ID to limit number of results 66 | 67 | Default: 100 68 | */ 69 | PageSize *int64 70 | 71 | timeout time.Duration 72 | Context context.Context 73 | HTTPClient *http.Client 74 | } 75 | 76 | // WithDefaults hydrates default values in the get queries params (not the query body). 77 | // 78 | // All values with no default are reset to their zero value. 79 | func (o *GetQueriesParams) WithDefaults() *GetQueriesParams { 80 | o.SetDefaults() 81 | return o 82 | } 83 | 84 | // SetDefaults hydrates default values in the get queries params (not the query body). 85 | // 86 | // All values with no default are reset to their zero value. 87 | func (o *GetQueriesParams) SetDefaults() { 88 | var ( 89 | pageSizeDefault = int64(100) 90 | ) 91 | 92 | val := GetQueriesParams{ 93 | PageSize: &pageSizeDefault, 94 | } 95 | 96 | val.timeout = o.timeout 97 | val.Context = o.Context 98 | val.HTTPClient = o.HTTPClient 99 | *o = val 100 | } 101 | 102 | // WithTimeout adds the timeout to the get queries params 103 | func (o *GetQueriesParams) WithTimeout(timeout time.Duration) *GetQueriesParams { 104 | o.SetTimeout(timeout) 105 | return o 106 | } 107 | 108 | // SetTimeout adds the timeout to the get queries params 109 | func (o *GetQueriesParams) SetTimeout(timeout time.Duration) { 110 | o.timeout = timeout 111 | } 112 | 113 | // WithContext adds the context to the get queries params 114 | func (o *GetQueriesParams) WithContext(ctx context.Context) *GetQueriesParams { 115 | o.SetContext(ctx) 116 | return o 117 | } 118 | 119 | // SetContext adds the context to the get queries params 120 | func (o *GetQueriesParams) SetContext(ctx context.Context) { 121 | o.Context = ctx 122 | } 123 | 124 | // WithHTTPClient adds the HTTPClient to the get queries params 125 | func (o *GetQueriesParams) WithHTTPClient(client *http.Client) *GetQueriesParams { 126 | o.SetHTTPClient(client) 127 | return o 128 | } 129 | 130 | // SetHTTPClient adds the HTTPClient to the get queries params 131 | func (o *GetQueriesParams) SetHTTPClient(client *http.Client) { 132 | o.HTTPClient = client 133 | } 134 | 135 | // WithPageSize adds the pageSize to the get queries params 136 | func (o *GetQueriesParams) WithPageSize(pageSize *int64) *GetQueriesParams { 137 | o.SetPageSize(pageSize) 138 | return o 139 | } 140 | 141 | // SetPageSize adds the pageSize to the get queries params 142 | func (o *GetQueriesParams) SetPageSize(pageSize *int64) { 143 | o.PageSize = pageSize 144 | } 145 | 146 | // WriteToRequest writes these params to a swagger request 147 | func (o *GetQueriesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 148 | 149 | if err := r.SetTimeout(o.timeout); err != nil { 150 | return err 151 | } 152 | var res []error 153 | 154 | if o.PageSize != nil { 155 | 156 | // query param page_size 157 | var qrPageSize int64 158 | 159 | if o.PageSize != nil { 160 | qrPageSize = *o.PageSize 161 | } 162 | qPageSize := swag.FormatInt64(qrPageSize) 163 | if qPageSize != "" { 164 | 165 | if err := r.SetQueryParam("page_size", qPageSize); err != nil { 166 | return err 167 | } 168 | } 169 | } 170 | 171 | if len(res) > 0 { 172 | return errors.CompositeValidationError(res...) 173 | } 174 | return nil 175 | } 176 | -------------------------------------------------------------------------------- /gen/client/queries/get_queries_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // GetQueriesReader is a Reader for the GetQueries structure. 19 | type GetQueriesReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *GetQueriesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewGetQueriesOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewGetQueriesDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewGetQueriesOK creates a GetQueriesOK with default headers values 45 | func NewGetQueriesOK() *GetQueriesOK { 46 | return &GetQueriesOK{} 47 | } 48 | 49 | /* GetQueriesOK describes a response with status code 200, with default header values. 50 | 51 | List queries 52 | */ 53 | type GetQueriesOK struct { 54 | Payload *models.QueryList 55 | } 56 | 57 | func (o *GetQueriesOK) Error() string { 58 | return fmt.Sprintf("[GET /queries][%d] getQueriesOK %+v", 200, o.Payload) 59 | } 60 | func (o *GetQueriesOK) GetPayload() *models.QueryList { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetQueriesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | o.Payload = new(models.QueryList) 67 | 68 | // response payload 69 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 70 | return err 71 | } 72 | 73 | return nil 74 | } 75 | 76 | // NewGetQueriesDefault creates a GetQueriesDefault with default headers values 77 | func NewGetQueriesDefault(code int) *GetQueriesDefault { 78 | return &GetQueriesDefault{ 79 | _statusCode: code, 80 | } 81 | } 82 | 83 | /* GetQueriesDefault describes a response with status code -1, with default header values. 84 | 85 | error 86 | */ 87 | type GetQueriesDefault struct { 88 | _statusCode int 89 | 90 | Payload *models.Error 91 | } 92 | 93 | // Code gets the status code for the get queries default response 94 | func (o *GetQueriesDefault) Code() int { 95 | return o._statusCode 96 | } 97 | 98 | func (o *GetQueriesDefault) Error() string { 99 | return fmt.Sprintf("[GET /queries][%d] GetQueries default %+v", o._statusCode, o.Payload) 100 | } 101 | func (o *GetQueriesDefault) GetPayload() *models.Error { 102 | return o.Payload 103 | } 104 | 105 | func (o *GetQueriesDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 106 | 107 | o.Payload = new(models.Error) 108 | 109 | // response payload 110 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 111 | return err 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /gen/client/queries/post_queries_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewPostQueriesIDParams creates a new PostQueriesIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewPostQueriesIDParams() *PostQueriesIDParams { 27 | return &PostQueriesIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewPostQueriesIDParamsWithTimeout creates a new PostQueriesIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewPostQueriesIDParamsWithTimeout(timeout time.Duration) *PostQueriesIDParams { 35 | return &PostQueriesIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewPostQueriesIDParamsWithContext creates a new PostQueriesIDParams object 41 | // with the ability to set a context for a request. 42 | func NewPostQueriesIDParamsWithContext(ctx context.Context) *PostQueriesIDParams { 43 | return &PostQueriesIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewPostQueriesIDParamsWithHTTPClient creates a new PostQueriesIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewPostQueriesIDParamsWithHTTPClient(client *http.Client) *PostQueriesIDParams { 51 | return &PostQueriesIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* PostQueriesIDParams contains all the parameters to send to the API endpoint 57 | for the post queries ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type PostQueriesIDParams struct { 62 | 63 | // Body. 64 | Body PostQueriesIDBody 65 | 66 | // ID. 67 | ID int64 68 | 69 | timeout time.Duration 70 | Context context.Context 71 | HTTPClient *http.Client 72 | } 73 | 74 | // WithDefaults hydrates default values in the post queries ID params (not the query body). 75 | // 76 | // All values with no default are reset to their zero value. 77 | func (o *PostQueriesIDParams) WithDefaults() *PostQueriesIDParams { 78 | o.SetDefaults() 79 | return o 80 | } 81 | 82 | // SetDefaults hydrates default values in the post queries ID params (not the query body). 83 | // 84 | // All values with no default are reset to their zero value. 85 | func (o *PostQueriesIDParams) SetDefaults() { 86 | // no default values defined for this parameter 87 | } 88 | 89 | // WithTimeout adds the timeout to the post queries ID params 90 | func (o *PostQueriesIDParams) WithTimeout(timeout time.Duration) *PostQueriesIDParams { 91 | o.SetTimeout(timeout) 92 | return o 93 | } 94 | 95 | // SetTimeout adds the timeout to the post queries ID params 96 | func (o *PostQueriesIDParams) SetTimeout(timeout time.Duration) { 97 | o.timeout = timeout 98 | } 99 | 100 | // WithContext adds the context to the post queries ID params 101 | func (o *PostQueriesIDParams) WithContext(ctx context.Context) *PostQueriesIDParams { 102 | o.SetContext(ctx) 103 | return o 104 | } 105 | 106 | // SetContext adds the context to the post queries ID params 107 | func (o *PostQueriesIDParams) SetContext(ctx context.Context) { 108 | o.Context = ctx 109 | } 110 | 111 | // WithHTTPClient adds the HTTPClient to the post queries ID params 112 | func (o *PostQueriesIDParams) WithHTTPClient(client *http.Client) *PostQueriesIDParams { 113 | o.SetHTTPClient(client) 114 | return o 115 | } 116 | 117 | // SetHTTPClient adds the HTTPClient to the post queries ID params 118 | func (o *PostQueriesIDParams) SetHTTPClient(client *http.Client) { 119 | o.HTTPClient = client 120 | } 121 | 122 | // WithBody adds the body to the post queries ID params 123 | func (o *PostQueriesIDParams) WithBody(body PostQueriesIDBody) *PostQueriesIDParams { 124 | o.SetBody(body) 125 | return o 126 | } 127 | 128 | // SetBody adds the body to the post queries ID params 129 | func (o *PostQueriesIDParams) SetBody(body PostQueriesIDBody) { 130 | o.Body = body 131 | } 132 | 133 | // WithID adds the id to the post queries ID params 134 | func (o *PostQueriesIDParams) WithID(id int64) *PostQueriesIDParams { 135 | o.SetID(id) 136 | return o 137 | } 138 | 139 | // SetID adds the id to the post queries ID params 140 | func (o *PostQueriesIDParams) SetID(id int64) { 141 | o.ID = id 142 | } 143 | 144 | // WriteToRequest writes these params to a swagger request 145 | func (o *PostQueriesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 146 | 147 | if err := r.SetTimeout(o.timeout); err != nil { 148 | return err 149 | } 150 | var res []error 151 | if err := r.SetBodyParam(o.Body); err != nil { 152 | return err 153 | } 154 | 155 | // path param id 156 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 157 | return err 158 | } 159 | 160 | if len(res) > 0 { 161 | return errors.CompositeValidationError(res...) 162 | } 163 | return nil 164 | } 165 | -------------------------------------------------------------------------------- /gen/client/queries/post_queries_id_regenerate_api_key_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewPostQueriesIDRegenerateAPIKeyParams creates a new PostQueriesIDRegenerateAPIKeyParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewPostQueriesIDRegenerateAPIKeyParams() *PostQueriesIDRegenerateAPIKeyParams { 27 | return &PostQueriesIDRegenerateAPIKeyParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewPostQueriesIDRegenerateAPIKeyParamsWithTimeout creates a new PostQueriesIDRegenerateAPIKeyParams object 33 | // with the ability to set a timeout on a request. 34 | func NewPostQueriesIDRegenerateAPIKeyParamsWithTimeout(timeout time.Duration) *PostQueriesIDRegenerateAPIKeyParams { 35 | return &PostQueriesIDRegenerateAPIKeyParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewPostQueriesIDRegenerateAPIKeyParamsWithContext creates a new PostQueriesIDRegenerateAPIKeyParams object 41 | // with the ability to set a context for a request. 42 | func NewPostQueriesIDRegenerateAPIKeyParamsWithContext(ctx context.Context) *PostQueriesIDRegenerateAPIKeyParams { 43 | return &PostQueriesIDRegenerateAPIKeyParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewPostQueriesIDRegenerateAPIKeyParamsWithHTTPClient creates a new PostQueriesIDRegenerateAPIKeyParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewPostQueriesIDRegenerateAPIKeyParamsWithHTTPClient(client *http.Client) *PostQueriesIDRegenerateAPIKeyParams { 51 | return &PostQueriesIDRegenerateAPIKeyParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* PostQueriesIDRegenerateAPIKeyParams contains all the parameters to send to the API endpoint 57 | for the post queries ID regenerate API key operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type PostQueriesIDRegenerateAPIKeyParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the post queries ID regenerate API key params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *PostQueriesIDRegenerateAPIKeyParams) WithDefaults() *PostQueriesIDRegenerateAPIKeyParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the post queries ID regenerate API key params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *PostQueriesIDRegenerateAPIKeyParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the post queries ID regenerate API key params 87 | func (o *PostQueriesIDRegenerateAPIKeyParams) WithTimeout(timeout time.Duration) *PostQueriesIDRegenerateAPIKeyParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the post queries ID regenerate API key params 93 | func (o *PostQueriesIDRegenerateAPIKeyParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the post queries ID regenerate API key params 98 | func (o *PostQueriesIDRegenerateAPIKeyParams) WithContext(ctx context.Context) *PostQueriesIDRegenerateAPIKeyParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the post queries ID regenerate API key params 104 | func (o *PostQueriesIDRegenerateAPIKeyParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the post queries ID regenerate API key params 109 | func (o *PostQueriesIDRegenerateAPIKeyParams) WithHTTPClient(client *http.Client) *PostQueriesIDRegenerateAPIKeyParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the post queries ID regenerate API key params 115 | func (o *PostQueriesIDRegenerateAPIKeyParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the post queries ID regenerate API key params 120 | func (o *PostQueriesIDRegenerateAPIKeyParams) WithID(id int64) *PostQueriesIDRegenerateAPIKeyParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the post queries ID regenerate API key params 126 | func (o *PostQueriesIDRegenerateAPIKeyParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *PostQueriesIDRegenerateAPIKeyParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/queries/post_queries_id_regenerate_api_key_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // PostQueriesIDRegenerateAPIKeyReader is a Reader for the PostQueriesIDRegenerateAPIKey structure. 19 | type PostQueriesIDRegenerateAPIKeyReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *PostQueriesIDRegenerateAPIKeyReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewPostQueriesIDRegenerateAPIKeyOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewPostQueriesIDRegenerateAPIKeyDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewPostQueriesIDRegenerateAPIKeyOK creates a PostQueriesIDRegenerateAPIKeyOK with default headers values 45 | func NewPostQueriesIDRegenerateAPIKeyOK() *PostQueriesIDRegenerateAPIKeyOK { 46 | return &PostQueriesIDRegenerateAPIKeyOK{} 47 | } 48 | 49 | /* PostQueriesIDRegenerateAPIKeyOK describes a response with status code 200, with default header values. 50 | 51 | The query which token was refreshed 52 | */ 53 | type PostQueriesIDRegenerateAPIKeyOK struct { 54 | } 55 | 56 | func (o *PostQueriesIDRegenerateAPIKeyOK) Error() string { 57 | return fmt.Sprintf("[POST /queries/{id}/regenerate_api_key][%d] postQueriesIdRegenerateApiKeyOK ", 200) 58 | } 59 | 60 | func (o *PostQueriesIDRegenerateAPIKeyOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 61 | 62 | return nil 63 | } 64 | 65 | // NewPostQueriesIDRegenerateAPIKeyDefault creates a PostQueriesIDRegenerateAPIKeyDefault with default headers values 66 | func NewPostQueriesIDRegenerateAPIKeyDefault(code int) *PostQueriesIDRegenerateAPIKeyDefault { 67 | return &PostQueriesIDRegenerateAPIKeyDefault{ 68 | _statusCode: code, 69 | } 70 | } 71 | 72 | /* PostQueriesIDRegenerateAPIKeyDefault describes a response with status code -1, with default header values. 73 | 74 | error 75 | */ 76 | type PostQueriesIDRegenerateAPIKeyDefault struct { 77 | _statusCode int 78 | 79 | Payload *models.Error 80 | } 81 | 82 | // Code gets the status code for the post queries ID regenerate API key default response 83 | func (o *PostQueriesIDRegenerateAPIKeyDefault) Code() int { 84 | return o._statusCode 85 | } 86 | 87 | func (o *PostQueriesIDRegenerateAPIKeyDefault) Error() string { 88 | return fmt.Sprintf("[POST /queries/{id}/regenerate_api_key][%d] PostQueriesIDRegenerateAPIKey default %+v", o._statusCode, o.Payload) 89 | } 90 | func (o *PostQueriesIDRegenerateAPIKeyDefault) GetPayload() *models.Error { 91 | return o.Payload 92 | } 93 | 94 | func (o *PostQueriesIDRegenerateAPIKeyDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 95 | 96 | o.Payload = new(models.Error) 97 | 98 | // response payload 99 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 100 | return err 101 | } 102 | 103 | return nil 104 | } 105 | -------------------------------------------------------------------------------- /gen/client/queries/post_queries_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "io" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | "github.com/go-openapi/strfmt" 16 | "github.com/go-openapi/swag" 17 | "github.com/go-openapi/validate" 18 | 19 | "github.com/recolabs/redash-go-sdk/gen/models" 20 | ) 21 | 22 | // PostQueriesIDReader is a Reader for the PostQueriesID structure. 23 | type PostQueriesIDReader struct { 24 | formats strfmt.Registry 25 | } 26 | 27 | // ReadResponse reads a server response into the received o. 28 | func (o *PostQueriesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 29 | switch response.Code() { 30 | case 200: 31 | result := NewPostQueriesIDOK() 32 | if err := result.readResponse(response, consumer, o.formats); err != nil { 33 | return nil, err 34 | } 35 | return result, nil 36 | default: 37 | result := NewPostQueriesIDDefault(response.Code()) 38 | if err := result.readResponse(response, consumer, o.formats); err != nil { 39 | return nil, err 40 | } 41 | if response.Code()/100 == 2 { 42 | return result, nil 43 | } 44 | return nil, result 45 | } 46 | } 47 | 48 | // NewPostQueriesIDOK creates a PostQueriesIDOK with default headers values 49 | func NewPostQueriesIDOK() *PostQueriesIDOK { 50 | return &PostQueriesIDOK{} 51 | } 52 | 53 | /* PostQueriesIDOK describes a response with status code 200, with default header values. 54 | 55 | Returned query object 56 | */ 57 | type PostQueriesIDOK struct { 58 | Payload *models.Query 59 | } 60 | 61 | func (o *PostQueriesIDOK) Error() string { 62 | return fmt.Sprintf("[POST /queries/{id}][%d] postQueriesIdOK %+v", 200, o.Payload) 63 | } 64 | func (o *PostQueriesIDOK) GetPayload() *models.Query { 65 | return o.Payload 66 | } 67 | 68 | func (o *PostQueriesIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 69 | 70 | o.Payload = new(models.Query) 71 | 72 | // response payload 73 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 74 | return err 75 | } 76 | 77 | return nil 78 | } 79 | 80 | // NewPostQueriesIDDefault creates a PostQueriesIDDefault with default headers values 81 | func NewPostQueriesIDDefault(code int) *PostQueriesIDDefault { 82 | return &PostQueriesIDDefault{ 83 | _statusCode: code, 84 | } 85 | } 86 | 87 | /* PostQueriesIDDefault describes a response with status code -1, with default header values. 88 | 89 | error 90 | */ 91 | type PostQueriesIDDefault struct { 92 | _statusCode int 93 | 94 | Payload *models.Error 95 | } 96 | 97 | // Code gets the status code for the post queries ID default response 98 | func (o *PostQueriesIDDefault) Code() int { 99 | return o._statusCode 100 | } 101 | 102 | func (o *PostQueriesIDDefault) Error() string { 103 | return fmt.Sprintf("[POST /queries/{id}][%d] PostQueriesID default %+v", o._statusCode, o.Payload) 104 | } 105 | func (o *PostQueriesIDDefault) GetPayload() *models.Error { 106 | return o.Payload 107 | } 108 | 109 | func (o *PostQueriesIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 110 | 111 | o.Payload = new(models.Error) 112 | 113 | // response payload 114 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 115 | return err 116 | } 117 | 118 | return nil 119 | } 120 | 121 | /*PostQueriesIDBody post queries ID body 122 | swagger:model PostQueriesIDBody 123 | */ 124 | type PostQueriesIDBody struct { 125 | 126 | // id 127 | ID int64 `json:"id,omitempty"` 128 | 129 | // is draft 130 | // Required: true 131 | IsDraft *bool `json:"is_draft"` 132 | 133 | // version 134 | Version *int64 `json:"version,omitempty"` 135 | } 136 | 137 | // Validate validates this post queries ID body 138 | func (o *PostQueriesIDBody) Validate(formats strfmt.Registry) error { 139 | var res []error 140 | 141 | if err := o.validateIsDraft(formats); err != nil { 142 | res = append(res, err) 143 | } 144 | 145 | if len(res) > 0 { 146 | return errors.CompositeValidationError(res...) 147 | } 148 | return nil 149 | } 150 | 151 | func (o *PostQueriesIDBody) validateIsDraft(formats strfmt.Registry) error { 152 | 153 | if err := validate.Required("body"+"."+"is_draft", "body", o.IsDraft); err != nil { 154 | return err 155 | } 156 | 157 | return nil 158 | } 159 | 160 | // ContextValidate validates this post queries ID body based on context it is used 161 | func (o *PostQueriesIDBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 162 | return nil 163 | } 164 | 165 | // MarshalBinary interface implementation 166 | func (o *PostQueriesIDBody) MarshalBinary() ([]byte, error) { 167 | if o == nil { 168 | return nil, nil 169 | } 170 | return swag.WriteJSON(o) 171 | } 172 | 173 | // UnmarshalBinary interface implementation 174 | func (o *PostQueriesIDBody) UnmarshalBinary(b []byte) error { 175 | var res PostQueriesIDBody 176 | if err := swag.ReadJSON(b, &res); err != nil { 177 | return err 178 | } 179 | *o = res 180 | return nil 181 | } 182 | -------------------------------------------------------------------------------- /gen/client/queries/post_queries_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package queries 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | ) 18 | 19 | // NewPostQueriesParams creates a new PostQueriesParams object, 20 | // with the default timeout for this client. 21 | // 22 | // Default values are not hydrated, since defaults are normally applied by the API server side. 23 | // 24 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 25 | func NewPostQueriesParams() *PostQueriesParams { 26 | return &PostQueriesParams{ 27 | timeout: cr.DefaultTimeout, 28 | } 29 | } 30 | 31 | // NewPostQueriesParamsWithTimeout creates a new PostQueriesParams object 32 | // with the ability to set a timeout on a request. 33 | func NewPostQueriesParamsWithTimeout(timeout time.Duration) *PostQueriesParams { 34 | return &PostQueriesParams{ 35 | timeout: timeout, 36 | } 37 | } 38 | 39 | // NewPostQueriesParamsWithContext creates a new PostQueriesParams object 40 | // with the ability to set a context for a request. 41 | func NewPostQueriesParamsWithContext(ctx context.Context) *PostQueriesParams { 42 | return &PostQueriesParams{ 43 | Context: ctx, 44 | } 45 | } 46 | 47 | // NewPostQueriesParamsWithHTTPClient creates a new PostQueriesParams object 48 | // with the ability to set a custom HTTPClient for a request. 49 | func NewPostQueriesParamsWithHTTPClient(client *http.Client) *PostQueriesParams { 50 | return &PostQueriesParams{ 51 | HTTPClient: client, 52 | } 53 | } 54 | 55 | /* PostQueriesParams contains all the parameters to send to the API endpoint 56 | for the post queries operation. 57 | 58 | Typically these are written to a http.Request. 59 | */ 60 | type PostQueriesParams struct { 61 | 62 | // Body. 63 | Body PostQueriesBody 64 | 65 | timeout time.Duration 66 | Context context.Context 67 | HTTPClient *http.Client 68 | } 69 | 70 | // WithDefaults hydrates default values in the post queries params (not the query body). 71 | // 72 | // All values with no default are reset to their zero value. 73 | func (o *PostQueriesParams) WithDefaults() *PostQueriesParams { 74 | o.SetDefaults() 75 | return o 76 | } 77 | 78 | // SetDefaults hydrates default values in the post queries params (not the query body). 79 | // 80 | // All values with no default are reset to their zero value. 81 | func (o *PostQueriesParams) SetDefaults() { 82 | // no default values defined for this parameter 83 | } 84 | 85 | // WithTimeout adds the timeout to the post queries params 86 | func (o *PostQueriesParams) WithTimeout(timeout time.Duration) *PostQueriesParams { 87 | o.SetTimeout(timeout) 88 | return o 89 | } 90 | 91 | // SetTimeout adds the timeout to the post queries params 92 | func (o *PostQueriesParams) SetTimeout(timeout time.Duration) { 93 | o.timeout = timeout 94 | } 95 | 96 | // WithContext adds the context to the post queries params 97 | func (o *PostQueriesParams) WithContext(ctx context.Context) *PostQueriesParams { 98 | o.SetContext(ctx) 99 | return o 100 | } 101 | 102 | // SetContext adds the context to the post queries params 103 | func (o *PostQueriesParams) SetContext(ctx context.Context) { 104 | o.Context = ctx 105 | } 106 | 107 | // WithHTTPClient adds the HTTPClient to the post queries params 108 | func (o *PostQueriesParams) WithHTTPClient(client *http.Client) *PostQueriesParams { 109 | o.SetHTTPClient(client) 110 | return o 111 | } 112 | 113 | // SetHTTPClient adds the HTTPClient to the post queries params 114 | func (o *PostQueriesParams) SetHTTPClient(client *http.Client) { 115 | o.HTTPClient = client 116 | } 117 | 118 | // WithBody adds the body to the post queries params 119 | func (o *PostQueriesParams) WithBody(body PostQueriesBody) *PostQueriesParams { 120 | o.SetBody(body) 121 | return o 122 | } 123 | 124 | // SetBody adds the body to the post queries params 125 | func (o *PostQueriesParams) SetBody(body PostQueriesBody) { 126 | o.Body = body 127 | } 128 | 129 | // WriteToRequest writes these params to a swagger request 130 | func (o *PostQueriesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 131 | 132 | if err := r.SetTimeout(o.timeout); err != nil { 133 | return err 134 | } 135 | var res []error 136 | if err := r.SetBodyParam(o.Body); err != nil { 137 | return err 138 | } 139 | 140 | if len(res) > 0 { 141 | return errors.CompositeValidationError(res...) 142 | } 143 | return nil 144 | } 145 | -------------------------------------------------------------------------------- /gen/client/redashclient_client.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package client 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "github.com/go-openapi/runtime" 10 | httptransport "github.com/go-openapi/runtime/client" 11 | "github.com/go-openapi/strfmt" 12 | 13 | "github.com/recolabs/redash-go-sdk/gen/client/administration" 14 | "github.com/recolabs/redash-go-sdk/gen/client/data_sources" 15 | "github.com/recolabs/redash-go-sdk/gen/client/queries" 16 | "github.com/recolabs/redash-go-sdk/gen/client/users" 17 | "github.com/recolabs/redash-go-sdk/gen/client/visualizations" 18 | ) 19 | 20 | // Default redashclient HTTP client. 21 | var Default = NewHTTPClient(nil) 22 | 23 | const ( 24 | // DefaultHost is the default Host 25 | // found in Meta (info) section of spec file 26 | DefaultHost string = "localhost" 27 | // DefaultBasePath is the default BasePath 28 | // found in Meta (info) section of spec file 29 | DefaultBasePath string = "/api" 30 | ) 31 | 32 | // DefaultSchemes are the default schemes found in Meta (info) section of spec file 33 | var DefaultSchemes = []string{"http", "https"} 34 | 35 | // NewHTTPClient creates a new redashclient HTTP client. 36 | func NewHTTPClient(formats strfmt.Registry) *Redashclient { 37 | return NewHTTPClientWithConfig(formats, nil) 38 | } 39 | 40 | // NewHTTPClientWithConfig creates a new redashclient HTTP client, 41 | // using a customizable transport config. 42 | func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *Redashclient { 43 | // ensure nullable parameters have default 44 | if cfg == nil { 45 | cfg = DefaultTransportConfig() 46 | } 47 | 48 | // create transport and client 49 | transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes) 50 | return New(transport, formats) 51 | } 52 | 53 | // New creates a new redashclient client 54 | func New(transport runtime.ClientTransport, formats strfmt.Registry) *Redashclient { 55 | // ensure nullable parameters have default 56 | if formats == nil { 57 | formats = strfmt.Default 58 | } 59 | 60 | cli := new(Redashclient) 61 | cli.Transport = transport 62 | cli.Administration = administration.New(transport, formats) 63 | cli.DataSources = data_sources.New(transport, formats) 64 | cli.Queries = queries.New(transport, formats) 65 | cli.Users = users.New(transport, formats) 66 | cli.Visualizations = visualizations.New(transport, formats) 67 | return cli 68 | } 69 | 70 | // DefaultTransportConfig creates a TransportConfig with the 71 | // default settings taken from the meta section of the spec file. 72 | func DefaultTransportConfig() *TransportConfig { 73 | return &TransportConfig{ 74 | Host: DefaultHost, 75 | BasePath: DefaultBasePath, 76 | Schemes: DefaultSchemes, 77 | } 78 | } 79 | 80 | // TransportConfig contains the transport related info, 81 | // found in the meta section of the spec file. 82 | type TransportConfig struct { 83 | Host string 84 | BasePath string 85 | Schemes []string 86 | } 87 | 88 | // WithHost overrides the default host, 89 | // provided by the meta section of the spec file. 90 | func (cfg *TransportConfig) WithHost(host string) *TransportConfig { 91 | cfg.Host = host 92 | return cfg 93 | } 94 | 95 | // WithBasePath overrides the default basePath, 96 | // provided by the meta section of the spec file. 97 | func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig { 98 | cfg.BasePath = basePath 99 | return cfg 100 | } 101 | 102 | // WithSchemes overrides the default schemes, 103 | // provided by the meta section of the spec file. 104 | func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig { 105 | cfg.Schemes = schemes 106 | return cfg 107 | } 108 | 109 | // Redashclient is a client for redashclient 110 | type Redashclient struct { 111 | Administration administration.ClientService 112 | 113 | DataSources data_sources.ClientService 114 | 115 | Queries queries.ClientService 116 | 117 | Users users.ClientService 118 | 119 | Visualizations visualizations.ClientService 120 | 121 | Transport runtime.ClientTransport 122 | } 123 | 124 | // SetTransport changes the transport on the client and all its subresources 125 | func (c *Redashclient) SetTransport(transport runtime.ClientTransport) { 126 | c.Transport = transport 127 | c.Administration.SetTransport(transport) 128 | c.DataSources.SetTransport(transport) 129 | c.Queries.SetTransport(transport) 130 | c.Users.SetTransport(transport) 131 | c.Visualizations.SetTransport(transport) 132 | } 133 | -------------------------------------------------------------------------------- /gen/client/users/get_users_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package users 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewGetUsersIDParams creates a new GetUsersIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewGetUsersIDParams() *GetUsersIDParams { 27 | return &GetUsersIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewGetUsersIDParamsWithTimeout creates a new GetUsersIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewGetUsersIDParamsWithTimeout(timeout time.Duration) *GetUsersIDParams { 35 | return &GetUsersIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetUsersIDParamsWithContext creates a new GetUsersIDParams object 41 | // with the ability to set a context for a request. 42 | func NewGetUsersIDParamsWithContext(ctx context.Context) *GetUsersIDParams { 43 | return &GetUsersIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewGetUsersIDParamsWithHTTPClient creates a new GetUsersIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewGetUsersIDParamsWithHTTPClient(client *http.Client) *GetUsersIDParams { 51 | return &GetUsersIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* GetUsersIDParams contains all the parameters to send to the API endpoint 57 | for the get users ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type GetUsersIDParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the get users ID params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *GetUsersIDParams) WithDefaults() *GetUsersIDParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the get users ID params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *GetUsersIDParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the get users ID params 87 | func (o *GetUsersIDParams) WithTimeout(timeout time.Duration) *GetUsersIDParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the get users ID params 93 | func (o *GetUsersIDParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the get users ID params 98 | func (o *GetUsersIDParams) WithContext(ctx context.Context) *GetUsersIDParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the get users ID params 104 | func (o *GetUsersIDParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the get users ID params 109 | func (o *GetUsersIDParams) WithHTTPClient(client *http.Client) *GetUsersIDParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the get users ID params 115 | func (o *GetUsersIDParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the get users ID params 120 | func (o *GetUsersIDParams) WithID(id int64) *GetUsersIDParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the get users ID params 126 | func (o *GetUsersIDParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *GetUsersIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/users/get_users_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package users 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // GetUsersIDReader is a Reader for the GetUsersID structure. 19 | type GetUsersIDReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *GetUsersIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewGetUsersIDOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewGetUsersIDDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewGetUsersIDOK creates a GetUsersIDOK with default headers values 45 | func NewGetUsersIDOK() *GetUsersIDOK { 46 | return &GetUsersIDOK{} 47 | } 48 | 49 | /* GetUsersIDOK describes a response with status code 200, with default header values. 50 | 51 | Get user by ID 52 | */ 53 | type GetUsersIDOK struct { 54 | Payload *models.User 55 | } 56 | 57 | func (o *GetUsersIDOK) Error() string { 58 | return fmt.Sprintf("[GET /users/{id}][%d] getUsersIdOK %+v", 200, o.Payload) 59 | } 60 | func (o *GetUsersIDOK) GetPayload() *models.User { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetUsersIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | o.Payload = new(models.User) 67 | 68 | // response payload 69 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 70 | return err 71 | } 72 | 73 | return nil 74 | } 75 | 76 | // NewGetUsersIDDefault creates a GetUsersIDDefault with default headers values 77 | func NewGetUsersIDDefault(code int) *GetUsersIDDefault { 78 | return &GetUsersIDDefault{ 79 | _statusCode: code, 80 | } 81 | } 82 | 83 | /* GetUsersIDDefault describes a response with status code -1, with default header values. 84 | 85 | error 86 | */ 87 | type GetUsersIDDefault struct { 88 | _statusCode int 89 | 90 | Payload *models.Error 91 | } 92 | 93 | // Code gets the status code for the get users ID default response 94 | func (o *GetUsersIDDefault) Code() int { 95 | return o._statusCode 96 | } 97 | 98 | func (o *GetUsersIDDefault) Error() string { 99 | return fmt.Sprintf("[GET /users/{id}][%d] GetUsersID default %+v", o._statusCode, o.Payload) 100 | } 101 | func (o *GetUsersIDDefault) GetPayload() *models.Error { 102 | return o.Payload 103 | } 104 | 105 | func (o *GetUsersIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 106 | 107 | o.Payload = new(models.Error) 108 | 109 | // response payload 110 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 111 | return err 112 | } 113 | 114 | return nil 115 | } 116 | -------------------------------------------------------------------------------- /gen/client/users/users_client.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package users 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "github.com/go-openapi/runtime" 10 | "github.com/go-openapi/strfmt" 11 | ) 12 | 13 | // New creates a new users API client. 14 | func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { 15 | return &Client{transport: transport, formats: formats} 16 | } 17 | 18 | /* 19 | Client for users API 20 | */ 21 | type Client struct { 22 | transport runtime.ClientTransport 23 | formats strfmt.Registry 24 | } 25 | 26 | // ClientOption is the option for Client methods 27 | type ClientOption func(*runtime.ClientOperation) 28 | 29 | // ClientService is the interface for Client methods 30 | type ClientService interface { 31 | GetUsersID(params *GetUsersIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetUsersIDOK, error) 32 | 33 | SetTransport(transport runtime.ClientTransport) 34 | } 35 | 36 | /* 37 | GetUsersID get users ID API 38 | */ 39 | func (a *Client) GetUsersID(params *GetUsersIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetUsersIDOK, error) { 40 | // TODO: Validate the params before sending 41 | if params == nil { 42 | params = NewGetUsersIDParams() 43 | } 44 | op := &runtime.ClientOperation{ 45 | ID: "GetUsersID", 46 | Method: "GET", 47 | PathPattern: "/users/{id}", 48 | ProducesMediaTypes: []string{"application/json"}, 49 | ConsumesMediaTypes: []string{"application/x-www-form-urlencoded"}, 50 | Schemes: []string{"http", "https"}, 51 | Params: params, 52 | Reader: &GetUsersIDReader{formats: a.formats}, 53 | AuthInfo: authInfo, 54 | Context: params.Context, 55 | Client: params.HTTPClient, 56 | } 57 | for _, opt := range opts { 58 | opt(op) 59 | } 60 | 61 | result, err := a.transport.Submit(op) 62 | if err != nil { 63 | return nil, err 64 | } 65 | success, ok := result.(*GetUsersIDOK) 66 | if ok { 67 | return success, nil 68 | } 69 | // unexpected success response 70 | unexpectedSuccess := result.(*GetUsersIDDefault) 71 | return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 72 | } 73 | 74 | // SetTransport changes the transport on the client 75 | func (a *Client) SetTransport(transport runtime.ClientTransport) { 76 | a.transport = transport 77 | } 78 | -------------------------------------------------------------------------------- /gen/client/visualizations/delete_visualizations_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package visualizations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | "github.com/go-openapi/swag" 18 | ) 19 | 20 | // NewDeleteVisualizationsIDParams creates a new DeleteVisualizationsIDParams object, 21 | // with the default timeout for this client. 22 | // 23 | // Default values are not hydrated, since defaults are normally applied by the API server side. 24 | // 25 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 26 | func NewDeleteVisualizationsIDParams() *DeleteVisualizationsIDParams { 27 | return &DeleteVisualizationsIDParams{ 28 | timeout: cr.DefaultTimeout, 29 | } 30 | } 31 | 32 | // NewDeleteVisualizationsIDParamsWithTimeout creates a new DeleteVisualizationsIDParams object 33 | // with the ability to set a timeout on a request. 34 | func NewDeleteVisualizationsIDParamsWithTimeout(timeout time.Duration) *DeleteVisualizationsIDParams { 35 | return &DeleteVisualizationsIDParams{ 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewDeleteVisualizationsIDParamsWithContext creates a new DeleteVisualizationsIDParams object 41 | // with the ability to set a context for a request. 42 | func NewDeleteVisualizationsIDParamsWithContext(ctx context.Context) *DeleteVisualizationsIDParams { 43 | return &DeleteVisualizationsIDParams{ 44 | Context: ctx, 45 | } 46 | } 47 | 48 | // NewDeleteVisualizationsIDParamsWithHTTPClient creates a new DeleteVisualizationsIDParams object 49 | // with the ability to set a custom HTTPClient for a request. 50 | func NewDeleteVisualizationsIDParamsWithHTTPClient(client *http.Client) *DeleteVisualizationsIDParams { 51 | return &DeleteVisualizationsIDParams{ 52 | HTTPClient: client, 53 | } 54 | } 55 | 56 | /* DeleteVisualizationsIDParams contains all the parameters to send to the API endpoint 57 | for the delete visualizations ID operation. 58 | 59 | Typically these are written to a http.Request. 60 | */ 61 | type DeleteVisualizationsIDParams struct { 62 | 63 | // ID. 64 | ID int64 65 | 66 | timeout time.Duration 67 | Context context.Context 68 | HTTPClient *http.Client 69 | } 70 | 71 | // WithDefaults hydrates default values in the delete visualizations ID params (not the query body). 72 | // 73 | // All values with no default are reset to their zero value. 74 | func (o *DeleteVisualizationsIDParams) WithDefaults() *DeleteVisualizationsIDParams { 75 | o.SetDefaults() 76 | return o 77 | } 78 | 79 | // SetDefaults hydrates default values in the delete visualizations ID params (not the query body). 80 | // 81 | // All values with no default are reset to their zero value. 82 | func (o *DeleteVisualizationsIDParams) SetDefaults() { 83 | // no default values defined for this parameter 84 | } 85 | 86 | // WithTimeout adds the timeout to the delete visualizations ID params 87 | func (o *DeleteVisualizationsIDParams) WithTimeout(timeout time.Duration) *DeleteVisualizationsIDParams { 88 | o.SetTimeout(timeout) 89 | return o 90 | } 91 | 92 | // SetTimeout adds the timeout to the delete visualizations ID params 93 | func (o *DeleteVisualizationsIDParams) SetTimeout(timeout time.Duration) { 94 | o.timeout = timeout 95 | } 96 | 97 | // WithContext adds the context to the delete visualizations ID params 98 | func (o *DeleteVisualizationsIDParams) WithContext(ctx context.Context) *DeleteVisualizationsIDParams { 99 | o.SetContext(ctx) 100 | return o 101 | } 102 | 103 | // SetContext adds the context to the delete visualizations ID params 104 | func (o *DeleteVisualizationsIDParams) SetContext(ctx context.Context) { 105 | o.Context = ctx 106 | } 107 | 108 | // WithHTTPClient adds the HTTPClient to the delete visualizations ID params 109 | func (o *DeleteVisualizationsIDParams) WithHTTPClient(client *http.Client) *DeleteVisualizationsIDParams { 110 | o.SetHTTPClient(client) 111 | return o 112 | } 113 | 114 | // SetHTTPClient adds the HTTPClient to the delete visualizations ID params 115 | func (o *DeleteVisualizationsIDParams) SetHTTPClient(client *http.Client) { 116 | o.HTTPClient = client 117 | } 118 | 119 | // WithID adds the id to the delete visualizations ID params 120 | func (o *DeleteVisualizationsIDParams) WithID(id int64) *DeleteVisualizationsIDParams { 121 | o.SetID(id) 122 | return o 123 | } 124 | 125 | // SetID adds the id to the delete visualizations ID params 126 | func (o *DeleteVisualizationsIDParams) SetID(id int64) { 127 | o.ID = id 128 | } 129 | 130 | // WriteToRequest writes these params to a swagger request 131 | func (o *DeleteVisualizationsIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 132 | 133 | if err := r.SetTimeout(o.timeout); err != nil { 134 | return err 135 | } 136 | var res []error 137 | 138 | // path param id 139 | if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil { 140 | return err 141 | } 142 | 143 | if len(res) > 0 { 144 | return errors.CompositeValidationError(res...) 145 | } 146 | return nil 147 | } 148 | -------------------------------------------------------------------------------- /gen/client/visualizations/delete_visualizations_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package visualizations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | "github.com/go-openapi/strfmt" 14 | 15 | "github.com/recolabs/redash-go-sdk/gen/models" 16 | ) 17 | 18 | // DeleteVisualizationsIDReader is a Reader for the DeleteVisualizationsID structure. 19 | type DeleteVisualizationsIDReader struct { 20 | formats strfmt.Registry 21 | } 22 | 23 | // ReadResponse reads a server response into the received o. 24 | func (o *DeleteVisualizationsIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 25 | switch response.Code() { 26 | case 200: 27 | result := NewDeleteVisualizationsIDOK() 28 | if err := result.readResponse(response, consumer, o.formats); err != nil { 29 | return nil, err 30 | } 31 | return result, nil 32 | default: 33 | result := NewDeleteVisualizationsIDDefault(response.Code()) 34 | if err := result.readResponse(response, consumer, o.formats); err != nil { 35 | return nil, err 36 | } 37 | if response.Code()/100 == 2 { 38 | return result, nil 39 | } 40 | return nil, result 41 | } 42 | } 43 | 44 | // NewDeleteVisualizationsIDOK creates a DeleteVisualizationsIDOK with default headers values 45 | func NewDeleteVisualizationsIDOK() *DeleteVisualizationsIDOK { 46 | return &DeleteVisualizationsIDOK{} 47 | } 48 | 49 | /* DeleteVisualizationsIDOK describes a response with status code 200, with default header values. 50 | 51 | Visualization was deleted 52 | */ 53 | type DeleteVisualizationsIDOK struct { 54 | } 55 | 56 | func (o *DeleteVisualizationsIDOK) Error() string { 57 | return fmt.Sprintf("[DELETE /visualizations/{id}][%d] deleteVisualizationsIdOK ", 200) 58 | } 59 | 60 | func (o *DeleteVisualizationsIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 61 | 62 | return nil 63 | } 64 | 65 | // NewDeleteVisualizationsIDDefault creates a DeleteVisualizationsIDDefault with default headers values 66 | func NewDeleteVisualizationsIDDefault(code int) *DeleteVisualizationsIDDefault { 67 | return &DeleteVisualizationsIDDefault{ 68 | _statusCode: code, 69 | } 70 | } 71 | 72 | /* DeleteVisualizationsIDDefault describes a response with status code -1, with default header values. 73 | 74 | error 75 | */ 76 | type DeleteVisualizationsIDDefault struct { 77 | _statusCode int 78 | 79 | Payload *models.Error 80 | } 81 | 82 | // Code gets the status code for the delete visualizations ID default response 83 | func (o *DeleteVisualizationsIDDefault) Code() int { 84 | return o._statusCode 85 | } 86 | 87 | func (o *DeleteVisualizationsIDDefault) Error() string { 88 | return fmt.Sprintf("[DELETE /visualizations/{id}][%d] DeleteVisualizationsID default %+v", o._statusCode, o.Payload) 89 | } 90 | func (o *DeleteVisualizationsIDDefault) GetPayload() *models.Error { 91 | return o.Payload 92 | } 93 | 94 | func (o *DeleteVisualizationsIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 95 | 96 | o.Payload = new(models.Error) 97 | 98 | // response payload 99 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 100 | return err 101 | } 102 | 103 | return nil 104 | } 105 | -------------------------------------------------------------------------------- /gen/client/visualizations/post_visualizations_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package visualizations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | "github.com/go-openapi/strfmt" 17 | ) 18 | 19 | // NewPostVisualizationsParams creates a new PostVisualizationsParams object, 20 | // with the default timeout for this client. 21 | // 22 | // Default values are not hydrated, since defaults are normally applied by the API server side. 23 | // 24 | // To enforce default values in parameter, use SetDefaults or WithDefaults. 25 | func NewPostVisualizationsParams() *PostVisualizationsParams { 26 | return &PostVisualizationsParams{ 27 | timeout: cr.DefaultTimeout, 28 | } 29 | } 30 | 31 | // NewPostVisualizationsParamsWithTimeout creates a new PostVisualizationsParams object 32 | // with the ability to set a timeout on a request. 33 | func NewPostVisualizationsParamsWithTimeout(timeout time.Duration) *PostVisualizationsParams { 34 | return &PostVisualizationsParams{ 35 | timeout: timeout, 36 | } 37 | } 38 | 39 | // NewPostVisualizationsParamsWithContext creates a new PostVisualizationsParams object 40 | // with the ability to set a context for a request. 41 | func NewPostVisualizationsParamsWithContext(ctx context.Context) *PostVisualizationsParams { 42 | return &PostVisualizationsParams{ 43 | Context: ctx, 44 | } 45 | } 46 | 47 | // NewPostVisualizationsParamsWithHTTPClient creates a new PostVisualizationsParams object 48 | // with the ability to set a custom HTTPClient for a request. 49 | func NewPostVisualizationsParamsWithHTTPClient(client *http.Client) *PostVisualizationsParams { 50 | return &PostVisualizationsParams{ 51 | HTTPClient: client, 52 | } 53 | } 54 | 55 | /* PostVisualizationsParams contains all the parameters to send to the API endpoint 56 | for the post visualizations operation. 57 | 58 | Typically these are written to a http.Request. 59 | */ 60 | type PostVisualizationsParams struct { 61 | 62 | // Body. 63 | Body PostVisualizationsBody 64 | 65 | timeout time.Duration 66 | Context context.Context 67 | HTTPClient *http.Client 68 | } 69 | 70 | // WithDefaults hydrates default values in the post visualizations params (not the query body). 71 | // 72 | // All values with no default are reset to their zero value. 73 | func (o *PostVisualizationsParams) WithDefaults() *PostVisualizationsParams { 74 | o.SetDefaults() 75 | return o 76 | } 77 | 78 | // SetDefaults hydrates default values in the post visualizations params (not the query body). 79 | // 80 | // All values with no default are reset to their zero value. 81 | func (o *PostVisualizationsParams) SetDefaults() { 82 | // no default values defined for this parameter 83 | } 84 | 85 | // WithTimeout adds the timeout to the post visualizations params 86 | func (o *PostVisualizationsParams) WithTimeout(timeout time.Duration) *PostVisualizationsParams { 87 | o.SetTimeout(timeout) 88 | return o 89 | } 90 | 91 | // SetTimeout adds the timeout to the post visualizations params 92 | func (o *PostVisualizationsParams) SetTimeout(timeout time.Duration) { 93 | o.timeout = timeout 94 | } 95 | 96 | // WithContext adds the context to the post visualizations params 97 | func (o *PostVisualizationsParams) WithContext(ctx context.Context) *PostVisualizationsParams { 98 | o.SetContext(ctx) 99 | return o 100 | } 101 | 102 | // SetContext adds the context to the post visualizations params 103 | func (o *PostVisualizationsParams) SetContext(ctx context.Context) { 104 | o.Context = ctx 105 | } 106 | 107 | // WithHTTPClient adds the HTTPClient to the post visualizations params 108 | func (o *PostVisualizationsParams) WithHTTPClient(client *http.Client) *PostVisualizationsParams { 109 | o.SetHTTPClient(client) 110 | return o 111 | } 112 | 113 | // SetHTTPClient adds the HTTPClient to the post visualizations params 114 | func (o *PostVisualizationsParams) SetHTTPClient(client *http.Client) { 115 | o.HTTPClient = client 116 | } 117 | 118 | // WithBody adds the body to the post visualizations params 119 | func (o *PostVisualizationsParams) WithBody(body PostVisualizationsBody) *PostVisualizationsParams { 120 | o.SetBody(body) 121 | return o 122 | } 123 | 124 | // SetBody adds the body to the post visualizations params 125 | func (o *PostVisualizationsParams) SetBody(body PostVisualizationsBody) { 126 | o.Body = body 127 | } 128 | 129 | // WriteToRequest writes these params to a swagger request 130 | func (o *PostVisualizationsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 131 | 132 | if err := r.SetTimeout(o.timeout); err != nil { 133 | return err 134 | } 135 | var res []error 136 | if err := r.SetBodyParam(o.Body); err != nil { 137 | return err 138 | } 139 | 140 | if len(res) > 0 { 141 | return errors.CompositeValidationError(res...) 142 | } 143 | return nil 144 | } 145 | -------------------------------------------------------------------------------- /gen/client/visualizations/post_visualizations_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package visualizations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "io" 12 | 13 | "github.com/go-openapi/runtime" 14 | "github.com/go-openapi/strfmt" 15 | "github.com/go-openapi/swag" 16 | 17 | "github.com/recolabs/redash-go-sdk/gen/models" 18 | ) 19 | 20 | // PostVisualizationsReader is a Reader for the PostVisualizations structure. 21 | type PostVisualizationsReader struct { 22 | formats strfmt.Registry 23 | } 24 | 25 | // ReadResponse reads a server response into the received o. 26 | func (o *PostVisualizationsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 27 | switch response.Code() { 28 | case 200: 29 | result := NewPostVisualizationsOK() 30 | if err := result.readResponse(response, consumer, o.formats); err != nil { 31 | return nil, err 32 | } 33 | return result, nil 34 | default: 35 | result := NewPostVisualizationsDefault(response.Code()) 36 | if err := result.readResponse(response, consumer, o.formats); err != nil { 37 | return nil, err 38 | } 39 | if response.Code()/100 == 2 { 40 | return result, nil 41 | } 42 | return nil, result 43 | } 44 | } 45 | 46 | // NewPostVisualizationsOK creates a PostVisualizationsOK with default headers values 47 | func NewPostVisualizationsOK() *PostVisualizationsOK { 48 | return &PostVisualizationsOK{} 49 | } 50 | 51 | /* PostVisualizationsOK describes a response with status code 200, with default header values. 52 | 53 | OK 54 | */ 55 | type PostVisualizationsOK struct { 56 | Payload *models.Visualization 57 | } 58 | 59 | func (o *PostVisualizationsOK) Error() string { 60 | return fmt.Sprintf("[POST /visualizations][%d] postVisualizationsOK %+v", 200, o.Payload) 61 | } 62 | func (o *PostVisualizationsOK) GetPayload() *models.Visualization { 63 | return o.Payload 64 | } 65 | 66 | func (o *PostVisualizationsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 67 | 68 | o.Payload = new(models.Visualization) 69 | 70 | // response payload 71 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 72 | return err 73 | } 74 | 75 | return nil 76 | } 77 | 78 | // NewPostVisualizationsDefault creates a PostVisualizationsDefault with default headers values 79 | func NewPostVisualizationsDefault(code int) *PostVisualizationsDefault { 80 | return &PostVisualizationsDefault{ 81 | _statusCode: code, 82 | } 83 | } 84 | 85 | /* PostVisualizationsDefault describes a response with status code -1, with default header values. 86 | 87 | error 88 | */ 89 | type PostVisualizationsDefault struct { 90 | _statusCode int 91 | 92 | Payload *models.Error 93 | } 94 | 95 | // Code gets the status code for the post visualizations default response 96 | func (o *PostVisualizationsDefault) Code() int { 97 | return o._statusCode 98 | } 99 | 100 | func (o *PostVisualizationsDefault) Error() string { 101 | return fmt.Sprintf("[POST /visualizations][%d] PostVisualizations default %+v", o._statusCode, o.Payload) 102 | } 103 | func (o *PostVisualizationsDefault) GetPayload() *models.Error { 104 | return o.Payload 105 | } 106 | 107 | func (o *PostVisualizationsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 108 | 109 | o.Payload = new(models.Error) 110 | 111 | // response payload 112 | if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { 113 | return err 114 | } 115 | 116 | return nil 117 | } 118 | 119 | /*PostVisualizationsBody post visualizations body 120 | swagger:model PostVisualizationsBody 121 | */ 122 | type PostVisualizationsBody struct { 123 | 124 | // name 125 | Name string `json:"name,omitempty"` 126 | 127 | // options 128 | Options interface{} `json:"options,omitempty"` 129 | 130 | // query id 131 | QueryID int64 `json:"query_id,omitempty"` 132 | 133 | // type 134 | Type string `json:"type,omitempty"` 135 | } 136 | 137 | // Validate validates this post visualizations body 138 | func (o *PostVisualizationsBody) Validate(formats strfmt.Registry) error { 139 | return nil 140 | } 141 | 142 | // ContextValidate validates this post visualizations body based on context it is used 143 | func (o *PostVisualizationsBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 144 | return nil 145 | } 146 | 147 | // MarshalBinary interface implementation 148 | func (o *PostVisualizationsBody) MarshalBinary() ([]byte, error) { 149 | if o == nil { 150 | return nil, nil 151 | } 152 | return swag.WriteJSON(o) 153 | } 154 | 155 | // UnmarshalBinary interface implementation 156 | func (o *PostVisualizationsBody) UnmarshalBinary(b []byte) error { 157 | var res PostVisualizationsBody 158 | if err := swag.ReadJSON(b, &res); err != nil { 159 | return err 160 | } 161 | *o = res 162 | return nil 163 | } 164 | -------------------------------------------------------------------------------- /gen/client/visualizations/visualizations_client.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package visualizations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "github.com/go-openapi/runtime" 10 | "github.com/go-openapi/strfmt" 11 | ) 12 | 13 | // New creates a new visualizations API client. 14 | func New(transport runtime.ClientTransport, formats strfmt.Registry) ClientService { 15 | return &Client{transport: transport, formats: formats} 16 | } 17 | 18 | /* 19 | Client for visualizations API 20 | */ 21 | type Client struct { 22 | transport runtime.ClientTransport 23 | formats strfmt.Registry 24 | } 25 | 26 | // ClientOption is the option for Client methods 27 | type ClientOption func(*runtime.ClientOperation) 28 | 29 | // ClientService is the interface for Client methods 30 | type ClientService interface { 31 | DeleteVisualizationsID(params *DeleteVisualizationsIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteVisualizationsIDOK, error) 32 | 33 | PostVisualizations(params *PostVisualizationsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostVisualizationsOK, error) 34 | 35 | SetTransport(transport runtime.ClientTransport) 36 | } 37 | 38 | /* 39 | DeleteVisualizationsID delete visualizations ID API 40 | */ 41 | func (a *Client) DeleteVisualizationsID(params *DeleteVisualizationsIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteVisualizationsIDOK, error) { 42 | // TODO: Validate the params before sending 43 | if params == nil { 44 | params = NewDeleteVisualizationsIDParams() 45 | } 46 | op := &runtime.ClientOperation{ 47 | ID: "DeleteVisualizationsID", 48 | Method: "DELETE", 49 | PathPattern: "/visualizations/{id}", 50 | ProducesMediaTypes: []string{"application/json"}, 51 | ConsumesMediaTypes: []string{"application/x-www-form-urlencoded"}, 52 | Schemes: []string{"http", "https"}, 53 | Params: params, 54 | Reader: &DeleteVisualizationsIDReader{formats: a.formats}, 55 | AuthInfo: authInfo, 56 | Context: params.Context, 57 | Client: params.HTTPClient, 58 | } 59 | for _, opt := range opts { 60 | opt(op) 61 | } 62 | 63 | result, err := a.transport.Submit(op) 64 | if err != nil { 65 | return nil, err 66 | } 67 | success, ok := result.(*DeleteVisualizationsIDOK) 68 | if ok { 69 | return success, nil 70 | } 71 | // unexpected success response 72 | unexpectedSuccess := result.(*DeleteVisualizationsIDDefault) 73 | return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 74 | } 75 | 76 | /* 77 | PostVisualizations post visualizations API 78 | */ 79 | func (a *Client) PostVisualizations(params *PostVisualizationsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*PostVisualizationsOK, error) { 80 | // TODO: Validate the params before sending 81 | if params == nil { 82 | params = NewPostVisualizationsParams() 83 | } 84 | op := &runtime.ClientOperation{ 85 | ID: "PostVisualizations", 86 | Method: "POST", 87 | PathPattern: "/visualizations", 88 | ProducesMediaTypes: []string{"application/json"}, 89 | ConsumesMediaTypes: []string{"application/json"}, 90 | Schemes: []string{"http", "https"}, 91 | Params: params, 92 | Reader: &PostVisualizationsReader{formats: a.formats}, 93 | AuthInfo: authInfo, 94 | Context: params.Context, 95 | Client: params.HTTPClient, 96 | } 97 | for _, opt := range opts { 98 | opt(op) 99 | } 100 | 101 | result, err := a.transport.Submit(op) 102 | if err != nil { 103 | return nil, err 104 | } 105 | success, ok := result.(*PostVisualizationsOK) 106 | if ok { 107 | return success, nil 108 | } 109 | // unexpected success response 110 | unexpectedSuccess := result.(*PostVisualizationsDefault) 111 | return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) 112 | } 113 | 114 | // SetTransport changes the transport on the client 115 | func (a *Client) SetTransport(transport runtime.ClientTransport) { 116 | a.transport = transport 117 | } 118 | -------------------------------------------------------------------------------- /gen/models/error.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | 11 | "github.com/go-openapi/errors" 12 | "github.com/go-openapi/strfmt" 13 | "github.com/go-openapi/swag" 14 | "github.com/go-openapi/validate" 15 | ) 16 | 17 | // Error error 18 | // 19 | // swagger:model error 20 | type Error struct { 21 | 22 | // code 23 | Code int64 `json:"code,omitempty"` 24 | 25 | // message 26 | // Required: true 27 | Message *string `json:"message"` 28 | } 29 | 30 | // Validate validates this error 31 | func (m *Error) Validate(formats strfmt.Registry) error { 32 | var res []error 33 | 34 | if err := m.validateMessage(formats); err != nil { 35 | res = append(res, err) 36 | } 37 | 38 | if len(res) > 0 { 39 | return errors.CompositeValidationError(res...) 40 | } 41 | return nil 42 | } 43 | 44 | func (m *Error) validateMessage(formats strfmt.Registry) error { 45 | 46 | if err := validate.Required("message", "body", m.Message); err != nil { 47 | return err 48 | } 49 | 50 | return nil 51 | } 52 | 53 | // ContextValidate validates this error based on context it is used 54 | func (m *Error) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 55 | return nil 56 | } 57 | 58 | // MarshalBinary interface implementation 59 | func (m *Error) MarshalBinary() ([]byte, error) { 60 | if m == nil { 61 | return nil, nil 62 | } 63 | return swag.WriteJSON(m) 64 | } 65 | 66 | // UnmarshalBinary interface implementation 67 | func (m *Error) UnmarshalBinary(b []byte) error { 68 | var res Error 69 | if err := swag.ReadJSON(b, &res); err != nil { 70 | return err 71 | } 72 | *m = res 73 | return nil 74 | } 75 | -------------------------------------------------------------------------------- /gen/models/job_result.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | 11 | "github.com/go-openapi/errors" 12 | "github.com/go-openapi/strfmt" 13 | "github.com/go-openapi/swag" 14 | ) 15 | 16 | // JobResult job result 17 | // 18 | // swagger:model jobResult 19 | type JobResult struct { 20 | 21 | // job 22 | Job *JobResultJob `json:"job,omitempty"` 23 | } 24 | 25 | // Validate validates this job result 26 | func (m *JobResult) Validate(formats strfmt.Registry) error { 27 | var res []error 28 | 29 | if err := m.validateJob(formats); err != nil { 30 | res = append(res, err) 31 | } 32 | 33 | if len(res) > 0 { 34 | return errors.CompositeValidationError(res...) 35 | } 36 | return nil 37 | } 38 | 39 | func (m *JobResult) validateJob(formats strfmt.Registry) error { 40 | if swag.IsZero(m.Job) { // not required 41 | return nil 42 | } 43 | 44 | if m.Job != nil { 45 | if err := m.Job.Validate(formats); err != nil { 46 | if ve, ok := err.(*errors.Validation); ok { 47 | return ve.ValidateName("job") 48 | } else if ce, ok := err.(*errors.CompositeError); ok { 49 | return ce.ValidateName("job") 50 | } 51 | return err 52 | } 53 | } 54 | 55 | return nil 56 | } 57 | 58 | // ContextValidate validate this job result based on the context it is used 59 | func (m *JobResult) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 60 | var res []error 61 | 62 | if err := m.contextValidateJob(ctx, formats); err != nil { 63 | res = append(res, err) 64 | } 65 | 66 | if len(res) > 0 { 67 | return errors.CompositeValidationError(res...) 68 | } 69 | return nil 70 | } 71 | 72 | func (m *JobResult) contextValidateJob(ctx context.Context, formats strfmt.Registry) error { 73 | 74 | if m.Job != nil { 75 | if err := m.Job.ContextValidate(ctx, formats); err != nil { 76 | if ve, ok := err.(*errors.Validation); ok { 77 | return ve.ValidateName("job") 78 | } else if ce, ok := err.(*errors.CompositeError); ok { 79 | return ce.ValidateName("job") 80 | } 81 | return err 82 | } 83 | } 84 | 85 | return nil 86 | } 87 | 88 | // MarshalBinary interface implementation 89 | func (m *JobResult) MarshalBinary() ([]byte, error) { 90 | if m == nil { 91 | return nil, nil 92 | } 93 | return swag.WriteJSON(m) 94 | } 95 | 96 | // UnmarshalBinary interface implementation 97 | func (m *JobResult) UnmarshalBinary(b []byte) error { 98 | var res JobResult 99 | if err := swag.ReadJSON(b, &res); err != nil { 100 | return err 101 | } 102 | *m = res 103 | return nil 104 | } 105 | 106 | // JobResultJob job result job 107 | // 108 | // swagger:model JobResultJob 109 | type JobResultJob struct { 110 | 111 | // error 112 | Error string `json:"error,omitempty"` 113 | 114 | // id 115 | ID string `json:"id,omitempty"` 116 | 117 | // query result id 118 | QueryResultID string `json:"query_result_id,omitempty"` 119 | 120 | // result 121 | Result string `json:"result,omitempty"` 122 | 123 | // status 124 | Status int32 `json:"status,omitempty"` 125 | 126 | // updated at 127 | UpdatedAt int32 `json:"updated_at,omitempty"` 128 | } 129 | 130 | // Validate validates this job result job 131 | func (m *JobResultJob) Validate(formats strfmt.Registry) error { 132 | return nil 133 | } 134 | 135 | // ContextValidate validates this job result job based on context it is used 136 | func (m *JobResultJob) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 137 | return nil 138 | } 139 | 140 | // MarshalBinary interface implementation 141 | func (m *JobResultJob) MarshalBinary() ([]byte, error) { 142 | if m == nil { 143 | return nil, nil 144 | } 145 | return swag.WriteJSON(m) 146 | } 147 | 148 | // UnmarshalBinary interface implementation 149 | func (m *JobResultJob) UnmarshalBinary(b []byte) error { 150 | var res JobResultJob 151 | if err := swag.ReadJSON(b, &res); err != nil { 152 | return err 153 | } 154 | *m = res 155 | return nil 156 | } 157 | -------------------------------------------------------------------------------- /gen/models/query_list.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "strconv" 11 | 12 | "github.com/go-openapi/errors" 13 | "github.com/go-openapi/strfmt" 14 | "github.com/go-openapi/swag" 15 | "github.com/go-openapi/validate" 16 | ) 17 | 18 | // QueryList query list 19 | // 20 | // swagger:model queryList 21 | type QueryList struct { 22 | 23 | // count 24 | // Read Only: true 25 | Count int64 `json:"count,omitempty"` 26 | 27 | // page 28 | // Read Only: true 29 | Page int64 `json:"page,omitempty"` 30 | 31 | // results 32 | Results []*Query `json:"results"` 33 | } 34 | 35 | // Validate validates this query list 36 | func (m *QueryList) Validate(formats strfmt.Registry) error { 37 | var res []error 38 | 39 | if err := m.validateResults(formats); err != nil { 40 | res = append(res, err) 41 | } 42 | 43 | if len(res) > 0 { 44 | return errors.CompositeValidationError(res...) 45 | } 46 | return nil 47 | } 48 | 49 | func (m *QueryList) validateResults(formats strfmt.Registry) error { 50 | if swag.IsZero(m.Results) { // not required 51 | return nil 52 | } 53 | 54 | for i := 0; i < len(m.Results); i++ { 55 | if swag.IsZero(m.Results[i]) { // not required 56 | continue 57 | } 58 | 59 | if m.Results[i] != nil { 60 | if err := m.Results[i].Validate(formats); err != nil { 61 | if ve, ok := err.(*errors.Validation); ok { 62 | return ve.ValidateName("results" + "." + strconv.Itoa(i)) 63 | } else if ce, ok := err.(*errors.CompositeError); ok { 64 | return ce.ValidateName("results" + "." + strconv.Itoa(i)) 65 | } 66 | return err 67 | } 68 | } 69 | 70 | } 71 | 72 | return nil 73 | } 74 | 75 | // ContextValidate validate this query list based on the context it is used 76 | func (m *QueryList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 77 | var res []error 78 | 79 | if err := m.contextValidateCount(ctx, formats); err != nil { 80 | res = append(res, err) 81 | } 82 | 83 | if err := m.contextValidatePage(ctx, formats); err != nil { 84 | res = append(res, err) 85 | } 86 | 87 | if err := m.contextValidateResults(ctx, formats); err != nil { 88 | res = append(res, err) 89 | } 90 | 91 | if len(res) > 0 { 92 | return errors.CompositeValidationError(res...) 93 | } 94 | return nil 95 | } 96 | 97 | func (m *QueryList) contextValidateCount(ctx context.Context, formats strfmt.Registry) error { 98 | 99 | if err := validate.ReadOnly(ctx, "count", "body", int64(m.Count)); err != nil { 100 | return err 101 | } 102 | 103 | return nil 104 | } 105 | 106 | func (m *QueryList) contextValidatePage(ctx context.Context, formats strfmt.Registry) error { 107 | 108 | if err := validate.ReadOnly(ctx, "page", "body", int64(m.Page)); err != nil { 109 | return err 110 | } 111 | 112 | return nil 113 | } 114 | 115 | func (m *QueryList) contextValidateResults(ctx context.Context, formats strfmt.Registry) error { 116 | 117 | for i := 0; i < len(m.Results); i++ { 118 | 119 | if m.Results[i] != nil { 120 | if err := m.Results[i].ContextValidate(ctx, formats); err != nil { 121 | if ve, ok := err.(*errors.Validation); ok { 122 | return ve.ValidateName("results" + "." + strconv.Itoa(i)) 123 | } else if ce, ok := err.(*errors.CompositeError); ok { 124 | return ce.ValidateName("results" + "." + strconv.Itoa(i)) 125 | } 126 | return err 127 | } 128 | } 129 | 130 | } 131 | 132 | return nil 133 | } 134 | 135 | // MarshalBinary interface implementation 136 | func (m *QueryList) MarshalBinary() ([]byte, error) { 137 | if m == nil { 138 | return nil, nil 139 | } 140 | return swag.WriteJSON(m) 141 | } 142 | 143 | // UnmarshalBinary interface implementation 144 | func (m *QueryList) UnmarshalBinary(b []byte) error { 145 | var res QueryList 146 | if err := swag.ReadJSON(b, &res); err != nil { 147 | return err 148 | } 149 | *m = res 150 | return nil 151 | } 152 | -------------------------------------------------------------------------------- /gen/models/schedule.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | 11 | "github.com/go-openapi/strfmt" 12 | "github.com/go-openapi/swag" 13 | ) 14 | 15 | // Schedule schedule 16 | // 17 | // swagger:model schedule 18 | type Schedule struct { 19 | 20 | // day of week 21 | DayOfWeek string `json:"day_of_week,omitempty"` 22 | 23 | // interval 24 | Interval int64 `json:"interval,omitempty"` 25 | 26 | // time 27 | Time string `json:"time,omitempty"` 28 | 29 | // until 30 | Until string `json:"until,omitempty"` 31 | } 32 | 33 | // Validate validates this schedule 34 | func (m *Schedule) Validate(formats strfmt.Registry) error { 35 | return nil 36 | } 37 | 38 | // ContextValidate validates this schedule based on context it is used 39 | func (m *Schedule) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 40 | return nil 41 | } 42 | 43 | // MarshalBinary interface implementation 44 | func (m *Schedule) MarshalBinary() ([]byte, error) { 45 | if m == nil { 46 | return nil, nil 47 | } 48 | return swag.WriteJSON(m) 49 | } 50 | 51 | // UnmarshalBinary interface implementation 52 | func (m *Schedule) UnmarshalBinary(b []byte) error { 53 | var res Schedule 54 | if err := swag.ReadJSON(b, &res); err != nil { 55 | return err 56 | } 57 | *m = res 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /gen/models/user.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | 11 | "github.com/go-openapi/errors" 12 | "github.com/go-openapi/strfmt" 13 | "github.com/go-openapi/swag" 14 | "github.com/go-openapi/validate" 15 | ) 16 | 17 | // User user 18 | // 19 | // swagger:model user 20 | type User struct { 21 | 22 | // api key 23 | APIKey string `json:"apiKey,omitempty"` 24 | 25 | // created at 26 | // Format: date-time 27 | CreatedAt strfmt.DateTime `json:"created_at,omitempty"` 28 | 29 | // email 30 | // Required: true 31 | // Format: email 32 | Email *strfmt.Email `json:"email"` 33 | 34 | // groups 35 | Groups []int64 `json:"groups"` 36 | 37 | // id 38 | // Read Only: true 39 | ID int64 `json:"id,omitempty"` 40 | 41 | // name 42 | // Required: true 43 | Name *string `json:"name"` 44 | 45 | // org name 46 | // Required: true 47 | OrgName *string `json:"orgName"` 48 | 49 | // updated at 50 | // Format: date-time 51 | UpdatedAt strfmt.DateTime `json:"updated_at,omitempty"` 52 | } 53 | 54 | // Validate validates this user 55 | func (m *User) Validate(formats strfmt.Registry) error { 56 | var res []error 57 | 58 | if err := m.validateCreatedAt(formats); err != nil { 59 | res = append(res, err) 60 | } 61 | 62 | if err := m.validateEmail(formats); err != nil { 63 | res = append(res, err) 64 | } 65 | 66 | if err := m.validateName(formats); err != nil { 67 | res = append(res, err) 68 | } 69 | 70 | if err := m.validateOrgName(formats); err != nil { 71 | res = append(res, err) 72 | } 73 | 74 | if err := m.validateUpdatedAt(formats); err != nil { 75 | res = append(res, err) 76 | } 77 | 78 | if len(res) > 0 { 79 | return errors.CompositeValidationError(res...) 80 | } 81 | return nil 82 | } 83 | 84 | func (m *User) validateCreatedAt(formats strfmt.Registry) error { 85 | if swag.IsZero(m.CreatedAt) { // not required 86 | return nil 87 | } 88 | 89 | if err := validate.FormatOf("created_at", "body", "date-time", m.CreatedAt.String(), formats); err != nil { 90 | return err 91 | } 92 | 93 | return nil 94 | } 95 | 96 | func (m *User) validateEmail(formats strfmt.Registry) error { 97 | 98 | if err := validate.Required("email", "body", m.Email); err != nil { 99 | return err 100 | } 101 | 102 | if err := validate.FormatOf("email", "body", "email", m.Email.String(), formats); err != nil { 103 | return err 104 | } 105 | 106 | return nil 107 | } 108 | 109 | func (m *User) validateName(formats strfmt.Registry) error { 110 | 111 | if err := validate.Required("name", "body", m.Name); err != nil { 112 | return err 113 | } 114 | 115 | return nil 116 | } 117 | 118 | func (m *User) validateOrgName(formats strfmt.Registry) error { 119 | 120 | if err := validate.Required("orgName", "body", m.OrgName); err != nil { 121 | return err 122 | } 123 | 124 | return nil 125 | } 126 | 127 | func (m *User) validateUpdatedAt(formats strfmt.Registry) error { 128 | if swag.IsZero(m.UpdatedAt) { // not required 129 | return nil 130 | } 131 | 132 | if err := validate.FormatOf("updated_at", "body", "date-time", m.UpdatedAt.String(), formats); err != nil { 133 | return err 134 | } 135 | 136 | return nil 137 | } 138 | 139 | // ContextValidate validate this user based on the context it is used 140 | func (m *User) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 141 | var res []error 142 | 143 | if err := m.contextValidateID(ctx, formats); err != nil { 144 | res = append(res, err) 145 | } 146 | 147 | if len(res) > 0 { 148 | return errors.CompositeValidationError(res...) 149 | } 150 | return nil 151 | } 152 | 153 | func (m *User) contextValidateID(ctx context.Context, formats strfmt.Registry) error { 154 | 155 | if err := validate.ReadOnly(ctx, "id", "body", int64(m.ID)); err != nil { 156 | return err 157 | } 158 | 159 | return nil 160 | } 161 | 162 | // MarshalBinary interface implementation 163 | func (m *User) MarshalBinary() ([]byte, error) { 164 | if m == nil { 165 | return nil, nil 166 | } 167 | return swag.WriteJSON(m) 168 | } 169 | 170 | // UnmarshalBinary interface implementation 171 | func (m *User) UnmarshalBinary(b []byte) error { 172 | var res User 173 | if err := swag.ReadJSON(b, &res); err != nil { 174 | return err 175 | } 176 | *m = res 177 | return nil 178 | } 179 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/recolabs/redash-go-sdk 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/go-openapi/errors v0.20.2 7 | github.com/go-openapi/runtime v0.24.1 8 | github.com/go-openapi/strfmt v0.21.2 9 | github.com/go-openapi/swag v0.21.1 10 | github.com/go-openapi/validate v0.22.0 11 | github.com/stretchr/testify v1.8.0 12 | ) 13 | 14 | require ( 15 | github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect 16 | github.com/aws/aws-sdk-go v1.34.28 // indirect 17 | github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect 18 | github.com/go-openapi/analysis v0.21.3 // indirect 19 | github.com/go-openapi/spec v0.20.6 // indirect 20 | github.com/go-stack/stack v1.8.1 // indirect 21 | github.com/kisielk/errcheck v1.2.0 // indirect 22 | github.com/kr/pty v1.1.5 // indirect 23 | github.com/mailru/easyjson v0.7.7 // indirect 24 | github.com/mitchellh/mapstructure v1.5.0 // indirect 25 | github.com/pborman/uuid v1.2.0 // indirect 26 | github.com/vektah/gqlparser v1.1.2 // indirect 27 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect 28 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect 29 | go.mongodb.org/mongo-driver v1.9.1 // indirect 30 | golang.org/x/net v0.0.0-20220630215102-69896b714898 // indirect 31 | golang.org/x/tools v0.0.0-20190617190820-da514acc4774 // indirect 32 | ) 33 | -------------------------------------------------------------------------------- /mocks/administration/ClientOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package administrationmock 4 | 5 | import ( 6 | runtime "github.com/go-openapi/runtime" 7 | mock "github.com/stretchr/testify/mock" 8 | ) 9 | 10 | // ClientOption is an autogenerated mock type for the ClientOption type 11 | type ClientOption struct { 12 | mock.Mock 13 | } 14 | 15 | // Execute provides a mock function with given fields: _a0 16 | func (_m *ClientOption) Execute(_a0 *runtime.ClientOperation) { 17 | _m.Called(_a0) 18 | } 19 | -------------------------------------------------------------------------------- /mocks/administration/ClientService.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package administrationmock 4 | 5 | import ( 6 | administration "github.com/recolabs/redash-go-sdk/gen/client/administration" 7 | mock "github.com/stretchr/testify/mock" 8 | 9 | runtime "github.com/go-openapi/runtime" 10 | ) 11 | 12 | // ClientService is an autogenerated mock type for the ClientService type 13 | type ClientService struct { 14 | mock.Mock 15 | } 16 | 17 | // GetPing provides a mock function with given fields: params, authInfo, opts 18 | func (_m *ClientService) GetPing(params *administration.GetPingParams, authInfo runtime.ClientAuthInfoWriter, opts ...administration.ClientOption) (*administration.GetPingOK, error) { 19 | _va := make([]interface{}, len(opts)) 20 | for _i := range opts { 21 | _va[_i] = opts[_i] 22 | } 23 | var _ca []interface{} 24 | _ca = append(_ca, params, authInfo) 25 | _ca = append(_ca, _va...) 26 | ret := _m.Called(_ca...) 27 | 28 | var r0 *administration.GetPingOK 29 | if rf, ok := ret.Get(0).(func(*administration.GetPingParams, runtime.ClientAuthInfoWriter, ...administration.ClientOption) *administration.GetPingOK); ok { 30 | r0 = rf(params, authInfo, opts...) 31 | } else { 32 | if ret.Get(0) != nil { 33 | r0 = ret.Get(0).(*administration.GetPingOK) 34 | } 35 | } 36 | 37 | var r1 error 38 | if rf, ok := ret.Get(1).(func(*administration.GetPingParams, runtime.ClientAuthInfoWriter, ...administration.ClientOption) error); ok { 39 | r1 = rf(params, authInfo, opts...) 40 | } else { 41 | r1 = ret.Error(1) 42 | } 43 | 44 | return r0, r1 45 | } 46 | 47 | // SetTransport provides a mock function with given fields: transport 48 | func (_m *ClientService) SetTransport(transport runtime.ClientTransport) { 49 | _m.Called(transport) 50 | } 51 | -------------------------------------------------------------------------------- /mocks/data_sources/ClientOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.14.0. DO NOT EDIT. 2 | 3 | package data_sourcesmock 4 | 5 | import ( 6 | runtime "github.com/go-openapi/runtime" 7 | mock "github.com/stretchr/testify/mock" 8 | ) 9 | 10 | // ClientOption is an autogenerated mock type for the ClientOption type 11 | type ClientOption struct { 12 | mock.Mock 13 | } 14 | 15 | // Execute provides a mock function with given fields: _a0 16 | func (_m *ClientOption) Execute(_a0 *runtime.ClientOperation) { 17 | _m.Called(_a0) 18 | } 19 | 20 | type mockConstructorTestingTNewClientOption interface { 21 | mock.TestingT 22 | Cleanup(func()) 23 | } 24 | 25 | // NewClientOption creates a new instance of ClientOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 26 | func NewClientOption(t mockConstructorTestingTNewClientOption) *ClientOption { 27 | mock := &ClientOption{} 28 | mock.Mock.Test(t) 29 | 30 | t.Cleanup(func() { mock.AssertExpectations(t) }) 31 | 32 | return mock 33 | } 34 | -------------------------------------------------------------------------------- /mocks/queries/ClientOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package queriesmock 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | 8 | runtime "github.com/go-openapi/runtime" 9 | ) 10 | 11 | // ClientOption is an autogenerated mock type for the ClientOption type 12 | type ClientOption struct { 13 | mock.Mock 14 | } 15 | 16 | // Execute provides a mock function with given fields: _a0 17 | func (_m *ClientOption) Execute(_a0 *runtime.ClientOperation) { 18 | _m.Called(_a0) 19 | } 20 | -------------------------------------------------------------------------------- /mocks/users/ClientOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package usersmock 4 | 5 | import ( 6 | runtime "github.com/go-openapi/runtime" 7 | mock "github.com/stretchr/testify/mock" 8 | ) 9 | 10 | // ClientOption is an autogenerated mock type for the ClientOption type 11 | type ClientOption struct { 12 | mock.Mock 13 | } 14 | 15 | // Execute provides a mock function with given fields: _a0 16 | func (_m *ClientOption) Execute(_a0 *runtime.ClientOperation) { 17 | _m.Called(_a0) 18 | } 19 | -------------------------------------------------------------------------------- /mocks/users/ClientService.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package usersmock 4 | 5 | import ( 6 | runtime "github.com/go-openapi/runtime" 7 | mock "github.com/stretchr/testify/mock" 8 | 9 | users "github.com/recolabs/redash-go-sdk/gen/client/users" 10 | ) 11 | 12 | // ClientService is an autogenerated mock type for the ClientService type 13 | type ClientService struct { 14 | mock.Mock 15 | } 16 | 17 | // GetUsersID provides a mock function with given fields: params, authInfo, opts 18 | func (_m *ClientService) GetUsersID(params *users.GetUsersIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...users.ClientOption) (*users.GetUsersIDOK, error) { 19 | _va := make([]interface{}, len(opts)) 20 | for _i := range opts { 21 | _va[_i] = opts[_i] 22 | } 23 | var _ca []interface{} 24 | _ca = append(_ca, params, authInfo) 25 | _ca = append(_ca, _va...) 26 | ret := _m.Called(_ca...) 27 | 28 | var r0 *users.GetUsersIDOK 29 | if rf, ok := ret.Get(0).(func(*users.GetUsersIDParams, runtime.ClientAuthInfoWriter, ...users.ClientOption) *users.GetUsersIDOK); ok { 30 | r0 = rf(params, authInfo, opts...) 31 | } else { 32 | if ret.Get(0) != nil { 33 | r0 = ret.Get(0).(*users.GetUsersIDOK) 34 | } 35 | } 36 | 37 | var r1 error 38 | if rf, ok := ret.Get(1).(func(*users.GetUsersIDParams, runtime.ClientAuthInfoWriter, ...users.ClientOption) error); ok { 39 | r1 = rf(params, authInfo, opts...) 40 | } else { 41 | r1 = ret.Error(1) 42 | } 43 | 44 | return r0, r1 45 | } 46 | 47 | // SetTransport provides a mock function with given fields: transport 48 | func (_m *ClientService) SetTransport(transport runtime.ClientTransport) { 49 | _m.Called(transport) 50 | } 51 | -------------------------------------------------------------------------------- /mocks/visualizations/ClientOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package visualizationsmock 4 | 5 | import ( 6 | runtime "github.com/go-openapi/runtime" 7 | mock "github.com/stretchr/testify/mock" 8 | ) 9 | 10 | // ClientOption is an autogenerated mock type for the ClientOption type 11 | type ClientOption struct { 12 | mock.Mock 13 | } 14 | 15 | // Execute provides a mock function with given fields: _a0 16 | func (_m *ClientOption) Execute(_a0 *runtime.ClientOperation) { 17 | _m.Called(_a0) 18 | } 19 | -------------------------------------------------------------------------------- /mocks/visualizations/ClientService.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.9.4. DO NOT EDIT. 2 | 3 | package visualizationsmock 4 | 5 | import ( 6 | runtime "github.com/go-openapi/runtime" 7 | mock "github.com/stretchr/testify/mock" 8 | 9 | visualizations "github.com/recolabs/redash-go-sdk/gen/client/visualizations" 10 | ) 11 | 12 | // ClientService is an autogenerated mock type for the ClientService type 13 | type ClientService struct { 14 | mock.Mock 15 | } 16 | 17 | // DeleteVisualizationsID provides a mock function with given fields: params, authInfo, opts 18 | func (_m *ClientService) DeleteVisualizationsID(params *visualizations.DeleteVisualizationsIDParams, authInfo runtime.ClientAuthInfoWriter, opts ...visualizations.ClientOption) (*visualizations.DeleteVisualizationsIDOK, error) { 19 | _va := make([]interface{}, len(opts)) 20 | for _i := range opts { 21 | _va[_i] = opts[_i] 22 | } 23 | var _ca []interface{} 24 | _ca = append(_ca, params, authInfo) 25 | _ca = append(_ca, _va...) 26 | ret := _m.Called(_ca...) 27 | 28 | var r0 *visualizations.DeleteVisualizationsIDOK 29 | if rf, ok := ret.Get(0).(func(*visualizations.DeleteVisualizationsIDParams, runtime.ClientAuthInfoWriter, ...visualizations.ClientOption) *visualizations.DeleteVisualizationsIDOK); ok { 30 | r0 = rf(params, authInfo, opts...) 31 | } else { 32 | if ret.Get(0) != nil { 33 | r0 = ret.Get(0).(*visualizations.DeleteVisualizationsIDOK) 34 | } 35 | } 36 | 37 | var r1 error 38 | if rf, ok := ret.Get(1).(func(*visualizations.DeleteVisualizationsIDParams, runtime.ClientAuthInfoWriter, ...visualizations.ClientOption) error); ok { 39 | r1 = rf(params, authInfo, opts...) 40 | } else { 41 | r1 = ret.Error(1) 42 | } 43 | 44 | return r0, r1 45 | } 46 | 47 | // PostVisualizations provides a mock function with given fields: params, authInfo, opts 48 | func (_m *ClientService) PostVisualizations(params *visualizations.PostVisualizationsParams, authInfo runtime.ClientAuthInfoWriter, opts ...visualizations.ClientOption) (*visualizations.PostVisualizationsOK, error) { 49 | _va := make([]interface{}, len(opts)) 50 | for _i := range opts { 51 | _va[_i] = opts[_i] 52 | } 53 | var _ca []interface{} 54 | _ca = append(_ca, params, authInfo) 55 | _ca = append(_ca, _va...) 56 | ret := _m.Called(_ca...) 57 | 58 | var r0 *visualizations.PostVisualizationsOK 59 | if rf, ok := ret.Get(0).(func(*visualizations.PostVisualizationsParams, runtime.ClientAuthInfoWriter, ...visualizations.ClientOption) *visualizations.PostVisualizationsOK); ok { 60 | r0 = rf(params, authInfo, opts...) 61 | } else { 62 | if ret.Get(0) != nil { 63 | r0 = ret.Get(0).(*visualizations.PostVisualizationsOK) 64 | } 65 | } 66 | 67 | var r1 error 68 | if rf, ok := ret.Get(1).(func(*visualizations.PostVisualizationsParams, runtime.ClientAuthInfoWriter, ...visualizations.ClientOption) error); ok { 69 | r1 = rf(params, authInfo, opts...) 70 | } else { 71 | r1 = ret.Error(1) 72 | } 73 | 74 | return r0, r1 75 | } 76 | 77 | // SetTransport provides a mock function with given fields: transport 78 | func (_m *ClientService) SetTransport(transport runtime.ClientTransport) { 79 | _m.Called(transport) 80 | } 81 | -------------------------------------------------------------------------------- /options/options.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | ) 8 | 9 | func MapFromString(optionsJSON string) (map[string]interface{}, error) { 10 | compactOptions := new(bytes.Buffer) 11 | if err := json.Compact(compactOptions, []byte(optionsJSON)); err != nil { 12 | return map[string]interface{}{}, fmt.Errorf("options is not a valid json string, options: %v", optionsJSON) 13 | } 14 | 15 | var options map[string]interface{} 16 | err := json.Unmarshal(compactOptions.Bytes(), &options) 17 | if err != nil { 18 | return map[string]interface{}{}, fmt.Errorf("failed to unmarshal options: %v, error: %v", compactOptions, err) 19 | } 20 | return options, nil 21 | } 22 | -------------------------------------------------------------------------------- /options/options_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "encoding/json" 5 | "reflect" 6 | "testing" 7 | ) 8 | 9 | const ( 10 | postgresqlOptions = `{ 11 | "dbname": "aa", 12 | "host": "1.1.1.1", 13 | "port": 5432 14 | }` 15 | compactPostgresqlOptions = `{"dbname": "aa","host": "1.1.1.1","port": 5432}` 16 | queryOptions = `{ 17 | "parameters": [] 18 | }` 19 | compactQueryOptions = `{"parameters": []}` 20 | invalidQueryOptions = `{ 21 | "parameters": [], 22 | }` 23 | ) 24 | 25 | func TestMapFromString(t *testing.T) { 26 | var dataSourceOptions map[string]interface{} 27 | _ = json.Unmarshal([]byte(compactPostgresqlOptions), &dataSourceOptions) 28 | var queryOptionsMap map[string]interface{} 29 | _ = json.Unmarshal([]byte(compactQueryOptions), &queryOptionsMap) 30 | type args struct { 31 | optionsJSON string 32 | } 33 | tests := []struct { 34 | name string 35 | args args 36 | want map[string]interface{} 37 | wantErr bool 38 | }{ 39 | { 40 | name: "valid data source json", 41 | args: args{optionsJSON: postgresqlOptions}, 42 | want: dataSourceOptions, 43 | wantErr: false, 44 | }, 45 | { 46 | name: "valid query json", 47 | args: args{optionsJSON: queryOptions}, 48 | want: queryOptionsMap, 49 | wantErr: false, 50 | }, 51 | { 52 | name: "empty json", 53 | args: args{optionsJSON: "{}"}, 54 | want: map[string]interface{}{}, 55 | wantErr: false, 56 | }, 57 | { 58 | name: "invalid json", 59 | args: args{optionsJSON: invalidQueryOptions}, 60 | want: map[string]interface{}{}, 61 | wantErr: true, 62 | }, 63 | } 64 | for _, tt := range tests { 65 | t.Run(tt.name, func(t *testing.T) { 66 | got, err := MapFromString(tt.args.optionsJSON) 67 | if (err != nil) != tt.wantErr { 68 | t.Errorf("MapFromString() error = %v, wantErr %v", err, tt.wantErr) 69 | return 70 | } 71 | if !reflect.DeepEqual(got, tt.want) { 72 | t.Errorf("MapFromString() = %v, want %v", got, tt.want) 73 | } 74 | }) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /queries/queries.go: -------------------------------------------------------------------------------- 1 | package queries 2 | 3 | import ( 4 | "github.com/recolabs/redash-go-sdk/gen/client" 5 | "github.com/recolabs/redash-go-sdk/gen/client/queries" 6 | "github.com/recolabs/redash-go-sdk/gen/models" 7 | "github.com/recolabs/redash-go-sdk/options" 8 | ) 9 | 10 | type RequestWrapper struct { 11 | httpClient *client.Redashclient 12 | opts []queries.ClientOption 13 | } 14 | 15 | var ( 16 | defaultVersion = int64(1) 17 | notPublish = false 18 | ) 19 | 20 | // NewQuery builds a Query object. The only validation this 21 | // methods provides is that options argument is a valid json string 22 | func NewQuery( 23 | name, 24 | optionsJSON, 25 | description, 26 | query string, 27 | id, 28 | dataSourceID, 29 | repeated, 30 | version int64, 31 | isDraft bool) ( 32 | *models.Query, 33 | error) { 34 | optionsDict, err := options.MapFromString(optionsJSON) 35 | if err != nil { 36 | return nil, err 37 | } 38 | 39 | queryObject := &models.Query{ 40 | Name: &name, 41 | Options: optionsDict, 42 | Description: description, 43 | Schedule: &models.Schedule{Interval: repeated}, 44 | Query: &query, 45 | DataSourceID: dataSourceID, 46 | IsDraft: isDraft, 47 | Version: &version, 48 | ID: id, 49 | } 50 | 51 | err = queryObject.Validate(nil) 52 | if err != nil { 53 | return nil, err 54 | } 55 | 56 | return queryObject, nil 57 | } 58 | 59 | func NewRequestWrapper(httpClient *client.Redashclient, opts ...queries.ClientOption) *RequestWrapper { 60 | return &RequestWrapper{httpClient: httpClient, opts: opts} 61 | } 62 | 63 | // List all queries 64 | func (requestWrapper *RequestWrapper) List() (*models.QueryList, error) { 65 | response, err := requestWrapper.httpClient.Queries.GetQueries(nil, nil) 66 | if err != nil { 67 | return nil, err 68 | } 69 | 70 | return response.GetPayload(), nil 71 | } 72 | 73 | // Get a specific query with by query ID 74 | func (requestWrapper *RequestWrapper) Get(queryID int64) (*models.Query, error) { 75 | getQueryParams := queries.NewGetQueriesIDParams() 76 | getQueryParams.ID = queryID 77 | response, err := requestWrapper.httpClient.Queries.GetQueriesID(getQueryParams, nil, requestWrapper.opts...) 78 | if err != nil { 79 | return nil, err 80 | } 81 | 82 | return response.GetPayload(), nil 83 | } 84 | 85 | // RegenerateQueryAPIKey changes the query's API key, thus invalidating all existing query URLs 86 | func (requestWrapper *RequestWrapper) RegenerateQueryAPIKey(queryID int64) error { 87 | regenerateParams := queries.NewPostQueriesIDRegenerateAPIKeyParams().WithID(queryID) 88 | _, err := requestWrapper.httpClient.Queries.PostQueriesIDRegenerateAPIKey(regenerateParams, nil, requestWrapper.opts...) 89 | if err != nil { 90 | return err 91 | } 92 | 93 | return nil 94 | } 95 | 96 | // Add adds a new query 97 | func (requestWrapper *RequestWrapper) Add(query *models.Query) (*models.Query, error) { 98 | err := query.Validate(nil) 99 | if err != nil { 100 | return nil, err 101 | } 102 | addParams := queries.NewPostQueriesParams().WithBody(queries.PostQueriesBody{ 103 | Name: *query.Name, 104 | Query: *query.Query, 105 | Options: query.Options, 106 | DataSourceID: query.DataSourceID, 107 | Description: query.Description, 108 | Schedule: query.Schedule, 109 | IsDraft: &query.IsDraft, 110 | Version: *query.Version, 111 | }) 112 | response, err := requestWrapper.httpClient.Queries.PostQueries(addParams, nil, requestWrapper.opts...) 113 | if err != nil { 114 | return nil, err 115 | } 116 | return response.GetPayload(), nil 117 | } 118 | 119 | // Archive query by ID 120 | func (requestWrapper *RequestWrapper) Archive(queryID int64) error { 121 | archiveParams := queries.NewDeleteQueriesIDParams().WithID(queryID) 122 | _, err := requestWrapper.httpClient.Queries.DeleteQueriesID(archiveParams, nil, requestWrapper.opts...) 123 | if err != nil { 124 | return err 125 | } 126 | return nil 127 | } 128 | 129 | // Publish sets the query's status as published 130 | func (requestWrapper *RequestWrapper) Publish(queryID int64) (*models.Query, error) { 131 | publishQueryParams := queries.NewPostQueriesIDParams().WithID(queryID).WithBody( 132 | queries.PostQueriesIDBody{ID: queryID, IsDraft: ¬Publish, Version: &defaultVersion}) 133 | response, err := requestWrapper.httpClient.Queries.PostQueriesID(publishQueryParams, nil, requestWrapper.opts...) 134 | if err != nil { 135 | return nil, err 136 | } 137 | 138 | return response.GetPayload(), nil 139 | } 140 | 141 | // Run executes the query, but does not check for the return value 142 | func (requestWrapper *RequestWrapper) ExecuteQuery(queryID int64) error { 143 | runQueryParams := queries.NewPostQueriesIDResultsParams().WithID(queryID) 144 | _, err := requestWrapper.httpClient.Queries.PostQueriesIDResults(runQueryParams, nil, requestWrapper.opts...) 145 | return err 146 | } 147 | 148 | // Get result of query by ID 149 | func (requestWrapper *RequestWrapper) GetResult(queryID int64) (*models.QueryResult, error) { 150 | runQueryParams := queries.NewGetQueriesIDResultsParams().WithID(queryID) 151 | res, err := requestWrapper.httpClient.Queries.GetQueriesIDResults(runQueryParams, nil, requestWrapper.opts...) 152 | if err != nil { 153 | return nil, err 154 | } 155 | return res.GetPayload(), nil 156 | } 157 | -------------------------------------------------------------------------------- /scripts/generate_client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd gen 3 | swagger generate client --name=redashclient --spec=../swagger.yaml --strict-responders 4 | cd .. 5 | -------------------------------------------------------------------------------- /users/users.go: -------------------------------------------------------------------------------- 1 | package users 2 | 3 | import ( 4 | "github.com/go-openapi/strfmt" 5 | "github.com/recolabs/redash-go-sdk/gen/client" 6 | "github.com/recolabs/redash-go-sdk/gen/client/users" 7 | "github.com/recolabs/redash-go-sdk/gen/models" 8 | ) 9 | 10 | type RequestWrapper struct { 11 | httpClient *client.Redashclient 12 | opts []users.ClientOption 13 | } 14 | 15 | func NewRequestWrapper(httpClient *client.Redashclient, opts ...users.ClientOption) *RequestWrapper { 16 | return &RequestWrapper{httpClient: httpClient, opts: opts} 17 | } 18 | 19 | // NewUser builds a User object. This method offers no validation, 20 | // it exists for compatibility with the other models 21 | func NewUser(name string, email strfmt.Email, orgName string) (*models.User, error) { 22 | user := &models.User{ 23 | Name: &name, 24 | Email: &email, 25 | OrgName: &orgName, 26 | } 27 | 28 | err := user.Validate(nil) 29 | if err != nil { 30 | return nil, err 31 | } 32 | 33 | return user, nil 34 | } 35 | 36 | // GetUser gets the details admin's user details 37 | func (requestWrapper *RequestWrapper) Get(userID int64) (*models.User, error) { 38 | getUserParams := users.NewGetUsersIDParams() 39 | getUserParams.ID = userID 40 | response, err := requestWrapper.httpClient.Users.GetUsersID(getUserParams, nil, requestWrapper.opts...) 41 | if err != nil { 42 | return nil, err 43 | } 44 | 45 | return response.GetPayload(), nil 46 | } 47 | -------------------------------------------------------------------------------- /users/users_test.go: -------------------------------------------------------------------------------- 1 | package users 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "testing" 7 | 8 | "github.com/go-openapi/strfmt" 9 | gen_users "github.com/recolabs/redash-go-sdk/gen/client/users" 10 | mock_users "github.com/recolabs/redash-go-sdk/mocks/users" 11 | 12 | "github.com/recolabs/redash-go-sdk/gen/client" 13 | "github.com/recolabs/redash-go-sdk/gen/models" 14 | ) 15 | 16 | const ( 17 | testAddress = "localhost:5005" 18 | userID = 1 19 | ) 20 | 21 | var ( 22 | userName = "testUser" 23 | userOrgName = "Corp" 24 | userEmail strfmt.Email = "test@corp.com" 25 | ) 26 | 27 | func TestNewUser(t *testing.T) { 28 | type args struct { 29 | name string 30 | email strfmt.Email 31 | orgName string 32 | } 33 | tests := []struct { 34 | name string 35 | args args 36 | want *models.User 37 | wantErr bool 38 | }{ 39 | { 40 | name: "Add a new data source successfully", 41 | args: args{ 42 | name: userName, email: userEmail, orgName: userOrgName, 43 | }, 44 | want: &models.User{ 45 | Name: &userName, 46 | Email: &userEmail, 47 | OrgName: &userOrgName, 48 | }, 49 | wantErr: false, 50 | }, 51 | { 52 | name: "Fail to build a new User instance since the email is malformed", 53 | args: args{ 54 | name: userName, email: "", orgName: userOrgName, 55 | }, 56 | wantErr: true, 57 | }, 58 | } 59 | for _, tt := range tests { 60 | t.Run(tt.name, func(t *testing.T) { 61 | got, err := NewUser(tt.args.name, tt.args.email, tt.args.orgName) 62 | if (err != nil) != tt.wantErr { 63 | t.Errorf("NewUser() error = %v, wantErr %v", err, tt.wantErr) 64 | return 65 | } 66 | if !reflect.DeepEqual(got, tt.want) { 67 | t.Errorf("NewUser() = %v, want %v", got, tt.want) 68 | } 69 | }) 70 | } 71 | } 72 | 73 | func TestRequestWrapper_Get(t *testing.T) { 74 | getUserParams := gen_users.NewGetUsersIDParams() 75 | getUserParams.ID = userID 76 | user, _ := NewUser(userName, userEmail, userOrgName) 77 | happyFlowClient := client.NewHTTPClientWithConfig(nil, 78 | &client.TransportConfig{Host: testAddress, BasePath: "/api"}) 79 | successfullyListUsersMock := mock_users.ClientService{} 80 | happyFlowClient.Users = &successfullyListUsersMock 81 | successfullyListUsersMock.On("GetUsersID", getUserParams, nil). 82 | Return(&gen_users.GetUsersIDOK{Payload: user}, nil) 83 | serverErrorClient := client.NewHTTPClientWithConfig(nil, 84 | &client.TransportConfig{Host: testAddress, BasePath: "/api"}) 85 | serverErrUserMock := mock_users.ClientService{} 86 | serverErrorClient.Users = &serverErrUserMock 87 | serverErrUserMock.On("GetUsersID", getUserParams, nil). 88 | Return(nil, fmt.Errorf("Internal Server Error")) 89 | 90 | type fields struct { 91 | httpClient *client.Redashclient 92 | } 93 | type args struct { 94 | userID int64 95 | } 96 | tests := []struct { 97 | name string 98 | fields fields 99 | args args 100 | want *models.User 101 | wantErr bool 102 | }{ 103 | { 104 | name: "Successfully get user", 105 | fields: fields{httpClient: happyFlowClient}, 106 | args: args{userID: userID}, 107 | want: user, 108 | wantErr: false, 109 | }, 110 | { 111 | name: "Failed to get user due to a server error", 112 | fields: fields{httpClient: serverErrorClient}, 113 | args: args{userID: userID}, 114 | want: nil, 115 | wantErr: true, 116 | }, 117 | } 118 | for _, tt := range tests { 119 | t.Run(tt.name, func(t *testing.T) { 120 | u := &RequestWrapper{ 121 | httpClient: tt.fields.httpClient, 122 | } 123 | got, err := u.Get(tt.args.userID) 124 | if (err != nil) != tt.wantErr { 125 | t.Errorf("RequestWrapper.Get() error = %v, wantErr %v", err, tt.wantErr) 126 | return 127 | } 128 | if !reflect.DeepEqual(got, tt.want) { 129 | t.Errorf("RequestWrapper.Get() = %v, want %v", got, tt.want) 130 | } 131 | }) 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /visualizations/visualizations.go: -------------------------------------------------------------------------------- 1 | package visualizations 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | 7 | "github.com/recolabs/redash-go-sdk/gen/client" 8 | vis "github.com/recolabs/redash-go-sdk/gen/client/visualizations" 9 | "github.com/recolabs/redash-go-sdk/gen/models" 10 | "github.com/recolabs/redash-go-sdk/options" 11 | ) 12 | 13 | const ( 14 | EmbedQueryURIFormat = "/embed/query/%d/visualization/%d" 15 | ) 16 | 17 | type RequestWrapper struct { 18 | httpClient *client.Redashclient 19 | host string 20 | scheme string 21 | opts []vis.ClientOption 22 | apiKey string 23 | } 24 | 25 | // NewVisualization builds a Visualization object. The only validation this 26 | // methods provides is that options argument is a valid json string 27 | // Note - valid type and name can be found in `gen/models/visualizations.go` - VisualizationType*, VisualizationName* 28 | func NewVisualization(visualizationType, name, optionsJSON, description string, queryID int64) (*models.Visualization, error) { 29 | optionsMap, err := options.MapFromString(optionsJSON) 30 | if err != nil { 31 | return nil, err 32 | } 33 | 34 | visualization := &models.Visualization{ 35 | Type: &visualizationType, 36 | Name: &name, 37 | QueryID: &queryID, 38 | Options: optionsMap, 39 | Description: description, 40 | } 41 | 42 | err = visualization.Validate(nil) 43 | if err != nil { 44 | return nil, err 45 | } 46 | 47 | return visualization, nil 48 | } 49 | 50 | func NewRequestWrapper(httpClient *client.Redashclient, host, scheme, apiKey string, opts ...vis.ClientOption) *RequestWrapper { 51 | return &RequestWrapper{httpClient: httpClient, host: host, apiKey: apiKey, scheme: scheme, opts: opts} 52 | } 53 | 54 | // GetURL gets a visualization URL of visualization number {visualizationID} of the {queryID} query using the query_api key 55 | func (requestWrapper *RequestWrapper) GetURL(visualizationID, queryID int64, 56 | hideParameters, hideHeader, hideLink, hideTimestamp bool) (visualizationURL string) { 57 | uri := fmt.Sprintf(EmbedQueryURIFormat, queryID, visualizationID) 58 | url := fmt.Sprintf("%s://%s%s?api_key=%s", requestWrapper.scheme, requestWrapper.host, uri, requestWrapper.apiKey) 59 | if hideParameters { 60 | url = fmt.Sprintf("%s&hide_parameters", url) 61 | } 62 | if hideHeader { 63 | url = fmt.Sprintf("%s&hide_header", url) 64 | } 65 | if hideLink { 66 | url = fmt.Sprintf("%s&hide_link", url) 67 | } 68 | if hideTimestamp { 69 | url = fmt.Sprintf("%s&hide_timestamp", url) 70 | } 71 | return url 72 | } 73 | 74 | // Add a new visualization to the query (the query is defined is visualization.QueryID 75 | func (requestWrapper *RequestWrapper) Add(visualization *models.Visualization) (resultVisualization *models.Visualization, err error) { 76 | err = visualization.Validate(nil) 77 | if err != nil { 78 | return nil, err 79 | } 80 | addParams := vis.NewPostVisualizationsParams().WithBody(vis.PostVisualizationsBody{ 81 | Name: *visualization.Name, 82 | Type: *visualization.Type, 83 | Options: visualization.Options, 84 | QueryID: *visualization.QueryID, 85 | }) 86 | 87 | response, err := requestWrapper.httpClient.Visualizations.PostVisualizations(addParams, nil, requestWrapper.opts...) 88 | if err != nil { 89 | return nil, err 90 | } 91 | return response.GetPayload(), nil 92 | } 93 | 94 | // Remove an existing visualization to the query(the query is defined is visualization.QueryID) 95 | func (requestWrapper *RequestWrapper) Delete(visualizationID int64) error { 96 | deleteParams := vis.NewDeleteVisualizationsIDParams().WithID(visualizationID) 97 | _, err := requestWrapper.httpClient.Visualizations.DeleteVisualizationsID(deleteParams, nil, requestWrapper.opts...) 98 | if err != nil { 99 | return err 100 | } 101 | return nil 102 | } 103 | 104 | func ToVisualization(visualizationData string) (*models.Visualization, error) { 105 | var visObj models.Visualization 106 | err := json.Unmarshal([]byte(visualizationData), &visObj) 107 | return &visObj, err 108 | } 109 | --------------------------------------------------------------------------------