Class: CardmarketCLI::Entities::Wantslist
- Inherits:
-
Changeable
- Object
- Entity
- Changeable
- CardmarketCLI::Entities::Wantslist
- Defined in:
- lib/cardmarket_cli/entities/wantslist.rb
Overview
Constant Summary collapse
- PARAMS =
i[name].freeze
- PATH_BASE =
'wantslist'
Instance Attribute Summary
Attributes inherited from Entity
Class Method Summary collapse
- .create(*args) ⇒ Object
- .from_hash(account, hash) ⇒ Object
- .read(account, eager: true) ⇒ Object
- .update ⇒ Object
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(id, account, params = {}) ⇒ Wantslist
constructor
A new instance of Wantslist.
- #path ⇒ Object
- #read ⇒ Object
- #update ⇒ Object
Methods included from Deletable
Methods included from Unique
Methods inherited from Changeable
Constructor Details
#initialize(id, account, params = {}) ⇒ Wantslist
Returns a new instance of Wantslist.
21 22 23 24 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 21 def initialize(id, account, params = {}) super(id, account, params.slice(*PARAMS)) Wantslist.send(:add, self) end |
Class Method Details
.create(*args) ⇒ Object
124 125 126 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 124 def create(*args) new(*args) end |
.from_hash(account, hash) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 128 def from_hash(account, hash) return nil unless hash['game']&.fetch('idGame') == 1 list = Wantslist.new(hash['idWantsList'], account, name: hash['name']) hash['item']&.each { |item| list.add_item(WantslistItem.from_hash(account, item)) } list end |
.read(account, eager: true) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 108 def read(account, eager: true) LOGGER.debug('Reading wantslists') response = account.get(PATH_BASE) hash = JSON.parse(response.response_body) hash['wantslist']&.each do |item| list = from_hash(account, item) list.read if eager && list end instances end |
.update ⇒ Object
119 120 121 122 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 119 def update instances.each(&:update) deleted_instances.each(&:delete) end |
Instance Method Details
#delete ⇒ Object
40 41 42 43 44 45 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 40 def delete LOGGER.debug("Deleting wantslist #{name}(#{id})") return unless id account.delete(path, body: { action: 'deleteWantslist' }) end |
#path ⇒ Object
26 27 28 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 26 def path "#{PATH_BASE}/#{id}" end |
#read ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 30 def read LOGGER.debug("Reading wantslist #{name}(#{id})") return unless id response = account.get(path) override_params(JSON.parse(response.response_body)['wantslist']) response end |
#update ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/cardmarket_cli/entities/wantslist.rb', line 47 def update LOGGER.debug("Updating wantslist #{name}(#{id})") responses = {} responses[:create] = create unless id responses[:update] = patch if changed? patch_items(responses) responses.compact! end |