module Itjobstack::API
Public Class Methods
returns [Hash] credentials for itjobstack
# File lib/itjobstack/api.rb, line 29 def config; ::Itjobstack.config end
creates a job
@param title [String] title of job @param tags [Array] word tags of job @param teaser [String] teaser of job @param link [String] link of job @param publish [Boolean] publication status of job
# 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
@return [Boolean] true for validity of credentials
# 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
deletes a job
@param id [String] id of job to update @raise [API::Exception] if delete failed
# 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
fetchs all jobs
@return [Array] array with job json objects
# 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
publishes a job
@param id [String] id of job to publish @raise [API::Exception] if publish failed @return [Boolean] true if job published
# 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
uploads file to job
@param id [String] id of job to upload file to @raise [API::Exception] if file path is no file @raise [API::Exception] if file was not updated @return [Boolean] true if file uploaded
# 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
unpublishes a job
@param id [String] id of job to unpublish @raise [API::Exception] if unpublish failed @return [Boolean] true if job unpublished
# 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
removes file of job
@param id [String] id of job to remove file from @raise [API::Exception] if file was not removed @return [Boolean] true if file removed
# 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
updates a job
@param id [String] id of job to update @param title [String] title of job @param tags [Array] word tags of job @param teaser [String] teaser of job @param link [String] link of job @param publish [Boolean] publication status of job @raise [API::Exception] if update failed @return [Boolean] true if job updated
# 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
@return [String] link to itjobstack
# File lib/itjobstack/api.rb, line 25 def url; @@url end
sets link to itjobstack
# File lib/itjobstack/api.rb, line 21 def url= url; @@url = url end
Private Instance Methods
returns [Hash] credentials for itjobstack
# File lib/itjobstack/api.rb, line 29 def config; ::Itjobstack.config end
creates a job
@param title [String] title of job @param tags [Array] word tags of job @param teaser [String] teaser of job @param link [String] link of job @param publish [Boolean] publication status of job
# 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
@return [Boolean] true for validity of credentials
# 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
deletes a job
@param id [String] id of job to update @raise [API::Exception] if delete failed
# 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
fetchs all jobs
@return [Array] array with job json objects
# 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
publishes a job
@param id [String] id of job to publish @raise [API::Exception] if publish failed @return [Boolean] true if job published
# 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
uploads file to job
@param id [String] id of job to upload file to @raise [API::Exception] if file path is no file @raise [API::Exception] if file was not updated @return [Boolean] true if file uploaded
# 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
unpublishes a job
@param id [String] id of job to unpublish @raise [API::Exception] if unpublish failed @return [Boolean] true if job unpublished
# 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
removes file of job
@param id [String] id of job to remove file from @raise [API::Exception] if file was not removed @return [Boolean] true if file removed
# 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
updates a job
@param id [String] id of job to update @param title [String] title of job @param tags [Array] word tags of job @param teaser [String] teaser of job @param link [String] link of job @param publish [Boolean] publication status of job @raise [API::Exception] if update failed @return [Boolean] true if job updated
# 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
@return [String] link to itjobstack
# File lib/itjobstack/api.rb, line 25 def url; @@url end
sets link to itjobstack
# File lib/itjobstack/api.rb, line 21 def url= url; @@url = url end