Class: FortyTwo::Client
- Inherits:
-
Object
- Object
- FortyTwo::Client
- Defined in:
- lib/fortytwo/client.rb
Constant Summary collapse
- API_HOST =
'https://api.intra.42.fr'
- REQUEST_CLASSES =
[FortyTwo::Endpoint::User, FortyTwo::Endpoint::Users, FortyTwo::Endpoint::UserSessions]
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #check_api_keys ⇒ Object
- #configure {|@configuration| ... } ⇒ Object
-
#initialize(options = nil) ⇒ Client
constructor
A new instance of Client.
- #token ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 |
# File 'lib/fortytwo/client.rb', line 17 def initialize( = nil) @configuration = nil define_request_methods unless .nil? @configuration = Configuration.new() check_api_keys end end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/fortytwo/client.rb', line 15 def configuration @configuration end |
Instance Method Details
#check_api_keys ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/fortytwo/client.rb', line 33 def check_api_keys if configuration.nil? || configuration.invalid? @configuration = nil else @configuration.freeze end end |
#configure {|@configuration| ... } ⇒ Object
27 28 29 30 31 |
# File 'lib/fortytwo/client.rb', line 27 def configure @configuration = Configuration.new yield(@configuration) check_api_keys end |
#token ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/fortytwo/client.rb', line 41 def token return @token if instance_variable_defined?(:@token) check_api_keys api_key = @configuration.api_key api_secret = @configuration.api_secret client = OAuth2::Client.new(api_key, api_secret, site: API_HOST) client.client_credentials.get_token end |