Class: StrixRuby::Client
- Inherits:
-
Object
- Object
- StrixRuby::Client
- Defined in:
- lib/strix_ruby/client.rb
Overview
Main client for interacting with the Strix Integration API
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
-
#clear_token! ⇒ Object
Clear the cached token.
-
#get_trail_locations(thing_id:, date_from:, date_to:, limit: 100, page: 1, type: "valid") ⇒ Hash
Get trail locations for a thing.
-
#get_trail_summarized(thing_id:, date_from:, date_to:, type: "_valid") ⇒ Hash
Get summarized trail for a thing.
-
#initialize(base_url: nil, username: nil, password: nil, account_id: nil) ⇒ Client
constructor
Initialize a new client.
-
#list_things(account_id: nil) ⇒ Hash
List all things in an account.
-
#list_things_filtered(types:, account_id: nil) ⇒ Hash
List things with filters.
-
#refresh_token! ⇒ String
Force refresh of the access token.
-
#token_account_id ⇒ String?
Returns the account_id extracted from the JWT token.
Constructor Details
#initialize(base_url: nil, username: nil, password: nil, account_id: nil) ⇒ Client
Initialize a new client
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/strix_ruby/client.rb', line 21 def initialize(base_url: nil, username: nil, password: nil, account_id: nil) @base_url = base_url || StrixRuby.configuration&.base_url @username = username || StrixRuby.configuration&.username @password = password || StrixRuby.configuration&.password @account_id = account_id || StrixRuby.configuration&.account_id validate_configuration! @connection = Connection.new(base_url: @base_url) @token_manager = TokenManager.new( connection: @connection, username: @username, password: @password ) end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
6 7 8 |
# File 'lib/strix_ruby/client.rb', line 6 def account_id @account_id end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
6 7 8 |
# File 'lib/strix_ruby/client.rb', line 6 def base_url @base_url end |
Instance Method Details
#clear_token! ⇒ Object
Clear the cached token
105 106 107 |
# File 'lib/strix_ruby/client.rb', line 105 def clear_token! @token_manager.clear! end |
#get_trail_locations(thing_id:, date_from:, date_to:, limit: 100, page: 1, type: "valid") ⇒ Hash
Get trail locations for a thing
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/strix_ruby/client.rb', line 68 def get_trail_locations(thing_id:, date_from:, date_to:, limit: 100, page: 1, type: "valid") authenticated_get( "/v1.5/things/#{thing_id}/trail_locations", params: { _from: datetime_to_ms(date_from), _to: datetime_to_ms(date_to), _limit: limit, _page: page, _type: type } ) end |
#get_trail_summarized(thing_id:, date_from:, date_to:, type: "_valid") ⇒ Hash
Get summarized trail for a thing
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/strix_ruby/client.rb', line 87 def get_trail_summarized(thing_id:, date_from:, date_to:, type: "_valid") authenticated_get( "/v1.5/things/#{thing_id}/trail_summarized", params: { _from: datetime_to_ms(date_from), _to: datetime_to_ms(date_to), _type: type } ) end |
#list_things(account_id: nil) ⇒ Hash
List all things in an account
40 41 42 43 |
# File 'lib/strix_ruby/client.rb', line 40 def list_things(account_id: nil) resolved_account_id = resolve_account_id(account_id) authenticated_get("/v1.5/accounts/#{resolved_account_id}/things") end |
#list_things_filtered(types:, account_id: nil) ⇒ Hash
List things with filters
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/strix_ruby/client.rb', line 49 def list_things_filtered(types:, account_id: nil) resolved_account_id = resolve_account_id(account_id) authenticated_get( "/v1.5/things", params: { account_id: resolved_account_id, types: types } ) end |
#refresh_token! ⇒ String
Force refresh of the access token
100 101 102 |
# File 'lib/strix_ruby/client.rb', line 100 def refresh_token! @token_manager.refresh_token end |
#token_account_id ⇒ String?
Returns the account_id extracted from the JWT token
10 11 12 13 14 |
# File 'lib/strix_ruby/client.rb', line 10 def token_account_id # Ensure token is fetched first @token_manager.access_token @token_manager.token_account_id end |