Class: ShopifyAPI::DiscountCode

Inherits:
Rest::Base show all
Extended by:
T::Sig
Defined in:
lib/shopify_api/rest/resources/2021_07/discount_code.rb,
lib/shopify_api/rest/resources/2021_10/discount_code.rb,
lib/shopify_api/rest/resources/2022_01/discount_code.rb,
lib/shopify_api/rest/resources/2022_04/discount_code.rb

Instance Attribute Summary collapse

Attributes inherited from Rest::Base

#errors, #original_state

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rest::Base

base_find, class_name, create_instance, create_instances_from_response, #delete, get_path, has_many?, has_one?, json_body_name, #method_missing, next_page?, next_page_info, prev_page?, prev_page_info, primary_key, read_only_attributes, request, #respond_to_missing?, #save, #save!, #to_hash

Constructor Details

#initialize(session: ShopifyAPI::Context.active_session) ⇒ DiscountCode

Returns a new instance of DiscountCode.


12
13
14
15
16
17
18
19
20
21
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 12

def initialize(session: ShopifyAPI::Context.active_session)
  super(session: session)

  @code = T.let(nil, T.nilable(String))
  @created_at = T.let(nil, T.nilable(String))
  @id = T.let(nil, T.nilable(Integer))
  @price_rule_id = T.let(nil, T.nilable(Integer))
  @updated_at = T.let(nil, T.nilable(String))
  @usage_count = T.let(nil, T.nilable(Integer))
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ShopifyAPI::Rest::Base

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.


39
40
41
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 39

def code
  @code
end

#created_atObject (readonly)

Returns the value of attribute created_at.


41
42
43
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 41

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.


43
44
45
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 43

def id
  @id
end

#price_rule_idObject (readonly)

Returns the value of attribute price_rule_id.


45
46
47
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 45

def price_rule_id
  @price_rule_id
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.


47
48
49
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 47

def updated_at
  @updated_at
end

#usage_countObject (readonly)

Returns the value of attribute usage_count.


49
50
51
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 49

def usage_count
  @usage_count
end

Class Method Details

.all(price_rule_id: nil, batch_id: nil, session: ShopifyAPI::Context.active_session, **kwargs) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 101

def all(
  price_rule_id: nil,
  batch_id: nil,
  session: ShopifyAPI::Context.active_session,
  **kwargs
)
  response = base_find(
    session: session,
    ids: {price_rule_id: price_rule_id, batch_id: batch_id},
    params: {}.merge(kwargs).compact,
  )

  T.cast(response, T::Array[DiscountCode])
end

.count(times_used: nil, times_used_min: nil, times_used_max: nil, session: ShopifyAPI::Context.active_session, **kwargs) ⇒ Object


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 125

def count(
  times_used: nil,
  times_used_min: nil,
  times_used_max: nil,
  session: ShopifyAPI::Context.active_session,
  **kwargs
)
  request(
    http_method: :get,
    operation: :count,
    session: session,
    ids: {},
    params: {times_used: times_used, times_used_min: times_used_min, times_used_max: times_used_max}.merge(kwargs).compact,
    body: {},
    entity: nil,
  )
end

.delete(id:, price_rule_id: nil, session: ShopifyAPI::Context.active_session) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 79

def delete(
  id:,
  price_rule_id: nil,
  session: ShopifyAPI::Context.active_session
)
  request(
    http_method: :delete,
    operation: :delete,
    session: session,
    ids: {id: id, price_rule_id: price_rule_id},
    params: {},
  )
end

.find(id:, price_rule_id: nil, session: ShopifyAPI::Context.active_session) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 59

def find(
  id:,
  price_rule_id: nil,
  session: ShopifyAPI::Context.active_session
)
  result = base_find(
    session: session,
    ids: {id: id, price_rule_id: price_rule_id},
    params: {},
  )
  T.cast(result[0], T.nilable(DiscountCode))
end

.get_all(price_rule_id: nil, batch_id: nil, session: ShopifyAPI::Context.active_session, **kwargs) ⇒ Object


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 151

def get_all(
  price_rule_id: nil,
  batch_id: nil,
  session: ShopifyAPI::Context.active_session,
  **kwargs
)
  request(
    http_method: :get,
    operation: :get_all,
    session: session,
    ids: {price_rule_id: price_rule_id, batch_id: batch_id},
    params: {}.merge(kwargs).compact,
    body: {},
    entity: nil,
  )
end

.lookup(code: nil, session: ShopifyAPI::Context.active_session, **kwargs) ⇒ Object


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 175

def lookup(
  code: nil,
  session: ShopifyAPI::Context.active_session,
  **kwargs
)
  request(
    http_method: :get,
    operation: :lookup,
    session: session,
    ids: {},
    params: {code: code}.merge(kwargs).compact,
    body: {},
    entity: nil,
  )
end

Instance Method Details

#batch(body: nil, **kwargs) ⇒ Object


199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/shopify_api/rest/resources/2021_07/discount_code.rb', line 199

def batch(
  body: nil,
  **kwargs
)
  self.class.request(
    http_method: :post,
    operation: :batch,
    session: @session,
    ids: {price_rule_id: @price_rule_id},
    params: {}.merge(kwargs).compact,
    body: body,
    entity: self,
  )
end