Class: Licensario::User
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#external_user_id ⇒ Object
Returns the value of attribute external_user_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#licensario_user_id ⇒ Object
Returns the value of attribute licensario_user_id.
Instance Method Summary collapse
-
#build_url(suffix) ⇒ Object
Build the appropriate url for the API call.
-
#create_license(payment_plan_id) ⇒ Object
Create a license for this User.
-
#ensure_has_license(payment_plan_id) ⇒ Object
Ensure’s that the User has the necessary License.
-
#get_available_feature_amount(feature_id, payment_plan_id = nil) ⇒ Object
Gets the amount available for a given Feature.
-
#get_licenses(feature_ids, payment_plan_ids = nil) ⇒ Object
Retrive this uses’s licenses.
-
#increment_feature_usage(amount, feature_id, payment_plan_id = nil) ⇒ Object
Increment a given Feature usage.
-
#update_feature_usage(amount, feature_id, payment_plan_id = nil) ⇒ Object
Update a given Feature usage.
Methods inherited from Base
api, date_format, establish_connection, #initialize
Constructor Details
This class inherits a constructor from Licensario::Base
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/licensario/user.rb', line 6 def email @email end |
#external_user_id ⇒ Object
Returns the value of attribute external_user_id.
6 7 8 |
# File 'lib/licensario/user.rb', line 6 def external_user_id @external_user_id end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/licensario/user.rb', line 6 def id @id end |
#licensario_user_id ⇒ Object
Returns the value of attribute licensario_user_id.
6 7 8 |
# File 'lib/licensario/user.rb', line 6 def licensario_user_id @licensario_user_id end |
Instance Method Details
#build_url(suffix) ⇒ Object
Build the appropriate url for the API call
9 10 11 12 13 14 15 16 17 |
# File 'lib/licensario/user.rb', line 9 def build_url(suffix) url = "/api/v1" if @external_user_id url += "/users/external/" + @external_user_id.to_s + suffix else url += "/users/" + @licensario_user_id.to_s + suffix end return url end |
#create_license(payment_plan_id) ⇒ Object
Create a license for this User
61 62 63 64 65 66 |
# File 'lib/licensario/user.rb', line 61 def create_license(payment_plan_id) res = @@api.do_request(:post, build_url("/licenses"), { 'paymentPlanId' => payment_plan_id.to_s }) xml = res[:body] license = Licensario::License.new(xml: xml) return license end |
#ensure_has_license(payment_plan_id) ⇒ Object
Ensure’s that the User has the necessary License
20 21 22 23 24 25 |
# File 'lib/licensario/user.rb', line 20 def ensure_has_license(payment_plan_id) res = @@api.do_request(:put, build_url('/licenses'), { 'paymentPlanId' => payment_plan_id }) xml = res[:body] license = Licensario::License.new(xml: xml) return license end |
#get_available_feature_amount(feature_id, payment_plan_id = nil) ⇒ Object
Gets the amount available for a given Feature
41 42 43 44 45 46 |
# File 'lib/licensario/user.rb', line 41 def get_available_feature_amount(feature_id, payment_plan_id = nil) amount = 0 res = @@api.do_request(:get, build_url("/features/#{feature_id}/alloc"), { 'paymentPlanId' => payment_plan_id }) amount = JSON.parse(res[:body])['available'].to_f return amount end |
#get_licenses(feature_ids, payment_plan_ids = nil) ⇒ Object
Retrive this uses’s licenses
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/licensario/user.rb', line 28 def get_licenses(feature_ids, payment_plan_ids = nil) licenses = [] res = @@api.do_request(:get, build_url("/licenses"), { 'featureIds' => feature_ids, 'paymentPlanIds' => payment_plan_ids }) xml = res[:body] doc = Nokogiri::XML(xml) doc.xpath("//userLicenses//licenseCertificate").each do |lnode| license = Licensario::License.new(xml_node: lnode) licenses << license end return licenses end |
#increment_feature_usage(amount, feature_id, payment_plan_id = nil) ⇒ Object
Increment a given Feature usage
49 50 51 52 |
# File 'lib/licensario/user.rb', line 49 def increment_feature_usage(amount, feature_id, payment_plan_id = nil) res = @@api.do_request(:post, build_url("/features/#{feature_id}/alloc"), { 'amount' => amount.to_s, 'paymentPlanId' => payment_plan_id }) return res[:status] == 200 end |
#update_feature_usage(amount, feature_id, payment_plan_id = nil) ⇒ Object
Update a given Feature usage
55 56 57 58 |
# File 'lib/licensario/user.rb', line 55 def update_feature_usage(amount, feature_id, payment_plan_id = nil) res = @@api.do_request(:put, build_url("/features/#{feature_id}/alloc"), { 'amount' => amount.to_s, 'paymentPlanId' => payment_plan_id }) return res[:status] == 200 end |