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?
Update a dossier entity.
Methods inherited from Base
Instance Method Details
#create_dossier(entity, **args) ⇒ PriceHubble::Dossier?
Create a new dossier.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/price_hubble/client/dossiers.rb', line 13 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/price_hubble/client/dossiers.rb', line 57 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.
92 93 94 95 |
# File 'lib/price_hubble/client/dossiers.rb', line 92 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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/price_hubble/client/dossiers.rb', line 34 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?
Update a dossier entity.
TODO: Implement this.
79 80 81 82 |
# File 'lib/price_hubble/client/dossiers.rb', line 79 def update_dossier(*) # PUT dossiers/<dossier_id> raise NotImplementedError end |