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
-
.config ⇒ Object
returns [Hash] credentials for itjobstack.
-
.create_job(title:, tags: [], teaser:, link:, publish: false) ⇒ Object
creates a job.
-
.credentials? ⇒ Boolean
True for validity of credentials.
-
.delete_job(id:) ⇒ Object
deletes a job.
-
.fetch_jobs ⇒ Array
fetchs all jobs.
-
.publish_job(id:) ⇒ Boolean
publishes a job.
-
.set_job_file(id:, file:) ⇒ Boolean
uploads file to job.
-
.unpublish_job(id:) ⇒ Boolean
unpublishes a job.
-
.unset_job_file(id:) ⇒ Boolean
removes file of job.
-
.update_job(id:, title:, tags: [], teaser:, link:, publish: false) ⇒ Boolean
updates a job.
-
.url ⇒ String
Link to itjobstack.
-
.url=(url) ⇒ Object
sets link to itjobstack.
Class Method Details
.config ⇒ Object
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
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: , 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.
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
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_jobs ⇒ Array
fetchs all jobs
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
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
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
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
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
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: , teaser: , link: link, publish: publish} end.body result = JSON.parse answer raise Exception.new result["advice"] if result["response"] == 'notOk' true end |
.url ⇒ String
Returns 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 |