Sha256: 2209379734e00a1934aac102990f6a820f9d4451343c70f9aabf2047eb488c60

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

# Class for Subscription Service
class K2Subscribe
  include K2Validation, K2Utilities
  attr_reader :location_url, :k2_response_body
  attr_accessor :access_token, :webhook_secret

  # Initialize with the event_type
  def initialize(access_token)
    raise ArgumentError, 'Nil or Empty Access Token Given!' if access_token.blank?
    @threads = []
    @access_token = access_token
  end

  # Implemented a Case condition that minimises repetition
  def webhook_subscribe(params)
    params = validate_webhook_input(params)
    validate_webhook(params)
    k2_request_body = {
        event_type: params[:event_type],
        url: params[:url],
        scope: params[:scope],
        scope_reference: params[:scope_reference]
    }
    subscribe_hash = make_hash(K2Config.path_url('webhook_subscriptions'), 'post', @access_token,'Subscription', k2_request_body)
    @location_url =  K2Connect.make_request(subscribe_hash)
  end

  # Query Recent Webhook
  def query_webhook(location_url = @location_url)
    query_hash = make_hash(location_url, 'get', @access_token, 'Subscription', nil)
    @threads << Thread.new do
      sleep 0.25
      @k2_response_body = K2Connect.make_request(query_hash)
    end
    @threads.each(&:join)
  end

  # Query Specific Webhook URL
  def query_resource_url(url)
    query_webhook(url)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
k2-connect-ruby-0.0.3 lib/k2-connect-ruby/k2_financial_entity/k2_subscribe.rb
k2-connect-ruby-0.0.2 lib/k2-connect-ruby/k2_financial_entity/k2_subscribe.rb
k2-connect-ruby-0.0.1 lib/k2-connect-ruby/k2_financial_entity/k2_subscribe.rb