Class: Twttr::Client

Inherits:
Object
  • Object
show all
Includes:
Endpoint::V2::Users, Endpoint::V2::Users::Follows
Defined in:
lib/twttr/client.rb,
lib/twttr/client/error.rb,
lib/twttr/client/config.rb,
lib/twttr/client/endpoint.rb,
lib/twttr/client/endpoint/v2.rb,
lib/twttr/client/oauth_request.rb,
lib/twttr/client/endpoint/v2/users.rb,
lib/twttr/client/endpoint/v2/users/follows.rb

Overview

 Twitter API Client

Defined Under Namespace

Modules: Endpoint, Error Classes: Config, OAuthRequest

Constant Summary collapse

BASE_URL =
'https://api.twitter.com'

Constants included from Endpoint::V2::Users::Follows

Endpoint::V2::Users::Follows::FOLLOWING_PATH

Constants included from Endpoint::V2::Users

Endpoint::V2::Users::ME_PATH, Endpoint::V2::Users::USERS_PATH, Endpoint::V2::Users::USER_BY_USERNAME_PATH, Endpoint::V2::Users::USER_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Endpoint::V2::Users::Follows

#following

Methods included from Endpoint::V2::Users

#me, #user, #user_by_username, #users

Constructor Details

#initialize {|config| ... } ⇒ Client

Returns a new instance of Client.

Yields:



29
30
31
32
# File 'lib/twttr/client.rb', line 29

def initialize
  @config = Config.new
  yield config if block_given?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



25
26
27
# File 'lib/twttr/client.rb', line 25

def config
  @config
end

Instance Method Details

#get(path, params: {}, query_params: {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/twttr/client.rb', line 34

def get(path, params: {}, query_params: {})
  uri = uri_for(path, params)
  uri.query = URI.encode_www_form(query_params.compact) unless query_params.compact.empty?

  response = OAuthRequest.get(uri, config)

  JSON.parse(response.body)
end