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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/aviate/client.rb', line 84 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) http.use_ssl = (uri.scheme == 'https') http.verify_mode = OpenSSL::SSL::VERIFY_PEER 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 17 18 19 |
# File 'lib/aviate/client.rb', line 9 def aviate_plugin_available?( = nil) path = "#{KILLBILL_AVIATE_PREFIX}/health/data" = () KillBillClient::API.get path, {}, [true, nil] rescue KillBillClient::API::ResponseError => e [false, e..to_s] end |
.aviate_plugin_installed(options = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aviate/client.rb', line 21 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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/aviate/client.rb', line 57 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, {}, JSON.parse(response.body) rescue StandardError => e JSON.parse(e.) end |
.modify_wallet(wallet_params, options = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/aviate/client.rb', line 41 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, {}, response.code end |
.retrieve_wallets(account_id, options = nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/aviate/client.rb', line 32 def retrieve_wallets(account_id, = nil) path = "#{KILLBILL_AVIATE_PREFIX}/wallet/#{account_id}" = () response = KillBillClient::API.get path, {}, JSON.parse(response.body) end |