Class: OracleHcm::Client
- Inherits:
-
Object
- Object
- OracleHcm::Client
- Defined in:
- lib/oracle_hcm/client.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.resource(method, resource:, url: resource.resource_name) ⇒ Object
Sugar syntax for defining top-level resources.
Instance Method Summary collapse
- #base_url ⇒ Object
-
#connection ⇒ Object
Get an authenticated Faraday connection using given credentials.
-
#document_record(id:) ⇒ Object
Retrieve a single document record resource by DocumentsOfRecordId.
-
#initialize(endpoint, username, password) ⇒ Client
constructor
A new instance of Client.
-
#worker(id:) ⇒ Object
Retrieve a single worker resource by PersonId.
Constructor Details
#initialize(endpoint, username, password) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 |
# File 'lib/oracle_hcm/client.rb', line 11 def initialize(endpoint, username, password) @endpoint = endpoint @username = username @password = password end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/oracle_hcm/client.rb', line 9 def endpoint @endpoint end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
9 10 11 |
# File 'lib/oracle_hcm/client.rb', line 9 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/oracle_hcm/client.rb', line 9 def username @username end |
Class Method Details
.resource(method, resource:, url: resource.resource_name) ⇒ Object
Sugar syntax for defining top-level resources
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/oracle_hcm/client.rb', line 18 def self.resource(method, resource:, url: resource.resource_name) define_method(method) do |offset: 0, limit: 20, q: []| if !q.is_a?(Array) q = [q] end res = connection.get do |req| req.url url req.params["offset"] = offset req.params["limit"] = limit if q.any? req.params["q"] = q.join(";") end end if res.success? ResourceList.new(JSON.parse(res.body), offset, limit, method, resource, self) else nil end end end |
Instance Method Details
#base_url ⇒ Object
54 55 56 |
# File 'lib/oracle_hcm/client.rb', line 54 def base_url "#{endpoint}/hcmRestApi/resources/11.13.18.05" end |
#connection ⇒ Object
Get an authenticated Faraday connection using given credentials.
59 60 61 62 63 |
# File 'lib/oracle_hcm/client.rb', line 59 def connection Faraday.new(url: base_url) do |conn| conn.basic_auth(username, password) end end |
#document_record(id:) ⇒ Object
Retrieve a single document record resource by DocumentsOfRecordId
50 51 52 |
# File 'lib/oracle_hcm/client.rb', line 50 def document_record(id:) document_records(q: "DocumentsOfRecordId=#{id}").items.first end |
#worker(id:) ⇒ Object
Retrieve a single worker resource by PersonId
45 46 47 |
# File 'lib/oracle_hcm/client.rb', line 45 def worker(id:) workers(q: "PersonId=#{id}").items.first end |