Class: HybiscusPdfReport::Request
- Inherits:
-
Object
- Object
- HybiscusPdfReport::Request
- Defined in:
- lib/hybiscus_pdf_report/request.rb
Overview
Request Handler with the individual endpoints handling the communication with the Hybiscus PDF Reports API
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#last_request_time_counting_against_rate_limit ⇒ Object
readonly
Returns the value of attribute last_request_time_counting_against_rate_limit.
-
#last_task_id ⇒ Object
readonly
Returns the value of attribute last_task_id.
-
#last_task_status ⇒ Object
readonly
Returns the value of attribute last_task_status.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#build_report(report_request_as_json) ⇒ Object
rubocop: disable Naming/AccessorMethodName method names are inline with the Hybiscus API endpoint names.
- #get_last_report ⇒ Object
- #get_last_task_status ⇒ Object
- #get_remaining_quota ⇒ Object
- #get_report(task_id) ⇒ Object
-
#get_task_status(task_id) ⇒ Object
GET.
-
#initialize(client) ⇒ Request
constructor
A new instance of Request.
-
#preview_report(report_request_as_json) ⇒ Object
POST.
Constructor Details
#initialize(client) ⇒ Request
Returns a new instance of Request.
12 13 14 15 |
# File 'lib/hybiscus_pdf_report/request.rb', line 12 def initialize(client) @client = client @response = nil end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/hybiscus_pdf_report/request.rb', line 10 def client @client end |
#last_request_time_counting_against_rate_limit ⇒ Object (readonly)
Returns the value of attribute last_request_time_counting_against_rate_limit.
10 11 12 |
# File 'lib/hybiscus_pdf_report/request.rb', line 10 def last_request_time_counting_against_rate_limit @last_request_time_counting_against_rate_limit end |
#last_task_id ⇒ Object (readonly)
Returns the value of attribute last_task_id.
10 11 12 |
# File 'lib/hybiscus_pdf_report/request.rb', line 10 def last_task_id @last_task_id end |
#last_task_status ⇒ Object (readonly)
Returns the value of attribute last_task_status.
10 11 12 |
# File 'lib/hybiscus_pdf_report/request.rb', line 10 def last_task_status @last_task_status end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/hybiscus_pdf_report/request.rb', line 10 def response @response end |
Instance Method Details
#build_report(report_request_as_json) ⇒ Object
rubocop: disable Naming/AccessorMethodName method names are inline with the Hybiscus API endpoint names. This is more explicit and easier to understand than following rubocop conventions.
20 21 22 23 24 25 26 |
# File 'lib/hybiscus_pdf_report/request.rb', line 20 def build_report(report_request_as_json) response_body = request(endpoint: "build-report", http_method: :post, body: report_request_as_json) ## HANDLE 402 RESPONSE --> PAYMENT REQUIRED update_last_request_information(response_body) @response = Response.new(response_body) end |
#get_last_report ⇒ Object
55 56 57 58 59 |
# File 'lib/hybiscus_pdf_report/request.rb', line 55 def get_last_report raise ArgumentError, "No task_id available. Please call build_report or preview_report first." unless last_task_id get_report(last_task_id) end |
#get_last_task_status ⇒ Object
44 45 46 47 48 |
# File 'lib/hybiscus_pdf_report/request.rb', line 44 def get_last_task_status raise ArgumentError, "No task_id available. Please call build_report or preview_report first." unless last_task_id get_task_status(last_task_id) end |
#get_remaining_quota ⇒ Object
61 62 63 64 65 |
# File 'lib/hybiscus_pdf_report/request.rb', line 61 def get_remaining_quota response_body = request(endpoint: "get-remaining-quota", http_method: :get) Response.new response_body end |
#get_report(task_id) ⇒ Object
50 51 52 53 |
# File 'lib/hybiscus_pdf_report/request.rb', line 50 def get_report(task_id) response_body = request(endpoint: "get-report", http_method: :get, params: { task_id: task_id }) Response.new(report: Base64.encode64(response_body), status: HTTP_OK_CODE) end |
#get_task_status(task_id) ⇒ Object
GET
36 37 38 39 40 41 42 |
# File 'lib/hybiscus_pdf_report/request.rb', line 36 def get_task_status(task_id) response_body = request(endpoint: "get-task-status", params: { task_id: task_id }) # The last task status is stored. If this method is called with the same task_id, the last task status is updated # in the instance variable @last_task_status = response_body["status"] if last_task_id == task_id Response.new(response_body) end |
#preview_report(report_request_as_json) ⇒ Object
POST
29 30 31 32 33 |
# File 'lib/hybiscus_pdf_report/request.rb', line 29 def preview_report(report_request_as_json) response_body = request(endpoint: "preview-report", http_method: :post, body: report_request_as_json) update_last_request_information(response_body) Response.new(response_body) end |