Class: Airtel::Pesa::Authorization
- Inherits:
-
Object
- Object
- Airtel::Pesa::Authorization
- Defined in:
- lib/airtel/pesa/authorization.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Authorization
constructor
A new instance of Authorization.
Constructor Details
#initialize ⇒ Authorization
Returns a new instance of Authorization.
12 |
# File 'lib/airtel/pesa/authorization.rb', line 12 def initialize; end |
Class Method Details
.call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/airtel/pesa/authorization.rb', line 14 def self.call url = URI("https://openapiuat.airtel.africa/auth/oauth2/token") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request.body = JSON.dump(body) response = http.request(request) parsed_body = JSON.parse(response.read_body) result = OpenStruct.new( access_token: parsed_body["access_token"], expires_in: parsed_body["expires_in"], token_type: parsed_body["token_type"] ) OpenStruct.new(result: result, error: nil) rescue JSON::ParserError => error OpenStruct.new(result: nil, error: error) end |