Class: Resumator::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/resumator-client/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Client

Sets up a client

Parameters:

  • API (String)

    key



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/resumator-client/client.rb', line 10

def initialize(key)
  raise "Missing API key" unless key and not key.empty?
  @api_key = key
  @connection = Faraday.new(url: "https://api.resumatorapi.com/v1/") do |faraday|
    faraday.request  :url_encoded             # form-encode POST params
    faraday.response :logger if ENV['DEBUG']
    faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
    faraday.request :retry, 2
    faraday.options[:timeout] = 2           # open/read timeout in seconds
    faraday.options[:open_timeout] = 2      # connection open timeout in seconds
  end
  @connection.params['apikey'] = @api_key
end

Instance Method Details

#activities(options = {}) ⇒ Object



61
62
63
# File 'lib/resumator-client/client.rb', line 61

def activities(options = {})
  get("activities", options)
end

#applicants(options = {}) ⇒ Object



53
54
55
# File 'lib/resumator-client/client.rb', line 53

def applicants(options = {})
  get("applicants", options)
end

#contents(options = {}) ⇒ Object



65
66
67
# File 'lib/resumator-client/client.rb', line 65

def contents(options = {})
  get("contents", options)
end

#get(object, options = {}) ⇒ Mash

Get any rest accessible object

Parameters:

  • object (String)

    name

  • optional (Hash)

    search parameters

Returns:

  • (Mash)

    your data



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/resumator-client/client.rb', line 29

def get(object, options = {})
  if options[:all_pages]
    options.delete(:all_pages)
    options[:page] = 1
    out = []
    begin
      data = get(object, options)
      out = out | data
      options[:page] += 1
    end while data.count >= 100
    return out
  else
    if options[:id]
      resp = @connection.get "#{object}/#{options[:id]}"
    elsif options.size > 0
      resp = @connection.get "#{object}#{Client.parse_options(options)}"
    else
      resp = @connection.get object
    end
    raise "Bad response: #{resp.status}" unless resp.status == 200
    Client.mash(JSON.parse(resp.body))
  end
end

#jobs(options = {}) ⇒ Object



57
58
59
# File 'lib/resumator-client/client.rb', line 57

def jobs(options = {})
  get("jobs", options)
end

#tasks(options = {}) ⇒ Object



73
74
75
# File 'lib/resumator-client/client.rb', line 73

def tasks(options = {})
  get("tasks", options)
end

#users(options = {}) ⇒ Object



69
70
71
# File 'lib/resumator-client/client.rb', line 69

def users(options = {})
  get("users", options)
end