Sha256: b68922f4feabc09f37257af800bc380cbe537d49937274201dff9610b9bebea1

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

require "faraday"
require "json"
require "logger"
require 'faraday_middleware'

module Incognia
  class Api
    # business layer: uses the Client to build domain objects
    # raises missing parameters errors
    attr_accessor :connection

    def initialize(client_id:, client_secret:)
      @connection = Client.new(client_id: client_id,
                               client_secret: client_secret,
                               host: "https://api.incognia.com/api")
    end

   def register_signup(installation_id:, address: nil, **opts)
      params = { installation_id: installation_id }
      params.merge!(opts)
      params.merge!(address&.to_hash) if address

      response = connection.request(
        :post,
        'v2/onboarding/signups',
        params
      )

      SignupAssessment.from_hash(response.body) if response.success?
    end

    def get_signup_assessment(signup_id:)
      response = connection.request(
        :get,
        "v2/onboarding/signups/#{signup_id}"
      )

      SignupAssessment.from_hash(response.body) if response.success?
    end

   def register_login(installation_id:, account_id:, **opts)
     params = {
       type: :login,
       installation_id: installation_id,
       account_id: account_id,
     }
     params.merge!(opts)

      response = connection.request(
        :post,
        'v2/authentication/transactions',
        params
      )

      LoginAssessment.from_hash(response.body) if response.success?
    end

    def register_feedback(event: , timestamp: nil, **ids)
      timestamp = timestamp.strftime('%s%L') if timestamp.respond_to? :strftime

      params = { event: event, timestamp: timestamp&.to_i }.compact
      params.merge!(ids)

      response = connection.request(
        :post,
        '/api/v2/feedbacks',
        params
      )

      response.success?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
incognia_api-0.5.0 lib/incognia_api/api.rb
incognia_api-0.4.1 lib/incognia_api/api.rb
incognia_api-0.4.0 lib/incognia_api/api.rb
incognia_api-0.3.1 lib/incognia/api.rb