Sha256: bbee8199fc712ed63acda07e528f27a66759df4f3e08f3e33f6e7bcc24f3b1ba

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

module NedbankApi
  class AuthenticationsApi < ApiWrapper
    class << self
      def request_token_light
        http = Http.new(url: endpoint('/nboauth/oauth20/token'))

        response = http.post(
          body: URI.encode_www_form({
            client_id: NedbankApi.configuration.client_id,
            client_secret: NedbankApi.configuration.client_secret,
            grant_type: 'client_credentials',
            scope: 'tpp_client_credential'
          })
        )

        intent_token = Models::IntentToken.new(JSON.parse(response.body, object_class: OpenStruct))

        NedbankApi.intent_token = intent_token

        return intent_token
      end

      def request_token_heavy(request_body: {})
        http = Http.new(url: endpoint('/nboauth/oauth20/token'))

        response = http.post(
          body: URI.encode_www_form({
            client_id: NedbankApi.configuration.client_id,
            client_secret: NedbankApi.configuration.client_secret,
            redirect_uri: NedbankApi.configuration.oauth_redirect_url,
            grant_type: 'authorization_code',
          }.merge(request_body))
        )

        intent_token = Models::IntentToken.new(JSON.parse(response.body, object_class: OpenStruct))

        NedbankApi.intent_token = intent_token

        return intent_token
      end

      def authorisation_url(request_body: {})
        url = endpoint('/nboauth/oauth20/authorize')

        body = URI.encode_www_form({
            client_id: NedbankApi.configuration.client_id,
            redirect_uri: NedbankApi.configuration.oauth_redirect_url,
            response_type: 'code',
            scope: 'payments',
            itype: 'payments'
        }.merge(request_body))

        return "#{url}?#{body}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nedbank_api-0.2.2 lib/nedbank_api/authentications_api.rb