Class: Gitter::API::Client
- Inherits:
-
Object
- Object
- Gitter::API::Client
- Defined in:
- lib/gitter/api/client.rb
Overview
The Gitter::API::Client is the main http component, and is in charge of auth and configuration of the base endpoint of the gitter API that is being connected to and interacted with.
Usage
Client Setup
In most cases, only a token is needed for the client instance:
client = Gitter::API::Client.new :token => "1a2b3c4d5e6f7a8b9c0d"
Example Queries
Fetching the configured user:
client.user
#=> #<Gitter::API::User:0x00007ff49b293c01 ... >
Fetch rooms/private chats for the configured user:
client.rooms
client.user.rooms # same as client.rooms, but is not memoized
#=> #<Gitter::API::Room::Collection:0x00007ff49b293c02 ... >
API Collections are Enumerable:
client.rooms.map(&:uri)
#=> ["gitterHQ/sandbox", "gitterHQ/api"]
See individual model classes for more examples
Additional methods
Gitter::API::User and Gitter::API::Room each provide methods that are included in the client as base methods. Refer to those classes for more info.
Instance Attribute Summary collapse
-
#api_prefix ⇒ Object
readonly
See Gitter::API::Config#api_prefix.
-
#api_uri ⇒ Object
(also: #uri)
readonly
See Gitter::API::Config#api_uri.
-
#auth_token ⇒ Object
readonly
Client User API token.
-
#ssl_verify ⇒ Object
readonly
See Gitter::API::Config#ssl_verify.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
Initialize a new
Gitter::API::Client.
Methods included from Room::ClientMethods
#find_room, #join_room, #rooms
Methods included from User::ClientMethods
Methods included from Net::HTTP::RestClientModule
#connection, #get, #post, #put
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize a new Gitter::API::Client
Aside from :token, all other options will be defaulted to what is configured in Gitter::API::Config
See Gitter::API::Config for defaults.
Options
(symbol keys only)
- :token (String)
-
(required) Auth token for the API client user
- :api_prefix (String)
-
Path prefix for all API routes
- :api_uri (URI)
-
Endpoint URI of the configured gitter API
- :ssl_verify (Boolean)
-
Indicates if net/http should verify ssl certs
95 96 97 98 99 100 |
# File 'lib/gitter/api/client.rb', line 95 def initialize = {} @api_prefix = [:api_prefix] || Config.api_prefix @api_uri = [:api_uri] || Config.api_uri @auth_token = [:token] @ssl_verify = .key? :ssl_verify ? [:ssl_verify] : Config.ssl_verify end |
Instance Attribute Details
#api_prefix ⇒ Object (readonly)
See Gitter::API::Config#api_prefix
66 67 68 |
# File 'lib/gitter/api/client.rb', line 66 def api_prefix @api_prefix end |
#api_uri ⇒ Object (readonly) Also known as: uri
See Gitter::API::Config#api_uri
63 64 65 |
# File 'lib/gitter/api/client.rb', line 63 def api_uri @api_uri end |
#auth_token ⇒ Object (readonly)
Client User API token
69 70 71 |
# File 'lib/gitter/api/client.rb', line 69 def auth_token @auth_token end |
#ssl_verify ⇒ Object (readonly)
See Gitter::API::Config#ssl_verify
72 73 74 |
# File 'lib/gitter/api/client.rb', line 72 def ssl_verify @ssl_verify end |