Home

Awesome

Twttr

Twitter API v2 Interface

example workflow Gem Version Coverage Status Maintainability

Summery

Modular Twitter API interface, initially targeting Twitter API v2

Examples

Config

# Creating a Client using OAuth 1.0a User context
client = Twttr::Client.new(user_id) do |config|
  # App credentials
  config.consumer_key        = "consumer_key"
  config.consumer_secret     = "consumer_secret"

  # User credentials
  config.access_token        = "access_token"
  config.access_token_secret = "access_secret"

  # Default user fields
  # https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/user
  config.user_fields         = %w(id, name, username)
end #=> #<Twttr::Client>

Client

# Twttr::Client#me
client.me #=> #<Twttr::Model::User>

#Twttr::Client#user(:user_id)
client.user("user_id") #=> #<Twttr::Model::User>

#Twttr::Client#user_by_username(:username)
client.user_by_username("username") #=> #<Twttr::Model::User>

#Twttr::Client#users(:user_ids)
client.users(["user_id_1", "user_id_2"]) #=> [#<Twttr::Model::User>]

# Twttr::Client#Followers
client.followers("user_id") == client.user("user_id").followers

# Twttr::Client#Following
client.following("user_id") == client.user("user_id").following

User

# Twttr::Model::User#followers
#
# Yields each page of users
user.followers do |users, pagination_token|
  users #=> [#<Twttr::Model::User>]
end #=> [#<Twttr::Model::User>]

# Follower users
user.followers #=> [#<Twttr::Model::User>]

# Twttr::Model::User#following
#
# Yields each page of users
user.following do |users, pagination_token|
  users #=> [#<Twttr::Model::User>]
end #=> [#<Twttr::Model::User>]

# Followed users
user.following #=> [#<Twttr::Model::User>]

Implemented Endpoints

Authentication

TypeInitial ReleaseImplemented?
OAuth 1.0av0.0.5:white_check_mark:
OAuth 2.0--

Users

Users Lookup

EndpointInitial ReleaseImplemented?
GET /2/usersv0.0.5:white_check_mark:
GET /2/users/:idv0.0.5:white_check_mark:
GET /2/users/byv0.0.6:white_check_mark:
GET /2/users/by/username/:usernamev0.0.5:white_check_mark:
GET /2/users/mev0.0.5:white_check_mark:

Follows

EndpointInitial ReleaseImplemented?
GET /2/users/:id/followingv0.0.5:white_check_mark:
GET /2/users/:id/followersv0.0.6:white_check_mark:
POST /2/users/:id/following--
DELETE /2/users/:source_user_id/following/:target_user_id--