Module: Itjobstack::API

Defined in:
lib/itjobstack/api.rb

Defined Under Namespace

Classes: Exception

Constant Summary collapse

@@url =

link to itjobstack @@url = ‘www.itjobstack.com

'http://localhost:3000'

Class Method Summary collapse

Class Method Details

.configObject

returns [Hash] credentials for itjobstack



29
# File 'lib/itjobstack/api.rb', line 29

def config; ::Itjobstack.config end

.create_job(title:, tags: [], teaser:, link:, publish: false) ⇒ Object

creates a job

Parameters:

  • title (String)

    title of job

  • tags (Array) (defaults to: [])

    word tags of job

  • teaser (String)

    teaser of job

  • link (String)

    link of job

  • publish (Boolean) (defaults to: false)

    publication status of job



67
68
69
70
71
72
73
74
75
# File 'lib/itjobstack/api.rb', line 67

def create_job title:, tags: [], teaser:, link:, publish: false
  conn = Faraday.new url: url
  answer = conn.post '/api/v1/employer/job/create' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], title: title, tags: tags, teaser: teaser, link: link, publish: publish}
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
  result["packet"]["_id"]
end

.credentials?Boolean

Returns true for validity of credentials.

Returns:

  • (Boolean)

    true for validity of credentials



33
34
35
36
37
38
39
40
41
42
# File 'lib/itjobstack/api.rb', line 33

def credentials?
  conn = Faraday.new url: url
  answer = conn.get '/api/v1/profiles/credentials/' do |req|
    req.params[:email]  = config[:email]
    req.params[:apiKey] = config[:apiKey]
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
			true
end

.delete_job(id:) ⇒ Object

deletes a job

Parameters:

  • id (String)

    id of job to update

Raises:



103
104
105
106
107
108
109
110
111
# File 'lib/itjobstack/api.rb', line 103

def delete_job id: 
  conn = Faraday.new url: url
  answer = conn.delete '/api/v1/employer/job/delete' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], _id: id}
  end.body
  return true if answer.empty?
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
end

.fetch_jobsArray

fetchs all jobs

Returns:

  • (Array)

    array with job json objects



48
49
50
51
52
53
54
55
56
57
# File 'lib/itjobstack/api.rb', line 48

def fetch_jobs 
  conn = Faraday.new url: url
  answer = conn.get '/api/v1/employer/jobs/' do |req|
    req.params[:email]  = config[:email]
    req.params[:apiKey] = config[:apiKey]
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
  JSON.parse result["packet"]["jobs"]
end

.publish_job(id:) ⇒ Boolean

publishes a job

Parameters:

  • id (String)

    id of job to publish

Returns:

  • (Boolean)

    true if job published

Raises:



119
120
121
122
123
124
125
126
127
# File 'lib/itjobstack/api.rb', line 119

def publish_job id: 
  conn = Faraday.new url: url
  answer = conn.post '/api/v1/employer/job/publish' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], _id: id, publish: true}
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
			true
end

.set_job_file(id:, file:) ⇒ Boolean

uploads file to job

Parameters:

  • id (String)

    id of job to upload file to

Returns:

  • (Boolean)

    true if file uploaded

Raises:



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/itjobstack/api.rb', line 152

def set_job_file id:, file:
  raise Exception.new "file don't exist - check file path given" unless File.exists? file
  conn = Faraday.new url: url do |f|
    f.request  :multipart
    f.request  :url_encoded
    f.adapter  :net_http
  end
  answer = conn.put '/api/v1/employer/job/spec/set' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], _id: id, data: Faraday::UploadIO.new(file, 'pdf') }
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
  true
end

.unpublish_job(id:) ⇒ Boolean

unpublishes a job

Parameters:

  • id (String)

    id of job to unpublish

Returns:

  • (Boolean)

    true if job unpublished

Raises:



135
136
137
138
139
140
141
142
143
# File 'lib/itjobstack/api.rb', line 135

def unpublish_job id: 
  conn = Faraday.new url: url
  answer = conn.post '/api/v1/employer/job/publish' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], _id: id, publish: false}
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
			true
end

.unset_job_file(id:) ⇒ Boolean

removes file of job

Parameters:

  • id (String)

    id of job to remove file from

Returns:

  • (Boolean)

    true if file removed

Raises:



173
174
175
176
177
178
179
180
181
# File 'lib/itjobstack/api.rb', line 173

def unset_job_file id:
  conn = Faraday.new url: url
  answer = conn.put '/api/v1/employer/job/spec/unset' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], _id: id }
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
  true
end

.update_job(id:, title:, tags: [], teaser:, link:, publish: false) ⇒ Boolean

updates a job

Parameters:

  • id (String)

    id of job to update

  • title (String)

    title of job

  • tags (Array) (defaults to: [])

    word tags of job

  • teaser (String)

    teaser of job

  • link (String)

    link of job

  • publish (Boolean) (defaults to: false)

    publication status of job

Returns:

  • (Boolean)

    true if job updated

Raises:



88
89
90
91
92
93
94
95
96
# File 'lib/itjobstack/api.rb', line 88

def update_job id:, title:, tags: [], teaser:, link:, publish: false
  conn = Faraday.new url: url
  answer = conn.put '/api/v1/employer/job/update' do |req|
    req.body = {email: config[:email], apiKey: config[:apiKey], _id: id, title: title, tags: tags, teaser: teaser, link: link, publish: publish}
  end.body
  result = JSON.parse answer
  raise Exception.new result["advice"] if result["response"] == 'notOk'
  true
end

.urlString

Returns link to itjobstack.

Returns:

  • (String)

    link to itjobstack



25
# File 'lib/itjobstack/api.rb', line 25

def url; @@url end

.url=(url) ⇒ Object

sets link to itjobstack



21
# File 'lib/itjobstack/api.rb', line 21

def url= url; @@url = url end