Sha256: ef29c05325acef1e2d89081ee610ca42351b5660fdcac2a54605f6c696279dc3

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

module OmniAuth
  module Strategies
    class Cronofy < OmniAuth::Strategies::OAuth2
      option :name, "cronofy"

      def self.api_url
        @api_url ||= (ENV['CRONOFY_API_URL'] || data_centre_api_url || "https://api.cronofy.com")
      end

      def self.data_centre_api_url
        case ENV['CRONOFY_DATA_CENTRE']
        when 'de'
          "https://api-#{ENV['CRONOFY_DATA_CENTRE']}.cronofy.com"
        end
      end

      def self.api_url=(value)
        @api_url = value
      end

      def self.app_url
        @app_url ||= (ENV['CRONOFY_APP_URL'] || data_centre_app_url || "https://app.cronofy.com")
      end

      def self.data_centre_app_url
        case ENV['CRONOFY_DATA_CENTRE']
        when 'de'
          "https://app-#{ENV['CRONOFY_DATA_CENTRE']}.cronofy.com"
        end
      end

      def self.app_url=(value)
        @app_url = value
      end

      option :client_options, {
        :site => ::OmniAuth::Strategies::Cronofy.app_url
      }

      uid{ raw_info['account_id'] }

      info do
        {
          :email => raw_info['email'],
          :name => raw_info['name']
        }
      end

      extra do
        {
          'raw_info' => raw_info,
          'linking_profile' => access_token['linking_profile'],
        }
      end

      def callback_url
        options[:redirect_uri] || (full_host + script_name + callback_path)
      end

      def raw_info
        @raw_info ||= access_token.get("#{::OmniAuth::Strategies::Cronofy.api_url}/v1/account").parsed['account']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-cronofy-0.8.0 lib/omniauth/strategies/cronofy.rb