Class: PriceHubble::Client::Dossiers
- Defined in:
- lib/price_hubble/client/dossiers.rb
Overview
A high level client library for the PriceHubble Dossiers API.
Constant Summary
Constants included from Utils::Request
Instance Method Summary collapse
-
#create_dossier(entity, **args) ⇒ PriceHubble::Dossier?
Create a new dossier.
-
#delete_dossier(entity, **args) ⇒ Object
Delete a dossier entity.
-
#search_dossiers ⇒ Array<PriceHubble::Dossier>?
Search for dossier entities.
-
#share_dossier(entity, ttl:, locale:, **args) ⇒ Object
Generates a permalink for the specified dossier which will expire after the set number of days.
-
#update_dossier ⇒ PriceHubble::Dossier?
rubocop:enable Metrics/MethodLength Update a dossier entity.
Methods inherited from Base
Methods included from Utils::Bangers
Methods included from Utils::Decision
Methods included from Utils::Response
#assign_entity, #bang_entity, #failed?, #status?
Methods included from Utils::Request
#use_authentication, #use_default_context
Instance Method Details
#create_dossier(entity, **args) ⇒ PriceHubble::Dossier?
Create a new dossier.
rubocop:disable Metrics/MethodLength because thats the bare minimum
handling is quite complex
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/price_hubble/client/dossiers.rb', line 16 def create_dossier(entity, **args) res = connection.post do |req| req.path = '/api/v1/dossiers' req.body = entity.attributes.compact use_default_context(req, :create_dossier) use_authentication(req) end decision(bang: args.fetch(:bang, false)) do |result| result.bang(&bang_entity(entity, res, {})) result.good(&assign_entity(entity, res)) successful?(res) end end |
#delete_dossier(entity, **args) ⇒ Object
Delete a dossier entity.
rubocop:disable Metrics/MethodLength because thats the bare minimumbecause the decission
handling is quite complex
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/price_hubble/client/dossiers.rb', line 70 def delete_dossier(entity, **args) res = connection.delete do |req| req.path = "/api/v1/dossiers/#{entity.id}" use_default_context(req, :delete_dossier) use_authentication(req) end decision(bang: args.fetch(:bang, false)) do |result| result.bang(&bang_entity(entity, res, id: entity.id)) result.good(&assign_entity(entity, res) do |assigned_entity| assigned_entity.mark_as_destroyed.freeze end) successful?(res) end end |
#search_dossiers ⇒ Array<PriceHubble::Dossier>?
Search for dossier entities.
TODO: Implement this.
106 107 108 109 |
# File 'lib/price_hubble/client/dossiers.rb', line 106 def search_dossiers(*) # POST dossiers/search raise NotImplementedError end |
#share_dossier(entity, ttl:, locale:, **args) ⇒ Object
Generates a permalink for the specified dossier which will expire after the set number of days.
rubocop:disable Metrics/MethodLength because thats the bare minimum rubocop:disable Metrics/AbcSize because the decission
handling is quite complex
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/price_hubble/client/dossiers.rb', line 42 def share_dossier(entity, ttl:, locale:, **args) res = connection.post do |req| req.path = '/api/v1/dossiers/links' req.body = { dossier_id: entity.id, days_to_live: ttl.fdiv(1.day.to_i).ceil, country_code: entity.country_code, locale: locale } use_default_context(req, :share_dossier) use_authentication(req) end decision(bang: args.fetch(:bang, false)) do |result| result.bang(&bang_entity(entity, res, id: entity.try(:id))) result.good { res.body.url } successful?(res) end end |
#update_dossier ⇒ PriceHubble::Dossier?
rubocop:enable Metrics/MethodLength Update a dossier entity.
TODO: Implement this.
93 94 95 96 |
# File 'lib/price_hubble/client/dossiers.rb', line 93 def update_dossier(*) # PUT dossiers/<dossier_id> raise NotImplementedError end |