Sha256: fdeb0cca7abc6ec529e683a7cb414b1d8bad434d59e67358619e88e5103953d7

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module PlatformSdk
  module Jira
    class ServiceManagementClient
      attr_accessor :conn, :cloud_id, :team_id

      def initialize(auth_email, auth_api_token, cloud_id, team_id, conn = nil)
        raise ArgumentError, 'auth_email cannot be nil' unless auth_email
        raise ArgumentError, 'auth_api_token cannot be nil' unless auth_api_token
        raise ArgumentError, 'cloud_id cannot be nil' unless cloud_id
        raise ArgumentError, 'team_id cannot be nil' unless team_id

        @conn = conn || build_connection(auth_email, auth_api_token)
        @cloud_id = cloud_id
        @team_id = team_id
      end

      def build_connection(auth_email, auth_api_token)
        Faraday.new(url: 'https://api.atlassian.com/jsm/ops/api') do |conn|
          conn.request(:authorization, :basic, auth_email, auth_api_token)
          conn.request :url_encoded
          conn.request :retry
          conn.response :raise_error
          conn.adapter :net_http
          conn.headers = headers
        end
      end

      def headers
        { 'Content-Type': 'application/json' }
      end

      def send_heartbeat(heartbeat_name)
        @conn.get("#{cloud_id}/v1/teams/#{team_id}/heartbeats/ping?name=#{heartbeat_name}")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
strongmind-platform-sdk-3.25.0 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.24.0 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.7 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.6 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.5 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.4 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.3 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.2 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.1 lib/platform_sdk/jira/service_management_client.rb
strongmind-platform-sdk-3.23.0 lib/platform_sdk/jira/service_management_client.rb