Class: Multiwoven::Integrations::Source::Http::Client
- Inherits:
-
SourceConnector
- Object
- SourceConnector
- Multiwoven::Integrations::Source::Http::Client
show all
- Includes:
- Core::OauthClientCredentials
- Defined in:
- lib/multiwoven/integrations/source/http/client.rb
Constant Summary
Core::OauthClientCredentials::AUTH_TYPE_OAUTH_CLIENT_CREDENTIALS, Core::OauthClientCredentials::TOKEN_EXPIRY_BUFFER_SECONDS
Instance Method Summary
collapse
#build_headers, #ensure_oauth_token
Instance Method Details
#check_connection(connection_config) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/multiwoven/integrations/source/http/client.rb', line 9
def check_connection(connection_config)
connection_config = prepare_config(connection_config)
create_connection(connection_config)
if connection_config[:sample_query].blank?
build_paginated_request(connection_config, {})
else
sample_query = JSON.parse(connection_config[:sample_query])
build_paginated_request(connection_config, sample_query.values.first)
end
response = send_request(
url: @url,
http_method: connection_config[:http_method],
payload: connection_config[:request_format],
headers: (connection_config),
config: connection_config[:config],
params: connection_config[:params]
)
success?(response) ? success_status : failure_status(nil)
rescue StandardError => e
handle_exception(e, { context: "HTTP:CHECK_CONNECTION:EXCEPTION", type: "error" })
failure_status(e)
end
|
#discover(connection_config) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/multiwoven/integrations/source/http/client.rb', line 32
def discover(connection_config)
connection_config = prepare_config(connection_config)
create_connection(connection_config)
if connection_config[:sample_query].blank?
build_paginated_request(connection_config, {})
else
sample_query = JSON.parse(connection_config[:sample_query])
build_paginated_request(connection_config, sample_query.values.first)
end
response = send_request(
url: @url,
http_method: connection_config[:http_method],
payload: connection_config[:request_format],
headers: (connection_config),
config: connection_config[:config],
params: connection_config[:params]
)
raise StandardError, "Response code: #{response.code}, Body: #{response.body}" unless success?(response)
catalog = Catalog.new(streams: create_streams(JSON.parse(response.body)))
catalog.to_multiwoven_message
rescue StandardError => e
handle_exception(e, { context: "HTTP:DISCOVER:EXCEPTION", type: "error" })
end
|
#read(sync_config) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/multiwoven/integrations/source/http/client.rb', line 57
def read(sync_config)
connection_config = sync_config.source.connection_specification
connection_config = connection_config.with_indifferent_access
@connector_instance = sync_config&.source&.connector_instance
connection_config = create_connection(connection_config)
if sync_config.increment_strategy_config&.increment_strategy == "page"
@limit = sync_config.increment_strategy_config.limit
@offset = sync_config.increment_strategy_config.offset
else
@limit = sync_config.limit
@offset = sync_config.offset
end
query = sync_config.model.query
query(connection_config, query)
rescue StandardError => e
handle_exception(e, {
context: "HTTP:READ:EXCEPTION",
type: "error",
sync_id: sync_config.sync_id,
sync_run_id: sync_config.sync_run_id
})
end
|