Class: CampaignMaster::Client
- Inherits:
-
Object
- Object
- CampaignMaster::Client
- Defined in:
- lib/campaign_master/client.rb
Constant Summary collapse
- AuthenticationError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #call(class_name) ⇒ Object
- #get_security_token ⇒ Object
-
#initialize(username, password, id) ⇒ Client
constructor
A new instance of Client.
- #token_expired ⇒ Object
Constructor Details
#initialize(username, password, id) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 |
# File 'lib/campaign_master/client.rb', line 7 def initialize(username, password, id) @login_expiration_seconds = -1 @security_token = false self.username = username self.password = password self.id = id end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/campaign_master/client.rb', line 5 def id @id end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/campaign_master/client.rb', line 5 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/campaign_master/client.rb', line 5 def username @username end |
Instance Method Details
#call(class_name) ⇒ Object
37 38 39 |
# File 'lib/campaign_master/client.rb', line 37 def call(class_name) CampaignMaster.const_get(class_name).new(self) end |
#get_security_token ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/campaign_master/client.rb', line 16 def get_security_token if self.token_expired soap_client = CampaignMaster::SoapClient.get_client() response = soap_client.call(:login, message: { clientID: self.id, userName: self.username, password: self.password }, :attributes => CampaignMaster::SoapClient.attributes ) raise AuthenticationError if !self.valid_response?(response) @login_expiration_seconds = Time.now.to_i + response.body[:login_response][:login_result][:minutes_till_token_expires].to_i * 60 @security_token = response.body[:login_response][:login_result][:token_string] end @security_token end |
#token_expired ⇒ Object
33 34 35 |
# File 'lib/campaign_master/client.rb', line 33 def token_expired @login_expiration_seconds < Time.now.to_i end |