Class: SourceLicenseSDK::Client
- Inherits:
-
Object
- Object
- SourceLicenseSDK::Client
- Defined in:
- lib/source_license_sdk/client.rb
Overview
HTTP client for communicating with Source-License API
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#activate_license(license_key, machine_id:, machine_fingerprint: nil) ⇒ Object
Activate a license on this machine.
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
-
#validate_license(license_key, machine_id: nil, machine_fingerprint: nil) ⇒ Object
Validate a license key.
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/source_license_sdk/client.rb', line 11 def initialize(config) @config = config validate_config! end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/source_license_sdk/client.rb', line 9 def config @config end |
Instance Method Details
#activate_license(license_key, machine_id:, machine_fingerprint: nil) ⇒ Object
Activate a license on this machine
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/source_license_sdk/client.rb', line 32 def activate_license(license_key, machine_id:, machine_fingerprint: nil) machine_fingerprint ||= SourceLicenseSDK::MachineIdentifier.generate_fingerprint path = "/api/license/#{license_key}/activate" body = { machine_id: machine_id, machine_fingerprint: machine_fingerprint, } response = make_request(:post, path, body: body) SourceLicenseSDK::LicenseValidationResult.new(response) rescue SourceLicenseSDK::NetworkError => e handle_network_error(e) end |
#validate_license(license_key, machine_id: nil, machine_fingerprint: nil) ⇒ Object
Validate a license key
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/source_license_sdk/client.rb', line 17 def validate_license(license_key, machine_id: nil, machine_fingerprint: nil) machine_fingerprint ||= SourceLicenseSDK::MachineIdentifier.generate_fingerprint if machine_id path = "/api/license/#{license_key}/validate" params = {} params[:machine_id] = machine_id if machine_id params[:machine_fingerprint] = machine_fingerprint if machine_fingerprint response = make_request(:get, path, params: params) SourceLicenseSDK::LicenseValidationResult.new(response) rescue SourceLicenseSDK::NetworkError => e handle_network_error(e) end |