Class: Notiflows::Resources::Users::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/notiflows/resources/users/subscriptions.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Subscriptions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Subscriptions.

Parameters:



129
130
131
# File 'lib/notiflows/resources/users/subscriptions.rb', line 129

def initialize(client:)
  @client = client
end

Instance Method Details

#list(user_external_id, after: nil, before: nil, created_after: nil, created_before: nil, limit: nil, request_options: {}) ⇒ Notiflows::Internal::CursorPage<Notiflows::Models::Users::Subscription>

Retrieve all topic subscriptions for a user.

Parameters:

  • user_external_id (String) —

    User external ID

  • after (String) —

    Cursor for fetching the next page

  • before (String) —

    Cursor for fetching the previous page

  • created_after (String) —

    Filter by created after (ISO 8601 datetime)

  • created_before (String) —

    Filter by created before (ISO 8601 datetime)

  • limit (Integer) —

    Number of items per page (default: 25, max: 1000)

  • request_options (Notiflows::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/notiflows/resources/users/subscriptions.rb', line 55

def list(user_external_id, params = {})
  parsed, options = ::Notiflows::Users::SubscriptionListParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["users/%1$s/subscriptions", user_external_id],
    query: parsed,
    page: ::Notiflows::Internal::CursorPage,
    model: ::Notiflows::Users::Subscription,
    options: options
  )
end

#retrieve(topic_name, user_external_id:, request_options: {}) ⇒ Notiflows::Models::Users::Subscription

Check if a user is subscribed to a specific topic.

Parameters:

  • topic_name (String) —

    Topic name

  • user_external_id (String) —

    User external ID

  • request_options (Notiflows::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/notiflows/resources/users/subscriptions.rb', line 20

def retrieve(topic_name, params)
  parsed, options = ::Notiflows::Users::SubscriptionRetrieveParams.dump_request(params)
  user_external_id =
    parsed.delete(:user_external_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["users/%1$s/subscriptions/%2$s", user_external_id, topic_name],
    model: ::Notiflows::Users::Subscription,
    options: options
  )
end

#subscribe(user_external_id, topic_name:, request_options: {}) ⇒ Notiflows::Models::Users::Subscription

Some parameter documentations has been truncated, see Models::Users::SubscriptionSubscribeParams for more details.

Subscribe a user to a topic. Topics are created automatically if they don't exist.

Idempotent: If the user is already subscribed, returns the existing subscription with 200 OK.

Parameters:

  • user_external_id (String) —

    User external ID

  • topic_name (String) —

    Name of the topic to subscribe to. Topics are created automatically if they don'

  • request_options (Notiflows::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



87
88
89
90
91
92
93
94
95
96
# File 'lib/notiflows/resources/users/subscriptions.rb', line 87

def subscribe(user_external_id, params)
  parsed, options = ::Notiflows::Users::SubscriptionSubscribeParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["users/%1$s/subscriptions", user_external_id],
    body: parsed,
    model: ::Notiflows::Users::Subscription,
    options: options
  )
end

#unsubscribe(topic_name, user_external_id:, request_options: {}) ⇒ nil

Remove a user's subscription from a topic. The user will no longer receive notifications triggered for this topic.

Parameters:

  • topic_name (String) —

    Topic name

  • user_external_id (String) —

    User external ID

  • request_options (Notiflows::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/notiflows/resources/users/subscriptions.rb', line 112

def unsubscribe(topic_name, params)
  parsed, options = ::Notiflows::Users::SubscriptionUnsubscribeParams.dump_request(params)
  user_external_id =
    parsed.delete(:user_external_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["users/%1$s/subscriptions/%2$s", user_external_id, topic_name],
    model: NilClass,
    options: options
  )
end