Class: Taleo::Client
- Inherits:
-
Object
- Object
- Taleo::Client
- Defined in:
- lib/taleo/client.rb
Overview
Base object for executing queries and wrapping HTTP requests.
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#org_code ⇒ Object
readonly
Returns the value of attribute org_code.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#service_url ⇒ Object
readonly
Returns the value of attribute service_url.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #activity(id) ⇒ Object
- #api_url ⇒ Object
- #api_url! ⇒ Object
- #candidate(id) ⇒ Object
- #connection ⇒ Object
- #cursor(resource, klass, start = 1, limit = 10, params: {}) ⇒ Object
- #download(url) ⇒ Object
- #employee(id) ⇒ Object
- #employees(start = 1, limit = 10, params: {}) ⇒ Object
-
#initialize(org_code, username, password, service_url) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #logout ⇒ Object
- #packet(id) ⇒ Object
- #show(resource, id) ⇒ Object
Constructor Details
#initialize(org_code, username, password, service_url) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 |
# File 'lib/taleo/client.rb', line 14 def initialize(org_code, username, password, service_url) @org_code = org_code @username = username @password = password @service_url = service_url end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
12 13 14 |
# File 'lib/taleo/client.rb', line 12 def auth_token @auth_token end |
#org_code ⇒ Object (readonly)
Returns the value of attribute org_code.
12 13 14 |
# File 'lib/taleo/client.rb', line 12 def org_code @org_code end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/taleo/client.rb', line 12 def password @password end |
#service_url ⇒ Object (readonly)
Returns the value of attribute service_url.
12 13 14 |
# File 'lib/taleo/client.rb', line 12 def service_url @service_url end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/taleo/client.rb', line 12 def username @username end |
Instance Method Details
#activity(id) ⇒ Object
33 34 35 |
# File 'lib/taleo/client.rb', line 33 def activity(id) Activity.new(show('activity', id), self) end |
#api_url ⇒ Object
92 93 94 95 96 |
# File 'lib/taleo/client.rb', line 92 def api_url return @api_url if !@api_url.nil? api_url! end |
#api_url! ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/taleo/client.rb', line 117 def api_url! conn = Faraday.new(url: "#{service_url}/#{org_code}") do |c| c.use Faraday::Response::RaiseError end res = conn.get data = JSON.parse(res.body) @api_url = data.dig('response', 'URL') @api_url end |
#candidate(id) ⇒ Object
29 30 31 |
# File 'lib/taleo/client.rb', line 29 def candidate(id) Candidate.new(show('candidate', id), self) end |
#connection ⇒ Object
98 99 100 101 102 103 |
# File 'lib/taleo/client.rb', line 98 def connection Faraday.new(url: api_url) do |conn| conn.use Faraday::Response::RaiseError conn.headers['Cookie'] = "authToken=#{auth_token}" end end |
#cursor(resource, klass, start = 1, limit = 10, params: {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/taleo/client.rb', line 43 def cursor(resource, klass, start = 1, limit = 10, params: {}) res = connection.get do |req| req.url "object/#{resource}/search" req.params.merge!(params).merge!({ 'start' => start, 'limit' => limit }) end data = JSON.parse(res.body) pagination = data.dig('response', 'pagination') results = data.dig('response', 'searchResults') cursor = Cursor.new(pagination, results, resource, klass, self) cursor.self_page end |
#download(url) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/taleo/client.rb', line 105 def download(url) io = StringIO.new connection.get do |req| req.url url req..on_data = Proc.new do |chunk| io << chunk end end io.rewind io end |
#employee(id) ⇒ Object
21 22 23 |
# File 'lib/taleo/client.rb', line 21 def employee(id) Employee.new(show('employee', id), self) end |
#employees(start = 1, limit = 10, params: {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/taleo/client.rb', line 37 def employees(start = 1, limit = 10, params: {}) raise ArgumentError, "At least one query parameter is required " \ "for employee search" if params.keys.size.zero? cursor('employee', Employee, start, limit, params: params) end |
#login ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/taleo/client.rb', line 66 def login params = { orgCode: org_code, userName: username, password: password } conn = Faraday.new(url: api_url) do |c| c.use Faraday::Response::RaiseError end res = conn.post do |req| req.url 'login' req.params.merge!(params) end data = JSON.parse(res.body) @auth_token = data.dig('response', 'authToken') end |
#logout ⇒ Object
86 87 88 89 90 |
# File 'lib/taleo/client.rb', line 86 def logout connection.post do |req| req.url 'logout' end end |
#packet(id) ⇒ Object
25 26 27 |
# File 'lib/taleo/client.rb', line 25 def packet(id) Packet.new(show('packet', id), self) end |
#show(resource, id) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/taleo/client.rb', line 58 def show(resource, id) res = connection.get do |req| req.url "object/#{resource}/#{id}" end data = JSON.parse(res.body) data.dig('response', resource) end |