Skip to content

robertodecurnex/twttr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Type Initial Release Implemented?
OAuth 1.0a v0.0.5
OAuth 2.0 - -

Users

Users Lookup

Endpoint Initial Release Implemented?
GET /2/users v0.0.5
GET /2/users/:id v0.0.5
GET /2/users/by v0.0.6
GET /2/users/by/username/:username v0.0.5
GET /2/users/me v0.0.5

Follows

Endpoint Initial Release Implemented?
GET /2/users/:id/following v0.0.5
GET /2/users/:id/followers v0.0.6
POST /2/users/:id/following - -
DELETE /2/users/:source_user_id/following/:target_user_id - -