Class: StrixRuby::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/strix_ruby/client.rb

Overview

Main client for interacting with the Strix Integration API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, username: nil, password: nil, account_id: nil) ⇒ Client

Initialize a new client

Parameters:

  • base_url (String) (defaults to: nil)

    the base URL of the API (optional if globally configured)

  • username (String) (defaults to: nil)

    the API username (optional if globally configured)

  • password (String) (defaults to: nil)

    the API password (optional if globally configured)

  • account_id (String, Integer) (defaults to: nil)

    the default account ID (optional)



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 =  || StrixRuby.configuration&.

  validate_configuration!

  @connection = Connection.new(base_url: @base_url)
  @token_manager = TokenManager.new(
    connection: @connection,
    username: @username,
    password: @password
  )
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



6
7
8
# File 'lib/strix_ruby/client.rb', line 6

def 
  @account_id
end

#base_urlObject (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

Parameters:

  • thing_id (String, Integer)

    the thing ID

  • date_from (DateTime, Time)

    start date (will be converted to UTC milliseconds)

  • date_to (DateTime, Time)

    end date (will be converted to UTC milliseconds)

  • limit (Integer) (defaults to: 100)

    number of results per page (default: 100)

  • page (Integer) (defaults to: 1)

    page number (default: 1)

  • type (String) (defaults to: "valid")

    location type filter (default: ‘valid’)

Returns:

  • (Hash)

    the API response with trail locations



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

Parameters:

  • thing_id (String, Integer)

    the thing ID

  • date_from (DateTime, Time)

    start date (will be converted to UTC milliseconds)

  • date_to (DateTime, Time)

    end date (will be converted to UTC milliseconds)

  • type (String) (defaults to: "_valid")

    summary type filter (default: ‘_valid’)

Returns:

  • (Hash)

    the API response with trail summary



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

Parameters:

  • account_id (String, Integer, nil) (defaults to: nil)

    the account ID (uses configured account_id if not provided)

Returns:

  • (Hash)

    the API response with things list



40
41
42
43
# File 'lib/strix_ruby/client.rb', line 40

def list_things(account_id: nil)
   = ()
  authenticated_get("/v1.5/accounts/#{}/things")
end

#list_things_filtered(types:, account_id: nil) ⇒ Hash

List things with filters

Parameters:

  • account_id (String, Integer, nil) (defaults to: nil)

    the account ID (uses configured account_id if not provided)

  • types (String)

    thing type filter (e.g., ‘mrn:thing:vehicle’)

Returns:

  • (Hash)

    the API response with filtered things list



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)
   = ()
  authenticated_get(
    "/v1.5/things",
    params: {
      account_id: ,
      types: types
    }
  )
end

#refresh_token!String

Force refresh of the access token

Returns:

  • (String)

    the new access token



100
101
102
# File 'lib/strix_ruby/client.rb', line 100

def refresh_token!
  @token_manager.refresh_token
end

#token_account_idString?

Returns the account_id extracted from the JWT token

Returns:

  • (String, nil)

    the account_id from token’s meta.business_account_id



10
11
12
13
14
# File 'lib/strix_ruby/client.rb', line 10

def 
  # Ensure token is fetched first
  @token_manager.access_token
  @token_manager.
end