synnex 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5dca190be2ccac057168d2415af830fdfcd05f375afd4f130729fa5ff314ec06
4
+ data.tar.gz: c91788d33598ee5b0d49d6248619c345ed54ca8734242e92f18928e84ac0c51e
5
+ SHA512:
6
+ metadata.gz: 8cb60fd89ef27dbd2752fa7c34763c7d943446e2fa3c5a6ea45debf6e0243c61a991f693f1de91b27f24b0a45d42383a2be845aea33b179c458e9c14c179cb19
7
+ data.tar.gz: bc17f3e42ec59cf58d4f2e515e627a1fdb09ab3cae9958e47d2b881a6fb9b8d2bfe630fc911f025430ce672e482e4751aa3fdf95ff4d4393f648106e8c7f3aba
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+ /.idea
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at andygauge@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in synnex-gem.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Andrew Gauger
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Synnex::Gem
2
+
3
+ Use this gem to interact with Synnex API to query against office 365
4
+ CSP. It is possible to get customers, purchase subscriptions, and manage
5
+ seats
6
+
7
+ ### To connect to the API, start with the Synnex::Msp object
8
+
9
+ `msp = Synnex::Msp.new(user_name: 'user', password: 'pass', reseller: 12345)`
10
+ to use the production instance include `endpoint: "production"`
11
+
12
+ ### To get customers
13
+
14
+ `msp.customers`
15
+
16
+ ### Synnex::Customer
17
+
18
+ The customer object has the following attributes:
19
+ - snx_eu_no
20
+ - company_name
21
+ - address1
22
+ - address2
23
+ - city
24
+ - state
25
+ - zip_code
26
+ - country
27
+ - contact_name
28
+ - email
29
+ - phone
30
+ - tenant_id
31
+
32
+ Customer can also perform the following operations:
33
+ - `create_order(line_items, reseller_po, end_user_po, email)`
34
+ - `line_items` follow the `{snx_sku_no: 12345, quantity: 1}` pattern
35
+
36
+ subscriptions for a customer can be queried and manipulated by calling
37
+ `.subscriptions` on the `Synnex::Customer` object
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "synnex/gem"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/synnex.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'httparty'
2
+ require 'synnex/synnex_customer'
3
+ require 'synnex/synnex_subscription'
4
+ require 'synnex/synnex_api'
5
+ require 'synnex/synnex_msp'
6
+
7
+ # Use msp = Synnex::Msp.new(user_name: 'user', password: 'pass', reseller: 12345)
8
+ # msp.customers.first.subscriptions.first
9
+ module Synnex
10
+ UAT = 'https://testws.synnex.com'
11
+ PROD = 'https://ws.synnex.com'
12
+ HEADERS = {
13
+ 'Content-Type' => 'application/json'
14
+ }
15
+ end
@@ -0,0 +1,105 @@
1
+ module Synnex
2
+
3
+ class API
4
+
5
+ # Pass the parameters to Synnex::API.new(user_name: 'user', password: 'pass', reseller: 12345)
6
+ # Pass the parameter {endpoint: 'production'} for the production endpoint
7
+ def initialize(hash)
8
+ raise "user_name is required" unless hash[:user_name]
9
+ raise "password is required" unless hash[:password]
10
+ raise "reseller is required" unless hash[:reseller]
11
+ @user_name = hash[:user_name]
12
+ @password = hash[:password]
13
+ @reseller = hash[:reseller]
14
+ @endpoint = hash[:endpoint] == 'production' ? Synnex::PROD : Synnex::UAT
15
+ get_auth_token
16
+ @headers = {'Authorization' => "Bearer #{@access_token}"}.merge(Synnex::HEADERS)
17
+ end
18
+
19
+ def customers
20
+ @customers ||= HTTParty.post("#{@endpoint}/webservice/solutions/csp",
21
+ body: {action_name: 'get_eu_list'}.to_json,
22
+ headers: @headers)
23
+ .parsed_response["items"]
24
+ .select {|customers| customers['tenant_id']}
25
+ end
26
+
27
+ def customer_subscription(cust_no)
28
+ HTTParty.post("#{@endpoint}/webservice/solutions/csp",
29
+ body: {
30
+ action_name: 'get_subscriptions_by_eu_no',
31
+ snx_eu_no: cust_no
32
+ }.to_json,
33
+ headers: @headers)
34
+ .parsed_response["items"]
35
+ end
36
+
37
+ def subscription(id)
38
+ HTTParty.post("#{@endpoint}/webservice/solutions/csp",
39
+ body: {
40
+ action_name: 'get_subscription_by_id',
41
+ subscription_id: id
42
+ }.to_json,
43
+ headers: @headers)
44
+ .parsed_response["items"]
45
+ end
46
+
47
+ def create_new_order(cust_no, li, rs, eu, email)
48
+ body = {
49
+ action_name: 'create_new_order',
50
+ snx_eu_no: cust_no,
51
+ line_items: li,
52
+ }
53
+ body[:rs_po_no] = rs if rs
54
+ body[:eu_po_no] = eu if eu
55
+ body[:notify_email] = email if email
56
+ HTTParty.post("#{@endpoint}/webservice/solutions/csp",
57
+ body: body.to_json,
58
+ headers: @headers)
59
+ .parsed_response
60
+ end
61
+
62
+ def update_seat(subscription, quantity, email)
63
+ body = {
64
+ action_name: "update_seat",
65
+ subscription_id: subscription,
66
+ new_quantity: quantity
67
+ }
68
+ body[:notify_email] = email if email
69
+ p body.to_json
70
+ HTTParty.post("#{@endpoint}/webservice/solutions/csp",
71
+ body: body.to_json,
72
+ headers: @headers)
73
+ .parsed_response
74
+
75
+ end
76
+
77
+ def cancel_subscription(subscription, email)
78
+ body = {
79
+ action_name: "cancel",
80
+ subscription_id: subscription,
81
+ }
82
+ body[:notify_email] = email if email
83
+ HTTParty.post("#{@endpoint}/webservice/solutions/csp",
84
+ body: body.to_json,
85
+ headers: @headers)
86
+ .parsed_response
87
+ end
88
+
89
+
90
+
91
+ private
92
+
93
+ def get_auth_token
94
+ body = {
95
+ action_name: "create_access_token",
96
+ user_name: @user_name,
97
+ password: @password,
98
+ snx_reseller_no: @reseller
99
+ }.to_json
100
+ result = HTTParty.post("#{@endpoint}/webservice/auth/token", body: body, headers: Synnex::HEADERS)
101
+ @access_token = result.parsed_response['access_token']
102
+ raise "Invalid Credentials" unless @access_token
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,47 @@
1
+ module Synnex
2
+ class Customer
3
+ attr_reader :snx_eu_no, :company_name, :address1, :address2, :city, :state, :zip_code, :country, :contact_name, :email, :phone, :tenant_id, :msp
4
+ def initialize(json, msp)
5
+ @snx_eu_no = json["snx_eu_no"]
6
+ @company_name = json["company_name"]
7
+ @address1 = json["address1"]
8
+ @address2 = json["address2"]
9
+ @city = json["city"]
10
+ @state = json["state"]
11
+ @zip_code = json["zip_code"]
12
+ @country = json["country"]
13
+ @contact_name = json["contact_name"]
14
+ @email = json["email"]
15
+ @phone = json["phone"]
16
+ @tenant_id = json["tenant_id"]
17
+ @msp = msp
18
+ end
19
+
20
+ def subscriptions
21
+ @subscriptions ||= api.customer_subscription(@snx_eu_no)
22
+ .map {|subscription| Synnex::Subscription.new(api.subscription(subscription["subscription_id"]), self)}
23
+ end
24
+
25
+ # line_items is an array (optional) of the following hash {snx_sku_no: 12345, quantity: 1}
26
+ # returns true for success
27
+ def create_order(line_items, rs_po=nil , eu_po=nil , email=nil)
28
+ case line_items
29
+ when Hash
30
+ 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)
31
+ line_items = [line_items]
32
+ when Array
33
+ 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)
34
+ else
35
+ raise "line_items must be a hash or array of hashes"
36
+ end
37
+ response = api.create_new_order(snx_eu_no, line_items, rs_po, eu_po, email)
38
+ response["status"] == "success" ? true : response["message"]
39
+ end
40
+
41
+ private
42
+
43
+ def api
44
+ msp.api
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,15 @@
1
+ module Synnex
2
+ class Msp
3
+ attr_reader :api
4
+ # Pass the parameters to Synnex::Msp.new(user_name: 'user', password: 'pass', reseller: 12345)
5
+ # Pass the parameter {endpoint: 'production'} for the production endpoint
6
+ def initialize(hash)
7
+ @api = Synnex::API.new(hash)
8
+ end
9
+
10
+ def customers
11
+ api.customers.map {|json| Synnex::Customer.new(json, self)}
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ module Synnex
2
+ class Subscription
3
+ attr_reader :id, :service_name, :snx_sku_no, :quantity, :status, :po, :price, :msrp, :customer
4
+ def initialize(json, customer)
5
+ info = json["subscriptions_info"][0]
6
+ @id = info["subscription_id"]
7
+ @service_name = info["service_name"]
8
+ @snx_sku_no = info["snx_sku_no"]
9
+ @quantity = info["quantity"]
10
+ @status = info["status"]
11
+ @po = json["rs_po_no"]
12
+ @price = info["unit_price"]
13
+ @msrp = info["msrp"]
14
+ @customer = customer
15
+ end
16
+
17
+ def change_quantity(qty, email=nil)
18
+ raise "Quantity must be greater than 0" unless qty > 0
19
+ response = api.update_seat(id, qty, email)
20
+ response["status"] == "success" ? true : response["message"]
21
+ end
22
+
23
+ def cancel(email=nil)
24
+ response = api.cancel_subscription(id, email)
25
+ response["status"] == "success" ? true : response["message"]
26
+ end
27
+
28
+ private
29
+
30
+ def api
31
+ customer.msp.api
32
+ end
33
+
34
+ end
35
+ end
data/synnex.gemspec ADDED
@@ -0,0 +1,26 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "synnex"
4
+ spec.version = '0.1.4'
5
+ spec.authors = ["Andrew Gauger"]
6
+ spec.email = ["andygauge@gmail.com"]
7
+
8
+ spec.summary = "API access to Synnex ECExpress Stellr Cloud"
9
+ spec.description = "Wraps the API up in object for managing office 365 licenses through Partner CSP"
10
+ spec.homepage = "http://www.yetanother.site"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/andygauge/synnex-gem"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.add_runtime_dependency "httparty"
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synnex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Gauger
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Wraps the API up in object for managing office 365 licenses through Partner
28
+ CSP
29
+ email:
30
+ - andygauge@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".idea/workspace.xml"
37
+ - ".travis.yml"
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/synnex.rb
46
+ - lib/synnex/synnex_api.rb
47
+ - lib/synnex/synnex_customer.rb
48
+ - lib/synnex/synnex_msp.rb
49
+ - lib/synnex/synnex_subscription.rb
50
+ - synnex.gemspec
51
+ homepage: http://www.yetanother.site
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: http://www.yetanother.site
56
+ source_code_uri: https://github.com/andygauge/synnex-gem
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.1.0.pre1
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: API access to Synnex ECExpress Stellr Cloud
76
+ test_files: []