Class: ReleaseHx::REST::YamlClient

Inherits:
Object
  • Object
show all
Defined in:
lib/releasehx/rest/yaml_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, version = nil) ⇒ YamlClient

Returns a new instance of YamlClient.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/releasehx/rest/yaml_client.rb', line 16

def initialize config, version = nil
  @version = version
  @config = config
  @origin_cfg = config['origin'] || {}
  @origin_source = @origin_cfg['source']
  @vars = build_scope
  @client_def = load_render_client_def
  @resolved_values = {}
  @cache_config = config.dig('paths', 'cache') || {}
  @raw_response = nil
  normalize_fields!
  setup_connection
  perform_resolutions!
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.


14
15
16
# File 'lib/releasehx/rest/yaml_client.rb', line 14

def raw_response
  @raw_response
end

Instance Method Details

#fetch_allObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/releasehx/rest/yaml_client.rb', line 31

def fetch_all
  # Check for cached response first (unless force fetch is requested)
  if cache_enabled? && !force_fetch_requested? && (cached_data = cached_response)
    ReleaseHx.logger.info "Using cached API response (#{cached_data.size} items) from #{@origin_source}"
    return cached_data
  end

  # Fetch fresh data from API
  results = fetch_fresh_data

  # Save to cache if caching is enabled
  save_to_cache(results) if cache_enabled?

  ReleaseHx.logger.info "Fetched #{results.size} items from #{@origin_source} API"
  results
end

#fetch_fresh_dataObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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/releasehx/rest/yaml_client.rb', line 48

def fetch_fresh_data
  results = []

  if pagination?
    page_param     = pagination['param']
    page_size_key  = pagination['page_size_param']
    page_size_val  = pagination['page_size']

    current_index = 0
    loop_count = 0
    max_pages = pagination['max_pages'] || 100

    loop do
      query = query_params.merge(
        {
          page_param => current_index,
                      page_size_key => page_size_val
        })

      # Report to logger debug the API URL and query params
      ReleaseHx.logger.debug "Fetching from: #{@href} with query: #{query.inspect}"

      resp = @conn.get(@href, query, @headers)
      body = resp.body
      raise "HTTP Error #{resp.status}" unless resp.success?

      # Save raw response from first page for payload export
      @raw_response = body if loop_count.zero?

      issues = extract_issues_from_response(body)
      results.concat(Array(issues))

      break if issues.nil? || issues.size.to_i < page_size_val

      current_index += page_size_val
      loop_count += 1
      break if loop_count >= max_pages
    end
  else
    resp = @conn.get(@href, query_params, @headers)
    raise "HTTP Error #{resp.status}" unless resp.success?

    # Save raw response before extraction
    @raw_response = resp.body

    issues = extract_issues_from_response(resp.body)
    results = Array(issues)
  end

  results
end