Module: Twitter::REST::AccountActivity

Includes:
Utils, Utils
Included in:
API
Defined in:
lib/twitter/rest/account_activity.rb

Constant Summary

Constants included from Utils

Utils::DEFAULT_CURSOR

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Instance Method Details

#check_subscription(env_name) ⇒ nil

Note:

Check if the user is subscribed to the given app

Provides a way to determine if a webhook configuration is subscribed to the provided user's events. If the provided user context has an active subscription with provided application, returns 204 OK.

Parameters:

  • env_name (String)

    Environment Name

Returns:

  • (nil)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context - all consumer and access tokens



82
83
84
# File 'lib/twitter/rest/account_activity.rb', line 82

def check_subscription(env_name)
  perform_request(:get, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
end

#create_subscription(env_name) ⇒ nil

Note:

Subscribe the user(whose credentials are provided) to the app so that the webhook can receive all types of events from user

Subscribes the provided application to all events for the provided environment for all message types. After activation, all events for the requesting user will be sent to the application's webhook via POST request.

Parameters:

  • env_name (String)

    Environment Name

Returns:

  • (nil)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context - all consumer and access tokens



70
71
72
# File 'lib/twitter/rest/account_activity.rb', line 70

def create_subscription(env_name)
  perform_request(:json_post, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
end

#create_webhook(env_name, url) ⇒ Hash

Note:

Create a webhook

Registers a webhook URL for all event types. The URL will be validated via CRC request before saving. In case the validation failed, returns comprehensive error message to the requester.

Parameters:

  • env_name (String)

    Environment Name.

  • url (String)

    Encoded URL for the callback endpoint.

Returns:

  • (Hash)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context - all consumer and access tokens



21
22
23
# File 'lib/twitter/rest/account_activity.rb', line 21

def create_webhook(env_name, url)
  perform_request(:json_post, "/1.1/account_activity/all/#{env_name}/webhooks.json?url=#{url}")
end

#deactivate_subscription(env_name) ⇒ nil

Note:

Deactivate a subscription, Users events will not be sent to the app

Deactivates subscription(s) for the provided user context and application for all activities. After deactivation, all events for the requesting user will no longer be sent to the webhook URL.

Parameters:

  • env_name (String)

    Environment Name

Returns:

  • (nil)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context - all consumer and access tokens



94
95
96
# File 'lib/twitter/rest/account_activity.rb', line 94

def deactivate_subscription(env_name)
  perform_request(:delete, "/1.1/account_activity/all/#{env_name}/subscriptions.json")
end

#delete_webhook(env_name, webhook_id) ⇒ nil

Note:

Delete a webhook

Removes the webhook from the provided application's all activities configuration. The webhook ID can be accessed by making a call to GET /1.1/account_activity/all/webhooks.

Parameters:

  • env_name (String)

    Environment Name.

  • webhook_id (String)

    Webhook ID.

Returns:

  • (nil)

Raises:

See Also:

Authentication:

  • Requires user context - all consumer and access tokens



45
46
47
# File 'lib/twitter/rest/account_activity.rb', line 45

def delete_webhook(env_name, webhook_id)
  perform_request(:delete, "/1.1/account_activity/all/#{env_name}/webhooks/#{webhook_id}.json")
end

#list_webhooks(env_name) ⇒ Hash

Note:

List webhooks

Returns all environments, webhook URLs and their statuses for the authenticating app. Currently, only one webhook URL can be registered to each environment.

Parameters:

  • env_name (String)

    Environment Name.

Returns:

  • (Hash)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context - all consumer and access tokens



33
34
35
# File 'lib/twitter/rest/account_activity.rb', line 33

def list_webhooks(env_name)
  perform_request(:get, "/1.1/account_activity/all/#{env_name}/webhooks.json")
end

#trigger_crc_check(env_name, webhook_id) ⇒ nil

Note:

Trigger CRC check to a webhook

Triggers the challenge response check (CRC) for the given enviroments webhook for all activites. If the check is successful, returns 204 and reenables the webhook by setting its status to valid.

Parameters:

  • env_name (String)

    Environment Name.

  • webhook_id (String)

    Webhook ID.

Returns:

  • (nil)

Raises:

See Also:

Rate Limited?:

  • Yes

Authentication:

  • Requires user context - all consumer and access tokens



58
59
60
# File 'lib/twitter/rest/account_activity.rb', line 58

def trigger_crc_check(env_name, webhook_id)
  perform_request(:json_put, "/1.1/account_activity/all/#{env_name}/webhooks/#{webhook_id}.json")
end