Class: Killbill::Aviate::AviateClient
- Inherits:
-
KillBillClient::Model::Resource
- Object
- KillBillClient::Model::Resource
- Killbill::Aviate::AviateClient
- Defined in:
- lib/aviate/client.rb
Constant Summary collapse
- KILLBILL_AVIATE_PREFIX =
'/plugins/aviate-plugin/v1'
Class Method Summary collapse
- .authenticate(email, password, options = nil) ⇒ Object
- .aviate_plugin_available?(options = nil) ⇒ Boolean
- .aviate_plugin_installed(options = nil) ⇒ Object
- .create_wallet(account_id, wallet, options = nil) ⇒ Object
- .modify_wallet(wallet_params, options = nil) ⇒ Object
- .retrieve_wallets(account_id, options = nil) ⇒ Object
Class Method Details
.authenticate(email, password, options = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aviate/client.rb', line 73 def authenticate(email, password, = nil) path = "#{KILLBILL_AVIATE_PREFIX}/auth" auth = Base64.strict_encode64("#{email}:#{password}") base_url = KillBillClient::API.base_uri uri = URI("#{base_url}#{path}") http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.path) request['Content-Type'] = 'application/json' request['X-killbill-apiKey'] = [:api_key] request['X-killbill-apisecret'] = [:api_secret] request['Authorization'] = "Basic #{auth}" request.body = {}.to_json response = http.request(request) JSON.parse(response.body) rescue StandardError => e e..to_s end |
.aviate_plugin_available?(options = nil) ⇒ Boolean
9 10 11 12 13 14 15 16 |
# File 'lib/aviate/client.rb', line 9 def aviate_plugin_available?( = nil) path = "#{KILLBILL_AVIATE_PREFIX}/health/data" KillBillClient::API.get path, {}, get_token() [true, nil] rescue KillBillClient::API::ResponseError => e [false, e..to_s] end |
.aviate_plugin_installed(options = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/aviate/client.rb', line 18 def aviate_plugin_installed( = nil) nodes_info = KillBillClient::Model::NodesInfo.nodes_info() || [] plugins_info = nodes_info.empty? ? [] : (nodes_info.first.plugins_info || []) return [true, nil] if plugins_info.any? { |plugin| plugin.plugin_name == 'aviate-plugin' } [false, nil] rescue KillBillClient::API::ResponseError => e [false, e..to_s] end |
.create_wallet(account_id, wallet, options = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aviate/client.rb', line 48 def create_wallet(account_id, wallet, = nil) path = "#{KILLBILL_AVIATE_PREFIX}/wallet" body = { kbAccountId: account_id, currency: wallet[:currency], initCredit: { creditType: wallet[:credit_type], amount: wallet[:amount], expDate: wallet[:exp_date] }, topOff: { topOffType: wallet[:top_off_type], lowWatermark: wallet[:low_watermark], amount: wallet[:top_off_amount], expDurationUnit: wallet[:exp_duration_unit], expDurationLength: wallet[:exp_duration_length] } } response = KillBillClient::API.post path, body.to_json, {}, get_token() JSON.parse(response.body) rescue StandardError => e JSON.parse(e.) end |
.modify_wallet(wallet_params, options = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aviate/client.rb', line 35 def modify_wallet(wallet_params, = nil) path = "#{KILLBILL_AVIATE_PREFIX}/wallet/#{wallet_params[:wallet_id]}/topOffConfig" body = { topOffType: wallet_params[:top_off_type], lowWatermark: wallet_params[:low_watermark], amount: wallet_params[:top_off_amount], expDurationUnit: wallet_params[:exp_duration_unit], expDurationLength: wallet_params[:exp_duration_length] } response = KillBillClient::API.put path, body.to_json, {}, get_token() response.code end |
.retrieve_wallets(account_id, options = nil) ⇒ Object
29 30 31 32 33 |
# File 'lib/aviate/client.rb', line 29 def retrieve_wallets(account_id, = nil) path = "#{KILLBILL_AVIATE_PREFIX}/wallet/#{account_id}" response = KillBillClient::API.get path, {}, get_token() JSON.parse(response.body) end |