fulfil_api 0.6.0 → 0.6.2

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: ffd7b3a51a8fa0a8f76213567280c36f7c273115f46a6e397bbd3e8aefbc42df
4
- data.tar.gz: 854ab5226509922e32fbccfdf7a2b49a7f8a2af25e313776a6a6d4284f4666c4
3
+ metadata.gz: b08b66a980bb816b1424c5bdf4b6f07bdc652a0dc0838715b6176dd8dd3a52ac
4
+ data.tar.gz: e659a978bd939c89aafc27bab91d36c3af9daad8c2779f8e87ff7f9dc8203766
5
5
  SHA512:
6
- metadata.gz: 41e59d1b1d6a746d7fee0286d5af9290a6a38e474c45e3181a2a4ebca24ad5c7e65df00b6e84128763b5d753ba8a7e89bc7be0279de2c12c31c67298a866d610
7
- data.tar.gz: d5598d3ae10daf60f75272cba43d185bb8a14cb8070297e9ab560bbca3758728dae40e9639d0bd6123f69cc17a9add6b61ac1a0d6d9113ea5fcd5c6cdf6ccdd4
6
+ metadata.gz: 1da9f24a29088c2a177717731176b75ba29fcd9db6281ea7834ec2627e76b3b9029fb7f006ab428caba8035e68c39e221f77cf903145058820a2ebbb93e73552
7
+ data.tar.gz: de48831aca1ac5ebc8aed263e61ccd0bdb25728240504dbf43c6a91c298f253e8d566141a29c7cab7c67b2d8366704b0f1d4b40f436dd9ea005c582df5f4086e
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FulfilApi
4
+ # The {FulfilApi::Report} class provides an interface for generating reports
5
+ # (e.g., PDF invoices) via Fulfil's report API. The API returns a temporary
6
+ # URL where the generated document can be downloaded.
7
+ #
8
+ # @example Generate and download an invoice PDF
9
+ # report = FulfilApi::Report.generate("account.invoice.html", 3991)
10
+ # report.url # => "https://..."
11
+ # report.filename # => "Invoice.pdf"
12
+ # report.mimetype # => "application/pdf"
13
+ #
14
+ # tempfile = report.download
15
+ # tempfile.path # => "/tmp/fulfil_report20260324-12345.pdf"
16
+ class Report
17
+ attr_reader :filename, :mimetype, :url
18
+
19
+ # Generates a report for the given record ID.
20
+ #
21
+ # @param report_name [String] The report identifier (e.g., "account.invoice.html").
22
+ # @param id [Integer] The record ID to generate the report for.
23
+ # @param data [Hash] Optional additional data for the report.
24
+ # @return [FulfilApi::Report] A report object with filename, mimetype, and url.
25
+ def self.generate(report_name, id, data: {})
26
+ response = FulfilApi.client.put("report/#{report_name}", body: { objects: [id], data: data })
27
+
28
+ new(
29
+ filename: response["filename"],
30
+ mimetype: response["mimetype"],
31
+ url: response["url"]
32
+ )
33
+ end
34
+
35
+ # @param filename [String] The filename of the generated report.
36
+ # @param mimetype [String] The MIME type of the generated report.
37
+ # @param url [String] The temporary URL to download the generated report.
38
+ def initialize(filename:, mimetype:, url:)
39
+ @filename = filename
40
+ @mimetype = mimetype
41
+ @url = url
42
+ end
43
+
44
+ # Downloads the report from the temporary URL and returns a {Tempfile}.
45
+ #
46
+ # The tempfile preserves the file extension from the report's filename
47
+ # (e.g., ".pdf") so it can be used directly with file upload APIs.
48
+ #
49
+ # @return [Tempfile] A tempfile containing the downloaded report.
50
+ def download
51
+ response = Faraday.get(url)
52
+
53
+ extension = File.extname(filename)
54
+ tempfile = Tempfile.new(["fulfil_report", extension])
55
+ tempfile.binmode
56
+ tempfile.write(response.body)
57
+ tempfile.rewind
58
+ tempfile
59
+ end
60
+ end
61
+ end
@@ -65,6 +65,26 @@ module FulfilApi
65
65
  .and_return(status: status, body: response.to_json, headers: { "Content-Type": "application/json" })
66
66
  end
67
67
 
68
+ # Stubs an HTTP PUT request to the Fulfil report API based on the provided parameters.
69
+ #
70
+ # @param [Hash] response The response body to return as a JSON object (default is {}).
71
+ # @param [Integer] status The HTTP status code to return (default is 200).
72
+ # @param [Hash] options Additional options for the request URL.
73
+ # @option options [String] :report_name The report identifier
74
+ # (e.g., 'account.invoice.html').
75
+ #
76
+ # @return [WebMock::RequestStub] The WebMock request stub object.
77
+ #
78
+ # @example Stub a report request for a specific report
79
+ # stub_fulfil_report_request(report_name: "account.invoice.html", response: { url: "https://..." })
80
+ #
81
+ # @example Stub all report requests
82
+ # stub_fulfil_report_request(response: { url: "https://..." })
83
+ def stub_fulfil_report_request(response: {}, status: 200, **options)
84
+ stubbed_report_request_for(**options)
85
+ .and_return(status: status, body: response.to_json, headers: { "Content-Type": "application/json" })
86
+ end
87
+
68
88
  private
69
89
 
70
90
  # Builds the WebMock request stub for the Fulfil 3PL API based on the provided method and options.
@@ -84,6 +104,22 @@ module FulfilApi
84
104
  end
85
105
  end
86
106
 
107
+ # Builds the WebMock request stub for the Fulfil report API based on the provided options.
108
+ #
109
+ # @param [Hash] options Additional options for the request URL.
110
+ # @option options [String] :report_name The report identifier
111
+ # (e.g., 'account.invoice.html').
112
+ #
113
+ # @return [WebMock::RequestStub] The WebMock request stub object.
114
+ def stubbed_report_request_for(**options)
115
+ case options.transform_keys(&:to_sym)
116
+ in { report_name: }
117
+ stub_request(:put, %r{fulfil.io/api/v\d+/report/#{report_name}(.*)}i)
118
+ else
119
+ stub_request(:put, %r{fulfil.io/api/v\d+/report}i)
120
+ end
121
+ end
122
+
87
123
  # Builds the WebMock request stub for the Fulfil API based on the provided method and options.
88
124
  #
89
125
  # @param [String, Symbol] method The HTTP method to be stubbed (e.g., :get, :post).
@@ -127,8 +127,7 @@ module FulfilApi
127
127
  # @return [Hash] The HTTP headers for any HTTP request to the 3PL API.
128
128
  def request_headers
129
129
  {
130
- "Authorization" => "Bearer #{auth_token}",
131
- "Content-Type" => "application/json"
130
+ "Authorization" => "Bearer #{auth_token}"
132
131
  }
133
132
  end
134
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FulfilApi
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulfil_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Vermaas
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-03-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -92,6 +91,7 @@ files:
92
91
  - lib/fulfil_api/relation/loadable.rb
93
92
  - lib/fulfil_api/relation/naming.rb
94
93
  - lib/fulfil_api/relation/query_methods.rb
94
+ - lib/fulfil_api/report.rb
95
95
  - lib/fulfil_api/resource.rb
96
96
  - lib/fulfil_api/resource/attribute_assignable.rb
97
97
  - lib/fulfil_api/resource/attribute_type.rb
@@ -111,7 +111,6 @@ metadata:
111
111
  source_code_uri: https://www.github.com/codeturebv/fulfil_api
112
112
  changelog_uri: https://www.github.com/codeturebv/fulfil_api/blob/main/CHANGELOG.md
113
113
  rubygems_mfa_required: 'true'
114
- post_install_message:
115
114
  rdoc_options: []
116
115
  require_paths:
117
116
  - lib
@@ -126,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
125
  - !ruby/object:Gem::Version
127
126
  version: '0'
128
127
  requirements: []
129
- rubygems_version: 3.5.11
130
- signing_key:
128
+ rubygems_version: 4.0.3
131
129
  specification_version: 4
132
130
  summary: A HTTP client to interact the Fulfil.io API
133
131
  test_files: []