Class: AdvancedBilling::SubscriptionFilter

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/subscription_filter.rb

Overview

Nested filter used for List Subscription Components For Site Filter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(states: SKIP, date_field: SKIP, start_date: SKIP, end_date: SKIP, start_datetime: SKIP, end_datetime: SKIP, additional_properties: {}) ⇒ SubscriptionFilter

Returns a new instance of SubscriptionFilter.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/advanced_billing/models/subscription_filter.rb', line 92

def initialize(states: SKIP, date_field: SKIP, start_date: SKIP,
               end_date: SKIP, start_datetime: SKIP, end_datetime: SKIP,
               additional_properties: {})
  @states = states unless states == SKIP
  @date_field = date_field unless date_field == SKIP
  @start_date = start_date unless start_date == SKIP
  @end_date = end_date unless end_date == SKIP
  @start_datetime = start_datetime unless start_datetime == SKIP
  @end_datetime = end_datetime unless end_datetime == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#date_fieldSubscriptionListDateField

The type of filter you’d like to apply to your search. To use this filter you also have to include the following param in the request ‘include=subscription`.



25
26
27
# File 'lib/advanced_billing/models/subscription_filter.rb', line 25

def date_field
  @date_field
end

#end_dateDate

The end date (format YYYY-MM-DD) with which to filter the date_field. Returns components that belong to the subscription with a timestamp up to and including 11:59:59PM in your site’s time zone on the date specified. To use this filter you also have to include the following param in the request ‘include=subscription`.

Returns:

  • (Date)


41
42
43
# File 'lib/advanced_billing/models/subscription_filter.rb', line 41

def end_date
  @end_date
end

#end_datetimeDateTime

The end date and time (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns components that belong to the subscription with a timestamp at or before exact time provided in query. You can specify timezone in query - otherwise your site”s time zone will be used. If provided, this parameter will be used instead of end_date. To use this filter you also have to include the following param in the request ‘include=subscription`.

Returns:

  • (DateTime)


61
62
63
# File 'lib/advanced_billing/models/subscription_filter.rb', line 61

def end_datetime
  @end_datetime
end

#start_dateDate

The start date (format YYYY-MM-DD) with which to filter the date_field. Returns components that belong to the subscription with a timestamp at or after midnight (12:00:00 AM) in your site’s time zone on the date specified. To use this filter you also have to include the following param in the request ‘include=subscription`.

Returns:

  • (Date)


33
34
35
# File 'lib/advanced_billing/models/subscription_filter.rb', line 33

def start_date
  @start_date
end

#start_datetimeDateTime

The start date and time (format YYYY-MM-DD HH:MM:SS) with which to filter the date_field. Returns components that belong to the subscription with a timestamp at or after exact time provided in query. You can specify timezone in query - otherwise your site”s time zone will be used. If provided, this parameter will be used instead of start_date. To use this filter you also have to include the following param in the request ‘include=subscription`.

Returns:

  • (DateTime)


51
52
53
# File 'lib/advanced_billing/models/subscription_filter.rb', line 51

def start_datetime
  @start_datetime
end

#statesArray[SubscriptionStateFilter]

Allows fetching components allocations that belong to the subscription with matching states based on provided values. To use this filter you also have to include the following param in the request ‘include=subscription`. Use in query `filter[states]=active,canceled&include=subscription`.

Returns:



19
20
21
# File 'lib/advanced_billing/models/subscription_filter.rb', line 19

def states
  @states
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/advanced_billing/models/subscription_filter.rb', line 109

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  states = hash.key?('states') ? hash['states'] : SKIP
  date_field = hash.key?('date_field') ? hash['date_field'] : SKIP
  start_date = hash.key?('start_date') ? hash['start_date'] : SKIP
  end_date = hash.key?('end_date') ? hash['end_date'] : SKIP
  start_datetime = if hash.key?('start_datetime')
                     (DateTimeHelper.from_rfc3339(hash['start_datetime']) if hash['start_datetime'])
                   else
                     SKIP
                   end
  end_datetime = if hash.key?('end_datetime')
                   (DateTimeHelper.from_rfc3339(hash['end_datetime']) if hash['end_datetime'])
                 else
                   SKIP
                 end

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  SubscriptionFilter.new(states: states,
                         date_field: date_field,
                         start_date: start_date,
                         end_date: end_date,
                         start_datetime: start_datetime,
                         end_datetime: end_datetime,
                         additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



64
65
66
67
68
69
70
71
72
73
# File 'lib/advanced_billing/models/subscription_filter.rb', line 64

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['states'] = 'states'
  @_hash['date_field'] = 'date_field'
  @_hash['start_date'] = 'start_date'
  @_hash['end_date'] = 'end_date'
  @_hash['start_datetime'] = 'start_datetime'
  @_hash['end_datetime'] = 'end_datetime'
  @_hash
end

.nullablesObject

An array for nullable fields



88
89
90
# File 'lib/advanced_billing/models/subscription_filter.rb', line 88

def self.nullables
  []
end

.optionalsObject

An array for optional fields



76
77
78
79
80
81
82
83
84
85
# File 'lib/advanced_billing/models/subscription_filter.rb', line 76

def self.optionals
  %w[
    states
    date_field
    start_date
    end_date
    start_datetime
    end_datetime
  ]
end

Instance Method Details

#to_custom_end_datetimeObject



145
146
147
# File 'lib/advanced_billing/models/subscription_filter.rb', line 145

def to_custom_end_datetime
  DateTimeHelper.to_rfc3339(end_datetime)
end

#to_custom_start_datetimeObject



141
142
143
# File 'lib/advanced_billing/models/subscription_filter.rb', line 141

def to_custom_start_datetime
  DateTimeHelper.to_rfc3339(start_datetime)
end