Module: Twitter::Client::Block

Included in:
Twitter::Client
Defined in:
lib/twitter/client/block.rb

Overview

Defines methods related to blocking and unblocking users

See Also:

Instance Method Summary collapse

Instance Method Details

#block(user, options = {}) ⇒ Twitter::User

Note:

Destroys a friendship to the blocked user if it exists.

Blocks the user specified by the authenticating user

Examples:

Block and unfriend @sferik as the authenticating user

Twitter.block("sferik")
Twitter.block(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



77
78
79
80
81
# File 'lib/twitter/client/block.rb', line 77

def block(user, options={})
  options.merge_user!(user)
  user = post("/1/blocks/create.json", options)
  Twitter::User.new(user)
end

#block?(user, options = {}) ⇒ Boolean

Returns true if the authenticating user is blocking a target user

Examples:

Check whether the authenticating user is blocking @sferik

Twitter.block?("sferik")
Twitter.block?(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Boolean)

    true if the authenticating user is blocking the target user, otherwise false.

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



55
56
57
58
59
60
61
# File 'lib/twitter/client/block.rb', line 55

def block?(user, options={})
  options.merge_user!(user)
  get("/1/blocks/exists.json", options, :raw => true)
  true
rescue Twitter::Error::NotFound
  false
end

#blocked_ids(options = {}) ⇒ Array

Returns an array of numeric user ids the authenticating user is blocking

Examples:

Return an array of numeric user ids the authenticating user is blocking

Twitter.blocking_ids

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Array)

    Numeric user ids the authenticating user is blocking.

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



39
40
41
# File 'lib/twitter/client/block.rb', line 39

def blocked_ids(options={})
  get("/1/blocks/blocking/ids.json", options)
end

#blocking(options = {}) ⇒ Array<Twitter::User>

Returns an array of user objects that the authenticating user is blocking

Examples:

Return an array of user objects that the authenticating user is blocking

Twitter.blocking

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    Specifies the page of results to retrieve.

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

  • (Array<Twitter::User>)

    User objects that the authenticating user is blocking.

Raises:

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • Yes



23
24
25
26
27
# File 'lib/twitter/client/block.rb', line 23

def blocking(options={})
  get("/1/blocks/blocking.json", options).map do |user|
    Twitter::User.new(user)
  end
end

#unblock(user, options = {}) ⇒ Twitter::User

Un-blocks the user specified by the authenticating user

Examples:

Un-block @sferik as the authenticating user

Twitter.unblock("sferik")
Twitter.unblock(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

Raises:

See Also:

Rate Limited?:

  • No

Requires Authentication?:

  • Yes



96
97
98
99
100
# File 'lib/twitter/client/block.rb', line 96

def unblock(user, options={})
  options.merge_user!(user)
  user = delete("/1/blocks/destroy.json", options)
  Twitter::User.new(user)
end