Class: Courier::Users::AsyncPreferencesClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/users/preferences/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Users::AsyncPreferencesClient

Parameters:



94
95
96
97
# File 'lib/trycourier/users/preferences/client.rb', line 94

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



90
91
92
# File 'lib/trycourier/users/preferences/client.rb', line 90

def request_client
  @request_client
end

Instance Method Details

#get(user_id:, topic_id:, request_options: nil) ⇒ Users::Preferences::UserPreferencesGetResponse

Fetch user preferences for a specific subscription topic.

Parameters:

  • user_id (String)

    A unique identifier associated with the user whose preferences you wish to retrieve.

  • topic_id (String)

    A unique identifier associated with a subscription topic.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/trycourier/users/preferences/client.rb', line 124

def get(user_id:, topic_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/users/#{user_id}/preferences/#{topic_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Users::Preferences::UserPreferencesGetResponse.from_json(json_object: response.body)
  end
end

#list(user_id:, request_options: nil) ⇒ Users::Preferences::UserPreferencesListResponse

Fetch all user preferences.

Parameters:

  • user_id (String)

    A unique identifier associated with the user whose preferences you wish to retrieve.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/trycourier/users/preferences/client.rb', line 104

def list(user_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/users/#{user_id}/preferences") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    end
    Users::Preferences::UserPreferencesListResponse.from_json(json_object: response.body)
  end
end

#update(user_id:, topic_id:, status:, default_status:, custom_routing: nil, has_custom_routing: nil, request_options: nil) ⇒ Users::Preferences::UserPreferencesUpdateResponse

Update or Create user preferences for a specific subscription topic.

Parameters:

  • user_id (String)

    A unique identifier associated with the user whose preferences you wish to retrieve.

  • topic_id (String)

    A unique identifier associated with a subscription topic.

  • status (Commons::PreferenceStatus)
  • custom_routing (Array<Commons::ChannelClassification>) (defaults to: nil)

    The Channels a user has chosen to receive notifications through for this topic

  • default_status (Commons::PreferenceStatus)
  • has_custom_routing (Boolean) (defaults to: nil)
  • request_options (RequestOptions) (defaults to: nil)

Returns:



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/trycourier/users/preferences/client.rb', line 148

def update(user_id:, topic_id:, status:, default_status:, custom_routing: nil, has_custom_routing: nil,
           request_options: nil)
  Async do
    response = @request_client.conn.put("/users/#{user_id}/preferences/#{topic_id}") do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      unless request_options&.authorization_token.nil?
        req.headers["Authorization"] =
          request_options.authorization_token
      end
      req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        status: status,
        custom_routing: custom_routing,
        default_status: default_status,
        has_custom_routing: has_custom_routing
      }.compact
    end
    Users::Preferences::UserPreferencesUpdateResponse.from_json(json_object: response.body)
  end
end