Class: Synnex::API
- Inherits:
-
Object
- Object
- Synnex::API
- Defined in:
- lib/synnex/synnex_api.rb
Instance Method Summary collapse
- #cancel_subscription(subscription, email) ⇒ Object
- #create_new_order(cust_no, li, rs, eu, email) ⇒ Object
- #customer_subscription(cust_no) ⇒ Object
- #customer_users(cust_no) ⇒ Object
- #customers ⇒ Object
- #endpoint ⇒ Object
- #get_licenses(auth_token, cust_no) ⇒ Object
- #headers ⇒ Object
-
#initialize(hash) ⇒ API
constructor
Pass the parameters to Synnex::API.new(user_name: ‘user’, password: ‘pass’, reseller: 12345) Pass the parameter ‘production’ for the production endpoint.
- #subscription(id) ⇒ Object
- #update_seat(subscription, quantity, email) ⇒ Object
Constructor Details
#initialize(hash) ⇒ API
Pass the parameters to Synnex::API.new(user_name: ‘user’, password: ‘pass’, reseller: 12345) Pass the parameter ‘production’ for the production endpoint
7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Method Details
#cancel_subscription(subscription, email) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# 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) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# 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 ⇒ Object
19 20 21 22 23 24 25 |
# 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 ⇒ Object
109 110 111 |
# File 'lib/synnex/synnex_api.rb', line 109 def endpoint @endpoint end |
#get_licenses(auth_token, cust_no) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# 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 ⇒ Object
113 114 115 |
# File 'lib/synnex/synnex_api.rb', line 113 def headers @headers end |
#subscription(id) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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 |