Module: Firstjob

Includes:
HTTParty
Defined in:
lib/firstjob.rb,
lib/firstjob/career.rb,
lib/firstjob/version.rb,
lib/firstjob/university.rb,
lib/firstjob/excel_level.rb,
lib/firstjob/http_parser.rb,
lib/firstjob/looking_for.rb,
lib/firstjob/publication.rb,
lib/firstjob/career_status.rb,
lib/firstjob/english_level.rb

Defined Under Namespace

Classes: Career, CareerStatus, EnglishLevel, ExcelLevel, HttpParser, LookingFor, Publication, University

Constant Summary collapse

VERSION =
"1.0.4"
@@grant_type =
"password"
@@client_id =
nil
@@username =
nil
@@email =
nil
@@password =
nil
@@access_token =
nil
@@token_type =
nil
@@expires_in =
nil
@@access_token_updated_at =
nil
@@options =
nil
@@body =
nil
@@last_request =
nil
@@last_response =
nil
@@try_counter =
0

Class Method Summary collapse

Class Method Details

.destroy_publication(publication_id) ⇒ Object



134
135
136
137
138
139
# File 'lib/firstjob.rb', line 134

def self.destroy_publication(publication_id)
  destroy_publication_path = "/v0/empresas/avisos/#{publication_id}"
  response = self.delete(destroy_publication_path, @@options)

  return HttpParser.parse_response(response)
end

.get_postulation(postulation_id) ⇒ Object



127
128
129
130
131
132
# File 'lib/firstjob.rb', line 127

def self.get_postulation(postulation_id)
  get_postulation_path = "/v0/empresas/postulaciones/#{postulation_id}"
  response = self.get(get_postulation_path, @@options)

  return HttpParser.parse_response_to_json(response)
end

.get_postulations_in_publication(publication_id, page = 0, postulations_per_page = 20) ⇒ Object



120
121
122
123
124
125
# File 'lib/firstjob.rb', line 120

def self.get_postulations_in_publication(publication_id, page=0, postulations_per_page=20)
  get_postulations_in_publication_path = "/v0/empresas/avisos/#{publication_id}/postulaciones"
  response = self.get(get_postulations_in_publication_path, @@options.merge(query: @@options[:query].merge({page: page, perPage: postulations_per_page})))

  return HttpParser.parse_response_to_json(response)
end

.get_publication(publication_id) ⇒ Object



113
114
115
116
117
118
# File 'lib/firstjob.rb', line 113

def self.get_publication(publication_id)
  get_publication_path = "/v0/empresas/avisos/#{publication_id}"
  response = self.get(get_publication_path, @@options)

  return HttpParser.parse_response_to_json(response)
end

.get_publication_url(publication_id) ⇒ Object



109
110
111
# File 'lib/firstjob.rb', line 109

def self.get_publication_url(publication_id)
  "http://www.laborum.cl/empleos/#{publication_id}.html"
end

.publish(params) ⇒ Object

Publicaciones creates and publish a publication



72
73
74
75
# File 'lib/firstjob.rb', line 72

def self.publish(params)
  publication = Firstjob::Publication.create(params)
  return publication
end

.publish_publication(publication_id, pais_id, plan_publication_id) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/firstjob.rb', line 93

def self.publish_publication(publication_id, pais_id, plan_publication_id)
  publish_publication_path = "/v0/empresas/avisos/#{publication_id}/publicacion/#{plan_publication_id}"
  response = self.put(publish_publication_path, @@options.merge(query: @@options[:query].merge({paisId: pais_id})))

  if HttpParser.parse_response(response)
    case response.code
      when 201
        # "Publication created, All good!"
        return response # body contains id del proceso publicado
      when 200
        # "TODO: Uhm.. no idea, is this good?"
        return response # body contains id del proceso publicado?
    end
  end
end

.setup {|_self| ... } ⇒ Object

Default way to setup Firstjob.

Yields:

  • (_self)

Yield Parameters:

  • _self (Firstjob)

    the object that the method was called on



62
63
64
65
66
67
68
# File 'lib/firstjob.rb', line 62

def self.setup
  yield self
  # It does not use basic http auth, it passes the username and password in the body of the request...
  #@@options = {headers: { "Accept" => "application/json", "Content-Type" => "application/json"}, basic_auth: {username: @@username, password: @@password}}
  @@options = {headers: { "Accept" => "application/json", "Content-Type" => "application/json"}}
  @@body = {username: @@username, password: @@password}
end

.update_publication(publication_id, json) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/firstjob.rb', line 77

def self.update_publication(publication_id, json)
  update_publication_path = "/v0/empresas/avisos/#{publication_id}"
  response = self.post(update_publication_path, @@options.merge(body: json, headers: { "Accept" => "application/json", "Content-Type" => "application/json"}))

  if HttpParser.parse_response(response)
    case response.code
      when 201
        # "Publication updated, All good!"
        return response # body contains id del proceso publicado
      when 200
        # "TODO: Uhm.. no idea, is this good?"
        return response # body contains id del proceso publicado?
    end
  end
end