Class: ShotgridApiRuby::Entities::Summarize
- Inherits:
-
Object
- Object
- ShotgridApiRuby::Entities::Summarize
- Extended by:
- T::Sig
- Defined in:
- lib/shotgrid_api_ruby/entities/summarize.rb
Defined Under Namespace
Classes: Summary
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #count(filter: nil, logical_operator: 'and') ⇒ Object
-
#initialize(connection, type, base_url_prefix) ⇒ Summarize
constructor
A new instance of Summarize.
- #summarize(filter: nil, grouping: nil, summary_fields: nil, logical_operator: 'and', include_archived_projects: nil) ⇒ Object
Constructor Details
#initialize(connection, type, base_url_prefix) ⇒ Summarize
Returns a new instance of Summarize.
19 20 21 22 23 24 |
# File 'lib/shotgrid_api_ruby/entities/summarize.rb', line 19 def initialize(connection, type, base_url_prefix) @connection = T.let(connection.dup, Faraday::Connection) @type = T.let(type, T.any(String, Symbol)) @connection.url_prefix = T.let("#{base_url_prefix}/entity/#{type}/_summarize", String) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
29 30 31 |
# File 'lib/shotgrid_api_ruby/entities/summarize.rb', line 29 def connection @connection end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/shotgrid_api_ruby/entities/summarize.rb', line 27 def type @type end |
Instance Method Details
#count(filter: nil, logical_operator: 'and') ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/shotgrid_api_ruby/entities/summarize.rb', line 35 def count(filter: nil, logical_operator: 'and') result = summarize( filter: filter, logical_operator: logical_operator, summary_fields: [{ type: :record_count, field: 'id' }], ) result.summaries&.[]('id') || 0 end |
#summarize(filter: nil, grouping: nil, summary_fields: nil, logical_operator: 'and', include_archived_projects: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/shotgrid_api_ruby/entities/summarize.rb', line 55 def summarize( filter: nil, grouping: nil, summary_fields: nil, logical_operator: 'and', include_archived_projects: nil ) params = Params.new params.add_filter(filter, logical_operator) params[:filters] = params[:filter] if params[:filter] params.delete(:filter) params.add_grouping(grouping) params.add_summary_fields(summary_fields) params.(nil, include_archived_projects) resp = @connection.post('', params) do |req| req.headers['Content-Type'] = if params[:filters].is_a? Array 'application/vnd+shotgun.api3_array+json' else 'application/vnd+shotgun.api3_hash+json' end req.body = params.to_h.to_json end resp_body = JSON.parse(resp.body) if resp.status >= 300 raise ShotgridCallError.new( response: resp, message: "Error while getting summarize for #{type}: #{resp_body['errors']}", ) end Summary.new( summaries: resp_body['data']['summaries'], groups: resp_body['data']&.[]('groups'), ) end |