haveapi-go-client 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/README.md +64 -0
- data/bin/haveapi-go-client +3 -0
- data/haveapi-go-client.gemspec +25 -0
- data/lib/haveapi/go_client/action.rb +128 -0
- data/lib/haveapi/go_client/api_version.rb +21 -0
- data/lib/haveapi/go_client/authentication/base.rb +13 -0
- data/lib/haveapi/go_client/authentication/basic.rb +21 -0
- data/lib/haveapi/go_client/authentication/token.rb +56 -0
- data/lib/haveapi/go_client/authentication/unsupported.rb +13 -0
- data/lib/haveapi/go_client/authentication_methods.rb +24 -0
- data/lib/haveapi/go_client/cli.rb +39 -0
- data/lib/haveapi/go_client/erb_template.rb +46 -0
- data/lib/haveapi/go_client/generator.rb +65 -0
- data/lib/haveapi/go_client/input_output.rb +48 -0
- data/lib/haveapi/go_client/metadata.rb +63 -0
- data/lib/haveapi/go_client/parameter.rb +27 -0
- data/lib/haveapi/go_client/parameters/association.rb +54 -0
- data/lib/haveapi/go_client/parameters/base.rb +66 -0
- data/lib/haveapi/go_client/parameters/global_meta_includes.rb +17 -0
- data/lib/haveapi/go_client/parameters/resource.rb +20 -0
- data/lib/haveapi/go_client/parameters/typed.rb +30 -0
- data/lib/haveapi/go_client/resource.rb +133 -0
- data/lib/haveapi/go_client/utils.rb +10 -0
- data/lib/haveapi/go_client/version.rb +5 -0
- data/lib/haveapi/go_client.rb +21 -0
- data/shell.nix +23 -0
- data/template/action.go.erb +475 -0
- data/template/authentication/basic.go.erb +22 -0
- data/template/authentication/token.go.erb +164 -0
- data/template/authentication.go.erb +10 -0
- data/template/client.go.erb +26 -0
- data/template/go.mod.erb +1 -0
- data/template/request.go.erb +96 -0
- data/template/resource.go.erb +36 -0
- data/template/response.go.erb +13 -0
- data/template/types.go.erb +41 -0
- metadata +125 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
package <%= package %>
|
2
|
+
|
3
|
+
import (
|
4
|
+
"bytes"
|
5
|
+
"encoding/json"
|
6
|
+
"io/ioutil"
|
7
|
+
"net/http"
|
8
|
+
)
|
9
|
+
|
10
|
+
// DoQueryStringRequests makes a HTTP requests in which input parameters are
|
11
|
+
// sent as query parameters.
|
12
|
+
func (client *Client) DoQueryStringRequest(path string, queryParams map[string]string, output interface{}) error {
|
13
|
+
httpClient := &http.Client{}
|
14
|
+
url := client.Url + path
|
15
|
+
|
16
|
+
req, err := http.NewRequest("GET", url, nil)
|
17
|
+
|
18
|
+
if err != nil {
|
19
|
+
return err
|
20
|
+
}
|
21
|
+
|
22
|
+
if client.Authentication != nil {
|
23
|
+
client.Authentication.Authenticate(req)
|
24
|
+
}
|
25
|
+
|
26
|
+
q := req.URL.Query()
|
27
|
+
|
28
|
+
for k, v := range queryParams {
|
29
|
+
q.Add(k, v)
|
30
|
+
}
|
31
|
+
|
32
|
+
req.URL.RawQuery = q.Encode()
|
33
|
+
|
34
|
+
resp, err := httpClient.Do(req)
|
35
|
+
|
36
|
+
if err != nil {
|
37
|
+
return err
|
38
|
+
}
|
39
|
+
|
40
|
+
defer resp.Body.Close()
|
41
|
+
body, err := ioutil.ReadAll(resp.Body)
|
42
|
+
|
43
|
+
if err != nil {
|
44
|
+
return err
|
45
|
+
}
|
46
|
+
|
47
|
+
if err := json.Unmarshal(body, output); err != nil {
|
48
|
+
return err
|
49
|
+
}
|
50
|
+
|
51
|
+
return nil
|
52
|
+
}
|
53
|
+
|
54
|
+
// DoBodyRequest makes a HTTP requests in which the input parameters are sent
|
55
|
+
// within the request body, encoded in JSON.
|
56
|
+
func (client *Client) DoBodyRequest(method string, path string, params interface{}, output interface{}) error {
|
57
|
+
httpClient := &http.Client{}
|
58
|
+
url := client.Url + path
|
59
|
+
|
60
|
+
jsonData, err := json.Marshal(params)
|
61
|
+
|
62
|
+
if err != nil {
|
63
|
+
return err
|
64
|
+
}
|
65
|
+
|
66
|
+
req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonData))
|
67
|
+
|
68
|
+
if err != nil {
|
69
|
+
return err
|
70
|
+
}
|
71
|
+
|
72
|
+
req.Header.Set("Content-Type", "application/json")
|
73
|
+
|
74
|
+
if client.Authentication != nil {
|
75
|
+
client.Authentication.Authenticate(req)
|
76
|
+
}
|
77
|
+
|
78
|
+
resp, err := httpClient.Do(req)
|
79
|
+
|
80
|
+
if err != nil {
|
81
|
+
return err
|
82
|
+
}
|
83
|
+
|
84
|
+
defer resp.Body.Close()
|
85
|
+
body, err := ioutil.ReadAll(resp.Body)
|
86
|
+
|
87
|
+
if err != nil {
|
88
|
+
return err
|
89
|
+
}
|
90
|
+
|
91
|
+
if err := json.Unmarshal(body, output); err != nil {
|
92
|
+
return err
|
93
|
+
}
|
94
|
+
|
95
|
+
return nil
|
96
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
package <%= package %>
|
2
|
+
|
3
|
+
// Type for resource <%= resource.full_dot_name %>
|
4
|
+
type <%= resource.go_type %> struct {
|
5
|
+
// Pointer to client
|
6
|
+
Client *Client
|
7
|
+
|
8
|
+
<% resource.resources.each do |r| -%>
|
9
|
+
// Resource <%= r.full_dot_name %>
|
10
|
+
<%= r.go_name %> *<%= r.go_type %>
|
11
|
+
<% end -%>
|
12
|
+
<% resource.actions.each do |a| -%>
|
13
|
+
<% a.all_names do |go_name| -%>
|
14
|
+
// Action <%= a.full_dot_name %>
|
15
|
+
<%= go_name %> *<%= a.go_type %>
|
16
|
+
<% end -%>
|
17
|
+
<% end -%>
|
18
|
+
}
|
19
|
+
|
20
|
+
func New<%= resource.go_type %>(client *Client) *<%= resource.go_type %> {
|
21
|
+
<% resource.actions.each do |a| -%>
|
22
|
+
action<%= a.go_name %> := New<%= a.go_type %>(client)
|
23
|
+
<% end -%>
|
24
|
+
|
25
|
+
return &<%= resource.go_type %>{
|
26
|
+
Client: client,
|
27
|
+
<% resource.resources.each do |r| -%>
|
28
|
+
<%= r.go_name %>: New<%= r.go_type %>(client),
|
29
|
+
<% end -%>
|
30
|
+
<% resource.actions.each do |a| -%>
|
31
|
+
<% a.all_names do |go_name| -%>
|
32
|
+
<%= go_name %>: action<%= a.go_name %>,
|
33
|
+
<% end -%>
|
34
|
+
<% end -%>
|
35
|
+
}
|
36
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
package <%= package %>
|
2
|
+
|
3
|
+
// Envelope represents a response from the API server
|
4
|
+
type Envelope struct {
|
5
|
+
// Determines action success
|
6
|
+
Status bool
|
7
|
+
|
8
|
+
// Error message is Status is false
|
9
|
+
Message string
|
10
|
+
|
11
|
+
// Errors for individual parameters if Status is false
|
12
|
+
Errors map[string][]string
|
13
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
package <%= package %>
|
2
|
+
|
3
|
+
import (
|
4
|
+
"strconv"
|
5
|
+
)
|
6
|
+
|
7
|
+
type ProgressCallbackReturn int
|
8
|
+
|
9
|
+
const (
|
10
|
+
ContinueWatching = iota
|
11
|
+
StopWatching = iota
|
12
|
+
)
|
13
|
+
|
14
|
+
type OperationProgressCallback func(*ActionActionStatePollOutput) ProgressCallbackReturn
|
15
|
+
|
16
|
+
type BlockingOperationWatcher interface {
|
17
|
+
IsBlocking() bool
|
18
|
+
OperationStatus() (*ActionActionStateShowResponse, error)
|
19
|
+
WaitForOperation(timeout float64) (*ActionActionStatePollResponse, error)
|
20
|
+
WatchOperation(timeout float64, updateIn float64, callback OperationProgressCallback) (*ActionActionStatePollResponse, error)
|
21
|
+
}
|
22
|
+
|
23
|
+
func convertInt64ToString(v int64) string {
|
24
|
+
return strconv.FormatInt(v, 10)
|
25
|
+
}
|
26
|
+
|
27
|
+
func convertFloat64ToString(v float64) string {
|
28
|
+
return strconv.FormatFloat(v, 'f', -1, 64)
|
29
|
+
}
|
30
|
+
|
31
|
+
func convertBoolToString(v bool) string {
|
32
|
+
if v {
|
33
|
+
return "1"
|
34
|
+
} else {
|
35
|
+
return "0"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
func convertResourceToString(v int64) string {
|
40
|
+
return convertInt64ToString(v)
|
41
|
+
}
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haveapi-go-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.13.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jakub Skokan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: haveapi-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.0
|
55
|
+
description: Go client generator
|
56
|
+
email:
|
57
|
+
- jakub.skokan@vpsfree.cz
|
58
|
+
executables:
|
59
|
+
- haveapi-go-client
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- bin/haveapi-go-client
|
67
|
+
- haveapi-go-client.gemspec
|
68
|
+
- lib/haveapi/go_client.rb
|
69
|
+
- lib/haveapi/go_client/action.rb
|
70
|
+
- lib/haveapi/go_client/api_version.rb
|
71
|
+
- lib/haveapi/go_client/authentication/base.rb
|
72
|
+
- lib/haveapi/go_client/authentication/basic.rb
|
73
|
+
- lib/haveapi/go_client/authentication/token.rb
|
74
|
+
- lib/haveapi/go_client/authentication/unsupported.rb
|
75
|
+
- lib/haveapi/go_client/authentication_methods.rb
|
76
|
+
- lib/haveapi/go_client/cli.rb
|
77
|
+
- lib/haveapi/go_client/erb_template.rb
|
78
|
+
- lib/haveapi/go_client/generator.rb
|
79
|
+
- lib/haveapi/go_client/input_output.rb
|
80
|
+
- lib/haveapi/go_client/metadata.rb
|
81
|
+
- lib/haveapi/go_client/parameter.rb
|
82
|
+
- lib/haveapi/go_client/parameters/association.rb
|
83
|
+
- lib/haveapi/go_client/parameters/base.rb
|
84
|
+
- lib/haveapi/go_client/parameters/global_meta_includes.rb
|
85
|
+
- lib/haveapi/go_client/parameters/resource.rb
|
86
|
+
- lib/haveapi/go_client/parameters/typed.rb
|
87
|
+
- lib/haveapi/go_client/resource.rb
|
88
|
+
- lib/haveapi/go_client/utils.rb
|
89
|
+
- lib/haveapi/go_client/version.rb
|
90
|
+
- shell.nix
|
91
|
+
- template/action.go.erb
|
92
|
+
- template/authentication.go.erb
|
93
|
+
- template/authentication/basic.go.erb
|
94
|
+
- template/authentication/token.go.erb
|
95
|
+
- template/client.go.erb
|
96
|
+
- template/go.mod.erb
|
97
|
+
- template/request.go.erb
|
98
|
+
- template/resource.go.erb
|
99
|
+
- template/response.go.erb
|
100
|
+
- template/types.go.erb
|
101
|
+
homepage: ''
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.7.6.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Go client generator
|
125
|
+
test_files: []
|