Class: WCC::Media::Client::Resource
- Inherits:
-
Struct
- Object
- Struct
- WCC::Media::Client::Resource
- Defined in:
- lib/wcc/media/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#model ⇒ Object
Returns the value of attribute model.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#find(id, **params) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #list(**filters) ⇒ Object
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
61 62 63 |
# File 'lib/wcc/media/client.rb', line 61 def client @client end |
#model ⇒ Object
Returns the value of attribute model
61 62 63 |
# File 'lib/wcc/media/client.rb', line 61 def model @model end |
#options ⇒ Object
Returns the value of attribute options
61 62 63 |
# File 'lib/wcc/media/client.rb', line 61 def @options end |
Instance Method Details
#find(id, **params) ⇒ Object
rubocop:disable Metrics/AbcSize
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wcc/media/client.rb', line 63 def find(id, **params) # rubocop:disable Metrics/AbcSize 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
74 75 76 77 78 79 80 |
# File 'lib/wcc/media/client.rb', line 74 def list(**filters) query = extract_params(filters) query.merge!(apply_filters(filters, model.filters)) resp = client.get(model.endpoint, query) resp.assert_ok! resp.items.map { |s| model.new(s) } end |