hybiscus_pdf_report 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 688afeb6ab9c2d4cd50f375c6b3e3817d50f917ba2d489b7860f4afd5bbc1fb5
4
- data.tar.gz: 57da67ca7e60bbcda279c5c9b23672d230e1116e34acf10a49c260df3edbbb66
3
+ metadata.gz: 0007a7c6d4494de9ca87ab92f259b192ad550d26172d225f5be109823a514298
4
+ data.tar.gz: ccc6a69f6c7d28b34b168a240b059c9e54c51a0802097ff829bb07111909ea53
5
5
  SHA512:
6
- metadata.gz: 113df65983859e7e7cbb6dca38fe6abf720dd25522c1a1e45ccaf0ffbc5f56a2b78a64eaa29ab1a2b709327b7a707bd0ed88ed967b1837e949fe00d743cabb1c
7
- data.tar.gz: 5aac878fc6d8ea65f6621e752b3f77edec8fb0ded23e8410473505070c2697212b3cc8836c69f60d3355ff041b875f61c795e396b8b65ab57a0455eee2b18cbf
6
+ metadata.gz: efbe50eb7882ce18576a146b77593e19364176b819973ded959f57d1f6a279982789839fb2503e34f66ca2022ff2bff5148d5c3c76d7f8ccb249cc68df756a4e
7
+ data.tar.gz: 63c0076efef641022cbf9be95a074bb0903b9386308ab7eb1541b6d2a456854c55831e4e17ab08171cf56fe41e4c33f4aa59605ff36edd937c2437cf5363f879
@@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.files = Dir.chdir(__dir__) do
24
24
  `git ls-files -z`.split("\x0").reject do |f|
25
25
  (File.expand_path(f) == __FILE__) ||
26
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .gitlab-ci.yml appveyor Gemfile])
26
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .gitlab-ci.yml appveyor Gemfile]) ||
27
+ f.end_with?(".gem")
27
28
  end
28
29
  end
29
30
  spec.bindir = "exe"
@@ -5,11 +5,30 @@ require_relative "api_errors"
5
5
  require_relative "config"
6
6
 
7
7
  module HybiscusPdfReport
8
- # Client handling the Faraday connection to the Hybiscus PDF Reports API
8
+ # HTTP client for the Hybiscus PDF Reports API.
9
+ #
10
+ # This class handles all HTTP communication with the Hybiscus API, including
11
+ # authentication, connection management, and request routing. It uses Faraday
12
+ # for HTTP requests and supports custom adapters for testing.
13
+ #
14
+ # @example Basic usage
15
+ # client = HybiscusPdfReport::Client.new(api_key: "your_api_key")
16
+ # response = client.request.build_report(report_data)
17
+ #
18
+ # @example Using environment variables
19
+ # ENV["HYBISCUS_API_KEY"] = "your_api_key"
20
+ # client = HybiscusPdfReport::Client.new
21
+ #
22
+ # @example Custom configuration
23
+ # client = HybiscusPdfReport::Client.new(
24
+ # api_key: "your_key",
25
+ # api_url: "https://api.hybiscus.dev/api/v1/",
26
+ # timeout: 30
27
+ # )
9
28
  class Client
10
29
  attr_reader :api_key, :api_url, :adapter, :last_request
11
30
 
12
- # rubocop:disable Metrics/CyclomaticComplexity)
31
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
13
32
  def initialize(api_key: nil, api_url: nil, timeout: nil, adapter: nil, stubs: nil)
14
33
  @api_key = (api_key || config.api_key)&.strip
15
34
  if @api_key.nil? || @api_key.empty?
@@ -25,7 +44,7 @@ module HybiscusPdfReport
25
44
  @adapter = adapter || config.adapter
26
45
  @stubs = stubs || config.stubs
27
46
  end
28
- # rubocop:enable Metrics/CyclomaticComplexity)
47
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
29
48
 
30
49
  def request
31
50
  @request ||= Request.new(self)
@@ -2,11 +2,28 @@
2
2
 
3
3
  require "faraday"
4
4
 
5
+ # Main module for the Hybiscus PDF Report gem
5
6
  module HybiscusPdfReport
7
+ # Configuration class for the Hybiscus PDF Report gem.
8
+ #
9
+ # This class manages all configuration settings including API credentials,
10
+ # URLs, timeouts, and connection adapters. Configuration can be set through
11
+ # environment variables or programmatically.
12
+ #
13
+ # @example Setting configuration programmatically
14
+ # HybiscusPdfReport.configure do |config|
15
+ # config.api_key = "your_api_key"
16
+ # config.api_url = "https://api.hybiscus.dev/api/v1/"
17
+ # config.timeout = 30
18
+ # end
19
+ #
20
+ # @example Using environment variables
21
+ # ENV["HYBISCUS_API_KEY"] = "your_api_key"
22
+ # ENV["HYBISCUS_API_URL"] = "https://api.hybiscus.dev/api/v1/"
6
23
  class Config
7
24
  attr_accessor :api_key, :api_url, :timeout, :adapter, :stubs
8
25
 
9
- DEFAULT_API_URL = "https://api.hybiscus.dev/api/v1/".freeze
26
+ DEFAULT_API_URL = "https://api.hybiscus.dev/api/v1/"
10
27
  DEFAULT_TIMEOUT = 10
11
28
 
12
29
  def initialize
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Legacy placeholder file for backward compatibility
4
+ # This file exists for historical reasons and may be removed in future versions.
5
+ # Use HybiscusPdfReport::ResponseObject instead.
6
+ module HybiscusPdfReport
7
+ # Placeholder for legacy compatibility
8
+ # @deprecated Use ResponseObject instead
9
+ module Object
10
+ # This module is deprecated
11
+ end
12
+ end
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Response wrapper class for Hybiscus PDF Report API responses
3
4
  require_relative "../response_object"
5
+
4
6
  module HybiscusPdfReport
7
+ # Standard response object that inherits from ResponseObject
5
8
  class Response < HybiscusPdfReport::ResponseObject
6
9
  end
7
10
  end
@@ -1,52 +1,99 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "erb"
4
+ require "pathname"
5
+
3
6
  module HybiscusPdfReport
4
- # Base class for all objects returned by the Hybiscus PDF Reports API
7
+ # Base class for building PDF reports with JSON templates
8
+ #
9
+ # This class allows users to create custom report builders by inheriting from it.
10
+ # It provides a simple way to generate JSON structures for the Hybiscus API using ERB templates.
11
+ #
12
+ # Usage:
13
+ # class InvoiceReport < HybiscusPdfReport::ReportBuilder
14
+ # def initialize(invoice:, **options)
15
+ # @invoice = invoice
16
+ # super(report_name: "Invoice Report", **options)
17
+ # end
18
+ # end
19
+ #
20
+ # report = InvoiceReport.new(invoice: my_invoice)
21
+ # json_data = report.generate
5
22
  class ReportBuilder
6
23
  DEFAULT_TEMPLATE_DIR = File.dirname(__FILE__)
7
24
 
8
- def initialize(report_name: nil, **template_params)
9
- # Dynamically set all parameters as instance variables
10
- @report_name = report_name ||  self.name.demodulize.humanize.titleize
25
+ attr_reader :report_name, :template_dir
11
26
 
27
+ def initialize(report_name: nil, template_dir: nil, **template_params)
28
+ # Set the report name - use provided name or derive from class name
29
+ @report_name = report_name || derive_report_name
30
+ @template_dir = template_dir || DEFAULT_TEMPLATE_DIR
31
+
32
+ # Dynamically set all parameters as instance variables
12
33
  template_params.each do |key, value|
13
34
  instance_variable_set("@#{key}", value)
14
35
  end
15
36
  end
16
37
 
17
- # Main method to generate the report - similar to a controller action
38
+ # Main method to generate the report JSON
39
+ # Returns a JSON string that can be sent to the Hybiscus API
18
40
  def generate
19
- # Render the JSON template with all instance variables available
20
41
  render_json
21
42
  end
22
43
 
23
- def report_name
24
- @report_name = @report_name.presence(name.demodulize.humanize.titleize)
25
- end
26
-
44
+ # Returns the full path to the template file
27
45
  def template_path
28
- Pathname.new(template_path || DEFAULT_TEMPLATE_DIR)
46
+ File.join(template_dir, template_name)
29
47
  end
30
48
 
49
+ # Returns the template filename (can be overridden in subclasses)
31
50
  def template_name
32
- "#{name.demodulize.underscore}.json.erb"
51
+ "#{underscore(class_name)}.json.erb"
33
52
  end
34
53
 
35
54
  def load_configuration_first?
36
- # By default, we assume the print doesn't have a configuration.
37
- # This can be overridden in subclasses and will load the configuration first.
55
+ # By default, we assume the report doesn't require pre-loading configuration.
56
+ # This can be overridden in subclasses if configuration loading is needed.
38
57
  false
39
58
  end
40
59
 
41
60
  private
42
61
 
62
+ # Renders the ERB template with all instance variables available
43
63
  def render_json
44
- # Use ERB to render the JSON template with all instance variables available
45
- template_path = File.join(File.dirname(__FILE__), json_template)
46
- template = ERB.new(File.read(template_path))
64
+ unless File.exist?(template_path)
65
+ raise "Template file not found: #{template_path}. " \
66
+ "Create a template file or override the render_json method."
67
+ end
68
+
69
+ template_content = File.read(template_path)
70
+ template = ERB.new(template_content)
47
71
 
48
- # Render and return the JSON with all instance variables in scope
72
+ # Render the template with all instance variables in scope
49
73
  template.result(binding)
50
74
  end
75
+
76
+ # Derives a report name from the class name
77
+ def derive_report_name
78
+ humanize(class_name)
79
+ end
80
+
81
+ # Returns the class name without module prefix
82
+ def class_name
83
+ self.class.name.split("::").last
84
+ end
85
+
86
+ # Converts CamelCase to snake_case
87
+ def underscore(string)
88
+ string
89
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
90
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
91
+ .downcase
92
+ end
93
+
94
+ # Converts CamelCase to human readable format
95
+ def humanize(string)
96
+ underscore(string).tr("_", " ").split.map(&:capitalize).join(" ")
97
+ end
51
98
  end
52
99
  end
@@ -76,10 +76,7 @@ module HybiscusPdfReport
76
76
  @response = client.connection.public_send(http_method, endpoint, params.merge(body), headers)
77
77
  raise_error unless response_successful? && no_json_error?
78
78
 
79
- <<<<<<< HEAD
80
- =======
81
79
  # Return raw body for binary data (no JSON parsing)
82
- >>>>>>> updates
83
80
  @response.body
84
81
  end
85
82
 
@@ -95,11 +92,7 @@ module HybiscusPdfReport
95
92
  end
96
93
 
97
94
  def raise_error
98
- <<<<<<< HEAD
99
- logger.debug response.body
100
- =======
101
95
  # logger.debug response.body
102
- >>>>>>> updates
103
96
 
104
97
  raise error_class(response.status), "Code: #{response.status}, response: #{response.reason_phrase}"
105
98
  end
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- <<<<<<< HEAD
4
- =======
5
3
  require "faraday"
6
4
  require_relative "api_errors"
7
5
 
8
- >>>>>>> updates
9
6
  module HybiscusPdfReport
10
7
  # RequestRetryWrapper provides automatic retry logic for transient errors
11
8
  # when communicating with the Hybiscus API (e.g., rate limits, timeouts).
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Version information for the Hybiscus PDF Report gem
3
4
  module HybiscusPdfReport
4
- VERSION = "0.9.0"
5
+ VERSION = "0.9.1"
5
6
  end
@@ -19,6 +19,9 @@ module HybiscusPdfReport
19
19
  # Error handling
20
20
  autoload :APIErrors, "hybiscus_pdf_report/api_errors"
21
21
 
22
+ # Report building
23
+ autoload :ReportBuilder, "hybiscus_pdf_report/report_builder"
24
+
22
25
  # Module-level configuration
23
26
  def self.config
24
27
  @config ||= Config.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hybiscus_pdf_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Baumann
@@ -66,7 +66,6 @@ files:
66
66
  - LICENSE.txt
67
67
  - README.md
68
68
  - Rakefile
69
- - hybiscus_pdf_report.gem
70
69
  - hybiscus_pdf_report.gemspec
71
70
  - lib/hybiscus_pdf_report.rb
72
71
  - lib/hybiscus_pdf_report/api_errors.rb
Binary file