Class: Synnex::Customer

Inherits:
Object
  • Object
show all
Defined in:
lib/synnex/synnex_customer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, msp) ⇒ Customer

Returns a new instance of Customer.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/synnex/synnex_customer.rb', line 4

def initialize(json, msp)
  @snx_eu_no = json["snx_eu_no"]
  @company_name = json["company_name"]
  @address1 = json["address1"]
  @address2 = json["address2"]
  @city = json["city"]
  @state = json["state"]
  @zip_code = json["zip_code"]
  @country = json["country"]
  @contact_name = json["contact_name"]
  @email = json["email"]
  @phone = json["phone"]
  @tenant_id = json["tenant_id"]
  @api = msp.api
end

Instance Attribute Details

#address1Object (readonly)

Returns the value of attribute address1.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def address1
  @address1
end

#address2Object (readonly)

Returns the value of attribute address2.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def address2
  @address2
end

#cityObject (readonly)

Returns the value of attribute city.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def city
  @city
end

#company_nameObject (readonly)

Returns the value of attribute company_name.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def company_name
  @company_name
end

#contact_nameObject (readonly)

Returns the value of attribute contact_name.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def contact_name
  @contact_name
end

#countryObject (readonly)

Returns the value of attribute country.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def country
  @country
end

#emailObject (readonly)

Returns the value of attribute email.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def email
  @email
end

#phoneObject (readonly)

Returns the value of attribute phone.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def phone
  @phone
end

#snx_eu_noObject (readonly)

Returns the value of attribute snx_eu_no.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def snx_eu_no
  @snx_eu_no
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def state
  @state
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def tenant_id
  @tenant_id
end

#zip_codeObject (readonly)

Returns the value of attribute zip_code.



3
4
5
# File 'lib/synnex/synnex_customer.rb', line 3

def zip_code
  @zip_code
end

Instance Method Details

#apiObject



49
50
51
# File 'lib/synnex/synnex_customer.rb', line 49

def api
  @api
end

#create_order(line_items, rs_po = nil, eu_po = nil, email = nil) ⇒ Object

line_items is an array (optional) of the following hash 12345, quantity: 1 returns true for success



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/synnex/synnex_customer.rb', line 35

def create_order(line_items, rs_po=nil , eu_po=nil , email=nil)
  case line_items
  when Hash
    raise "line_items must follow {snx_sku_no: 12345, quantity: 1} convention" unless (line_items[:snx_sku_no].to_i > 0 && line_items[:quantity].to_i > 0)
    line_items = [line_items]
  when Array
    raise "line_items must follow [{snx_sku_no: 12345, quantity: 1}, ...] convention" unless (line_items[0][:snx_sku_no].to_i > 0 && line_items[0][:quantity].to_i > 0)
  else
    raise "line_items must be a hash or array of hashes"
  end
  response = api.create_new_order(snx_eu_no, line_items, rs_po, eu_po, email)
  response["status"] == "success" ? true : response["message"]
end

#licensesObject



25
26
27
# File 'lib/synnex/synnex_customer.rb', line 25

def licenses
  api.get_licenses(tenant_access_token, @snx_eu_no)
end

#subscriptionsObject



20
21
22
23
# File 'lib/synnex/synnex_customer.rb', line 20

def subscriptions
  @subscriptions ||= api.customer_subscription(@snx_eu_no)
                         .map {|subscription| Synnex::Subscription.new(api.subscription(subscription["subscription_id"]), self.api)}
end

#usersObject



29
30
31
# File 'lib/synnex/synnex_customer.rb', line 29

def users
  @users ||= api.customer_users(@snx_eu_no)
end