Class: BigCommerce::ManagementAPI::Customers::Metafields

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

Constant Summary collapse

PATH =
"customers/%d/metafields"
RESULT_INSTANCE =
Metafield

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(metafield) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/big_commerce/management_api/customers.rb', line 95

def create(metafield)
  metafield = metafield.to_h
  id = metafield.delete(:resource_id)

  if id.nil?
    raise ArgumentError, "Cannot create customer metafield: given metafield record has no resource_id"
  end

  POST(path(id), metafield)
end

#get(customer_id, options = {}) ⇒ Object



91
92
93
# File 'lib/big_commerce/management_api/customers.rb', line 91

def get(customer_id, options = {})
  GET(path(customer_id), options)
end

#update(metafield) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/big_commerce/management_api/customers.rb', line 106

def update(metafield)
  metafield = metafield.to_h

  resource = metafield.delete(:resource_id)
  if resource.nil?
    raise ArgumentError, "Cannot update customer metafield: given metafield has no resource_id"
  end

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

  result = PUT(path(resource_id, id), metafield)
  unwrap(result)
end