Class: Resumator::Client
- Inherits:
-
Object
- Object
- Resumator::Client
- Defined in:
- lib/resumator-client/client.rb
Instance Method Summary collapse
- #activities(options = {}) ⇒ Object
- #applicants(options = {}) ⇒ Object
- #contents(options = {}) ⇒ Object
-
#get(object, options = {}) ⇒ Mash
Get any rest accessible object.
-
#initialize(key) ⇒ Client
constructor
Sets up a client.
- #jobs(options = {}) ⇒ Object
- #tasks(options = {}) ⇒ Object
- #users(options = {}) ⇒ Object
Constructor Details
#initialize(key) ⇒ Client
Sets up a client
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.[:timeout] = 2 # open/read timeout in seconds faraday.[: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( = {}) get("activities", ) end |
#applicants(options = {}) ⇒ Object
53 54 55 |
# File 'lib/resumator-client/client.rb', line 53 def applicants( = {}) get("applicants", ) end |
#contents(options = {}) ⇒ Object
65 66 67 |
# File 'lib/resumator-client/client.rb', line 65 def contents( = {}) get("contents", ) end |
#get(object, options = {}) ⇒ Mash
Get any rest accessible object
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, = {}) if [:all_pages] .delete(:all_pages) [:page] = 1 out = [] begin data = get(object, ) out = out | data [:page] += 1 end while data.count >= 100 return out else if [:id] resp = @connection.get "#{object}/#{[:id]}" elsif .size > 0 resp = @connection.get "#{object}#{Client.()}" 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( = {}) get("jobs", ) end |
#tasks(options = {}) ⇒ Object
73 74 75 |
# File 'lib/resumator-client/client.rb', line 73 def tasks( = {}) get("tasks", ) end |
#users(options = {}) ⇒ Object
69 70 71 |
# File 'lib/resumator-client/client.rb', line 69 def users( = {}) get("users", ) end |