Class: PlatformSdk::Edkey::Client
- Inherits:
-
Object
- Object
- PlatformSdk::Edkey::Client
- Defined in:
- lib/platform_sdk/edkey/client.rb
Instance Attribute Summary collapse
-
#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.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_expires_at ⇒ Object
readonly
Returns the value of attribute token_expires_at.
Instance Method Summary collapse
- #access_token ⇒ Object
- #attendance(start_date, end_date) ⇒ Object
- #expired? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(base_url, client_id, client_secret) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(base_url, client_id, client_secret) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/platform_sdk/edkey/client.rb', line 8 def initialize(base_url, client_id, client_secret) @client_id = client_id @client_secret = client_secret @base_url = base_url # @token = "q8XNbZJRJjB4AkCgVlGAxjvEFYm7xeK9" @conn = Faraday.new(base_url) do |faraday| faraday.adapter :net_http faraday.request :json faraday.response :json faraday.response :raise_error end end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
6 7 8 |
# File 'lib/platform_sdk/edkey/client.rb', line 6 def base_url @base_url end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/platform_sdk/edkey/client.rb', line 6 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
6 7 8 |
# File 'lib/platform_sdk/edkey/client.rb', line 6 def client_secret @client_secret end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
6 7 8 |
# File 'lib/platform_sdk/edkey/client.rb', line 6 def conn @conn end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/platform_sdk/edkey/client.rb', line 6 def token @token end |
#token_expires_at ⇒ Object (readonly)
Returns the value of attribute token_expires_at.
6 7 8 |
# File 'lib/platform_sdk/edkey/client.rb', line 6 def token_expires_at @token_expires_at end |
Instance Method Details
#access_token ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/platform_sdk/edkey/client.rb', line 31 def access_token if expired? response = @conn.post("api/v2/auth/request-token", token_request_body.to_json, { "Content-Type" => "application/json", "Accept" => "*/*" }) @token = response.body["token"] @token_expires_at = DateTime.strptime(response.body["expires_at"], "%Y-%m-%d %H:%M:%S") end @token end |
#attendance(start_date, end_date) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/platform_sdk/edkey/client.rb', line 49 def attendance(start_date, end_date) path = "/api/v2/attendance-exporter/long-term" body = { startDate: start_date, endDate: end_date }.to_json response = @conn.post(path, body, headers) response.body end |
#expired? ⇒ Boolean
43 44 45 46 47 |
# File 'lib/platform_sdk/edkey/client.rb', line 43 def expired? return true if @token.nil? @token_expires_at < DateTime.now end |
#headers ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/platform_sdk/edkey/client.rb', line 23 def headers { "Authorization" => "Bearer #{access_token}", "Content-Type" => "application/json", "Accept" => "application/json" } end |