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

Instance Method Details

#create_dossier(entity, **args) ⇒ PriceHubble::Dossier?

Create a new dossier.

Parameters:

Returns:



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.

Parameters:



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_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)


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.

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



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

Update a dossier entity.

TODO: Implement this.

Parameters:

Returns:

Raises:

  • (NotImplementedError)


79
80
81
82
# File 'lib/price_hubble/client/dossiers.rb', line 79

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