Class: BigCommerce::ManagementAPI::Subscribers

Inherits:
Endpoint
  • Object
show all
Defined in:
lib/big_commerce/management_api/subscribers.rb

Constant Summary collapse

PATH =
"customers/subscribers"
RESULT_INSTANCE =
Subscriber

Constants inherited from Endpoint

Endpoint::CONTENT_TYPE, Endpoint::CONTENT_TYPE_JSON, Endpoint::HOST, Endpoint::JSON_CONTENT_TYPES, Endpoint::PORT, Endpoint::RESULT_KEY, Endpoint::USER_AGENT

Instance Method Summary collapse

Methods inherited from Endpoint

#initialize

Constructor Details

This class inherits a constructor from BigCommerce::ManagementAPI::Endpoint

Instance Method Details

#create(attributes) ⇒ Object



11
12
13
14
# File 'lib/big_commerce/management_api/subscribers.rb', line 11

def create(attributes)
  result = POST(PATH, attributes)
  unwrap(result)
end

#delete(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/big_commerce/management_api/subscribers.rb', line 16

def delete(options)
  DELETE(
    PATH,
    with_in_param(
      options,
      :date_created,
      :date_modified,
      :email,
      :first_name,
      :id,
      :last_name,
      :order_id,
      :source
    )
  )
end

#get(options_or_id) ⇒ Object

Given an ID find a single Subscriber. Given a Hash find Subscribers by the provided criteria.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/big_commerce/management_api/subscribers.rb', line 37

def get(options_or_id)
  query = options_or_id

  if query.is_a?(Hash)
    query = with_in_param(
      query,
      :date_created,
      :date_modified,
      :email,
      :first_name,
      :id,
      :last_name,
      :order_id,
      :source
    )
  end

  GET(PATH, query)
end

#update(attributes) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/big_commerce/management_api/subscribers.rb', line 57

def update(attributes)
  attributes = attributes.to_h

  id = attributes.delete(:id)
  if id.nil?
    raise ArgumentError, "Cannot update subscriber: given subscriber has no id"
  end

  result = UPDATE("#{PATH}/#{id}", attributes)
  unwrap(result)
end