Class: ExtensisPortfolio::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/extensis_portfolio/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, username, password, options = {}) ⇒ Connection

Creates a new instance of ExtensisPortfolio::Connection

Parameters:

  • server (String)
  • username (String)
  • password (String)


27
28
29
30
31
32
33
34
# File 'lib/extensis_portfolio/connection.rb', line 27

def initialize(server, username, password, options = {})
  @username = username
  @password = password
  savon_options = options.merge(wsdl: "#{server}/ws/1.0/AssetService?wsdl")
  @soap_client = Savon.client(savon_options)
  @http_client = Faraday.new(url: server)
  @session_id = get_session_id
end

Instance Attribute Details

#http_clientFaraday::Connection (readonly)

Returns a Faraday::Connection object for making http requests to the Extensis Portfolio API

Returns:

  • (Faraday::Connection)


14
15
16
# File 'lib/extensis_portfolio/connection.rb', line 14

def http_client
  @http_client
end

#session_idString (readonly)

Returns the session_id used to make calls to the Extensis Portfolio API

Returns:

  • (String)


8
9
10
# File 'lib/extensis_portfolio/connection.rb', line 8

def session_id
  @session_id
end

#soap_clientSavon::Client (readonly)

Returns a Savon::Client for making calls soap requests to the Extensis Portfolio API

Returns:

  • (Savon::Client)


20
21
22
# File 'lib/extensis_portfolio/connection.rb', line 20

def soap_client
  @soap_client
end

Instance Method Details

#get_asset_by_id(catalog_id, asset_id, result_options = {}) ⇒ Hash

Returns the asset that has the provided id

Parameters:

  • catalog_id (String)
  • asset_id (String)
  • result_options (Hash) (defaults to: {})

    optional hash with options how to display the results

Returns:

  • (Hash)


81
82
83
84
85
86
# File 'lib/extensis_portfolio/connection.rb', line 81

def get_asset_by_id(catalog_id, asset_id, result_options = {})
  query_term = ExtensisPortfolio::AssetQueryTerm.new('asset_id', 'equalValue', asset_id)
  query = ExtensisPortfolio::AssetQuery.new(query_term.to_hash)

  get_assets(catalog_id, query, result_options)
end

#get_assets(catalog_id, query, result_options = {}) ⇒ Array

Returns a list of assets based on a query TODO: Simple method to get asset by id

Parameters:

  • catalog_id (String)
  • query (AssetQuery)
  • result_options (Hash) (defaults to: {})

    optional hash with options how to display the results

Returns:

  • (Array)


69
70
71
72
73
# File 'lib/extensis_portfolio/connection.rb', line 69

def get_assets(catalog_id, query, result_options = {})
  message = { session_id: @session_id, catalog_id: catalog_id, assets: query.to_hash, result_options: result_options }

  @soap_client.call(:get_assets, message: message).body[:get_assets_response][:return][:assets]
end

#get_catalogsArray

Returns a list of catalogs

Returns:

  • (Array)


91
92
93
94
95
# File 'lib/extensis_portfolio/connection.rb', line 91

def get_catalogs
  message = { session_id: @session_id }

  @soap_client.call(:get_catalogs, message: message).body[:get_catalogs_response][:return]
end

#get_error_details_for_job(job_id) ⇒ Hash

Get the error details of a job

Parameters:

  • job_id (String)

    job id

Returns:

  • (Hash)


120
121
122
123
# File 'lib/extensis_portfolio/connection.rb', line 120

def get_error_details_for_job(job_id)
  message = { session_id: @session_id, job_id: job_id }
  @soap_client.call(:get_error_details_for_job, message: message).body[:get_error_details_for_job_response][:return]
end

#get_job_idsArray

Returns a list of job ids

Returns:

  • (Array)


100
101
102
103
104
# File 'lib/extensis_portfolio/connection.rb', line 100

def get_job_ids
  message = { session_id: @session_id }

  @soap_client.call(:get_job_i_ds, message: message).body[:get_job_i_ds_response][:return]
end

#get_soap_operationsArray

Returns a list of available soap operations

Returns:

  • (Array)


58
59
60
# File 'lib/extensis_portfolio/connection.rb', line 58

def get_soap_operations
  @soap_client.operations
end

#get_status_for_jobs(job_ids) ⇒ Array

Get the status of jobs

Parameters:

  • job_ids (Array)

    array of job ids

Returns:

  • (Array)


110
111
112
113
114
# File 'lib/extensis_portfolio/connection.rb', line 110

def get_status_for_jobs(job_ids)
  message = { session_id: @session_id, job_ids: job_ids }

  @soap_client.call(:get_status_for_jobs, message: message).body[:get_status_for_jobs_response][:return]
end

#login(_username, _password) ⇒ Savon::Response

Logs in the soap client

Parameters:

  • username (String)
  • password (String)

Returns:

  • (Savon::Response)


41
42
43
44
45
# File 'lib/extensis_portfolio/connection.rb', line 41

def (_username, _password)
  message = { user_name: @username, encrypted_password: get_encrypted_password }

  @soap_client.call(:login, message: message)
end

#logoutObject

Logs out the soap client, making the session id invalid



49
50
51
52
53
# File 'lib/extensis_portfolio/connection.rb', line 49

def logout
  message = { session_id: @session_id }

  @soap_client.call(:logout, message: message)
end