class Momoapi::CLI
Public Class Methods
new(option)
click to toggle source
# File lib/momoapi-ruby/cli.rb, line 17 def initialize(option) @uuid = SecureRandom.uuid @host = option[:host] @key = option[:key] create_sandbox_user end
Public Instance Methods
create_sandbox_user()
click to toggle source
Create an API user in the sandbox target environment
# File lib/momoapi-ruby/cli.rb, line 25 def create_sandbox_user body = { "providerCallbackHost": @host } @url = 'https://ericssonbasicapi2.azure-api.net/v1_0/apiuser' response = Faraday.post(@url) do |req| req.headers['Content-Type'] = 'application/json' req.headers['X-Reference-Id'] = @uuid req.headers['Ocp-Apim-Subscription-Key'] = @key req.body = body.to_json end unless response.status == 201 raise Momoapi::Error.new(response.body, response.status) end generate_api_key end
generate_api_key()
click to toggle source
Generate an API key in the sandbox target environment
# File lib/momoapi-ruby/cli.rb, line 43 def generate_api_key @url = 'https://ericssonbasicapi2.azure-api.net/v1_0/apiuser/' + @uuid + '/apikey' response = Faraday.post(@url) do |req| req.headers['Ocp-Apim-Subscription-Key'] = @key end unless response.status == 201 raise Momoapi::Error.new(response.body, response.status) end key = JSON.parse(response.body) puts "\n User ID: #{@uuid} \n API key: #{key['apiKey']} \n\n" end