bumeran 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ec92657e51763c31d4189b1143d2fe11b2e6c79
4
- data.tar.gz: 382b3388ee89b76d3899fcb2112a36910d7e0af7
3
+ metadata.gz: 37b2f87959c603add72f8d64e39e12a87ec98068
4
+ data.tar.gz: 68d4c04eab9e76b471578b48ed65a593b500e215
5
5
  SHA512:
6
- metadata.gz: b5574974a67d37495293cb787724f7ce73b40d481fdeb5fdea7e9256dff69092256555796226ff312ff911aaf7429aec48251ff1e8cb684d9db1f9d6dd6d38c2
7
- data.tar.gz: 882f1acf18b19e0dc1a7f6c201ed7191067222aa807d6550cde603bef5cc092f78d73abd909b381475f5764b6efb9c0114985bb08293e78c8b591438a058c1c9
6
+ metadata.gz: 000aa8707ed6e7260ff625c743834181789d9e62f448a647711b275e870d97b6926bc5038f288efcba0bfb66d485997ee0b5f24c1aa488579d2562ce50c7b0ea
7
+ data.tar.gz: 05af03a1ef23896601327d9ebb0c2e211f9ddee2c77660206ad2a5b9037f02ac75e6b52d39cdd4785ef0076f66edc4f9c830cf7cbe488748a1a15f7bbcc190e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bumeran (0.1.2)
4
+ bumeran (0.2.0)
5
5
  httparty (>= 0.13.3)
6
6
  rails (>= 3.2)
7
7
 
data/lib/bumeran.rb CHANGED
@@ -37,22 +37,22 @@ module Bumeran
37
37
  mattr_accessor :options
38
38
  @@options = nil
39
39
 
40
- @@areas = []
41
- @@subareas = []
42
- @@paises = []
43
- @@zonas = []
44
- @@localidades = []
45
- @@plan_publicaciones = []
46
- @@frecuencias_pago = []
47
- @@idiomas = []
48
- @@industrias = []
49
- @@niveles_idiomas = []
50
- @@tipos_trabajo = []
51
- @@areas_estudio = []
52
- @@estados_estudio = []
53
- @@tipos_estudio = []
54
- @@direcciones = []
55
- @@denominaciones = []
40
+ @@areas = {}
41
+ @@subareas = {}
42
+ @@paises = {}
43
+ @@zonas = {}
44
+ @@localidades = {}
45
+ @@plan_publicaciones = {}
46
+ @@frecuencias_pago = {}
47
+ @@idiomas = {}
48
+ @@industrias = {}
49
+ @@niveles_idiomas = {}
50
+ @@tipos_trabajo = {}
51
+ @@areas_estudio = {}
52
+ @@estados_estudio = {}
53
+ @@tipos_estudio = {}
54
+ @@direcciones = {}
55
+ @@denominaciones = {}
56
56
 
57
57
 
58
58
 
@@ -171,37 +171,76 @@ module Bumeran
171
171
  return Parser.parse_response(response)
172
172
  end
173
173
 
174
+ # Generation of service helpers
175
+ SERVICES = {
176
+ areas: {object: :area},
177
+ subareas: {object: :subarea, parent: :area},
178
+ paises: {object: :pais},
179
+ zonas: {object: :zona, parent: :pais, parent_service: :paises},
180
+ localidades: {object: :localidad, parent: :zona, parent_service: :zonas},
181
+ plan_publicaciones: {object: :plan_publicacion, parent: :pais, parent_service: :paises},
182
+ denominaciones: {object: :denominacion},
183
+ direcciones: {object: :direccion},
184
+ frecuencias_pago: {object: :frencuencia_pago},
185
+ idiomas: {object: :idioma},
186
+ industrias: {object: :industria},
187
+ niveles_idiomas: {object: :niveles_idioma},
188
+ tipos_trabajo: {object: :tipo_trabajo},
189
+ areas_estudio: {object: :area_estudio},
190
+ estados_estudio: {object: :estado_estudio},
191
+ tipos_estudio: {object: :tipo_estudio}
192
+ }
193
+
194
+ # GENERIC HELPER
195
+ def self.generic_find_by_id(objects_sym, object_id) #def self.pais(pais_id)
196
+ object = send(objects_sym).select{|id, content| id == object_id} # pais = paises.select{|id, pais| id == pais_id}
197
+ object ? object[object_id] : nil # pais ? pais[pais_id] : nil
198
+ end #end
199
+
200
+ def self.generic_find_all_in(objects_sym, parent_object_sym, parent_service_sym, parent_object_id)
201
+ if class_variable_get("@@#{objects_sym}").empty? # if @@zonas.empty?
202
+ parent_object = send(parent_service_sym)[parent_object_id] # pais = paises[pais_id]
203
+
204
+ if parent_object[objects_sym.to_s] # if pais["zonas"]
205
+ parent_object[objects_sym.to_s].merge!(send("get_#{objects_sym}_in", parent_object_id)) # pais["zonas"].merge!(get_zonas_in(pais_id))
206
+ else # else
207
+ parent_object[objects_sym.to_s] = send("get_#{objects_sym}_in", parent_object_id) # pais["zonas"] = get_zonas_in(pais_id)
208
+ end # end
209
+ else # else
210
+ send(parent_object_sym, parent_object_id)[objects_sym.to_s] # pais(pais_id)["zonas"] # pais(pais_id)["zonas"]
211
+ end # end
212
+ end
213
+
214
+ # Generation of dynamic static methods
215
+ SERVICES.each do |service_name, service|
216
+
217
+ #def self.pais(pais_id)
218
+ define_singleton_method(service[:object]) do |object_id|
219
+ generic_find_by_id(service_name, object_id)
220
+ end
221
+
222
+ # def self.zonas_in(pais_id)
223
+ if service[:parent]
224
+ define_singleton_method("#{service_name}_in") do |parent_object_id|
225
+ generic_find_all_in(service_name, service[:parent], service[:parent_service], parent_object_id)
226
+ end
227
+ end
228
+ end
229
+
230
+ # Helpers
174
231
  def self.areas
175
232
  @@areas.empty? ? get_areas : @@areas
176
233
  end
177
234
 
178
235
  def self.subareas
179
236
  if @@subareas.empty?
180
- areas.each do |area|
181
- area["subareas"] = get_subareas_in(area["id"])
182
- area["subareas"].map{|subarea| @@subareas << subarea}
237
+ areas.each do |area_id, area|
238
+ area["subareas"] ? area["subarea"].merge!(get_subareas_in(area_id)) : area["subarea"] = get_subareas_in(area_id)
183
239
  end
184
240
  end
185
241
  @@subareas
186
242
  end
187
243
 
188
- # Servicios comunes
189
- def self.get_areas #jobs areas
190
- Bumeran.initialize
191
- areas_path = "/v0/empresas/comunes/areas"
192
- response = self.get(areas_path, @@options)
193
-
194
- @@areas = Parser.parse_response_to_json(response)
195
- end
196
-
197
- def self.get_subareas_in(area_id)
198
- Bumeran.initialize
199
- subareas_path = "/v0/empresas/comunes/areas/#{area_id}/subAreas"
200
- response = self.get(subareas_path, @@options)
201
-
202
- Parser.parse_response_to_json(response)
203
- end
204
-
205
244
  def self.paises
206
245
  @@paises.empty? ? get_paises : @@paises
207
246
  end
@@ -209,9 +248,8 @@ module Bumeran
209
248
  def self.zonas
210
249
  # zonas by pais
211
250
  if @@zonas.empty?
212
- paises.each do |pais|
213
- pais["zonas"] = get_zonas_in(pais["id"])
214
- pais["zonas"].map{|zona| @@zonas << zona}
251
+ paises.each do |pais_id, pais|
252
+ pais["zonas"] ? pais["zonas"].merge!(get_zonas_in(pais_id)) : pais["zonas"] = get_zonas_in(pais_id)
215
253
  end
216
254
  end
217
255
  @@zonas
@@ -219,10 +257,9 @@ module Bumeran
219
257
 
220
258
  def self.localidades
221
259
  if @@localidades.empty?
222
- zonas.each do |zona|
260
+ zonas.each do |zona_id, zona|
223
261
  begin
224
- zona["localidades"] = get_localidades_in(zona["id"])
225
- zona["localidades"].map{|localidad| @@localidades << localidad}
262
+ zona["localidades"] ? zona["localidades"].merge!(get_localidades_in(zona_id)) : zona["localidades"] = get_localidades_in(zona_id)
226
263
  rescue StandardError => e
227
264
  pp "Error at get_localidades_in(#{zona["id"]}): #{e}"
228
265
  end
@@ -231,13 +268,84 @@ module Bumeran
231
268
  @@localidades
232
269
  end
233
270
 
271
+ def self.plan_publicaciones
272
+ if @@plan_publicaciones.empty?
273
+ paises.each do |pais_id, pais|
274
+ pais["plan_publicaciones"] ? pais["plan_publicaciones"].merge!(get_plan_publicaciones_in(pais_id)) : pais["plan_publicaciones"] = get_plan_publicaciones_in(pais_id)
275
+ end
276
+ end
277
+ @@plan_publicaciones
278
+ end
279
+
280
+ def self.denominaciones
281
+ @@denominaciones.empty? ? get_denominaciones : @@denominaciones
282
+ end
283
+
284
+ def self.direcciones
285
+ @@direcciones.empty? ? get_direcciones : @@direcciones
286
+ end
287
+
288
+ def self.frecuencias_pago
289
+ @@frecuencias_pago.empty? ? get_frecuencias_pago : @@frecuencias_pago
290
+ end
291
+
292
+ def self.idiomas
293
+ @@idiomas.empty? ? get_idiomas : @@idiomas
294
+ end
295
+
296
+ def self.industrias
297
+ @@industrias.empty? ? get_industrias : @@industrias
298
+ end
299
+
300
+ def self.niveles_idiomas
301
+ @@niveles_idiomas.empty? ? get_niveles_idiomas : @@niveles_idiomas
302
+ end
303
+
304
+ def self.tipos_trabajo
305
+ @@tipos_trabajo.empty? ? get_tipos_trabajo : @@tipos_trabajo
306
+ end
307
+
308
+ def self.areas_estudio
309
+ @@areas_estudio.empty? ? get_areas_estudio : @@areas_estudio
310
+ end
311
+
312
+ def self.estados_estudio
313
+ @@estados_estudio.empty? ? get_estados_estudio : @@estados_estudio
314
+ end
315
+
316
+ def self.tipos_estudio
317
+ @@tipos_estudio.empty? ? get_tipos_estudio : @@tipos_estudio
318
+ end
319
+
320
+ # Servicios comunes
321
+ # Getters
322
+ def self.get_areas #jobs areas
323
+ Bumeran.initialize
324
+ areas_path = "/v0/empresas/comunes/areas"
325
+ response = self.get(areas_path, @@options)
326
+
327
+ json = Parser.parse_response_to_json(response)
328
+ Parser.parse_json_to_hash(json, @@areas)
329
+ end
330
+
331
+ def self.get_subareas_in(area_id)
332
+ Bumeran.initialize
333
+ subareas_path = "/v0/empresas/comunes/areas/#{area_id}/subAreas"
334
+ response = self.get(subareas_path, @@options)
335
+
336
+ json = Parser.parse_response_to_json(response)
337
+ Parser.parse_json_to_hash(json, @@subareas) # to save the subareas in the @@subareas
338
+ Parser.parse_json_to_hash(json, {}) # to return only the subareas in the area
339
+ end
340
+
234
341
  # Servicios generales asociados a datos de localización
235
342
  def self.get_paises
236
343
  Bumeran.initialize
237
344
  paises_path = "/v0/empresas/locacion/paises"
238
345
  response = self.get(paises_path, @@options)
239
346
 
240
- @@paises = Parser.parse_response_to_json(response)
347
+ paises_json = Parser.parse_response_to_json(response)
348
+ Parser.parse_json_to_hash(paises_json, @@paises)
241
349
  end
242
350
 
243
351
  def self.get_zonas_in(pais_id)
@@ -245,7 +353,9 @@ module Bumeran
245
353
  zonas_path = "/v0/empresas/locacion/paises/#{pais_id}/zonas"
246
354
  response = self.get(zonas_path, @@options)
247
355
 
248
- Parser.parse_response_to_json(response)
356
+ json_zonas = Parser.parse_response_to_json(response)
357
+ Parser.parse_json_to_hash(json_zonas, @@zonas) # to save the zone in the zonas hash
358
+ Parser.parse_json_to_hash(json_zonas, {}) # to return only the zonas from the country
249
359
  end
250
360
 
251
361
  def self.get_localidades_in(zona_id)
@@ -256,38 +366,24 @@ module Bumeran
256
366
  Parser.parse_response_to_json(response)
257
367
  end
258
368
 
259
- def self.plan_publicaciones
260
- if @@plan_publicaciones.empty?
261
- paises.each do |pais|
262
- pais["plan_publicaciones"] = get_plan_publicaciones_in(pais["id"])
263
- pais["plan_publicaciones"].map{|plan_publicacion| @@plan_publicaciones << plan_publicacion}
264
- end
265
- end
266
- @@plan_publicaciones
267
- end
268
-
269
369
  def self.get_plan_publicaciones_in(pais_id)
270
370
  Bumeran.initialize
271
371
  plan_publicaciones_path = "/v0/empresas/planPublicaciones/#{pais_id}"
272
372
  response = self.get(plan_publicaciones_path, @@options)
273
373
 
274
- return Parser.parse_response_to_json(response)
275
- end
276
-
277
- def self.denominaciones
278
- @@denominaciones.empty? ? get_denominaciones : @@denominaciones
374
+ json = Parser.parse_response_to_json(response)
375
+ Parser.parse_json_to_hash(json, @@plan_publicaciones) # to save the zone in the zonas hash
376
+ return Parser.parse_json_to_hash(json, {})
279
377
  end
280
378
 
379
+ # Otros servicios
281
380
  def self.get_denominaciones
282
381
  Bumeran.initialize
283
382
  denominaciones_path = "/v0/empresas/denominaciones"
284
383
  response = self.get(denominaciones_path, @@options)
285
384
 
286
- @@denominaciones = Parser.parse_response_to_json(response)
287
- end
288
-
289
- def self.direcciones
290
- @@direcciones.empty? ? get_direcciones : @@direcciones
385
+ json = Parser.parse_response_to_json(response)
386
+ return Parser.parse_json_to_hash(json, @@denominaciones)
291
387
  end
292
388
 
293
389
  def self.get_direcciones
@@ -295,11 +391,8 @@ module Bumeran
295
391
  direcciones_path = "/v0/empresas/direcciones"
296
392
  response = self.get(direcciones_path, @@options)
297
393
 
298
- @@direcciones = Parser.parse_response_to_json(response)
299
- end
300
-
301
- def self.frecuencias_pago
302
- @@frecuencias_pago.empty? ? get_frecuencias_pago : @@frecuencias_pago
394
+ json = Parser.parse_response_to_json(response)
395
+ return Parser.parse_json_to_hash(json, @@direcciones)
303
396
  end
304
397
 
305
398
  def self.get_frecuencias_pago
@@ -307,11 +400,8 @@ module Bumeran
307
400
  frecuencias_pago_path = "/v0/empresas/comunes/frecuenciasPago"
308
401
  response = self.get(frecuencias_pago_path, @@options)
309
402
 
310
- @@frecuencias_pago = Parser.parse_response_to_json(response)
311
- end
312
-
313
- def self.idiomas
314
- @@idiomas.empty? ? get_idiomas : @@idiomas
403
+ json = Parser.parse_response_to_json(response)
404
+ return Parser.parse_json_to_hash(json, @@frecuencias_pago)
315
405
  end
316
406
 
317
407
  def self.get_idiomas
@@ -319,11 +409,8 @@ module Bumeran
319
409
  idiomas_path = "/v0/empresas/comunes/idiomas"
320
410
  response = self.get(idiomas_path, @@options)
321
411
 
322
- @@idiomas = Parser.parse_response_to_json(response)
323
- end
324
-
325
- def self.industrias
326
- @@industrias.empty? ? get_industrias : @@industrias
412
+ json = Parser.parse_response_to_json(response)
413
+ return Parser.parse_json_to_hash(json, @@idiomas)
327
414
  end
328
415
 
329
416
  def self.get_industrias
@@ -331,11 +418,8 @@ module Bumeran
331
418
  industrias_path = "/v0/empresas/comunes/industrias"
332
419
  response = self.get(industrias_path, @@options)
333
420
 
334
- @@industrias = Parser.parse_response_to_json(response)
335
- end
336
-
337
- def self.niveles_idiomas
338
- @@niveles_idiomas.empty? ? get_niveles_idiomas : @@niveles_idiomas
421
+ json = Parser.parse_response_to_json(response)
422
+ return Parser.parse_json_to_hash(json, @@industrias)
339
423
  end
340
424
 
341
425
  def self.get_niveles_idiomas
@@ -343,11 +427,8 @@ module Bumeran
343
427
  niveles_idiomas_path = "/v0/empresas/comunes/nivelesIdiomas"
344
428
  response = self.get(niveles_idiomas_path, @@options)
345
429
 
346
- @niveles_idiomas = Parser.parse_response_to_json(response)
347
- end
348
-
349
- def self.tipos_trabajo
350
- @@tipos_trabajo.empty? ? get_tipos_trabajo : @@tipos_trabajo
430
+ json = Parser.parse_response_to_json(response)
431
+ return Parser.parse_json_to_hash(json, @@niveles_idiomas)
351
432
  end
352
433
 
353
434
  def self.get_tipos_trabajo
@@ -355,11 +436,8 @@ module Bumeran
355
436
  tipos_trabajo_path = "/v0/empresas/comunes/tiposTrabajo"
356
437
  response = self.get(tipos_trabajo_path, @@options)
357
438
 
358
- @@tipos_trabajo = Parser.parse_response_to_json(response)
359
- end
360
-
361
- def self.areas_estudio
362
- @@areas_estudio.empty? ? get_areas_estudio : @@areas_estudio
439
+ json = Parser.parse_response_to_json(response)
440
+ return Parser.parse_json_to_hash(json, @@tipos_trabajo)
363
441
  end
364
442
 
365
443
  # Servicios de estudios de los postulantes
@@ -368,11 +446,8 @@ module Bumeran
368
446
  areas_estudio_path = "/v0/estudios/areasEstudio"
369
447
  response = self.get(areas_estudio_path, @@options)
370
448
 
371
- @@areas_estudio = Parser.parse_response_to_json(response)
372
- end
373
-
374
- def self.estados_estudio
375
- @@estados_estudio.empty? ? get_estados_estudio : @@estados_estudio
449
+ json = Parser.parse_response_to_json(response)
450
+ return Parser.parse_json_to_hash(json, @@areas_estudio)
376
451
  end
377
452
 
378
453
  def self.get_estados_estudio
@@ -380,11 +455,8 @@ module Bumeran
380
455
  estados_estudio_path = "/v0/estudios/estadosEstudio"
381
456
  response = self.get(estados_estudio_path, @@options)
382
457
 
383
- @@estados_estudio = Parser.parse_response_to_json(response)
384
- end
385
-
386
- def self.tipos_estudio
387
- @@tipos_estudio.empty? ? get_tipos_estudio : @@tipos_estudio
458
+ json = Parser.parse_response_to_json(response)
459
+ return Parser.parse_json_to_hash(json, @@estados_estudio)
388
460
  end
389
461
 
390
462
  def self.get_tipos_estudio
@@ -392,7 +464,8 @@ module Bumeran
392
464
  tipos_estudio_path = "/v0/estudios/tiposEstudio"
393
465
  response = self.get(tipos_estudio_path, @@options)
394
466
 
395
- @@tipos_estudio = Parser.parse_response_to_json(response)
467
+ json = Parser.parse_response_to_json(response)
468
+ return Parser.parse_json_to_hash(json, @@tipos_estudio)
396
469
  end
397
470
 
398
471
  def self.get_estudio(estudio_id)
@@ -477,6 +550,11 @@ module Bumeran
477
550
 
478
551
 
479
552
  class Parser
553
+ def self.parse_json_to_hash(json, hash)
554
+ json.each{|object| hash[object["id"]] ? hash[object["id"]].merge!(object) : hash[object["id"]] = object}
555
+ return hash
556
+ end
557
+
480
558
  def self.parse_response(response)
481
559
  case response.code
482
560
  when 200..201
@@ -1,3 +1,3 @@
1
1
  module Bumeran
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -54,7 +54,8 @@ describe Bumeran do
54
54
  Bumeran.frecuencias_pago.count.should > 0
55
55
  end
56
56
 
57
- it 'can get paises, zonas, localidades, and plan plublicaciones', getters: true do
57
+ # localidades gives error! (API problem)
58
+ it 'can get paises, zonas, localidades, and plan plublicaciones' do
58
59
  pp Bumeran.paises
59
60
  Bumeran.paises.count.should > 0
60
61
  Bumeran.zonas.count.should > 0
@@ -77,6 +78,7 @@ describe Bumeran do
77
78
  Bumeran.frecuencias_pago.count.should > 0
78
79
  end
79
80
 
81
+
80
82
  it 'can get idiomas', getters: true do
81
83
  pp Bumeran.idiomas
82
84
  Bumeran.idiomas.count.should > 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bumeran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Fernandez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.2.2
126
+ rubygems_version: 2.4.5
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: A gem to access the Bumeran api