Class: TeamdynamixApi
- Inherits:
-
Object
- Object
- TeamdynamixApi
- Includes:
- Singleton
- Defined in:
- app/services/teamdynamix_api.rb
Constant Summary collapse
- API_CONFIG =
SETTINGS[:teamdynamix][:api]
- APP_ID =
API_CONFIG[:appId]
- API_URL =
API_CONFIG[:url]
Instance Method Summary collapse
- #create_asset(host) ⇒ Object
-
#get_asset(asset_id) ⇒ Object
returns TeamDynamix.Api.Assets.Asset.
-
#initialize ⇒ TeamdynamixApi
constructor
A new instance of TeamdynamixApi.
- #retire_asset(host) ⇒ Object
-
#search_asset(search_params) ⇒ Object
Gets a list of assets matching the specified criteria.
- #update_asset(host) ⇒ Object
Constructor Details
#initialize ⇒ TeamdynamixApi
Returns a new instance of TeamdynamixApi.
19 20 21 22 |
# File 'app/services/teamdynamix_api.rb', line 19 def initialize @auth_token = request_token raise('Invalid authentication token') unless valid_auth_token?(@auth_token) end |
Instance Method Details
#create_asset(host) ⇒ Object
34 35 36 37 |
# File 'app/services/teamdynamix_api.rb', line 34 def create_asset(host) uri = URI.parse("#{API_URL}/#{APP_ID}/assets") rest(:post, uri, create_asset_payload(host)) end |
#get_asset(asset_id) ⇒ Object
returns TeamDynamix.Api.Assets.Asset
25 26 27 28 29 30 31 32 |
# File 'app/services/teamdynamix_api.rb', line 25 def get_asset(asset_id) return nil unless asset_id uri = URI.parse("#{API_URL}/#{APP_ID}/assets/#{asset_id}") rest(:get, uri) rescue RuntimeError nil end |
#retire_asset(host) ⇒ Object
44 45 46 47 |
# File 'app/services/teamdynamix_api.rb', line 44 def retire_asset(host) uri = URI.parse("#{API_URL}/#{APP_ID}/assets/#{host.teamdynamix_asset_uid}") rest(:post, uri, retire_asset_payload(host)) end |
#search_asset(search_params) ⇒ Object
Gets a list of assets matching the specified criteria. (IEnumerable(Of TeamDynamix.Api.Assets.Asset))
50 51 52 53 |
# File 'app/services/teamdynamix_api.rb', line 50 def search_asset(search_params) uri = URI.parse("#{API_URL}/#{APP_ID}/assets/search") rest(:post, uri, search_params) end |