Class: WCC::Media::Client::Resource

Inherits:
Struct
  • Object
show all
Defined in:
lib/wcc/media/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



56
57
58
# File 'lib/wcc/media/client.rb', line 56

def client
  @client
end

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



56
57
58
# File 'lib/wcc/media/client.rb', line 56

def model
  @model
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



56
57
58
# File 'lib/wcc/media/client.rb', line 56

def options
  @options
end

Instance Method Details

#find(id, **params) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
66
67
# File 'lib/wcc/media/client.rb', line 58

def find(id, **params)
  raise ArgumentError, "id param must be present, got: #{id}" unless id && /\S/.match(id.to_s)

  resp = client.get(
    "#{model.endpoint}/#{id}",
    default_params('target').merge(params)
  )
  resp.assert_ok!
  model.new(resp.body[model.key], resp.headers.freeze)
end

#list(**filters) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/wcc/media/client.rb', line 69

def list(**filters)
  query = extract_params(filters)
  query = query.merge!(apply_filters(filters, model.filters))
  resp = client.get(model.endpoint, query)
  resp.assert_ok!
  resp.items.map { |s| model.new(s) }
end