Class: TeamdynamixApi

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeTeamdynamixApi

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

#update_asset(host) ⇒ Object



39
40
41
42
# File 'app/services/teamdynamix_api.rb', line 39

def update_asset(host)
  uri = URI.parse("#{API_URL}/#{APP_ID}/assets/#{host.teamdynamix_asset_uid}")
  rest(:post, uri, update_asset_payload(host))
end