Class: ConnectorsSdk::Atlassian::CustomClient
- Inherits:
-
Base::CustomClient
- Object
- Base::CustomClient
- ConnectorsSdk::Atlassian::CustomClient
- Defined in:
- lib/connectors_sdk/atlassian/custom_client.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ClientError, ContentConvertibleError, ServiceUnavailableError
Constant Summary collapse
- MEDIA_API_BASE_URL =
'https://api.media.atlassian.com'
Constants inherited from Base::CustomClient
Base::CustomClient::MAX_RETRIES
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#basic_auth_token ⇒ Object
readonly
Returns the value of attribute basic_auth_token.
Attributes inherited from Base::CustomClient
#ensure_fresh_auth, #middleware
Instance Method Summary collapse
- #additional_middleware ⇒ Object
- #default_middleware ⇒ Object
- #download(url) ⇒ Object
-
#initialize(base_url:, access_token: nil, basic_auth_token: nil, ensure_fresh_auth: nil) ⇒ CustomClient
constructor
A new instance of CustomClient.
- #update_auth_data!(new_access_token) ⇒ Object
Methods inherited from Base::CustomClient
#http_client, #http_client!, #middleware!, #retry_config
Constructor Details
#initialize(base_url:, access_token: nil, basic_auth_token: nil, ensure_fresh_auth: nil) ⇒ CustomClient
Returns a new instance of CustomClient.
36 37 38 39 40 41 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 36 def initialize(base_url:, access_token: nil, basic_auth_token: nil, ensure_fresh_auth: nil) raise 'Either access_token or basic_auth_token must be provided' unless access_token.present? || basic_auth_token.present? @access_token = access_token @basic_auth_token = basic_auth_token super(:base_url => base_url, :ensure_fresh_auth => ensure_fresh_auth) end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
34 35 36 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 34 def access_token @access_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
34 35 36 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 34 def base_url @base_url end |
#basic_auth_token ⇒ Object (readonly)
Returns the value of attribute basic_auth_token.
34 35 36 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 34 def basic_auth_token @basic_auth_token end |
Instance Method Details
#additional_middleware ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 47 def additional_middleware result = [ FaradayMiddleware::FollowRedirects, [ConnectorsShared::Middleware::RestrictHostnames, { :allowed_hosts => [base_url, MEDIA_API_BASE_URL] }] ] if @access_token.present? result.append([ConnectorsShared::Middleware::BearerAuth, { :bearer_auth_token => @access_token }]) elsif @basic_auth_token.present? result.append([ConnectorsShared::Middleware::BasicAuth, { :basic_auth_token => @basic_auth_token }]) else raise 'Either access token or basic auth must be provided' end end |
#default_middleware ⇒ Object
43 44 45 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 43 def default_middleware [] # Ignoring Base default for now, but we should probably revert to using Base default? end |
#download(url) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 69 def download(url) response = get(url) unless HTTP::Status.successful?(response.status) raise ClientError.new(url, response.status, response.body) end response end |
#update_auth_data!(new_access_token) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/connectors_sdk/atlassian/custom_client.rb', line 61 def update_auth_data!(new_access_token) @access_token = new_access_token middleware! http_client! # force a new client to pick up new middleware self end |