Class: ZipRecruiter::JobAlerts::API

Inherits:
API
  • Object
show all
Defined in:
lib/zip_recruiter/job_alerts/api.rb

Class Method Summary collapse

Methods inherited from API

api_key, api_key=

Class Method Details

.perform_action(action, arg) ⇒ Object

Performs the specified API action.

This will perform the specified API action. The action must be one of:

  • subscribe

  • unsubscribe

  • status

The subscribe and unsubscribe actions require an argument that is the path to a CSV file. The status action requires an argument that is the task ID of a previously submitted API request.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zip_recruiter/job_alerts/api.rb', line 20

def self.perform_action(action, arg)
  c = Curl::Easy.new("https://api.ziprecruiter.com/job-alerts/v1/#{action.to_s}")
  c.http_auth_types = :basic
  c.userpwd = "#{api_key}:"

  case action
  when :subscribe, :unsubscribe
    path = File.expand_path(arg.to_s)
    if !File.exists?(path)
      raise "File \"#{path}\" does not exist."
    end

    c.multipart_form_post = true
    c.http_post(Curl::PostField.file('content', path.to_s)) # http_post calls perform

  when :status
    c.url += "/#{arg.to_s}"
    c.perform

  else
    raise "Unknown action \"#{action.to_s}\"."
  end

  c.body_str
end

.status(task_id) ⇒ Object

A Status action returns the current status of a previously-submitted request.



63
64
65
# File 'lib/zip_recruiter/job_alerts/api.rb', line 63

def self.status(task_id)
  ZipRecruiter::JobAlerts::API.perform_action :status, task_id
end

.subscribe(path) ⇒ Object

A Subscribe action is used to upload a collection of job seekers to subscribe to the job alerts program.



49
50
51
# File 'lib/zip_recruiter/job_alerts/api.rb', line 49

def self.subscribe(path)
  ZipRecruiter::JobAlerts::API.perform_action :subscribe, path
end

.unsubscribe(path) ⇒ Object

An Unsubscribe action is used to upload a collection of job seekers to unsubscribe from the job alerts program.



56
57
58
# File 'lib/zip_recruiter/job_alerts/api.rb', line 56

def self.unsubscribe(path)
  ZipRecruiter::JobAlerts::API.perform_action :unsubscribe, path
end