bumeran 0.0.2 → 0.1.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +121 -0
  6. data/LICENSE +22 -0
  7. data/README.md +80 -0
  8. data/Rakefile +8 -13
  9. data/bumeran.gemspec +32 -0
  10. data/lib/bumeran.rb +322 -247
  11. data/lib/bumeran/publication.rb +91 -0
  12. data/lib/bumeran/version.rb +1 -1
  13. data/spec/bumeran_initializer_helper_example.rb +7 -0
  14. data/spec/fixtures/bumeran_fixture.rb +69 -0
  15. data/spec/lib/bumeran_spec.rb +144 -0
  16. data/spec/spec_helper.rb +29 -0
  17. metadata +60 -74
  18. data/test/bumeran_test.rb +0 -7
  19. data/test/dummy/README.rdoc +0 -28
  20. data/test/dummy/Rakefile +0 -6
  21. data/test/dummy/app/assets/javascripts/application.js +0 -13
  22. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  23. data/test/dummy/app/controllers/application_controller.rb +0 -5
  24. data/test/dummy/app/helpers/application_helper.rb +0 -2
  25. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  26. data/test/dummy/bin/bundle +0 -3
  27. data/test/dummy/bin/rails +0 -4
  28. data/test/dummy/bin/rake +0 -4
  29. data/test/dummy/bin/setup +0 -29
  30. data/test/dummy/config.ru +0 -4
  31. data/test/dummy/config/application.rb +0 -26
  32. data/test/dummy/config/boot.rb +0 -5
  33. data/test/dummy/config/database.yml +0 -25
  34. data/test/dummy/config/environment.rb +0 -5
  35. data/test/dummy/config/environments/development.rb +0 -41
  36. data/test/dummy/config/environments/production.rb +0 -79
  37. data/test/dummy/config/environments/test.rb +0 -42
  38. data/test/dummy/config/initializers/assets.rb +0 -11
  39. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  40. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  41. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  42. data/test/dummy/config/initializers/inflections.rb +0 -16
  43. data/test/dummy/config/initializers/mime_types.rb +0 -4
  44. data/test/dummy/config/initializers/session_store.rb +0 -3
  45. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  46. data/test/dummy/config/locales/en.yml +0 -23
  47. data/test/dummy/config/routes.rb +0 -56
  48. data/test/dummy/config/secrets.yml +0 -22
  49. data/test/dummy/public/404.html +0 -67
  50. data/test/dummy/public/422.html +0 -67
  51. data/test/dummy/public/500.html +0 -66
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/test_helper.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81d81ce21ddcbb420694be00624d395d06293d0d
4
- data.tar.gz: d2844c98bcd242e2c8f3e3c844d41be30b9245f2
3
+ metadata.gz: f7653fd856f6e286e08d343200b9a70e996f6b16
4
+ data.tar.gz: 2312b5ec3b15bb67a866127f6608b71ee14edc9c
5
5
  SHA512:
6
- metadata.gz: 71f1b87fcfb20d638343214519ec9312a6e8fba048045db0f75ea2ea3cfecadcd5db537a96b641eb3553e3c21e2fda29f2004c826484203fa5be41f7fc05247f
7
- data.tar.gz: 2222e75b6425f60f313e4e1cbac04564e21d794fe5650df62bab1b15d456fc76bda78fe9216152f640c7942e82474cda5b76592ce9dcaeb35a21838e8cc8d9ba
6
+ metadata.gz: 293417c1103e148b6363cd5e46e82fcba205b5881716f4ea727a4831257dfff3a6a1765e7845fbb98c1aa7f07d52f10e7199010dbbf022275245c3a967311e1f
7
+ data.tar.gz: 513cc54d365a38e9af7abcab47cc55dfd2ce0f1afd9572ec8531c548f51e77feec340bbb0e3280b31761d6bf34e5486e33d43466241ea3d9820db3d7dc60de5d
@@ -0,0 +1,10 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ test/dummy/.sass-cache
9
+ spec/bumeran_initializer_helper.rb
10
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in bumeran.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
@@ -0,0 +1,121 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bumeran (0.1.0)
5
+ httparty (>= 0.13.3)
6
+ rails (~> 3.2.19)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.19)
12
+ actionpack (= 3.2.19)
13
+ mail (~> 2.5.4)
14
+ actionpack (3.2.19)
15
+ activemodel (= 3.2.19)
16
+ activesupport (= 3.2.19)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.4)
20
+ rack (~> 1.4.5)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.2.1)
24
+ activemodel (3.2.19)
25
+ activesupport (= 3.2.19)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.19)
28
+ activemodel (= 3.2.19)
29
+ activesupport (= 3.2.19)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.19)
33
+ activemodel (= 3.2.19)
34
+ activesupport (= 3.2.19)
35
+ activesupport (3.2.19)
36
+ i18n (~> 0.6, >= 0.6.4)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.3)
39
+ builder (3.0.4)
40
+ byebug (4.0.5)
41
+ columnize (= 0.9.0)
42
+ coderay (1.1.0)
43
+ columnize (0.9.0)
44
+ diff-lcs (1.1.3)
45
+ erubis (2.7.0)
46
+ hike (1.2.3)
47
+ httparty (0.13.4)
48
+ json (~> 1.8)
49
+ multi_xml (>= 0.5.2)
50
+ i18n (0.7.0)
51
+ journey (1.0.4)
52
+ json (1.8.2)
53
+ mail (2.5.4)
54
+ mime-types (~> 1.16)
55
+ treetop (~> 1.4.8)
56
+ method_source (0.8.2)
57
+ mime-types (1.25.1)
58
+ multi_json (1.10.1)
59
+ multi_xml (0.5.2)
60
+ polyglot (0.3.5)
61
+ pry (0.10.1)
62
+ coderay (~> 1.1.0)
63
+ method_source (~> 0.8.1)
64
+ slop (~> 3.4)
65
+ pry-byebug (3.1.0)
66
+ byebug (~> 4.0)
67
+ pry (~> 0.10)
68
+ rack (1.4.5)
69
+ rack-cache (1.2)
70
+ rack (>= 0.4)
71
+ rack-ssl (1.3.4)
72
+ rack
73
+ rack-test (0.6.3)
74
+ rack (>= 1.0)
75
+ rails (3.2.19)
76
+ actionmailer (= 3.2.19)
77
+ actionpack (= 3.2.19)
78
+ activerecord (= 3.2.19)
79
+ activeresource (= 3.2.19)
80
+ activesupport (= 3.2.19)
81
+ bundler (~> 1.0)
82
+ railties (= 3.2.19)
83
+ railties (3.2.19)
84
+ actionpack (= 3.2.19)
85
+ activesupport (= 3.2.19)
86
+ rack-ssl (~> 1.3.2)
87
+ rake (>= 0.8.7)
88
+ rdoc (~> 3.4)
89
+ thor (>= 0.14.6, < 2.0)
90
+ rake (10.4.2)
91
+ rdoc (3.12.2)
92
+ json (~> 1.4)
93
+ rspec (2.12.0)
94
+ rspec-core (~> 2.12.0)
95
+ rspec-expectations (~> 2.12.0)
96
+ rspec-mocks (~> 2.12.0)
97
+ rspec-core (2.12.2)
98
+ rspec-expectations (2.12.1)
99
+ diff-lcs (~> 1.1.3)
100
+ rspec-mocks (2.12.2)
101
+ slop (3.6.0)
102
+ sprockets (2.2.2)
103
+ hike (~> 1.2)
104
+ multi_json (~> 1.0)
105
+ rack (~> 1.0)
106
+ tilt (~> 1.1, != 1.3.0)
107
+ thor (0.19.1)
108
+ tilt (1.4.1)
109
+ treetop (1.4.15)
110
+ polyglot
111
+ polyglot (>= 0.3.1)
112
+ tzinfo (0.3.42)
113
+
114
+ PLATFORMS
115
+ ruby
116
+
117
+ DEPENDENCIES
118
+ bumeran!
119
+ pry-byebug
120
+ rake
121
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Rodrigo Fernandez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,80 @@
1
+ # Bumeran
2
+
3
+ This gem was made to connect to the Bumeran api found in https://developers.bumeran.com
4
+
5
+ ## Getting started
6
+
7
+ Bumeran works with Rails 3.2 onwards. You can add it to your Gemfile with:
8
+
9
+ ```ruby
10
+ gem 'bumeran'
11
+ ```
12
+
13
+ ...or can fetch the lastest developer version with:
14
+
15
+ ```ruby
16
+ gem 'bumeran', :git => 'git@github.com:rfernand/bumeran.git', :branch => 'develop'
17
+ ```
18
+ ### Configuration
19
+
20
+ After you finished the gem installation, you need to configure it with your Bumeran user information. You can do it filling a file like config/initializers/bumeran.rb with:
21
+
22
+ ```ruby
23
+ Bumeran.setup do |config|
24
+ config.grant_type = "password" # Default value
25
+ config.client_id = "" # Bumeran client id
26
+ config.username = "" # Bumeran client username
27
+ config.email = "" # Bumeran client email
28
+ config.password = "" # Bumeran client password
29
+ end
30
+ ```
31
+ ## How to use
32
+
33
+
34
+ And more that don't need an ID. All return a json object, and raise an error (401, 404, 500) if there was one:
35
+ ### Create a new publication
36
+ ```ruby
37
+ publication = Bumeran::Publication.new
38
+ Bumeran.publish(publication.body.to_json)
39
+ ```
40
+ ### Get a publication
41
+ ```ruby
42
+ Bumeran.get_publication(publication_id)
43
+ ```
44
+ ### And a lot of more getters
45
+
46
+ They recieve a corresponding object id and return a json object.
47
+
48
+ ```ruby
49
+ Bumeran.get_estudio(estudio_id)
50
+ Bumeran.get_conocimiento(conocimiento_id)
51
+ Bumeran.get_conocimiento_custom(conocimiento_custom_id)
52
+ Bumeran.get_experiencia_laboral(experiencia_laboral_id)
53
+ Bumeran.get_postulacion(postulacion_id)
54
+ Bumeran.get_curriculum(curriculum_id)
55
+ Bumeran.get_subareas_in(area_id)
56
+ Bumeran.get_zonas_in(pais_id)
57
+ Bumeran.get_localidades_id(pais_id)
58
+ Bumeran.get_plan_publicaciones_in(pais_id)
59
+ ```
60
+
61
+ ### More queries and helpers
62
+ All return a json object. After the first query, the returned json is cached in the Bumeran module.
63
+
64
+ ```ruby
65
+ Bumeran.areas
66
+ Bumeran.subareas
67
+ Bumeran.frecuencias_pago
68
+ Bumeran.paises
69
+ Bumeran.denominaciones
70
+ Bumeran.direcciones
71
+ Bumeran.frecuencias_pago
72
+ Bumeran.idiomas
73
+ Bumeran.industrias
74
+ Bumeran.niveles_idiomas
75
+ Bumeran.tipos_trabajo
76
+ Bumeran.areas_estudio
77
+ Bumeran.estados_estudio
78
+ Bumeran.tipos_estudio
79
+ Bumeran.tipos_estudio
80
+ ```
data/Rakefile CHANGED
@@ -14,21 +14,16 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
-
18
-
19
-
20
-
21
-
22
17
  Bundler::GemHelper.install_tasks
23
18
 
24
- require 'rake/testtask'
19
+ require "bundler/gem_tasks"
20
+ require "rspec/core/rake_task"
25
21
 
26
- Rake::TestTask.new(:test) do |t|
27
- t.libs << 'lib'
28
- t.libs << 'test'
29
- t.pattern = 'test/**/*_test.rb'
30
- t.verbose = false
31
- end
22
+ RSpec::Core::RakeTask.new
32
23
 
24
+ task :default => :spec
25
+ task :test => :spec
26
+ task :console do
27
+ exec "pry -r bumeran -I ./"
28
+ end
33
29
 
34
- task default: :test
@@ -0,0 +1,32 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "bumeran/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "bumeran"
9
+ s.version = Bumeran::VERSION
10
+ s.authors = ["Rodrigo Fernandez"]
11
+ s.email = ["chaotiklv@gmail.com"]
12
+ s.homepage = "https://github.com/rfernand/bumeran"
13
+ s.summary = "A gem to access the Bumeran api"
14
+ s.description = "A gem to access the Bumeran api: https://developers.bumeran.com"
15
+ s.license = "MIT"
16
+
17
+ #s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
18
+ #s.test_files = Dir["test/**/*"]
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ s.add_dependency "rails", "~> 3.2.19"
26
+ s.add_dependency "httparty", ">= 0.13.3"
27
+ #s.add_dependency "activesupport", "3.2.19"
28
+
29
+ s.add_development_dependency 'rake'
30
+ s.add_development_dependency "rspec"
31
+ s.add_development_dependency "pry-byebug"
32
+ end
@@ -1,9 +1,9 @@
1
- #module Bumeran
2
- #end
1
+ require 'rails'
2
+ require 'time'
3
3
  require 'httparty'
4
4
  require 'erb'
5
5
 
6
- class Bumeran
6
+ module Bumeran
7
7
  include HTTParty
8
8
  base_uri 'https://developers.bumeran.com'
9
9
 
@@ -23,346 +23,421 @@ class Bumeran
23
23
  mattr_accessor :password
24
24
  @@password = nil
25
25
 
26
+ mattr_accessor :access_token
27
+ @@access_token = nil
28
+
29
+ @@token_type= nil
30
+
31
+ mattr_accessor :expires_in
32
+ @@expires_in = nil
33
+
34
+ mattr_accessor :access_token_updated_at
35
+ @@access_token_updated_at = nil
36
+
37
+ mattr_accessor :options
38
+ @@options = nil
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 = []
56
+
57
+
26
58
 
27
59
  # Default way to setup Bumeran.
28
60
  def self.setup
29
61
  yield self
30
62
  end
31
63
 
32
- def initialize
33
- auth_token = login
34
- @options = { query: {access_token: auth_token} }
35
- end
36
-
37
-
38
- def default_publication_json
39
- return {
40
- descripcion: "",
41
- titulo: "",
42
- referencia: "", #optional
43
- tipoTrabajoId: 0,
44
- denominacion: {
45
- id: 0,
46
- nombre: "",
47
- logo: ""
48
- },
49
- preguntas: [ # optional
50
- {
51
- simple: {
52
- texto: ""
53
- }
54
- }
55
- ],
56
- postulantesDiscapacitados: false, #optional
57
- lugarTrabajo: {
58
- id: 0,
59
- direccion: "",
60
- zonaId: 0,
61
- paisId: 0,
62
- localidadId: 0,
63
- mostrarDireccionEnAviso: false
64
- },
65
- recepcionCandidato: {},
66
- areaId: 0,
67
- subAreaId: 0,
68
- requisitos: { # optional
69
- experiencia: {
70
- minimo: 0,
71
- excluyente: false
72
- },
73
- edad: {
74
- edadMinima: 0,
75
- edadMaxima: 0,
76
- excluyente: false
77
- },
78
- educacion: {
79
- estadoEstudioId: 0,
80
- tipoEstudioId: 0,
81
- excluyente: false
82
- },
83
- idiomas: [
84
- {
85
- nivelId: 0,
86
- idiomaId: 0,
87
- excluyente: false
88
- }
89
- ],
90
- residencia: {
91
- cercania: "",
92
- cantidadKm: 0,
93
- excluyente: false
94
- },
95
- salario: {
96
- tipo: "",
97
- salarioMinimo: 0,
98
- salarioMaximo: 0,
99
- frecuenciaPagoId: 0,
100
- mostrarAviso: false,
101
- solicitarCandidato: false,
102
- excluyente: false
103
- },
104
- genero: {
105
- nombre: "",
106
- excluyente: false
107
- }
108
- }
109
- }
110
- end
111
-
112
- def publish_test
113
- json = default_publication_json
114
- json[:descripcion] = ""
115
- json[:titulo] = ""
116
- #json[:referencia] = "" #optional
117
-
118
- json[:denominacion][:id] = 0
119
- json[:denominacion][:nombre] = ""
120
- json[:denominacion][:logo] = ""
121
-
122
- json[:preguntas] # optional
123
- #json[:preguntas][:texto]
124
-
125
- #json["postulantesDiscapacitados"] false, #optional
126
-
127
- #json["lugarTrabajo"]
128
- json[:lugarTrabajo][:id] = 0
129
- json[:lugarTrabajo][:direccion] = ""
130
- json[:lugarTrabajo][:zonaId] = 0
131
- json[:lugarTrabajo][:paisId] = 0
132
- json[:lugarTrabajo][:localidadId] = 0
133
- json[:lugarTrabajo][:mostrarDireccionEnAviso] = false
134
-
135
- json[:recepcionCandidato] = {}
136
- json[:areaId] = 0
137
- json[:subAreaId] = 0
138
- ####json[:requisitos] # optional
139
- ###json[:requisitos][:experiencia]
140
- #json[:requisitos][:experiencia][:minimo] = 0
141
- #json[:requisitos][:experiencia][:excluyente] = false
142
- ###json[:requisitos][:edad]
143
- #json[:requisitos][:edad][:edadMinima] = 0
144
- #json[:requisitos][:edad][:edadMaxima] = 0
145
- #json[:requisitos][:edad][:excluyente] = false
146
- ###json["requisitos"]["educacion"]
147
- #json["requisitos"]["educacion"]["estadoEstudioId"] = 0
148
- #json["requisitos"]["educacion"]["tipoEstudioId"] = 0
149
- #json["requisitos"]["educacion"]["excluyente"] = false
150
- ###json["requisitos"]["idiomas"]
151
- #json["requisitos"]["idiomas"]["nivelId"] = 0
152
- #json["requisitos"]["idiomas"]["idiomaId"] = 0
153
- #json["requisitos"]["idiomas"]["excluyente"] = false
154
- ###json["requisitos"]["residencia"]
155
- #json["requisitos"]["residencia"]["cercania"] = ""
156
- #json["requisitos"]["residencia"]["cantidadKm"] = 0
157
- #json["requisitos"]["residencia"]["excluyente"] = false
158
- ###json["requisitos"]["salario"]
159
- #json["requisitos"]["salario"]["tipo"] = ""
160
- #json["requisitos"]["salario"]["salarioMinimo"] = 0
161
- #json["requisitos"]["salario"]["salarioMaximo"] = 0
162
- #json["requisitos"]["salario"]["frecuenciaPagoId"] = 0
163
- #json["requisitos"]["salario"]["mostrarAviso"] = false
164
- #json["requisitos"]["salario"]["solicitarCandidato"] = false
165
- #json["requisitos"]["salario"]["excluyente"] = false
166
- ###json["requisitos"]["genero"]
167
- #json["requisitos"]["genero"]["nombre"] = ""
168
- #json["requisitos"]["genero"]["excluyente"] = false
169
- json[:tipoTrabajoId] = 0
170
-
171
- publish(json.to_json)
64
+ def self.initialize
65
+ unless has_valid_access_token?
66
+ login
67
+ @@options = { query: {access_token: @@access_token} }
68
+ end
172
69
  end
173
70
 
71
+
72
+ def self.has_valid_access_token?
73
+ if @@access_token_updated_at && @@expires_in
74
+ (Time.now < @@access_token_updated_at + @@expires_in)
75
+ else
76
+ false
77
+ end
78
+ end
79
+
174
80
  # Publicaciones
175
- def publish(json)
81
+ def self.publish(json)
82
+ Bumeran.initialize
176
83
  new_publish_path = "/v0/empresas/avisos"
177
- response = self.class.put(new_publish_path, @options.merge(body: json, headers: { "Accept" => "application/json", "Content-Type" => "application/json"}))
84
+ response = self.put(new_publish_path, @@options.merge(body: json, headers: { "Accept" => "application/json", "Content-Type" => "application/json"}))
178
85
 
179
- if check_response(response)
86
+ if Parser.parse_response(response)
180
87
  case response.code
181
88
  when 201
182
89
  # "Publication created, All good!"
183
- return response.body # id del proceso publicado
90
+ return response # body contains id del proceso publicado
184
91
  when 200
185
92
  # "TODO: Uhm.. no idea, is this good?"
186
- return response.body # id del proceso publicado?
93
+ return response # body contains id del proceso publicado?
187
94
  end
188
95
  end
189
96
  end
190
97
 
191
- def get_publication(publication_id)
98
+ def self.get_publication(publication_id)
192
99
  get_publish_path = "/v0/empresas/avisos/#{publication_id}"
193
- response = self.class.put(get_publish_path, @options)
100
+ response = self.get(get_publish_path, @@options)
101
+
102
+ return Parser.parse_response_to_json(response)
103
+ end
104
+
105
+ def self.areas
106
+ @@areas.empty? ? get_areas : @@areas
107
+ end
194
108
 
195
- return check_response(response)
109
+ def self.subareas
110
+ if @@subareas.empty?
111
+ areas.each do |area|
112
+ area["subareas"] = get_subareas_in(area["id"])
113
+ area["subareas"].map{|subarea| @@subareas << subarea}
114
+ end
115
+ end
116
+ @@subareas
196
117
  end
197
118
 
198
119
  # Servicios comunes
199
- def areas #jobs areas
120
+ def self.get_areas #jobs areas
121
+ Bumeran.initialize
200
122
  areas_path = "/v0/empresas/comunes/areas"
201
- response = self.class.get(areas_path, @options)
123
+ response = self.get(areas_path, @@options)
202
124
 
203
- return check_response(response)
125
+ @@areas = Parser.parse_response_to_json(response)
204
126
  end
205
127
 
206
- def subareas_in(area_id)
128
+ def self.get_subareas_in(area_id)
129
+ Bumeran.initialize
207
130
  subareas_path = "/v0/empresas/comunes/areas/#{area_id}/subAreas"
208
- response = self.class.get(subareas_path, @options)
131
+ response = self.get(subareas_path, @@options)
132
+
133
+ Parser.parse_response_to_json(response)
134
+ end
135
+
136
+ def self.paises
137
+ @@paises.empty? ? get_paises : @@paises
138
+ end
139
+
140
+ def self.zonas
141
+ # zonas by pais
142
+ if @@zonas.empty?
143
+ paises.each do |pais|
144
+ pais["zonas"] = get_zonas_in(pais["id"])
145
+ pais["zonas"].map{|zona| @@zonas << zona}
146
+ end
147
+ end
148
+ @@zonas
149
+ end
150
+
151
+ def self.localidades
152
+ if @@localidades.empty?
153
+ zonas.each do |zona|
154
+ begin
155
+ zona["localidades"] = get_localidades_in(zona["id"])
156
+ zona["localidades"].map{|localidad| @@localidades << localidad}
157
+ rescue StandardError => e
158
+ pp "Error at get_localidades_in(#{zona["id"]}): #{e}"
159
+ end
160
+ end
161
+ end
162
+ @@localidades
163
+ end
164
+
165
+ # Servicios generales asociados a datos de localización
166
+ def self.get_paises
167
+ Bumeran.initialize
168
+ paises_path = "/v0/empresas/locacion/paises"
169
+ response = self.get(paises_path, @@options)
170
+
171
+ @@paises = Parser.parse_response_to_json(response)
172
+ end
173
+
174
+ def self.get_zonas_in(pais_id)
175
+ Bumeran.initialize
176
+ zonas_path = "/v0/empresas/locacion/paises/#{pais_id}/zonas"
177
+ response = self.get(zonas_path, @@options)
178
+
179
+ Parser.parse_response_to_json(response)
180
+ end
181
+
182
+ def self.get_localidades_in(zona_id)
183
+ Bumeran.initialize
184
+ localidades_path = "/v0/empresas/locacion/zonas/#{zona_id}/localidades"
185
+ response = self.get(localidades_path, @@options)
186
+
187
+ Parser.parse_response_to_json(response)
188
+ end
189
+
190
+ def self.plan_publicaciones
191
+ if @@plan_publicaciones.empty?
192
+ paises.each do |pais|
193
+ pais["plan_publicaciones"] = get_plan_publicaciones_in(pais["id"])
194
+ pais["plan_publicaciones"].map{|plan_publicacion| @@plan_publicaciones << plan_publicacion}
195
+ end
196
+ end
197
+ @@plan_publicaciones
198
+ end
199
+
200
+ def self.get_plan_publicaciones_in(pais_id)
201
+ Bumeran.initialize
202
+ plan_publicaciones_path = "/v0/empresas/planPublicaciones/#{pais_id}"
203
+ response = self.get(plan_publicaciones_path, @@options)
204
+
205
+ return Parser.parse_response_to_json(response)
206
+ end
207
+
208
+ def self.denominaciones
209
+ @@denominaciones.empty? ? get_denominaciones : @@denominaciones
210
+ end
211
+
212
+ def self.get_denominaciones
213
+ Bumeran.initialize
214
+ denominaciones_path = "/v0/empresas/denominaciones"
215
+ response = self.get(denominaciones_path, @@options)
216
+
217
+ @@denominaciones = Parser.parse_response_to_json(response)
218
+ end
219
+
220
+ def self.direcciones
221
+ @@direcciones.empty? ? get_direcciones : @@direcciones
222
+ end
223
+
224
+ def self.get_direcciones
225
+ Bumeran.initialize
226
+ direcciones_path = "/v0/empresas/direcciones"
227
+ response = self.get(direcciones_path, @@options)
228
+
229
+ @@direcciones = Parser.parse_response_to_json(response)
230
+ end
209
231
 
210
- return check_response(response)
232
+ def self.frecuencias_pago
233
+ @@frecuencias_pago.empty? ? get_frecuencias_pago : @@frecuencias_pago
211
234
  end
212
235
 
213
- def frecuencias_pago
236
+ def self.get_frecuencias_pago
237
+ Bumeran.initialize
214
238
  frecuencias_pago_path = "/v0/empresas/comunes/frecuenciasPago"
215
- response = self.class.get(frecuencias_pago_path, @options)
239
+ response = self.get(frecuencias_pago_path, @@options)
216
240
 
217
- return check_response(response)
241
+ @@frecuencias_pago = Parser.parse_response_to_json(response)
218
242
  end
219
243
 
220
- def idiomas
244
+ def self.idiomas
245
+ @@idiomas.empty? ? get_idiomas : @@idiomas
246
+ end
247
+
248
+ def self.get_idiomas
249
+ Bumeran.initialize
221
250
  idiomas_path = "/v0/empresas/comunes/idiomas"
222
- response = self.class.get(idiomas_path, @options)
251
+ response = self.get(idiomas_path, @@options)
252
+
253
+ @@idiomas = Parser.parse_response_to_json(response)
254
+ end
223
255
 
224
- return check_response(response)
256
+ def self.industrias
257
+ @@industrias.empty? ? get_industrias : @@industrias
225
258
  end
226
259
 
227
- def industrias
260
+ def self.get_industrias
261
+ Bumeran.initialize
228
262
  industrias_path = "/v0/empresas/comunes/industrias"
229
- response = self.class.get(industrias_path, @options)
263
+ response = self.get(industrias_path, @@options)
264
+
265
+ @@industrias = Parser.parse_response_to_json(response)
266
+ end
230
267
 
231
- return check_response(response)
268
+ def self.niveles_idiomas
269
+ @@niveles_idiomas.empty? ? get_niveles_idiomas : @@niveles_idiomas
232
270
  end
233
271
 
234
- def niveles_idiomas
272
+ def self.get_niveles_idiomas
273
+ Bumeran.initialize
235
274
  niveles_idiomas_path = "/v0/empresas/comunes/nivelesIdiomas"
236
- response = self.class.get(niveles_idiomas_path, @options)
275
+ response = self.get(niveles_idiomas_path, @@options)
237
276
 
238
- return check_response(response)
277
+ @niveles_idiomas = Parser.parse_response_to_json(response)
239
278
  end
240
279
 
241
- def tipos_trabajo
280
+ def self.tipos_trabajo
281
+ @@tipos_trabajo.empty? ? get_tipos_trabajo : @@tipos_trabajo
282
+ end
283
+
284
+ def self.get_tipos_trabajo
285
+ Bumeran.initialize
242
286
  tipos_trabajo_path = "/v0/empresas/comunes/tiposTrabajo"
243
- response = self.class.get(tipos_trabajo_path, @options)
287
+ response = self.get(tipos_trabajo_path, @@options)
244
288
 
245
- return check_response(response)
289
+ @@tipos_trabajo = Parser.parse_response_to_json(response)
290
+ end
291
+
292
+ def self.areas_estudio
293
+ @@areas_estudio.empty? ? get_areas_estudio : @@areas_estudio
246
294
  end
247
295
 
248
296
  # Servicios de estudios de los postulantes
249
- def areas_estudio
297
+ def self.get_areas_estudio
298
+ Bumeran.initialize
250
299
  areas_estudio_path = "/v0/estudios/areasEstudio"
251
- response = self.class.get(areas_estudio_path, @options)
300
+ response = self.get(areas_estudio_path, @@options)
301
+
302
+ @@areas_estudio = Parser.parse_response_to_json(response)
303
+ end
252
304
 
253
- return check_response(response)
305
+ def self.estados_estudio
306
+ @@estados_estudio.empty? ? get_estados_estudio : @@estados_estudio
254
307
  end
255
308
 
256
- def estados_estudio
309
+ def self.get_estados_estudio
310
+ Bumeran.initialize
257
311
  estados_estudio_path = "/v0/estudios/estadosEstudio"
258
- response = self.class.get(estados_estudio_path, @options)
312
+ response = self.get(estados_estudio_path, @@options)
313
+
314
+ @@estados_estudio = Parser.parse_response_to_json(response)
315
+ end
259
316
 
260
- return check_response(response)
317
+ def self.tipos_estudio
318
+ @@tipos_estudio.empty? ? get_tipos_estudio : @@tipos_estudio
261
319
  end
262
320
 
263
- def tipos_estudio
321
+ def self.get_tipos_estudio
322
+ Bumeran.initialize
264
323
  tipos_estudio_path = "/v0/estudios/tiposEstudio"
265
- response = self.class.get(tipos_estudio_path, @options)
324
+ response = self.get(tipos_estudio_path, @@options)
266
325
 
267
- return check_response(response)
326
+ @@tipos_estudio = Parser.parse_response_to_json(response)
268
327
  end
269
328
 
270
- def get_estudio(estudio_id)
329
+ def self.get_estudio(estudio_id)
330
+ Bumeran.initialize
271
331
  estudio_path = "/v0/estudios/#{estudio_id}"
272
- response = self.class.get(estudio_path, @options)
332
+ response = self.get(estudio_path, @@options)
273
333
 
274
- return check_response(response)
334
+ return Parser.parse_response_to_json(response)
275
335
  end
276
336
 
277
- # Servicios de la experiencia laboral de los postulantes
278
- def get_experiencia_laboral(experiencia_laboral_id)
279
- experiencia_laboral_path = "/v0/experienciaLaborales/#{experiencia_laboral_id}"
280
- response = self.class.get(experiencia_laboral_path, @options)
337
+ def self.get_conocimiento(conocimiento_id)
338
+ Bumeran.initialize
339
+ conocimiento_path = "/v0/conocimientos/#{conocimiento_id}"
340
+ response = self.get(conocimiento_path, @@options)
281
341
 
282
- return check_response(response)
342
+ Parser.parse_response_to_json(response)
283
343
  end
284
344
 
285
- # Servicios generales asociados a datos de localización
286
- def paises
287
- paises_path = "/v0/empresas/locacion/paises"
288
- response = self.class.get(paises_path, @options)
289
345
 
290
- return check_response(response)
346
+ def self.get_conocimiento_custom(conocimiento_id)
347
+ Bumeran.initialize
348
+ conocimiento_custom_path = "/v0/conocimientos/custom/#{conocimiento_id}"
349
+ response = self.get(conocimiento_custom_path, @@options)
350
+
351
+ Parser.parse_response_to_json(response)
291
352
  end
292
353
 
293
- def zonas_in(pais_id)
294
- zonas_path = "/v0/empresas/locacion/paises/#{pais_id}/zonas"
295
- response = self.class.get(zonas_path, @options)
296
354
 
297
- return check_response(response)
355
+ # Servicios de la experiencia laboral de los postulantes
356
+ def self.get_experiencia_laboral(experiencia_laboral_id)
357
+ Bumeran.initialize
358
+ experiencia_laboral_path = "/v0/experienciaLaborales/#{experiencia_laboral_id}"
359
+ response = self.get(experiencia_laboral_path, @@options)
360
+
361
+ return Parser.parse_response_to_json(response)
298
362
  end
299
363
 
300
- def localidades_in(zona_id)
301
- localidades_path = "/v0/empresas/locacion/zonas/#{zona_id}/localidades"
302
- response = self.class.get(localidades_path, @options)
364
+ # Servicio de postulaciones a los avisos publicados por las empresas
365
+ def self.get_postulacion(postulacion_id)
366
+ Bumeran.initialize
367
+ postulacion_path = "/v0/empresas/postulaciones/#{postulacion_id}"
368
+ response = self.get(postulacion_path, @@options)
303
369
 
304
- return check_response(response)
370
+ return Parser.parse_response_to_json(response)
305
371
  end
306
372
 
307
- # Servicio de postulaciones a los avisos publicados por las empresas
308
- def get_postulacion(postulacion_id)
309
- postulaciones_path = "/v0/empresas/postulaciones/#{postulacion_id}"
310
- response = self.class.get(postulaciones_path, @options)
373
+ def self.get_curriculum(curriculum_id)
374
+ Bumeran.initialize
375
+ curriculum_path = "/v0/empresas/curriculums/#{curriculum_id}"
376
+ response = self.get(curriculum_path, @@options)
311
377
 
312
- return check_response(response)
378
+ return Parser.parse_response_to_json(response)
313
379
  end
314
380
 
315
- def discard_postulacion(postulacion_id)
381
+ def self.discard_postulacion(postulacion_id)
382
+ Bumeran.initialize
316
383
  discard_postulaciones_path = "/v0/empresas/postulaciones/#{postulacion_id}/descartar"
317
- response = self.class.put(discard_postulaciones_path, @options)
384
+ response = self.put(discard_postulaciones_path, @@options)
318
385
 
319
- return check_response(response)
386
+ return Parser.parse_response_to_json(response)
320
387
  end
321
388
 
322
389
 
323
- def login
390
+ def self.login(client_id=@@client_id, username=@@username, password=@@password, grant_type=@@grant_type)
324
391
  login_path = "/v0/empresas/usuarios/login"
325
- # POST /v0/empresas/usuarios/login
326
- # sends post request with:
327
- # grant_type= Tipo de permiso de OAuth2 query string
328
- # client_id= Identificador del cliente de OAuth2 query string
329
- # username= Nombre de usuario query string
330
- # password= Password del usuario query string
331
- # recieves json
332
- # {
333
- # "accessToken": "bdf48bc4-6b7a-4de9-82e5-5bf278d23855",
334
- # "tokenType": "bearer",
335
- # "expiresIn": 1199
336
- # }
337
-
338
- response = self.class.post(login_path, query: {grant_type: @@grant_type, client_id: @@client_id, username: @@username, password: @@password})
339
-
340
- if check_response(response)
392
+ response = self.post(login_path, query: {grant_type: grant_type, client_id: client_id, username: username, password: password})
393
+
394
+ if Parser.parse_response_to_json(response)
341
395
  # "All good!"
342
- access_token = response["accessToken"]
343
- token_type = response["tokenType"]
344
- expires_in = response["expiresIn"]
345
- return access_token
396
+ @@access_token = response["accessToken"]
397
+ @@token_type = response["tokenType"]
398
+ @@expires_in = response["expiresIn"]
399
+ @@access_token_updated_at = Time.now
400
+ return @@access_token
346
401
  end
347
402
  end
348
403
 
349
404
 
350
- private
351
- def check_response(response)
352
- case response.code
353
- when 200..201
354
- # "All good!"
355
- return response
356
- when 401
357
- raise "Unauthorized, check login info"
358
- when 403
359
- raise "Error 403: Forbidden"
360
- when 404
361
- raise "Error 404 not found"
362
- when 500...600
363
- raise "ZOMG ERROR #{response.code}"
364
- else
365
- raise "Error #{response.code}, unkown response"
405
+ class Parser
406
+ def self.parse_response(response)
407
+ case response.code
408
+ when 200..201
409
+ # "All good!"
410
+ return response.body
411
+ when 401
412
+ raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
413
+ when 403
414
+ raise "Error 403: Forbidden"
415
+ when 404
416
+ raise "Error 404 not found"
417
+ when 500...600
418
+ raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}"
419
+ else
420
+ raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}"
421
+ end
422
+ end
423
+ def self.parse_response_to_json(response)
424
+ case response.code
425
+ when 200..201
426
+ # "All good!"
427
+ return JSON.parse(response.body)
428
+ when 401
429
+ raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
430
+ when 403
431
+ raise "Error 403: Forbidden"
432
+ when 404
433
+ raise "Error 404 not found"
434
+ when 500...600
435
+ raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}"
436
+ else
437
+ raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}"
438
+ end
366
439
  end
367
440
  end
368
441
  end
442
+
443
+ require 'bumeran/publication'