ruby-onfleet 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile +1 -0
- data/README.es.md +242 -0
- data/README.md +44 -18
- data/lib/configuration.rb +7 -2
- data/lib/utils.rb +10 -5
- data/package.json +1 -1
- data/ruby-onfleet.gemspec +7 -3
- metadata +48 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c913c4264901921e84ce53f8e1c24fbf755e62c69e2586309cc3eead7737a61d
|
4
|
+
data.tar.gz: f15218f9c46109307e8ee636721f6a0fe9bc5eba722c417bc3cd18daf0fb06d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfa7bdec5b10a83926a11215762f8dfa737007aa5f8ccd2e38d8106eeb529c71999edad46bc247a1332a88a6107af555852cd43ceeeaca01f8d6a0465f31007b
|
7
|
+
data.tar.gz: a67e5e08c0af7b704a06bed80272db30b9de42c50c52ae5a9242669b133b737b65f0703fbe0523fcbfeaf6a1808482995783054ca029222ca3e437d428b1d9ac
|
data/CHANGELOG.md
CHANGED
@@ -10,4 +10,10 @@ Added
|
|
10
10
|
|
11
11
|
## [1.0.1](https://github.com/onfleet/ruby-onfleet/releases/tag/v1.0.1) - 2023-05-12
|
12
12
|
Added
|
13
|
-
* Refactored resources for module/class inheritance
|
13
|
+
* Refactored resources for module/class inheritance
|
14
|
+
|
15
|
+
## [1.0.2](https://github.com/onfleet/ruby-onfleet/releases/tag/v1.0.2) - 2023-05-19
|
16
|
+
Added
|
17
|
+
* Added README support for spanish
|
18
|
+
* Included throttling constraints for 20 API requests per second using faraday-rate_limiter
|
19
|
+
* Updated headers on initialization to allow for custom headers
|
data/Gemfile
CHANGED
data/README.es.md
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
# Onfleet Ruby Wrapper
|
2
|
+
|
3
|
+
> *Consulta este documento en otro idioma*:
|
4
|
+
> [English](https://github.com/onfleet/ruby-onfleet/blob/main/README.md)
|
5
|
+
|
6
|
+
Los invitamos a visitar nuestra publicación sobre el [proyecto de librerías para la API](https://onfleet.com/blog/api-wrappers-explained/) para conocer más sobre nuestras iniciativas.
|
7
|
+
En caso de preguntas, pueden contactarnos a través de un issue [aquí](https://github.com/onfleet/pyonfleet/issues) o escribirnos a support@onfleet.com.
|
8
|
+
|
9
|
+
## Tabla de contenidos
|
10
|
+
- [Onfleet Ruby Wrapper](#onfleet-ruby-wrapper)
|
11
|
+
- [Tabla de contenidos](#tabla-de-contenidos)
|
12
|
+
- [Sinopsis](#sinopsis)
|
13
|
+
- [Instalación](#instalación)
|
14
|
+
- [Requirements](#requirements)
|
15
|
+
- [Uso](#uso)
|
16
|
+
- [Autenticación](#autenticación)
|
17
|
+
- [Límites](#límites)
|
18
|
+
- [Operaciones CRUD soportadas](#operaciones-crud-soportadas)
|
19
|
+
- [Ejemplos de cómo utilizar las operaciones CRUD](#ejemplos-de-cómo-utilizar-las-operaciones-crud)
|
20
|
+
- [Errors](#errors)
|
21
|
+
|
22
|
+
## Sinopsis
|
23
|
+
La librería en Ruby de Onfleet nos permite un acceso fácil y cómodo a la API de Onfleet.
|
24
|
+
|
25
|
+
## Instalación
|
26
|
+
```
|
27
|
+
gem install ruby-onfleet
|
28
|
+
```
|
29
|
+
|
30
|
+
# Requirements
|
31
|
+
Puede encontrar una lista de las gemas de paquetes necesarias para instalar en el [Gemfile](#https://github.com/onfleet/ruby-onfleet/blob/main/gemfile).
|
32
|
+
|
33
|
+
## Uso
|
34
|
+
Antes de usar la librería, es indispensable obtener una llave para la API a través de alguno de los administradores de la organización a la que pertenecemos.
|
35
|
+
|
36
|
+
La creación e integración de llaves se realiza a través del [panel principal de Onfleet](https://onfleet.com/dashboard#/manage).
|
37
|
+
|
38
|
+
Para utilizar la librería sólo tenemos que crear uns instancia de `Onfleet` usando la llave:
|
39
|
+
```
|
40
|
+
config = Onfleet::Configuration.new("API_KEY")
|
41
|
+
```
|
42
|
+
|
43
|
+
Se pueden incluir dos parámetros opcionales al inicializar el módulo Onfleet - `base_url` y `headers`.
|
44
|
+
Si está ejecutando pruebas en el entorno sandbox, lo siguiente `base_url` debe ser definido - "https://staging.onfleet.com/api/v2". De lo contrario, la producción será la predeterminada.
|
45
|
+
|
46
|
+
Los encabezados predeterminados requeridos se establecen en la inicialización de su configuración. También recomendamos incluir el siguiente encabezado personalizado para ayudarnos a identificar el tráfico de origen:
|
47
|
+
|
48
|
+
```
|
49
|
+
headers = {
|
50
|
+
"X-Onfleet-Organization": "ORGANIZATION_NAME-onfleet"
|
51
|
+
}
|
52
|
+
|
53
|
+
config = Onfleet::Configuration.new("API_KEY", "https://staging.onfleet.com/api/v2", headers)
|
54
|
+
```
|
55
|
+
|
56
|
+
Será necesario pasar una instancia de `Onfleet config` como argumento a cualquier llamada API posterior que contenga sus configuraciones.
|
57
|
+
|
58
|
+
### Autenticación
|
59
|
+
Cada solicitud de API a la plataforma Onfleet se autentica mediante autenticación básica. Al inicializar el objeto `Onfleet`, se ejecutará una prueba para validar sus credenciales de API con el siguiente método:
|
60
|
+
|
61
|
+
```
|
62
|
+
Onfleet.validate_authentication(@base_url, @api_key)
|
63
|
+
```
|
64
|
+
|
65
|
+
Si tiene éxito, esta variable se establecerá con su instancia `Onfleet`:
|
66
|
+
|
67
|
+
```
|
68
|
+
onfleet.auth_validated = true
|
69
|
+
```
|
70
|
+
|
71
|
+
De lo contrario, se generará un error o este valor será igual a `false` si no se realiza correctamente.
|
72
|
+
|
73
|
+
### Límites
|
74
|
+
La API impone un límite de 20 peticiones por segundo entre todas las peticiones de todas las llaves de la organización. Más detalles [aquí](https://docs.onfleet.com/reference/throttling).
|
75
|
+
|
76
|
+
La librería también implementa un limitador para prevenir excesos accidentales de los límites y, eventualmente, posibles sanciones.
|
77
|
+
|
78
|
+
### Operaciones CRUD soportadas
|
79
|
+
Estas son las operaciones disponibles para cada endpoint:
|
80
|
+
|
81
|
+
| Entidad | GET | POST | PUT | DELETE |
|
82
|
+
| :-: | :-: | :-: | :-: | :-: |
|
83
|
+
|[administrators](https://docs.onfleet.com/reference/administrators)|list()|create()|update(id, body={})|delete(id)|
|
84
|
+
|[containers](https://docs.onfleet.com/reference/containers)|get('workers', id)<br />get('teams', id)<br />get('organizations', id)|x|update_tasks(workerId, body={})|x|
|
85
|
+
|[destinations](https://docs.onfleet.com/reference/destinations)|get(id)|create(body={})<br />match_metadata(body={})|x|x|
|
86
|
+
|[hubs](https://docs.onfleet.com/reference/hubs)|list()|create(body={})|update(id, body={})|x|
|
87
|
+
|[organizations](https://docs.onfleet.com/reference/organizations)|get(delegateeId=nil)|x|insert_task(orgId, body={})|x|
|
88
|
+
|[recipients](https://docs.onfleet.com/reference/recipients)|get(id)<br />get_by_name(name)<br />get_by_phone(phone)|create(body={})<br />match_metadata(body={})|update(id, body={})|x|
|
89
|
+
|[tasks](https://docs.onfleet.com/reference/tasks)|get(id)<br />list(queryParameters={})<br />get_by_short_id(shortId)|create(body={})<br />batch_create(body={})<br />batch_create_async(body={})<br />complete(id, body={})<br />clone(id)<br />auto_assign(body={})<br />match_metadata(body={})|update(id, body={})|delete(id)|
|
90
|
+
|[teams](https://docs.onfleet.com/reference/teams)|get(id)<br />list()<br />driver_time_estimate(workerId, queryParameters={})<br />get_unassigned_tasks(id)|create(body={})<br />auto_dispatch(id, body={})|update(id, body={})<br />insert_task(teamId, body={})|delete(id)|
|
91
|
+
|[webhooks](https://docs.onfleet.com/reference/webhooks)|list()|create(body={})|X|delete(id)|
|
92
|
+
|[workers](https://docs.onfleet.com/reference/workers)|get(id=nil, queryParameters={})<br />get_tasks(id)<br />get_by_location(longitude, latitude, radius)<br />get_schedule(id)|create(body={})<br />set_schedule(id, body={})<br />match_metadata(body={})|update(id, body={})<br />insert_task(id, body={})|delete(id)|
|
93
|
+
|
94
|
+
### **Peticiones GET**
|
95
|
+
Para obtener todos los objetos de entidad dentro de un endpoint, use `list`:
|
96
|
+
|
97
|
+
```
|
98
|
+
list()
|
99
|
+
```
|
100
|
+
|
101
|
+
Ejemplos de `list()`:
|
102
|
+
|
103
|
+
```
|
104
|
+
tasks = Onfleet::Tasks.new
|
105
|
+
tasks.list(config)
|
106
|
+
tasks.list(config, queryParameters{})
|
107
|
+
```
|
108
|
+
|
109
|
+
Opcionalmente, puede enviar un hash de parámetros de consulta para ciertos endpoints. El hash de Ruby se codificará en parámetros de consulta de URL utilizando la gema `uri`. Referirse de nuevo a [API documentation](https://docs.onfleet.com/) para endpoints que admiten parámetros de consulta.
|
110
|
+
|
111
|
+
```
|
112
|
+
tasks = Onfleet::Tasks.new
|
113
|
+
tasks.list(config, queryParameters={'from': '1455072025000', 'state': '1, 2, 3'})
|
114
|
+
```
|
115
|
+
|
116
|
+
Para obtener un objeto de entidad dentro de un endpoint, especifique un `entity id`:
|
117
|
+
|
118
|
+
```
|
119
|
+
# obtener ejemplos con la búsqueda de entityId
|
120
|
+
tasks = Onfleet::Tasks.new
|
121
|
+
tasks.get(config, 'taskId')
|
122
|
+
|
123
|
+
recipients = Onfleet::Recipients.new
|
124
|
+
recipients.get(config, 'workerId')
|
125
|
+
```
|
126
|
+
|
127
|
+
Junto con la búsqueda de un objeto de entidad con un `id` asociado, los siguientes parámetros de consulta también están disponibles en un grupo selecto de endpoints:
|
128
|
+
|
129
|
+
* `queryParameters` (hash)
|
130
|
+
* `name`
|
131
|
+
* `entity`
|
132
|
+
* `phone`
|
133
|
+
* `shortId`
|
134
|
+
|
135
|
+
```
|
136
|
+
# obtener ejemplos con argumentos adicionales
|
137
|
+
workers = Onfleet::Workers.new
|
138
|
+
workers.get(config, 'workerId', queryParameters={'analytics': 'true'})
|
139
|
+
|
140
|
+
containers = Onfleet::Containers.new
|
141
|
+
containers.get(config, 'workers', 'workerId')
|
142
|
+
containers.get(config, 'teams', 'teamId')
|
143
|
+
containers.get(config, 'organizations', 'organizationId')
|
144
|
+
```
|
145
|
+
|
146
|
+
Para obtener un controlador por ubicación, utilice el método `get_by_location`:
|
147
|
+
```
|
148
|
+
workers = Onfleet::Workers.new
|
149
|
+
worker.get_by_location(config, 'longitude_value', 'latitude_value', 'radius_value')
|
150
|
+
```
|
151
|
+
El valor predeterminado del `radius` es 1000 metros si no se proporciona como argumento.
|
152
|
+
|
153
|
+
### **Peticiones POST**
|
154
|
+
Para crear un objeto de entidad dentro de un endpoint:
|
155
|
+
```
|
156
|
+
.create(config, body={})
|
157
|
+
```
|
158
|
+
|
159
|
+
Ejemplos de `create()`:
|
160
|
+
```
|
161
|
+
body = {
|
162
|
+
"name": "A Swartz",
|
163
|
+
"phone": "617-342-8853",
|
164
|
+
"teams": [
|
165
|
+
"nz1nG1Hpx9EHjQCJsT2VAs~o"
|
166
|
+
],
|
167
|
+
"vehicle": {
|
168
|
+
"type": "CAR",
|
169
|
+
"description": "Tesla Model 3",
|
170
|
+
"licensePlate": "FKNS9A",
|
171
|
+
"color": "purple"
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
workers = Onfleet::Workers.new
|
176
|
+
workers.create(config, body)
|
177
|
+
```
|
178
|
+
|
179
|
+
Las solicitudes POST extendidas incluyen clon, batch_create, auto_assign en el endpoint de las tareas; set_schedule en el endpoint de los trabajadores; y auto_dispatch en el endpoint de los equipos. A continuación, se muestran ejemplos de estos endpoints:
|
180
|
+
|
181
|
+
```
|
182
|
+
tasks = Onfleet::Tasks.new
|
183
|
+
tasks.clone(config, 'id')
|
184
|
+
tasks.batch_create(config, body)
|
185
|
+
tasks.auto_assign(config, body)
|
186
|
+
|
187
|
+
workers = Onfleet::Workers.new
|
188
|
+
workers.set_schedule(config, 'id', body)
|
189
|
+
|
190
|
+
teams = Onfleet::Teams.new
|
191
|
+
teams.auto_dispatch(config, 'id', body)
|
192
|
+
```
|
193
|
+
|
194
|
+
Para más detalles, consulte nuestra documentación en [clone](https://docs.onfleet.com/reference#clone-task), [batch_create](https://docs.onfleet.com/reference#create-tasks-in-batch), [auto_assign](https://docs.onfleet.com/reference#automatically-assign-list-of-tasks), [set_schedule](https://docs.onfleet.com/reference#set-workers-schedule), y [auto_dispatch](https://docs.onfleet.com/reference#team-auto-dispatch).
|
195
|
+
|
196
|
+
### **Peticiones PUT**
|
197
|
+
Para actualizar un objeto de entidad dentro de un endpoint:
|
198
|
+
```
|
199
|
+
.update(config, entityId, 'body')
|
200
|
+
```
|
201
|
+
Ejemplos de `update()`:
|
202
|
+
```
|
203
|
+
body = {
|
204
|
+
"name": "Laura P",
|
205
|
+
"teams": [
|
206
|
+
"lHCUJFvh6v0YDURKjokZbvau"
|
207
|
+
]
|
208
|
+
}
|
209
|
+
|
210
|
+
workers = Onfleet::Workers.new
|
211
|
+
workers.update(config, 'workerId', body)
|
212
|
+
```
|
213
|
+
|
214
|
+
Ejemplos de `insert_task()`:
|
215
|
+
```
|
216
|
+
workers = Onfleet::Workers.new
|
217
|
+
workers.insert_task(config, 'taskId', body)
|
218
|
+
```
|
219
|
+
|
220
|
+
### **Peticiones DELETE**
|
221
|
+
Para eliminar un objeto de entidad dentro de un endpoint:
|
222
|
+
```
|
223
|
+
.delete(config, id)
|
224
|
+
```
|
225
|
+
|
226
|
+
Ejemplos de `delete()`:
|
227
|
+
```
|
228
|
+
workers = Onfleet::Workers.new
|
229
|
+
workers.delete(config, id)
|
230
|
+
```
|
231
|
+
|
232
|
+
## Errors
|
233
|
+
Se pueden producir los siguientes tipos de errores:
|
234
|
+
1. errores HTTP
|
235
|
+
2. errores de permisos
|
236
|
+
3. errores de límite de velocidad
|
237
|
+
4. errores de servicio
|
238
|
+
5. errores de validación
|
239
|
+
|
240
|
+
Actualmente, solo las clases `PermissionError`, `HttpError` y `ServiceError` están en uso según `status` de la API devuelto por la API de Onfleet. Este paquete maneja los errores de API devueltos en el método `handle_api_error` en el archivo `utils.rb`.
|
241
|
+
|
242
|
+
*Ir al [inicio](#onfleet-ruby-wrapper)*.
|
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# ruby-onfleet
|
2
|
+
|
3
|
+
> *Consulta este documento en otro idioma*:
|
4
|
+
> [Español](https://github.com/onfleet/ruby-onfleet/blob/main/README.es.md)
|
5
|
+
|
2
6
|
Visit our blog post on the [API wrapper project](https://onfleet.com/blog/api-wrappers-explained/) to learn more about our initiatives. If you have any questions, please reach us by submitting an issue [here](https://github.com/onfleet/ruby-onfleet/issues) or contact support@onfleet.com.
|
3
7
|
|
4
8
|
## Table of Contents
|
@@ -29,15 +33,22 @@ Before using the API wrapper, you will need to obtain an API key from one of you
|
|
29
33
|
|
30
34
|
Creation and integration of API keys are performed through the [Onfleet dashboard](https://onfleet.com/dashboard#/manage).
|
31
35
|
|
32
|
-
To start utilizing the library, you simply need to create an `Onfleet` object with your API key:
|
36
|
+
To start utilizing the library, you simply need to create an `Onfleet` object and set your `Configuration` with your API key:
|
33
37
|
```
|
34
|
-
config = Onfleet.new("
|
38
|
+
config = Onfleet::Configuration.new("API_KEY")
|
35
39
|
```
|
36
40
|
|
37
|
-
|
41
|
+
Two optional parameters can be included when initializing the Onfleet module - `base_url` and `headers`.
|
42
|
+
If you are running testing in the sandbox environment, the following `base_url` should be defined - "https://staging.onfleet.com/api/v2". Otherwise, production will be the default.
|
43
|
+
|
44
|
+
The required default headers are set on your configuration initialization. We also recommend including the following custom header to help us identify source traffic:
|
38
45
|
|
39
46
|
```
|
40
|
-
|
47
|
+
headers = {
|
48
|
+
"X-Onfleet-Organization": "ORGANIZATION_NAME-onfleet"
|
49
|
+
}
|
50
|
+
|
51
|
+
config = Onfleet::Configuration.new("API_KEY", "https://staging.onfleet.com/api/v2", headers)
|
41
52
|
```
|
42
53
|
|
43
54
|
An `Onfleet config` instance will need to be passed as an argument to any subsequent API calls that will contain your configurations.
|
@@ -52,7 +63,7 @@ Onfleet.validate_authentication(@base_url, @api_key)
|
|
52
63
|
If successful, this variable will be set with your `Onfleet` instance:
|
53
64
|
|
54
65
|
```
|
55
|
-
|
66
|
+
onfleet.auth_validated = true
|
56
67
|
```
|
57
68
|
|
58
69
|
Otherwise, an error will be raised or this value would equal `false` if unsuccessful.
|
@@ -65,18 +76,18 @@ We have also implemented a limiter on this library to avoid you from unintention
|
|
65
76
|
## Supported CRUD Operations
|
66
77
|
Here are the operations available for each entity:
|
67
78
|
|
68
|
-
|Entity|GET|POST|PUT|DELETE|
|
69
|
-
|
70
|
-
|administrators|list()|create()|update(id, body={})|delete(id)|
|
71
|
-
|containers|get('workers', id)
|
72
|
-
|destinations|get(id)|create(body={})
|
73
|
-
|hubs|list()|create(body={})|update(id, body={})|x|
|
74
|
-
|organizations|get(delegateeId=nil)|x|insert_task(orgId, body={})|x|
|
75
|
-
|recipients|get(id)
|
76
|
-
|tasks|get(id)
|
77
|
-
|teams|get(id)
|
78
|
-
|webhooks|list()|create(body={})|X|delete(id)|
|
79
|
-
|workers|get(id=nil, queryParameters={})
|
79
|
+
| Entity | GET | POST | PUT | DELETE |
|
80
|
+
| :-: | :-: | :-: | :-: | :-: |
|
81
|
+
|[administrators](https://docs.onfleet.com/reference/administrators)|list()|create()|update(id, body={})|delete(id)|
|
82
|
+
|[containers](https://docs.onfleet.com/reference/containers)|get('workers', id)<br />get('teams', id)<br />get('organizations', id)|x|update_tasks(workerId, body={})|x|
|
83
|
+
|[destinations](https://docs.onfleet.com/reference/destinations)|get(id)|create(body={})<br />match_metadata(body={})|x|x|
|
84
|
+
|[hubs](https://docs.onfleet.com/reference/hubs)|list()|create(body={})|update(id, body={})|x|
|
85
|
+
|[organizations](https://docs.onfleet.com/reference/organizations)|get(delegateeId=nil)|x|insert_task(orgId, body={})|x|
|
86
|
+
|[recipients](https://docs.onfleet.com/reference/recipients)|get(id)<br />get_by_name(name)<br />get_by_phone(phone)|create(body={})<br />match_metadata(body={})|update(id, body={})|x|
|
87
|
+
|[tasks](https://docs.onfleet.com/reference/tasks)|get(id)<br />list(queryParameters={})<br />get_by_short_id(shortId)|create(body={})<br />batch_create(body={})<br />batch_create_async(body={})<br />complete(id, body={})<br />clone(id)<br />auto_assign(body={})<br />match_metadata(body={})|update(id, body={})|delete(id)|
|
88
|
+
|[teams](https://docs.onfleet.com/reference/teams)|get(id)<br />list()<br />driver_time_estimate(workerId, queryParameters={})<br />get_unassigned_tasks(id)|create(body={})<br />auto_dispatch(id, body={})|update(id, body={})<br />insert_task(teamId, body={})|delete(id)|
|
89
|
+
|[webhooks](https://docs.onfleet.com/reference/webhooks)|list()|create(body={})|X|delete(id)|
|
90
|
+
|[workers](https://docs.onfleet.com/reference/workers)|get(id=nil, queryParameters={})<br />get_tasks(id)<br />get_by_location(longitude, latitude, radius)<br />get_schedule(id)|create(body={})<br />set_schedule(id, body={})<br />match_metadata(body={})|update(id, body={})<br />insert_task(id, body={})|delete(id)|
|
80
91
|
|
81
92
|
### **GET Requests**
|
82
93
|
To get all the entity objects within an endpoint use `list`:
|
@@ -88,13 +99,15 @@ list()
|
|
88
99
|
Examples of `list()`:
|
89
100
|
|
90
101
|
```
|
102
|
+
tasks = Onfleet::Tasks.new
|
91
103
|
tasks.list(config)
|
92
104
|
tasks.list(config, queryParameters{})
|
93
105
|
```
|
94
106
|
|
95
|
-
Optionally you can send a hash of query parameters for certain endpoints. The Ruby hash will be encoded to url query parameters using the `uri` gem.
|
107
|
+
Optionally you can send a hash of query parameters for certain endpoints. The Ruby hash will be encoded to url query parameters using the `uri` gem. Refer back to [API documentation](https://docs.onfleet.com/) for endpoints that support query parameters.
|
96
108
|
|
97
109
|
```
|
110
|
+
tasks = Onfleet::Tasks.new
|
98
111
|
tasks.list(config, queryParameters={'from': '1455072025000', 'state': '1, 2, 3'})
|
99
112
|
```
|
100
113
|
|
@@ -102,7 +115,10 @@ To get one entity object within an endpoint, specify the an `entity id`:
|
|
102
115
|
|
103
116
|
```
|
104
117
|
# get examples with entityId lookup
|
118
|
+
tasks = Onfleet::Tasks.new
|
105
119
|
tasks.get(config, 'taskId')
|
120
|
+
|
121
|
+
recipients = Onfleet::Recipients.new
|
106
122
|
recipients.get(config, 'workerId')
|
107
123
|
```
|
108
124
|
|
@@ -116,8 +132,10 @@ Along with searching for an entity object with an associated `id`, the following
|
|
116
132
|
|
117
133
|
```
|
118
134
|
# get examples with additional arguments
|
135
|
+
workers = Onfleet::Workers.new
|
119
136
|
workers.get(config, 'workerId', queryParameters={'analytics': 'true'})
|
120
137
|
|
138
|
+
containers = Onfleet::Containers.new
|
121
139
|
containers.get(config, 'workers', 'workerId')
|
122
140
|
containers.get(config, 'teams', 'teamId')
|
123
141
|
containers.get(config, 'organizations', 'organizationId')
|
@@ -125,6 +143,7 @@ containers.get(config, 'organizations', 'organizationId')
|
|
125
143
|
|
126
144
|
To get a driver by location, use the `get_by_location` method:
|
127
145
|
```
|
146
|
+
workers = Onfleet::Workers.new
|
128
147
|
worker.get_by_location(config, 'longitude_value', 'latitude_value', 'radius_value')
|
129
148
|
```
|
130
149
|
The `radius` value defaults to 1000 meters if not provided as an argument.
|
@@ -151,18 +170,22 @@ body = {
|
|
151
170
|
}
|
152
171
|
}
|
153
172
|
|
173
|
+
workers = Onfleet::Workers.new
|
154
174
|
workers.create(config, body)
|
155
175
|
```
|
156
176
|
|
157
177
|
Extended POST requests include clone, batch_create, auto_assign on the tasks endpoint; set_schedule on the workers endpoint; and auto_dispatch on the teams endpoint. Examples of these endpoints are below:
|
158
178
|
|
159
179
|
```
|
180
|
+
tasks = Onfleet::Tasks.new
|
160
181
|
tasks.clone(config, 'id')
|
161
182
|
tasks.batch_create(config, body)
|
162
183
|
tasks.auto_assign(config, body)
|
163
184
|
|
185
|
+
workers = Onfleet::Workers.new
|
164
186
|
workers.set_schedule(config, 'id', body)
|
165
187
|
|
188
|
+
teams = Onfleet::Teams.new
|
166
189
|
teams.auto_dispatch(config, 'id', body)
|
167
190
|
```
|
168
191
|
|
@@ -182,11 +205,13 @@ body = {
|
|
182
205
|
]
|
183
206
|
}
|
184
207
|
|
208
|
+
workers = Onfleet::Workers.new
|
185
209
|
workers.update(config, 'workerId', body)
|
186
210
|
```
|
187
211
|
|
188
212
|
Examples of `insert_task()`:
|
189
213
|
```
|
214
|
+
workers = Onfleet::Workers.new
|
190
215
|
workers.insert_task(config, 'taskId', body)
|
191
216
|
```
|
192
217
|
|
@@ -198,6 +223,7 @@ To delete an entity object within an endpoint:
|
|
198
223
|
|
199
224
|
Examples of `delete()`:
|
200
225
|
```
|
226
|
+
workers = Onfleet::Workers.new
|
201
227
|
workers.delete(config, id)
|
202
228
|
```
|
203
229
|
|
data/lib/configuration.rb
CHANGED
@@ -2,9 +2,9 @@ require 'json'
|
|
2
2
|
|
3
3
|
module Onfleet
|
4
4
|
class Configuration
|
5
|
-
attr_reader :default_timeout, :api_key, :base_url, :version, :name
|
5
|
+
attr_reader :default_timeout, :api_key, :base_url, :headers, :version, :name
|
6
6
|
|
7
|
-
def initialize(api_key, base_url = nil)
|
7
|
+
def initialize(api_key, base_url = nil, headers = {})
|
8
8
|
file = File.read('/Users/danmenza/onfleet/code/api_wrappers/ruby-onfleet/package.json')
|
9
9
|
package_data = JSON.parse(file)
|
10
10
|
|
@@ -17,6 +17,11 @@ module Onfleet
|
|
17
17
|
@version = package_data['version']
|
18
18
|
@name = package_data['name']
|
19
19
|
|
20
|
+
# Default headers included in all API requests
|
21
|
+
headers['Content-Type'] = 'application/json'
|
22
|
+
headers['User-Agent'] = "#{@name}-#{@version}"
|
23
|
+
@headers = headers
|
24
|
+
|
20
25
|
@auth_validated = Onfleet.validate_authentication(@base_url, @api_key)
|
21
26
|
end
|
22
27
|
end
|
data/lib/utils.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'faraday-rate_limiter'
|
2
3
|
|
3
4
|
module Onfleet
|
4
|
-
def self.request(config, method, path, body = nil
|
5
|
+
def self.request(config, method, path, body = nil)
|
5
6
|
response = nil
|
6
|
-
headers['Content-Type'] = 'application/json'
|
7
|
-
headers['User-Agent'] = "#{config.name}-#{config.version}"
|
8
|
-
request = Faraday.new
|
9
7
|
url = "#{config.base_url}/#{path}"
|
10
8
|
|
9
|
+
# throttling configuration to match rate limiting enforced by the API
|
10
|
+
request = Faraday.new do |r|
|
11
|
+
# allow up to 20 API requests per second
|
12
|
+
r.request :rate_limiter, interval: 0.05
|
13
|
+
r.adapter :net_http
|
14
|
+
end
|
15
|
+
|
11
16
|
begin
|
12
17
|
request.set_basic_auth(config.api_key, config.api_key)
|
13
|
-
response = request.run_request(method, url, body, headers)
|
18
|
+
response = request.run_request(method, url, body, config.headers)
|
14
19
|
handle_api_error(response)
|
15
20
|
rescue Faraday::Response::RaiseError => e
|
16
21
|
raise HttpError, "Received the following error when making HTTP request: #{e}"
|
data/package.json
CHANGED
data/ruby-onfleet.gemspec
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ruby-onfleet'
|
3
|
-
s.version = '1.0.
|
4
|
-
s.date = '2023-05-
|
3
|
+
s.version = '1.0.2'
|
4
|
+
s.date = '2023-05-19'
|
5
5
|
s.summary = 'Onfleet Ruby API wrapper package'
|
6
6
|
s.description = 'The Onfleet Ruby library provides convenient access to the Onfleet API.'
|
7
7
|
s.authors = ['Dan Menza']
|
8
|
-
s.email = '
|
8
|
+
s.email = 'support@onfleet.com'
|
9
9
|
s.homepage = 'https://rubygems.org/gems/ruby-onfleet'
|
10
10
|
s.license = 'MIT'
|
11
|
+
s.metadata = { 'source_code_uri' => 'https://github.com/onfleet/ruby-onfleet' }
|
11
12
|
|
12
13
|
s.add_dependency('faraday', '~> 1.10.0')
|
14
|
+
s.add_dependency('faraday-rate_limiter', '~> 0.0.4')
|
15
|
+
s.add_dependency('json', '~> 2.6.3')
|
16
|
+
s.add_dependency('uri', '~> 0.12.1')
|
13
17
|
|
14
18
|
s.add_development_dependency('rspec', '~> 3.12.0')
|
15
19
|
s.add_development_dependency('webmock', '~> 3.18.1')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-onfleet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Menza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-rate_limiter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.6.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: uri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.12.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.12.1
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: rspec
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +95,7 @@ dependencies:
|
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: 3.18.1
|
55
97
|
description: The Onfleet Ruby library provides convenient access to the Onfleet API.
|
56
|
-
email:
|
98
|
+
email: support@onfleet.com
|
57
99
|
executables: []
|
58
100
|
extensions: []
|
59
101
|
extra_rdoc_files: []
|
@@ -62,6 +104,7 @@ files:
|
|
62
104
|
- CHANGELOG.md
|
63
105
|
- Gemfile
|
64
106
|
- LICENSE
|
107
|
+
- README.es.md
|
65
108
|
- README.md
|
66
109
|
- lib/configuration.rb
|
67
110
|
- lib/errors/http_error.rb
|
@@ -89,7 +132,8 @@ files:
|
|
89
132
|
homepage: https://rubygems.org/gems/ruby-onfleet
|
90
133
|
licenses:
|
91
134
|
- MIT
|
92
|
-
metadata:
|
135
|
+
metadata:
|
136
|
+
source_code_uri: https://github.com/onfleet/ruby-onfleet
|
93
137
|
post_install_message:
|
94
138
|
rdoc_options: []
|
95
139
|
require_paths:
|