Class: X::Client
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.twitter.com/2/".freeze
- DEFAULT_ARRAY_CLASS =
Array
- DEFAULT_OBJECT_CLASS =
Hash
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_key_secret ⇒ Object
Returns the value of attribute api_key_secret.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
-
#default_array_class ⇒ Object
Returns the value of attribute default_array_class.
-
#default_object_class ⇒ Object
Returns the value of attribute default_object_class.
Instance Method Summary collapse
- #delete(endpoint, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
- #get(endpoint, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
-
#initialize(api_key: nil, api_key_secret: nil, access_token: nil, access_token_secret: nil, bearer_token: nil, base_url: DEFAULT_BASE_URL, open_timeout: Connection::DEFAULT_OPEN_TIMEOUT, read_timeout: Connection::DEFAULT_READ_TIMEOUT, write_timeout: Connection::DEFAULT_WRITE_TIMEOUT, debug_output: Connection::DEFAULT_DEBUG_OUTPUT, proxy_url: nil, default_array_class: DEFAULT_ARRAY_CLASS, default_object_class: DEFAULT_OBJECT_CLASS, max_redirects: RedirectHandler::DEFAULT_MAX_REDIRECTS) ⇒ Client
constructor
A new instance of Client.
- #post(endpoint, body = nil, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
- #put(endpoint, body = nil, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
Constructor Details
#initialize(api_key: nil, api_key_secret: nil, access_token: nil, access_token_secret: nil, bearer_token: nil, base_url: DEFAULT_BASE_URL, open_timeout: Connection::DEFAULT_OPEN_TIMEOUT, read_timeout: Connection::DEFAULT_READ_TIMEOUT, write_timeout: Connection::DEFAULT_WRITE_TIMEOUT, debug_output: Connection::DEFAULT_DEBUG_OUTPUT, proxy_url: nil, default_array_class: DEFAULT_ARRAY_CLASS, default_object_class: DEFAULT_OBJECT_CLASS, max_redirects: RedirectHandler::DEFAULT_MAX_REDIRECTS) ⇒ Client
Returns a new instance of Client.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/x/client.rb', line 25 def initialize(api_key: nil, api_key_secret: nil, access_token: nil, access_token_secret: nil, bearer_token: nil, base_url: DEFAULT_BASE_URL, open_timeout: Connection::DEFAULT_OPEN_TIMEOUT, read_timeout: Connection::DEFAULT_READ_TIMEOUT, write_timeout: Connection::DEFAULT_WRITE_TIMEOUT, debug_output: Connection::DEFAULT_DEBUG_OUTPUT, proxy_url: nil, default_array_class: DEFAULT_ARRAY_CLASS, default_object_class: DEFAULT_OBJECT_CLASS, max_redirects: RedirectHandler::DEFAULT_MAX_REDIRECTS) initialize_oauth(api_key, api_key_secret, access_token, access_token_secret, bearer_token) initialize_authenticator @base_url = base_url initialize_default_classes(default_array_class, default_object_class) @connection = Connection.new(open_timeout: open_timeout, read_timeout: read_timeout, write_timeout: write_timeout, debug_output: debug_output, proxy_url: proxy_url) @request_builder = RequestBuilder.new @redirect_handler = RedirectHandler.new(connection: @connection, request_builder: @request_builder, max_redirects: max_redirects) @response_parser = ResponseParser.new end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
18 19 20 |
# File 'lib/x/client.rb', line 18 def access_token @access_token end |
#access_token_secret ⇒ Object
Returns the value of attribute access_token_secret.
18 19 20 |
# File 'lib/x/client.rb', line 18 def access_token_secret @access_token_secret end |
#api_key ⇒ Object
Returns the value of attribute api_key.
18 19 20 |
# File 'lib/x/client.rb', line 18 def api_key @api_key end |
#api_key_secret ⇒ Object
Returns the value of attribute api_key_secret.
18 19 20 |
# File 'lib/x/client.rb', line 18 def api_key_secret @api_key_secret end |
#base_url ⇒ Object
Returns the value of attribute base_url.
17 18 19 |
# File 'lib/x/client.rb', line 17 def base_url @base_url end |
#bearer_token ⇒ Object
Returns the value of attribute bearer_token.
18 19 20 |
# File 'lib/x/client.rb', line 18 def bearer_token @bearer_token end |
#default_array_class ⇒ Object
Returns the value of attribute default_array_class.
17 18 19 |
# File 'lib/x/client.rb', line 17 def default_array_class @default_array_class end |
#default_object_class ⇒ Object
Returns the value of attribute default_object_class.
17 18 19 |
# File 'lib/x/client.rb', line 17 def default_object_class @default_object_class end |
Instance Method Details
#delete(endpoint, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
63 64 65 |
# File 'lib/x/client.rb', line 63 def delete(endpoint, headers: {}, array_class: default_array_class, object_class: default_object_class) execute_request(:delete, endpoint, headers: headers, array_class: array_class, object_class: object_class) end |
#get(endpoint, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
49 50 51 |
# File 'lib/x/client.rb', line 49 def get(endpoint, headers: {}, array_class: default_array_class, object_class: default_object_class) execute_request(:get, endpoint, headers: headers, array_class: array_class, object_class: object_class) end |
#post(endpoint, body = nil, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
53 54 55 56 |
# File 'lib/x/client.rb', line 53 def post(endpoint, body = nil, headers: {}, array_class: default_array_class, object_class: default_object_class) execute_request(:post, endpoint, body: body, headers: headers, array_class: array_class, object_class: object_class) end |
#put(endpoint, body = nil, headers: {}, array_class: default_array_class, object_class: default_object_class) ⇒ Object
58 59 60 61 |
# File 'lib/x/client.rb', line 58 def put(endpoint, body = nil, headers: {}, array_class: default_array_class, object_class: default_object_class) execute_request(:put, endpoint, body: body, headers: headers, array_class: array_class, object_class: object_class) end |