Class: Sorenson::ThreeSixty::Account

Inherits:
Base
  • Object
show all
Defined in:
lib/sorenson/threesixty/account.rb

Constant Summary

Constants inherited from Base

Base::TOKEN_SALT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

debug=, debug?, host, #post_to, post_to, protocol, token_for, use_ssl=, use_ssl?

Constructor Details

#initialize(data, sessionId = nil) ⇒ Account

Instance Methods



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sorenson/threesixty/account.rb', line 80

def initialize(data, sessionId = nil)
  self.sessionId                = data['sessionId'] || sessionId
  self.token                    = data['token']
  self.subaccountId             = data['subaccountId']
  self.goto360URL               = data['gotoJuiceURL']

  # depricated
  self.gotoJuiceURL             = data['gotoJuiceURL']

  # account specific data
                         = data['account']
  if 
    self.username               = ['username']
    self.status                 = ['status']
    self.customerId             = ['id']
    self.id                     = ['id']
    self.ratePlanExpirationDate = ['ratePlanExpirationDate']
    self.dateLastModified       = ['dateLastModified']
    self.sorensonId             = ['sorensonId']
    self.lastLoginTime          = ['lastLoginTime']
    self.dateRetrieved          = ['dateRetrieved']
    self.totalAssetCount        = getAssetCount

    self.ratePlan              = RatePlan.new(['ratePlan']) if ['ratePlan']
  end
end

Instance Attribute Details

#customerIdObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def customerId
  @customerId
end

#dateLastModifiedObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def dateLastModified
  @dateLastModified
end

#dateRetrievedObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def dateRetrieved
  @dateRetrieved
end

#goto360URLObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def goto360URL
  @goto360URL
end

#gotoJuiceURLObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def gotoJuiceURL
  @gotoJuiceURL
end

#idObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def id
  @id
end

#lastLoginTimeObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def lastLoginTime
  @lastLoginTime
end

#ratePlanObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def ratePlan
  @ratePlan
end

#ratePlanExpirationDateObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def ratePlanExpirationDate
  @ratePlanExpirationDate
end

#sessionIdObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def sessionId
  @sessionId
end

#sorensonIdObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def sorensonId
  @sorensonId
end

#statusObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def status
  @status
end

#subaccountIdObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def subaccountId
  @subaccountId
end

#tokenObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def token
  @token
end

#totalAssetCountObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def totalAssetCount
  @totalAssetCount
end

#usernameObject

Attributes



6
7
8
# File 'lib/sorenson/threesixty/account.rb', line 6

def username
  @username
end

Class Method Details

._login(url) ⇒ Object

Class Methods



10
11
12
# File 'lib/sorenson/threesixty/account.rb', line 10

def self.(url)
  new(post_to(url))
end

.activate!(username) ⇒ Object



41
42
43
# File 'lib/sorenson/threesixty/account.rb', line 41

def self.activate!(username)
  activateAccount(username)
end

.activateAccount(username) ⇒ Object



36
37
38
39
# File 'lib/sorenson/threesixty/account.rb', line 36

def self.activateAccount(username)
  data = post_to("/api/activateAccount?username=#{username}&vToken=#{token_for(username)}")
  !!data['success']
end

.allAccountsObject



73
74
75
# File 'lib/sorenson/threesixty/account.rb', line 73

def self.allAccounts
  data = post_to("/api/getAllAccounts")
end

.createAccount(username, password, ratePlanId, activate = false) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sorenson/threesixty/account.rb', line 54

def self.createAccount(username, password, ratePlanId, activate = false)
  data = post_to("/api/createAccount?vToken=#{token_for(username)}&username=#{username}&password=#{password}&ratePlanId=#{ratePlanId}")
  result = !!data['success']
  
  if (result)
    updatePasswordHack(username, password)
  end
  
  if (result && activate && activate!(username))
    result = (username, password)
  end
  result
end

.deactivate!(username) ⇒ Object



45
46
47
# File 'lib/sorenson/threesixty/account.rb', line 45

def self.deactivate!(username)
  deactivateAccount(username)
end

.deactivateAccount(username) ⇒ Object



49
50
51
52
# File 'lib/sorenson/threesixty/account.rb', line 49

def self.deactivateAccount(username)
  data = post_to("/api/deactivateAccount?username=#{username}&vToken=#{token_for(username)}")
  !!data['success']
end

.doesAccountExist(username) ⇒ Object



26
27
28
29
# File 'lib/sorenson/threesixty/account.rb', line 26

def self.doesAccountExist(username)
  data = post_to("/api/doesAccountExist?username=#{username}")
  !!data['accountExists']
end

.exists?(username) ⇒ Boolean

Alias for doesAccountExist

Returns:

  • (Boolean)


32
33
34
# File 'lib/sorenson/threesixty/account.rb', line 32

def self.exists?(username)
  doesAccountExist(username)
end

.find(accountId, sessionId) ⇒ Object



18
19
20
# File 'lib/sorenson/threesixty/account.rb', line 18

def self.find(accountId, sessionId)
  new(post_to("/api/getAccount?accountId=#{accountId}&sessionId=#{sessionId}"), sessionId)
end

.login(username, password) ⇒ Object



14
15
16
# File 'lib/sorenson/threesixty/account.rb', line 14

def self.(username, password)
  ("/api/loginApi?username=#{CGI.escape(username.to_s)}&password=#{CGI.escape(password.to_s)}")
end

.loginWithAccountId(accountId, sessionId) ⇒ Object



22
23
24
# File 'lib/sorenson/threesixty/account.rb', line 22

def self.loginWithAccountId(accountId, sessionId)
  ("/api/loginApi?accountId=#{accountId}&sessionId=#{sessionId}")
end

.updatePasswordHack(username, password) ⇒ Object



68
69
70
71
# File 'lib/sorenson/threesixty/account.rb', line 68

def self.updatePasswordHack(username, password)
  data = post_to("/api/updatePassword?username=#{username}&password=#{password}&sessionId=blah")
  !!data['success']
end

Instance Method Details

#createSubaccount(username, email, password) ⇒ Object



167
168
169
170
# File 'lib/sorenson/threesixty/account.rb', line 167

def createSubaccount(username, email, password)
  data = post_to("/api/createSubaccount?accountId=#{id}&sessionId=#{sessionId}&username=#{username}&email=#{email}&password=#{password}")
  data['success'] == 1
end

#emptyTrashObject



162
163
164
165
# File 'lib/sorenson/threesixty/account.rb', line 162

def emptyTrash
  data = post_to("/api/emptyTrash?accountId=#{id}&sessionId=#{sessionId}")
  data
end

#getAccountMetricsObject



153
154
155
156
# File 'lib/sorenson/threesixty/account.rb', line 153

def getAccountMetrics
  data = post_to("/api/getAccountMetrics?accountId=#{id}&sessionId=#{sessionId}")
  data['accountMetricsList']
end

#getAsset(id) ⇒ Object



114
115
116
# File 'lib/sorenson/threesixty/account.rb', line 114

def getAsset(id)
  Asset.find(self, id)
end

#getAssetCountObject



118
119
120
121
# File 'lib/sorenson/threesixty/account.rb', line 118

def getAssetCount
  data = post_to("/api/getMediaListSummary?accountId=#{id}&sessionId=#{sessionId}")
  data['totalMediaCount']
end

#getAssetMetrics(startDate, endDate) ⇒ Object



158
159
160
# File 'lib/sorenson/threesixty/account.rb', line 158

def getAssetMetrics(startDate, endDate)
  AssetMetrics.find(self, startDate, endDate)
end

#getAssets(offset = nil, quantity = nil) ⇒ Object



107
108
109
110
111
112
# File 'lib/sorenson/threesixty/account.rb', line 107

def getAssets(offset = nil, quantity = nil)
  assets = Asset.find_all(self, offset, quantity)
  return assets if self.subaccountId.blank?

  assets.select {|a| a.subaccountId == self.subaccountId}
end

#getOverageActionObject



138
139
140
141
# File 'lib/sorenson/threesixty/account.rb', line 138

def getOverageAction
  data = post_to("/api/getOverageAction?accountId=#{id}&sessionId=#{sessionId}")
  data['overageAction']
end

#getStorageUsed(startDate, endDate) ⇒ Object



133
134
135
136
# File 'lib/sorenson/threesixty/account.rb', line 133

def getStorageUsed(startDate, endDate)
  data = post_to("/api/getStorageUsed?accountId=#{id}&startDate=#{startDate}&endDate=#{endDate}&sessionId=#{sessionId}")
  data['storageUsed']
end

#getSubaccountsObject



172
173
174
175
176
177
178
179
# File 'lib/sorenson/threesixty/account.rb', line 172

def getSubaccounts
  data = post_to("/api/getAllSubaccounts?accountId=#{id}&sessionId=#{sessionId}")
  subaccounts = []
  data['subaccounts'].each do |data|
    subaccounts << Sorenson::ThreeSixty::Subaccount.new(self, data)
  end
  subaccounts
end

#getTotalPlaysObject



128
129
130
131
# File 'lib/sorenson/threesixty/account.rb', line 128

def getTotalPlays
  data = post_to("/api/getTotalPlays?accountId=#{id}&sessionId=#{sessionId}")
  data['totalPlays']
end

#getTotalStorageUsedObject



123
124
125
126
# File 'lib/sorenson/threesixty/account.rb', line 123

def getTotalStorageUsed
  data = post_to("/api/getTotalStorageUsed?accountId=#{id}&sessionId=#{sessionId}")
  data['storageUsed']
end

#updatePassword(password) ⇒ Object



143
144
145
146
# File 'lib/sorenson/threesixty/account.rb', line 143

def updatePassword(password)
  data = post_to("/api/updatePassword?username=#{username}&password=#{password}&sessionId=#{sessionId}")
  !!data['success']
end

#updateUsername(newUsername) ⇒ Object



148
149
150
151
# File 'lib/sorenson/threesixty/account.rb', line 148

def updateUsername(newUsername)
  data = post_to("/api/updateUsername?username=#{username}&newUsername=#{newUsername}&sessionId=#{sessionId}")
  !!data['success']
end