Class: Schematic::Events::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/schematic/events/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create_event(request_options: {}, **params) ⇒ Schematic::Events::Types::CreateEventResponse

Examples:

client.events.create_event(event_type: "flag_check")

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/schematic/events/client.rb', line 174

def create_event(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "events",
    body: Schematic::Types::CreateEventRequestBody.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Events::Types::CreateEventResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_event_batch(request_options: {}, **params) ⇒ Schematic::Events::Types::CreateEventBatchResponse

Examples:

client.events.create_event_batch(events: [{
  event_type: "flag_check"
}])

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/schematic/events/client.rb', line 27

def create_event_batch(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "event-batch",
    body: Schematic::Events::Types::CreateEventBatchRequestBody.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Events::Types::CreateEventBatchResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_event(request_options: {}, **params) ⇒ Schematic::Events::Types::GetEventResponse

Examples:

client.events.get_event(event_id: "event_id")

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :event_id (String)

Returns:



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/schematic/events/client.rb', line 210

def get_event(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "events/#{URI.encode_uri_component(params[:event_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Events::Types::GetEventResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_event_summaries(request_options: {}, **params) ⇒ Schematic::Events::Types::GetEventSummariesResponse

Examples:

client.events.get_event_summaries(
  q: "q",
  event_subtypes: ["event_subtypes"],
  limit: 1000000,
  offset: 1000000
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :q (String, nil)
  • :event_subtypes (String, nil)
  • :limit (Integer, nil)
  • :offset (Integer, nil)

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/schematic/events/client.rb', line 71

def get_event_summaries(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["q"] = params[:q] if params.key?(:q)
  query_params["event_subtypes"] = params[:event_subtypes] if params.key?(:event_subtypes)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["offset"] = params[:offset] if params.key?(:offset)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "event-types",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Events::Types::GetEventSummariesResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#get_segment_integration_status(request_options: {}, **_params) ⇒ Schematic::Events::Types::GetSegmentIntegrationStatusResponse

Examples:

client.events.get_segment_integration_status

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/schematic/events/client.rb', line 244

def get_segment_integration_status(request_options: {}, **_params)
  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "segment-integration",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Events::Types::GetSegmentIntegrationStatusResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_events(request_options: {}, **params) ⇒ Schematic::Events::Types::ListEventsResponse

Examples:

client.events.list_events(
  company_id: "company_id",
  event_subtype: "event_subtype",
  event_types: ["flag_check"],
  flag_id: "flag_id",
  idempotency_key: "idempotency_key",
  user_id: "user_id",
  limit: 1000000,
  offset: 1000000
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :company_id (String, nil)
  • :event_subtype (String, nil)
  • :event_types (Schematic::Types::EventType, nil)
  • :flag_id (String, nil)
  • :idempotency_key (String, nil)
  • :user_id (String, nil)
  • :limit (Integer, nil)
  • :offset (Integer, nil)

Returns:



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/schematic/events/client.rb', line 129

def list_events(request_options: {}, **params)
  params = Schematic::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["event_subtype"] = params[:event_subtype] if params.key?(:event_subtype)
  query_params["event_types"] = params[:event_types] if params.key?(:event_types)
  query_params["flag_id"] = params[:flag_id] if params.key?(:flag_id)
  query_params["idempotency_key"] = params[:idempotency_key] if params.key?(:idempotency_key)
  query_params["user_id"] = params[:user_id] if params.key?(:user_id)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["offset"] = params[:offset] if params.key?(:offset)

  request = Schematic::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "events",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Schematic::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Schematic::Events::Types::ListEventsResponse.load(response.body)
  else
    error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end