Class: Multiwoven::Integrations::Source::Http::Client
- Inherits:
-
SourceConnector
- Object
- SourceConnector
- Multiwoven::Integrations::Source::Http::Client
- Defined in:
- lib/multiwoven/integrations/source/http/client.rb
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(connection_config) ⇒ Object
- #read(sync_config) ⇒ Object
Instance Method Details
#check_connection(connection_config) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/multiwoven/integrations/source/http/client.rb', line 7 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[:headers], 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/multiwoven/integrations/source/http/client.rb', line 30 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[:headers], 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. rescue StandardError => e handle_exception(e, { context: "HTTP:DISCOVER:EXCEPTION", type: "error" }) end |
#read(sync_config) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/multiwoven/integrations/source/http/client.rb', line 55 def read(sync_config) connection_config = sync_config.source.connection_specification connection_config = connection_config.with_indifferent_access 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 |