Class: LearnWorlds::Client
- Inherits:
-
Object
- Object
- LearnWorlds::Client
- Defined in:
- lib/learn_worlds/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#expires_in ⇒ Object
Returns the value of attribute expires_in.
Instance Method Summary collapse
- #authentication ⇒ Object
- #connection ⇒ Object
-
#initialize(client_id: nil, client_secret: nil, base_url: nil, access_token: nil) ⇒ Client
constructor
A new instance of Client.
- #required_headers ⇒ Object
- #sso ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(client_id: nil, client_secret: nil, base_url: nil, access_token: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 |
# File 'lib/learn_worlds/client.rb', line 11 def initialize(client_id: nil, client_secret: nil, base_url: nil, access_token: nil) @client_id = client_id || ENV.fetch('LEARN_WORLDS_CLIENT_ID') @client_secret = client_secret || ENV.fetch('LEARN_WORLDS_CLIENT_SECRET', nil) @base_url = base_url || ENV.fetch('LEARN_WORLDS_BASE_URL') @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/learn_worlds/client.rb', line 9 def access_token @access_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/learn_worlds/client.rb', line 8 def base_url @base_url end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/learn_worlds/client.rb', line 8 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
8 9 10 |
# File 'lib/learn_worlds/client.rb', line 8 def client_secret @client_secret end |
#expires_in ⇒ Object
Returns the value of attribute expires_in.
9 10 11 |
# File 'lib/learn_worlds/client.rb', line 9 def expires_in @expires_in end |
Instance Method Details
#authentication ⇒ Object
22 23 24 |
# File 'lib/learn_worlds/client.rb', line 22 def authentication AuthenticationResource.new(self) end |
#connection ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/learn_worlds/client.rb', line 30 def connection @connection ||= Faraday.new(base_url) do |conn| conn.request :json conn.response :json, content_type: "application/json" conn.headers = required_headers end end |
#required_headers ⇒ Object
38 39 40 41 42 43 |
# File 'lib/learn_worlds/client.rb', line 38 def required_headers headers = { 'Lw-Client': client_id } headers.merge({ Authorization: "Bearer #{access_token}" }) if access_token headers end |
#sso ⇒ Object
26 27 28 |
# File 'lib/learn_worlds/client.rb', line 26 def sso SingleSignOnResource.new(self) end |
#user ⇒ Object
18 19 20 |
# File 'lib/learn_worlds/client.rb', line 18 def user UserResource.new(self) end |