Skip to content

Commit 6d4dccb

Browse files
committed
Added client wrappers, opening issue on builder_client_helpers/public.go and create_client_helpers/public.go
1 parent 273e30a commit 6d4dccb

22 files changed

+4032
-0
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Inserire le impostazioni in questo file per sovrascrivere quelle utente e predefinite.
2+
{
3+
}

builder_client_helpers/alive.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* arduino-cli is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
28+
*/
29+
30+
package builderClient
31+
32+
import (
33+
"context"
34+
"fmt"
35+
"net/http"
36+
"net/url"
37+
)
38+
39+
// PingAlivePath computes a request path to the ping action of alive.
40+
func PingAlivePath() string {
41+
return fmt.Sprintf("/builder/alive")
42+
}
43+
44+
// PingAlive returns 200 if the instance is healthy.
45+
func (c *Client) PingAlive(ctx context.Context, path string) (*http.Response, error) {
46+
req, err := c.NewPingAliveRequest(ctx, path)
47+
if err != nil {
48+
return nil, err
49+
}
50+
return c.Client.Do(ctx, req)
51+
}
52+
53+
// NewPingAliveRequest create the request corresponding to the ping action endpoint of the alive resource.
54+
func (c *Client) NewPingAliveRequest(ctx context.Context, path string) (*http.Request, error) {
55+
scheme := c.Scheme
56+
if scheme == "" {
57+
scheme = "http"
58+
}
59+
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
60+
req, err := http.NewRequest("GET", u.String(), nil)
61+
if err != nil {
62+
return nil, err
63+
}
64+
return req, nil
65+
}

builder_client_helpers/boards.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* arduino-cli is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
28+
*/
29+
30+
package builderClient
31+
32+
import (
33+
"context"
34+
"fmt"
35+
"net/http"
36+
"net/url"
37+
)
38+
39+
// ListBoardsPath computes a request path to the list action of boards.
40+
func ListBoardsPath() string {
41+
return fmt.Sprintf("/builder/v1/boards")
42+
}
43+
44+
// ListBoards provides a list of all the boards supported by Arduino Create. Doesn't require any authentication.
45+
func (c *Client) ListBoards(ctx context.Context, path string) (*http.Response, error) {
46+
req, err := c.NewListBoardsRequest(ctx, path)
47+
if err != nil {
48+
return nil, err
49+
}
50+
return c.Client.Do(ctx, req)
51+
}
52+
53+
// NewListBoardsRequest create the request corresponding to the list action endpoint of the boards resource.
54+
func (c *Client) NewListBoardsRequest(ctx context.Context, path string) (*http.Request, error) {
55+
scheme := c.Scheme
56+
if scheme == "" {
57+
scheme = "http"
58+
}
59+
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
60+
req, err := http.NewRequest("GET", u.String(), nil)
61+
if err != nil {
62+
return nil, err
63+
}
64+
return req, nil
65+
}
66+
67+
// ShowBoardsPath computes a request path to the show action of boards.
68+
func ShowBoardsPath(vid string, pid string) string {
69+
param0 := vid
70+
param1 := pid
71+
72+
return fmt.Sprintf("/builder/v1/boards/%s/%s", param0, param1)
73+
}
74+
75+
// ShowBoards provides the board identified by the :vid and :pid params. Doesn't require authentication.
76+
func (c *Client) ShowBoards(ctx context.Context, path string) (*http.Response, error) {
77+
req, err := c.NewShowBoardsRequest(ctx, path)
78+
if err != nil {
79+
return nil, err
80+
}
81+
return c.Client.Do(ctx, req)
82+
}
83+
84+
// NewShowBoardsRequest create the request corresponding to the show action endpoint of the boards resource.
85+
func (c *Client) NewShowBoardsRequest(ctx context.Context, path string) (*http.Request, error) {
86+
scheme := c.Scheme
87+
if scheme == "" {
88+
scheme = "http"
89+
}
90+
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
91+
req, err := http.NewRequest("GET", u.String(), nil)
92+
if err != nil {
93+
return nil, err
94+
}
95+
return req, nil
96+
}

builder_client_helpers/boards_v2.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* arduino-cli is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
28+
*/
29+
30+
package builderClient
31+
32+
import (
33+
"context"
34+
"fmt"
35+
"net/http"
36+
"net/url"
37+
"strconv"
38+
)
39+
40+
// ByVidPidBoardsV2Path computes a request path to the byVidPid action of boards_v2.
41+
func ByVidPidBoardsV2Path(vid string, pid string) string {
42+
param0 := vid
43+
param1 := pid
44+
45+
return fmt.Sprintf("/builder/v2/boards/byVidPid/%s/%s", param0, param1)
46+
}
47+
48+
// Provides the board identified by the :vid and :pid params. Doesn't require authentication.
49+
func (c *Client) ByVidPidBoardsV2(ctx context.Context, path string) (*http.Response, error) {
50+
req, err := c.NewByVidPidBoardsV2Request(ctx, path)
51+
if err != nil {
52+
return nil, err
53+
}
54+
return c.Client.Do(ctx, req)
55+
}
56+
57+
// NewByVidPidBoardsV2Request create the request corresponding to the byVidPid action endpoint of the boards_v2 resource.
58+
func (c *Client) NewByVidPidBoardsV2Request(ctx context.Context, path string) (*http.Request, error) {
59+
scheme := c.Scheme
60+
if scheme == "" {
61+
scheme = "http"
62+
}
63+
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
64+
req, err := http.NewRequest("GET", u.String(), nil)
65+
if err != nil {
66+
return nil, err
67+
}
68+
return req, nil
69+
}
70+
71+
// ListBoardsV2Path computes a request path to the list action of boards_v2.
72+
func ListBoardsV2Path() string {
73+
74+
return fmt.Sprintf("/builder/v2/boards")
75+
}
76+
77+
// Provides a list of all the boards supported by Arduino Create. Doesn't require any authentication.
78+
func (c *Client) ListBoardsV2(ctx context.Context, path string, limit *int, offset *int) (*http.Response, error) {
79+
req, err := c.NewListBoardsV2Request(ctx, path, limit, offset)
80+
if err != nil {
81+
return nil, err
82+
}
83+
return c.Client.Do(ctx, req)
84+
}
85+
86+
// NewListBoardsV2Request create the request corresponding to the list action endpoint of the boards_v2 resource.
87+
func (c *Client) NewListBoardsV2Request(ctx context.Context, path string, limit *int, offset *int) (*http.Request, error) {
88+
scheme := c.Scheme
89+
if scheme == "" {
90+
scheme = "http"
91+
}
92+
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
93+
values := u.Query()
94+
if limit != nil {
95+
tmp15 := strconv.Itoa(*limit)
96+
values.Set("limit", tmp15)
97+
}
98+
if offset != nil {
99+
tmp16 := strconv.Itoa(*offset)
100+
values.Set("offset", tmp16)
101+
}
102+
u.RawQuery = values.Encode()
103+
req, err := http.NewRequest("GET", u.String(), nil)
104+
if err != nil {
105+
return nil, err
106+
}
107+
return req, nil
108+
}
109+
110+
// ShowBoardsV2Path computes a request path to the show action of boards_v2.
111+
func ShowBoardsV2Path(fqbn string) string {
112+
param0 := fqbn
113+
114+
return fmt.Sprintf("/builder/v2/boards/%s", param0)
115+
}
116+
117+
// Provides the board identified by an fqbn. Doesn't require authentication.
118+
func (c *Client) ShowBoardsV2(ctx context.Context, path string) (*http.Response, error) {
119+
req, err := c.NewShowBoardsV2Request(ctx, path)
120+
if err != nil {
121+
return nil, err
122+
}
123+
return c.Client.Do(ctx, req)
124+
}
125+
126+
// NewShowBoardsV2Request create the request corresponding to the show action endpoint of the boards_v2 resource.
127+
func (c *Client) NewShowBoardsV2Request(ctx context.Context, path string) (*http.Request, error) {
128+
scheme := c.Scheme
129+
if scheme == "" {
130+
scheme = "http"
131+
}
132+
u := url.URL{Host: c.Host, Scheme: scheme, Path: path}
133+
req, err := http.NewRequest("GET", u.String(), nil)
134+
if err != nil {
135+
return nil, err
136+
}
137+
return req, nil
138+
}

builder_client_helpers/client.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* arduino-cli is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
28+
*/
29+
30+
package builderClient
31+
32+
import (
33+
"github.com/goadesign/goa"
34+
goaclient "github.com/goadesign/goa/client"
35+
)
36+
37+
// Client is the ArduinoBuilderV1 service client.
38+
type Client struct {
39+
*goaclient.Client
40+
Oauth2Signer goaclient.Signer
41+
Encoder *goa.HTTPEncoder
42+
Decoder *goa.HTTPDecoder
43+
}
44+
45+
// New instantiates the client.
46+
func New(c goaclient.Doer) *Client {
47+
client := &Client{
48+
Client: goaclient.New(c),
49+
Encoder: goa.NewHTTPEncoder(),
50+
Decoder: goa.NewHTTPDecoder(),
51+
}
52+
53+
// Setup encoders and decoders
54+
client.Encoder.Register(goa.NewJSONEncoder, "application/json")
55+
client.Decoder.Register(goa.NewJSONDecoder, "application/json")
56+
57+
// Setup default encoder and decoder
58+
client.Encoder.Register(goa.NewJSONEncoder, "*/*")
59+
client.Decoder.Register(goa.NewJSONDecoder, "*/*")
60+
61+
return client
62+
}
63+
64+
// SetOauth2Signer sets the request signer for the oauth2 security scheme.
65+
func (c *Client) SetOauth2Signer(signer goaclient.Signer) {
66+
c.Oauth2Signer = signer
67+
}

0 commit comments

Comments
 (0)