Class: Imis::Api
- Inherits:
-
Object
- Object
- Imis::Api
- Defined in:
- lib/imis/api.rb
Constant Summary collapse
- AUTHENTICATION_PATH =
'Token'- API_PATH =
'api'- QUERY_PATH =
'api/Query'
Instance Attribute Summary collapse
-
#imis_id ⇒ Object
Returns the value of attribute imis_id.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_expiration ⇒ Object
readonly
Returns the value of attribute token_expiration.
Instance Method Summary collapse
-
#get(business_object_name) ⇒ Object
Get a business object for the current member.
-
#imis_id_for(certificate) ⇒ Object
Convert a member’s certificate number into an iMIS ID number.
-
#initialize(skip_authentication: false) ⇒ Api
constructor
A new instance of Api.
- #mapper ⇒ Object
-
#put(business_object_name, fields) ⇒ Object
Update only specific fields on a business object for the current member.
-
#query(query_name, query_params = {}) ⇒ Object
Run an IQA Query.
Constructor Details
#initialize(skip_authentication: false) ⇒ Api
Returns a new instance of Api.
11 12 13 |
# File 'lib/imis/api.rb', line 11 def initialize(skip_authentication: false) authenticate unless skip_authentication end |
Instance Attribute Details
#imis_id ⇒ Object
Returns the value of attribute imis_id.
9 10 11 |
# File 'lib/imis/api.rb', line 9 def imis_id @imis_id end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/imis/api.rb', line 9 def token @token end |
#token_expiration ⇒ Object (readonly)
Returns the value of attribute token_expiration.
9 10 11 |
# File 'lib/imis/api.rb', line 9 def token_expiration @token_expiration end |
Instance Method Details
#get(business_object_name) ⇒ Object
Get a business object for the current member
30 31 32 33 34 35 |
# File 'lib/imis/api.rb', line 30 def get(business_object_name) uri = uri_for(business_object_name) request = Net::HTTP::Get.new(uri) result = submit(uri, (request)) JSON.parse(result.body) end |
#imis_id_for(certificate) ⇒ Object
Convert a member’s certificate number into an iMIS ID number
23 24 25 26 |
# File 'lib/imis/api.rb', line 23 def imis_id_for(certificate) result = query(Imis.configuration.imis_id_query_name, { certificate: certificate }) @imis_id = result['Items']['$values'][0]['ID'] end |
#mapper ⇒ Object
64 65 66 |
# File 'lib/imis/api.rb', line 64 def mapper @mapper ||= Mapper.new(self) end |
#put(business_object_name, fields) ⇒ Object
Update only specific fields on a business object for the current member
fields - hash of shape: { field_name => new_value }
41 42 43 44 45 46 47 48 |
# File 'lib/imis/api.rb', line 41 def put(business_object_name, fields) uri = uri_for(business_object_name) request = Net::HTTP::Put.new(uri) updated = filter_fields(business_object_name, fields) request.body = JSON.dump(updated) result = submit(uri, (request)) JSON.parse(result.body) end |
#query(query_name, query_params = {}) ⇒ Object
Run an IQA Query
query_name - the full path of the query in IQA, e.g. `$/_ABC/Fiander/iMIS_ID`
query_params - hash of shape: { param_name => param_value }
55 56 57 58 59 60 61 62 |
# File 'lib/imis/api.rb', line 55 def query(query_name, query_params = {}) query_params[:QueryName] = query_name path = "#{QUERY_PATH}?#{query_params.to_query}" uri = URI(File.join(imis_hostname, path)) request = Net::HTTP::Get.new(uri) result = submit(uri, (request)) JSON.parse(result.body) end |