Class: Ryext::Models::Customer

Inherits:
Object
  • Object
show all
Extended by:
Finder
Includes:
Model
Defined in:
lib/ryext/models/customer.rb

Constant Summary collapse

COLLECTION_KEY =
'customers'
YEXT_ATTRIBUTES =
{
  id: 'id',
  business_name: 'businessName',
  contact_first_name: 'contactFirstName',
  contact_last_name: 'contactLastName',
  contact_phone: 'contactPhone',
  contact_email: 'contactEmail',
  customer_attributes: 'customerAttributes',
  order: 'order',
  subscriptions: 'subscriptions',
  locations: 'locations'
}

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Finder

all, base_uri, base_url, collection_from, get, instance_klass

Methods included from Model

#build, included, #initialize, #instance_klass

Class Method Details

.clean_params(params) ⇒ Object



17
18
19
# File 'lib/ryext/models/customer.rb', line 17

def self.clean_params(params)
  params.reject { |k| ['id'].include? k }
end

.default_path(params) ⇒ Object



8
9
10
# File 'lib/ryext/models/customer.rb', line 8

def self.default_path(params)
  path(params) || '/customers'
end

.path(params) ⇒ Object



12
13
14
15
# File 'lib/ryext/models/customer.rb', line 12

def self.path(params)
  id = params['id']
  "/customers/#{id}" unless id.nil?
end

Instance Method Details

#location(location_id) ⇒ Object



52
53
54
# File 'lib/ryext/models/customer.rb', line 52

def location(location_id)
  Location.get(, 'customerId' => id, 'locationId' => location_id) unless location_id.nil? || id.nil?
end

#locationsObject



44
45
46
47
48
49
50
# File 'lib/ryext/models/customer.rb', line 44

def locations
  if id.nil?
    []
  else
    ::Ryext::Query.new(Location, 'customerId' => id, :account => )
  end
end

#optimization(op_id) ⇒ Object



76
77
78
# File 'lib/ryext/models/customer.rb', line 76

def optimization(op_id)
  Optimization.get(, 'customerId' => id, 'optimizationId' => op_id) unless op_id.nil? || id.nil?
end

#optimizationsObject



68
69
70
71
72
73
74
# File 'lib/ryext/models/customer.rb', line 68

def optimizations
  if id.nil?
    []
  else
    ::Ryext::Query.new(Optimization, 'customerId' => id, :account => )
  end
end

#statusesObject



36
37
38
39
40
41
42
# File 'lib/ryext/models/customer.rb', line 36

def statuses
  if id.nil?
    []
  else
    ::Ryext::Query.new(Status, 'customerId' => id, :account => )
  end
end

#subscription(subscription_id) ⇒ Object



64
65
66
# File 'lib/ryext/models/customer.rb', line 64

def subscription(subscription_id)
  Subscription.get(, 'customerId' => id, 'subscriptionId' => subscription_id) unless subscription_id.nil? || id.nil?
end

#subscriptionsObject



56
57
58
59
60
61
62
# File 'lib/ryext/models/customer.rb', line 56

def subscriptions
  if id.nil?
    []
  else
    ::Ryext::Query.new(Subscription, 'customerId' => id, :account => )
  end
end