class Synnex::API

Public Class Methods

new(hash) click to toggle source

Pass the parameters to Synnex::API.new(user_name: 'user', password: 'pass', reseller: 12345) Pass the parameter {endpoint: 'production'} for the production endpoint

# File lib/synnex/synnex_api.rb, line 7
def initialize(hash)
  raise "user_name is required" unless hash[:user_name]
  raise "password is required" unless hash[:password]
  raise "reseller is required" unless hash[:reseller]
  @user_name = hash[:user_name]
  @password = hash[:password]
  @reseller = hash[:reseller]
  @endpoint = hash[:endpoint] == 'production' ? Synnex::PROD : Synnex::UAT
  get_auth_token
  @headers = {'Authorization' => "Bearer #{@access_token}"}.merge(Synnex::HEADERS)
end

Public Instance Methods

cancel_subscription(subscription, email) click to toggle source
# File lib/synnex/synnex_api.rb, line 77
def cancel_subscription(subscription, email)
  body = {
      action_name: "cancel",
      subscription_id: subscription,
  }
  body[:notify_email] = email if email
  HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                body: body.to_json,
                headers: @headers)
      .parsed_response
end
create_new_order(cust_no, li, rs, eu, email) click to toggle source
# File lib/synnex/synnex_api.rb, line 47
def create_new_order(cust_no, li, rs, eu, email)
  body = {
      action_name: 'create_new_order',
      snx_eu_no: cust_no,
      line_items: li,
  }
  body[:rs_po_no] = rs if rs
  body[:eu_po_no] = eu if eu
  body[:notify_email] = email if email
  HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                body: body.to_json,
                headers: @headers)
      .parsed_response
end
customer_subscription(cust_no) click to toggle source
# File lib/synnex/synnex_api.rb, line 27
def customer_subscription(cust_no)
  HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                body: {
                    action_name: 'get_subscriptions_by_eu_no',
                    snx_eu_no: cust_no
                }.to_json,
                headers: @headers)
      .parsed_response["items"]
end
customer_users(cust_no) click to toggle source
# File lib/synnex/synnex_api.rb, line 89
def customer_users(cust_no)
  HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                body: {
                    action_name: 'get_customer_users',
                    snx_eu_no: cust_no
                }.to_json,
                headers: @headers)
      .parsed_response["items"]
end
customers() click to toggle source
# File lib/synnex/synnex_api.rb, line 19
def customers
  @customers ||= HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                               body: {action_name: 'get_eu_list'}.to_json,
                               headers: @headers)
                     .parsed_response["items"]
                     .select {|customers| customers['tenant_id']}
end
endpoint() click to toggle source
# File lib/synnex/synnex_api.rb, line 109
def endpoint
  @endpoint
end
get_licenses(auth_token, cust_no) click to toggle source
# File lib/synnex/synnex_api.rb, line 99
def get_licenses(auth_token, cust_no)
  HTTParty.post("#{@endpoint}/webservice/solutions/csp/license",
                body: {
                    action_name: 'get_subscribed_sku',
                    snx_eu_no: cust_no
                }.to_json,
                headers: {'Authorization' => "Bearer #{auth_token}"}.merge(Synnex::HEADERS))
      .parsed_response["items"]
end
headers() click to toggle source
# File lib/synnex/synnex_api.rb, line 113
def headers
  @headers
end
subscription(id) click to toggle source
# File lib/synnex/synnex_api.rb, line 37
def subscription(id)
  HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                body: {
                    action_name: 'get_subscription_by_id',
                    subscription_id: id
                }.to_json,
                headers: @headers)
      .parsed_response["items"]
end
update_seat(subscription, quantity, email) click to toggle source
# File lib/synnex/synnex_api.rb, line 62
def update_seat(subscription, quantity, email)
  body = {
      action_name: "update_seat",
      subscription_id: subscription,
      new_quantity: quantity
  }
  body[:notify_email] = email if email
  p body.to_json
  HTTParty.post("#{@endpoint}/webservice/solutions/csp",
                body: body.to_json,
                headers: @headers)
      .parsed_response

end

Private Instance Methods

get_auth_token() click to toggle source
# File lib/synnex/synnex_api.rb, line 120
def get_auth_token
  return @access_token if @access_token

  body = {
      action_name: "create_access_token",
      user_name: @user_name,
      password: @password,
      snx_reseller_no: @reseller
  }.to_json
  result = HTTParty.post("#{@endpoint}/webservice/auth/token", body: body, headers: Synnex::HEADERS)
  @access_token = result.parsed_response['access_token']
  raise "Invalid Credentials" unless @access_token
end