firstjob_api 1.0.4

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.
@@ -0,0 +1,5 @@
1
+ english_levels:
2
+ 1: basico
3
+ 2: medio
4
+ 3: avanzado
5
+ 4: nativo
@@ -0,0 +1,5 @@
1
+ excel_levels:
2
+ 1: No aplica
3
+ 2: Basico
4
+ 3: Medio
5
+ 4: Avanzado
@@ -0,0 +1,4 @@
1
+ looking_fors:
2
+ 1: Practica
3
+ 2: Memoria
4
+ 3: Trabajo
@@ -0,0 +1,121 @@
1
+ universities:
2
+ 2: Universidad de Chile
3
+ 3: Universidad Técnica Federico Santa María (UTFSM)
4
+ 4: Universidad Adolfo Ibáñez (UAI)
5
+ 5: Universidad de los Andes
6
+ 6: Universidad de Santiago de Chile (USACH)
7
+ 7: Universidad Diego Portales (UDP)
8
+ 9: Universidad del desarrollo (UDD)
9
+ 10: Universidad de Concepción
10
+ 11: INACAP
11
+ 12: DUOC UC
12
+ 96: Instituto Profesional Esucomex
13
+ 171: Universidad Santo Tomás (UST)
14
+ 170: Universidad San Sebastián (USS)
15
+ 110: Instituto Profesional Providencia
16
+ 116: Universidad Arturo Prat (UNAP)
17
+ 117: Universidad Austral de Chile
18
+ 123: Universidad de Atacama
19
+ 119: Universidad Católica de Temuco (UCT)
20
+ 120: Universidad Católica del Maule (UCM)
21
+ 122: Universidad de Antofagasta
22
+ 121: Universidad Católica del Norte (UCN)
23
+ 127: Universidad de la Serena
24
+ 128: Universidad de Los Lagos
25
+ 129: Universidad de Magallanes
26
+ 132: Universidad de Talca
27
+ 133: Universidad de Tarapacá
28
+ 134: Universidad de Valparaíso
29
+ 135: Universidad del Bío-Bío
30
+ 138: Universidad Tecnológica Metropolitana (UTEM)
31
+ 139: Universidad Academia de Humanismo Cristiano
32
+ 141: Universidad Adventista de Chile
33
+ 142: Universidad Alberto Hurtado (UAH)
34
+ 143: Universidad Autónoma de Chile
35
+ 144: Universidad Bernardo O'Higgins (UBO)
36
+ 147: Universidad Central de Chile
37
+ 146: Universidad Católica Cardenal Silva Henríquez
38
+ 152: Universidad de Las Américas (UDLA)
39
+ 154: Universidad de Viña del Mar
40
+ 149: Universidad de Aconcagua
41
+ 151: Universidad de Artes, Ciencias y Comunicación (UNIACC)
42
+ 156: Universidad del Mar
43
+ 157: Universidad del Pacífico
44
+ 145: Universidad Bolivariana
45
+ 148: Universidad Chileno Británica de Cultura
46
+ 159: Universidad Finis Terrae
47
+ 160: Universidad Gabriela Mistral (UGM)
48
+ 161: Universidad Iberoamericana de Ciencias y Tecnología (UNICIT)
49
+ 162: Universidad Internacional SEK
50
+ 163: Universidad La Araucana
51
+ 164: Universidad La República
52
+ 166: Universidad Mayor
53
+ 167: Universidad Miguel de Cervantes
54
+ 169: Universidad Pedro de Valdivia
55
+ 108: Instituto Profesional Los Leones
56
+ 1: Pontificia Universidad Católica de Chile (PUC)
57
+ 8: Pontificia Universidad Católica de Valparaíso (PUCV)
58
+ 173: Universidad de Ciencias de la Informática (UCINF)
59
+ 126: Universidad de la Frontera (UFRO)
60
+ 130: Universidad de Playa Ancha de Ciencias de la Educación (UPLA)
61
+ 155: Universidad Católica de la Santísima Concepción (UCSC)
62
+ 1627: Escuela de Comercio de Santiago
63
+ 1626: Instituto Tecnológico de Chile (ITC)
64
+ 1628: Instituto de Estudios Bancarios Guillermo Subercaseaux (IEB)
65
+ 1624: Instituto Profesional de Chile
66
+ 1623: AIEP
67
+ 1625: INSEC
68
+ 136: Universidad Metropolitana de Ciencias de la Educación (UMCE)
69
+ 150: Universidad de Arte y Ciencias Sociales (UARCIS)
70
+ 168: Universidad Nacional Andrés Bello (UNAB)
71
+ 1862: Instituto Profesional Los Lagos
72
+ 1868: Manpower
73
+ 2033: Instituto Profesional Virginio Gómez
74
+ 2034: Instituto Profesional Valle Central
75
+ 2035: Universidad Tecnólogica de Chile
76
+ 2037: Instituto Profesional La Araucana
77
+ 2039: CFT San Agustín de Talca
78
+ 2040: CFT Santiago
79
+ 2041: CFT UCEVALPO
80
+ 2042: Instituto Profesional Iplacex
81
+ 2043: CFT Santo Tomás
82
+ 2036: Instituto Profesional Arcos
83
+ 2044: Instituto Profesional Santo Tomás
84
+ 2045: Centro de Formación Técnica del Medio Ambiente (IDMA)
85
+ 2049: Escuela Internacional de Estética Integral Germaine de Capuccini
86
+ 2050: Instituto Profesional EATRI
87
+ 2038: Instituto Chileno Norteamericano
88
+ 2053: Instituto Profesional CIISA
89
+ 2054: Instituto Profesional ICEL
90
+ 2058: Escuela de Imagen y Comunicación Alpes
91
+ 2059: CFT Enac
92
+ 2060: CFT Prodata
93
+ 2061: Instituto Internacional de Artes Culinarias y Servicio - Culinary
94
+ 2064: CFT ProAndes‎
95
+ 2068:  Instituto Benjamín Teplizky 
96
+ 2069: Ceduc UCN
97
+ 2070: CFT Lota Arauco
98
+ 2071: Instituto Profesional CENAFOM
99
+ 2072: CFT Cenco Quillota
100
+ 2073: Escuela de Contadores Auditores de Santiago
101
+ 2074: Instituto Profesional Diego Portales
102
+ 2075: Instituto Superior Alemán de Comercio (INSALCO)
103
+ 2078: Instituto Profesional IPG
104
+ 2081: Instituto Profesional Vertical
105
+ 2091: Universidad Los Leones
106
+ 2092: I.P. LATINOAMERICANO DE COMERCIO EXTERIOR
107
+ 2093: I.P. IACC
108
+ 2094: I.P. CÁMARA DE COMERCIO DE SANTIAGO
109
+ 2095: I.P. DE CIENCIAS Y ARTES INCA-CEA
110
+ 2096: C.F.T. IPROSEC
111
+ 2097: C.F.T. DE TARAPACÁ
112
+ 2098: C.F.T. ANDRÉS BELLO
113
+ 2099: C.F.T. INACAP
114
+ 2100: I.P. CARLOS CASANUEVA
115
+ 2101: C.F.T. JUAN BOHON
116
+ 2102: C.F.T. CÁMARA DE COMERCIO DE SANTIAGO
117
+ 2103: I.P. IPEGE
118
+ 2104: C.F.T. DEL MAULE
119
+ 2105: C.F.T. PROTEC
120
+ 2106: C.F.T. MASSACHUSETTS
121
+ 2107: U. DE PLAYA ANCHA DE CIENCIAS DE LA EDUCACIÓN
@@ -0,0 +1,142 @@
1
+ require 'rails'
2
+ require 'time'
3
+ require 'httparty'
4
+ require 'erb'
5
+
6
+ require 'firstjob_api/university'
7
+ require 'firstjob_api/career'
8
+ require 'firstjob_api/career_status'
9
+ require 'firstjob_api/english_level'
10
+ require 'firstjob_api/excel_level'
11
+ require 'firstjob_api/looking_for'
12
+ require 'firstjob_api/university'
13
+ require 'firstjob_api/publication'
14
+ require 'firstjob_api/http_parser'
15
+
16
+ module FirstjobApi
17
+ include HTTParty
18
+ base_uri 'https://api.firstjob.com'
19
+
20
+ # API login configuration, need initialization setup to work
21
+ mattr_accessor :grant_type
22
+ @@grant_type = "password"
23
+
24
+ mattr_accessor :client_id
25
+ @@client_id = nil
26
+
27
+ mattr_accessor :username
28
+ @@username = nil
29
+
30
+ mattr_accessor :email
31
+ @@email = nil
32
+
33
+ mattr_accessor :password
34
+ @@password = nil
35
+
36
+ mattr_accessor :access_token
37
+ @@access_token = nil
38
+
39
+ @@token_type= nil
40
+
41
+ mattr_accessor :expires_in
42
+ @@expires_in = nil
43
+
44
+ mattr_accessor :access_token_updated_at
45
+ @@access_token_updated_at = nil
46
+
47
+ mattr_accessor :options
48
+ @@options = nil
49
+
50
+ mattr_accessor :body
51
+ @@body = nil
52
+
53
+ mattr_accessor :last_request
54
+ mattr_accessor :last_response
55
+ @@last_request = nil
56
+ @@last_response = nil
57
+
58
+ @@try_counter = 0
59
+
60
+
61
+ # Default way to setup FirstjobApi.
62
+ def self.setup
63
+ yield self
64
+ # It does not use basic http auth, it passes the username and password in the body of the request...
65
+ #@@options = {headers: { "Accept" => "application/json", "Content-Type" => "application/json"}, basic_auth: {username: @@username, password: @@password}}
66
+ @@options = {headers: { "Accept" => "application/json", "Content-Type" => "application/json"}}
67
+ @@body = {username: @@username, password: @@password}
68
+ end
69
+
70
+ # Publicaciones
71
+ # creates and publish a publication
72
+ def self.publish(params)
73
+ publication = FirstjobApi::Publication.create(params)
74
+ return publication
75
+ end
76
+
77
+ def self.update_publication(publication_id, json)
78
+ update_publication_path = "/v0/empresas/avisos/#{publication_id}"
79
+ response = self.post(update_publication_path, @@options.merge(body: json, headers: { "Accept" => "application/json", "Content-Type" => "application/json"}))
80
+
81
+ if HttpParser.parse_response(response)
82
+ case response.code
83
+ when 201
84
+ # "Publication updated, All good!"
85
+ return response # body contains id del proceso publicado
86
+ when 200
87
+ # "TODO: Uhm.. no idea, is this good?"
88
+ return response # body contains id del proceso publicado?
89
+ end
90
+ end
91
+ end
92
+
93
+ def self.publish_publication(publication_id, pais_id, plan_publication_id)
94
+ publish_publication_path = "/v0/empresas/avisos/#{publication_id}/publicacion/#{plan_publication_id}"
95
+ response = self.put(publish_publication_path, @@options.merge(query: @@options[:query].merge({paisId: pais_id})))
96
+
97
+ if HttpParser.parse_response(response)
98
+ case response.code
99
+ when 201
100
+ # "Publication created, All good!"
101
+ return response # body contains id del proceso publicado
102
+ when 200
103
+ # "TODO: Uhm.. no idea, is this good?"
104
+ return response # body contains id del proceso publicado?
105
+ end
106
+ end
107
+ end
108
+
109
+ def self.get_publication_url(publication_id)
110
+ "http://www.laborum.cl/empleos/#{publication_id}.html"
111
+ end
112
+
113
+ def self.get_publication(publication_id)
114
+ get_publication_path = "/v0/empresas/avisos/#{publication_id}"
115
+ response = self.get(get_publication_path, @@options)
116
+
117
+ return HttpParser.parse_response_to_json(response)
118
+ end
119
+
120
+ def self.get_postulations_in_publication(publication_id, page=0, postulations_per_page=20)
121
+ get_postulations_in_publication_path = "/v0/empresas/avisos/#{publication_id}/postulaciones"
122
+ response = self.get(get_postulations_in_publication_path, @@options.merge(query: @@options[:query].merge({page: page, perPage: postulations_per_page})))
123
+
124
+ return HttpParser.parse_response_to_json(response)
125
+ end
126
+
127
+ def self.get_postulation(postulation_id)
128
+ get_postulation_path = "/v0/empresas/postulaciones/#{postulation_id}"
129
+ response = self.get(get_postulation_path, @@options)
130
+
131
+ return HttpParser.parse_response_to_json(response)
132
+ end
133
+
134
+ def self.destroy_publication(publication_id)
135
+ destroy_publication_path = "/v0/empresas/avisos/#{publication_id}"
136
+ response = self.delete(destroy_publication_path, @@options)
137
+
138
+ return HttpParser.parse_response(response)
139
+ end
140
+
141
+ end
142
+
@@ -0,0 +1,15 @@
1
+ module FirstjobApi
2
+ class Career
3
+ CAREERS = YAML.load_file(File.join(File.dirname(__FILE__),"../data/careers.yaml"))["careers"].symbolize_keys!
4
+
5
+ # Poor's man all
6
+ def self.all
7
+ CAREERS
8
+ end
9
+
10
+ # Poor's man find
11
+ def self.find(id)
12
+ CAREERS[id]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module FirstjobApi
2
+ class CareerStatus
3
+ CAREER_STATUSES = YAML.load_file(File.join(File.dirname(__FILE__),"../data/career_statuses.yaml"))["career_statuses"].symbolize_keys!
4
+
5
+ # Poor's man all
6
+ def self.all
7
+ CAREER_STATUSES
8
+ end
9
+
10
+ # Poor's man find
11
+ def self.find(id)
12
+ CAREER_STATUSES[id]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module FirstjobApi
2
+ class EnglishLevel
3
+ ENGLISH_LEVELS = YAML.load_file(File.join(File.dirname(__FILE__),"../data/english_levels.yaml"))["english_levels"].symbolize_keys!
4
+
5
+ # Poor's man all
6
+ def self.all
7
+ ENGLISH_LEVELS
8
+ end
9
+
10
+ # Poor's man find
11
+ def self.find(id)
12
+ ENGLISH_LEVELS[id]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module FirstjobApi
2
+ class ExcelLevel
3
+ EXCEL_LEVELS = YAML.load_file(File.join(File.dirname(__FILE__),"../data/excel_levels.yaml"))["excel_levels"].symbolize_keys!
4
+
5
+ # Poor's man all
6
+ def self.all
7
+ EXCEL_LEVELS
8
+ end
9
+
10
+ # Poor's man find
11
+ def self.find(id)
12
+ EXCEL_LEVELS[id]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,49 @@
1
+ module FirstjobApi
2
+ class HttpParser
3
+ def self.parse_json_to_hash(json, hash)
4
+ json.each{|object| hash[object["id"]] ? hash[object["id"]].merge!(object) : hash[object["id"]] = object}
5
+ return hash
6
+ end
7
+
8
+ def self.parse_response(response)
9
+ FirstjobApi.last_response = response
10
+ FirstjobApi.last_request = response.request
11
+ case response.code
12
+ when 200..201
13
+ # "All good!"
14
+ return response.body
15
+ when 401
16
+ FirstjobApi.invalidate_access_token!
17
+ raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
18
+ when 403
19
+ raise "Error 403: Forbidden"
20
+ when 404
21
+ raise "Error 404 not found"
22
+ when 500...600
23
+ raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}"
24
+ else
25
+ raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}"
26
+ end
27
+ end
28
+ def self.parse_json_response(response)
29
+ FirstjobApi.last_response = response
30
+ FirstjobApi.last_request = response.request
31
+ case response.code
32
+ when 200..201
33
+ # "All good!"
34
+ return JSON.parse(response.body)
35
+ when 401
36
+ FirstjobApi.invalidate_access_token!
37
+ raise "Error 401: Unauthorized. Check login info.\n #{response.body}"
38
+ when 403
39
+ raise "Error 403: Forbidden"
40
+ when 404
41
+ raise "Error 404 not found"
42
+ when 500...600
43
+ raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}"
44
+ else
45
+ raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}"
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ module FirstjobApi
2
+ class LookingFor
3
+ LOOKING_FORS = YAML.load_file(File.join(File.dirname(__FILE__),"../data/looking_fors.yaml"))["looking_fors"].symbolize_keys!
4
+
5
+ # Poor's man all
6
+ def self.all
7
+ LOOKING_FORS
8
+ end
9
+
10
+ # Poor's man find
11
+ def self.find(id)
12
+ LOOKING_FORS[id]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,97 @@
1
+ module FirstjobApi
2
+ class Publication
3
+ attr_accessor :title, :description, :career_status_id,
4
+ :looking_for_id, :location, :years_experience, :salary,
5
+ :english_level_id, :excel_level_id, :careers_ids,
6
+ :universities_ids, :id, :slug, :status, :postulantes
7
+
8
+ def initialize(attributes={})
9
+ # Default values
10
+ @salary = 0
11
+ @location = "Chile"
12
+ @career_status_id = 1
13
+ @years_experience = 0
14
+ @english_level_id = 1
15
+ @excel_level_id = 1
16
+
17
+ attributes.each do |key, value|
18
+ self.send("#{key}=", value)
19
+ end
20
+ end
21
+
22
+ def body
23
+ default_publication_json()
24
+ end
25
+
26
+ def self.create(params)
27
+ publication = new(params)
28
+ response = publication.publish()
29
+ end
30
+
31
+ def publish
32
+ # Post publication
33
+ response = FirstjobApi.post("/api/publish_job",
34
+ FirstjobApi.options.merge(
35
+ body: FirstjobApi.body.merge({publish_job: self.body}).to_json
36
+ )
37
+ )
38
+ response_body = HttpParser.parse_json_response(response)
39
+
40
+ # load results
41
+ @slug = response_body["slug"]
42
+ @id = response_body["id"]
43
+ @status = response_body["status"]
44
+ return self
45
+ end
46
+
47
+ def url
48
+ "#{FirstjobApi.base_uri}/jobs/#{slug}"
49
+ end
50
+
51
+ def postulants
52
+ # Get postulants
53
+ response = FirstjobApi.post("/api/get_applicants_job",
54
+ FirstjobApi.options.merge(
55
+ body: FirstjobApi.body.merge({job_id: @id}).to_json
56
+ )
57
+ )
58
+ response_body = HttpParser.parse_json_response(response)
59
+
60
+ # load results
61
+ @postulantes = response_body["postulantes"]
62
+ return @postulantes
63
+ end
64
+
65
+ def destroy
66
+ response = FirstjobApi.post("/api/doregister_job",
67
+ FirstjobApi.options.merge(
68
+ body: FirstjobApi.body.merge({job_id: id}).to_json
69
+ )
70
+ )
71
+ response_body = HttpParser.parse_response(response)
72
+ end
73
+
74
+ private
75
+ def default_publication_json
76
+ hash = {
77
+ title: title, # required
78
+ description: description, # required, max 300 caracters
79
+ career_status: career_status_id, # required
80
+ looking_for: looking_for_id, # required
81
+ location: location, # required
82
+ years_experience: years_experience, # required, number
83
+ salary: salary, # required, number. Can be 0
84
+ english_level: english_level_id, # required, number
85
+ excel_level: excel_level_id, # required, number
86
+ }
87
+ if careers_ids.present?
88
+ hash[:careers] = careers_ids # optional, array or NOT PRESENT
89
+ end
90
+ if universities_ids.present?
91
+ hash[:universities] = universities_ids # optional, array or NOT PRESENT
92
+ end
93
+ return hash
94
+ end
95
+
96
+ end
97
+ end