Class: PriceHubble::Client::Dossiers

Inherits:
Base
  • Object
show all
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

Utils::Request::CONTENT_TYPE

Instance Method Summary collapse

Methods inherited from Base

#configure, #connection

Methods included from Utils::Bangers

bangers

Methods included from Utils::Decision

#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

Parameters:

Returns:



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

Parameters:



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_dossiersArray<PriceHubble::Dossier>?

Search for dossier entities.

TODO: Implement this.

Parameters:

  • criteria (Mixed)

    the search criteria

  • args (Hash{Symbol => Mixed})

    additional arguments

Returns:

Raises:

  • (NotImplementedError)


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

Parameters:

  • entity (PriceHubble::Dossier)

    the entity to use

  • ttl (ActiveSupport::Duration)

    the time to live for the new link

  • locale (String)

    the user frontend locale

  • args (Hash{Symbol => Mixed})

    additional arguments



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_dossierPriceHubble::Dossier?

rubocop:enable Metrics/MethodLength Update a dossier entity.

TODO: Implement this.

Parameters:

Returns:

Raises:

  • (NotImplementedError)


93
94
95
96
# File 'lib/price_hubble/client/dossiers.rb', line 93

def update_dossier(*)
  # PUT dossiers/<dossier_id>
  raise NotImplementedError
end