dal 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a3c2d2759202ea5f27205ce8abea0bce1737085
4
+ data.tar.gz: 3183537c9c27eda16d552deb79d624524bd0f8c6
5
+ SHA512:
6
+ metadata.gz: 674a7798465f67c0d1a8c5020e81ac398f281d690a9d0e9c27b74e579dab153f4b75c87d163defd27a5c291174473920b52260b28b448334796027cb2b1c24fb
7
+ data.tar.gz: 1baaca20504dc99343d298a974a3b7ad2ae4274fe8799dd591df1e48011e1f96e435011830592920d908f02615f78d75954098af6706b104047b0758eb03f4ba
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea/
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.6
7
+ before_install: gem install bundler -v 1.17.3
@@ -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 joshua.humphrey@hp.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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dal.gemspec
6
+ gemspec
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dal (0.1.9)
5
+ activesupport (~> 5.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.3)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ addressable (2.6.0)
16
+ public_suffix (>= 2.0.2, < 4.0)
17
+ concurrent-ruby (1.1.5)
18
+ crack (0.4.3)
19
+ safe_yaml (~> 1.0.0)
20
+ diff-lcs (1.3)
21
+ hashdiff (0.3.9)
22
+ i18n (1.6.0)
23
+ concurrent-ruby (~> 1.0)
24
+ minitest (5.11.3)
25
+ public_suffix (3.0.3)
26
+ rake (10.5.0)
27
+ rspec (3.8.0)
28
+ rspec-core (~> 3.8.0)
29
+ rspec-expectations (~> 3.8.0)
30
+ rspec-mocks (~> 3.8.0)
31
+ rspec-core (3.8.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-expectations (3.8.3)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-mocks (3.8.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.8.0)
39
+ rspec-support (3.8.0)
40
+ safe_yaml (1.0.5)
41
+ thread_safe (0.3.6)
42
+ tzinfo (1.2.5)
43
+ thread_safe (~> 0.1)
44
+ webmock (3.5.1)
45
+ addressable (>= 2.3.6)
46
+ crack (>= 0.3.2)
47
+ hashdiff
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.17)
54
+ dal!
55
+ rake (~> 10.0)
56
+ rspec (~> 3.0)
57
+ webmock
58
+
59
+ BUNDLED WITH
60
+ 1.17.3
@@ -0,0 +1,56 @@
1
+ # Dal
2
+
3
+ This is the DAL client gem created by the Sulu team for making queries to the DAL.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dal', git: 'https://the-oauth-creds@github.azc.ext.hp.com/3DSoftware/dal.git', :tag => 'tag-version'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ To use this gem in your Rails project it will need some configuration.
20
+
21
+ Inside an initializer:
22
+ ```ruby
23
+ Dal.configure do |config|
24
+ config.logger = Rails.logger
25
+
26
+ config.dal_api_key = DAL_API_KEY
27
+ config.dal_api_secret = DAL_API_SECRET
28
+ config.dal_api_service = DAL_API_SERVICE
29
+ config.dal_api_base_url = DAL_API_BASE_URL
30
+ config.dal_api_region = DAL_API_REGION
31
+ end
32
+ ```
33
+
34
+ `UsageClient:`
35
+ ```ruby
36
+ UsageClient.get_usage([aaa_device_ids], start_day, end_day, unit)
37
+ ```
38
+ `JobClient`
39
+ ```ruby
40
+ JobClient.get_jobs([aaa_device_id], start_day, end_day)
41
+ JobClient.get_job_by_id(job_id)
42
+ JobClient.get_jobs_by_id([job_id])
43
+ ```
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
53
+
54
+ ## Code of Conduct
55
+
56
+ Everyone interacting in the Dal project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.azc.ext.hp.com/3DSoftware/dal/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dal"
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__)
@@ -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
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dal/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dal"
8
+ spec.version = Dal::VERSION
9
+ spec.authors = ["Josh Humphrey"]
10
+ spec.email = ["joshua.humphrey@hp.com"]
11
+
12
+ spec.summary = %q{Dal Client Library}
13
+ spec.description = %q{Dal Client Library}
14
+ spec.homepage = "https://github.azc.ext.hp.com/3DSoftware/dal"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "webmock"
29
+
30
+ spec.add_dependency "activesupport", "~> 5.1"
31
+ end
@@ -0,0 +1,10 @@
1
+ require_relative "dal/version"
2
+ require_relative "dal/configuration"
3
+ require_relative "dal/base_client"
4
+ require_relative "dal/job_client"
5
+ require_relative "dal/usage_client"
6
+ require_relative "dal/device_client"
7
+
8
+ module Dal
9
+
10
+ end
@@ -0,0 +1,106 @@
1
+ class BaseClient
2
+ require 'uri'
3
+ require 'openssl'
4
+ require 'net/http'
5
+ require 'cgi'
6
+
7
+ private
8
+
9
+ def self.json(content)
10
+ JSON.parse(content, symbolize_names: :true)
11
+ rescue => e
12
+ Dal.config.logger.error({message: e.message})
13
+ nil
14
+ end
15
+
16
+ def self.getSignatureKey(key, dateStamp, regionName, serviceName)
17
+ kDate = OpenSSL::HMAC.digest('sha256', "AWS4" + key, dateStamp)
18
+ kRegion = OpenSSL::HMAC.digest('sha256', kDate, regionName)
19
+ kService = OpenSSL::HMAC.digest('sha256', kRegion, serviceName)
20
+ kSigning = OpenSSL::HMAC.digest('sha256', kService, "aws4_request")
21
+ kSigning
22
+ end
23
+
24
+ # source: https://gist.github.com/blelump/9e6880a87fefa6397032
25
+ def self.api_request(method, uri, params, body = '')
26
+ access_key = Dal.config.dal_api_key
27
+ secret_key = Dal.config.dal_api_secret
28
+ service = Dal.config.dal_api_service
29
+ host = Dal.config.dal_api_base_url
30
+ region = Dal.config.dal_api_region
31
+
32
+ endpoint = "https://#{host}"
33
+ request_parameters = params.to_param
34
+
35
+ t = Time.now.utc
36
+ amzdate = t.strftime('%Y%m%dT%H%M%SZ')
37
+ datestamp = t.strftime('%Y%m%d')
38
+
39
+ # Task 1: Create a Canonical Request For Signature Version 4
40
+ # http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
41
+ canonical_uri = uri
42
+ signed_headers = 'host;x-amz-date'
43
+ payload_hash = OpenSSL::Digest.new("sha256").hexdigest(body)
44
+ canonical_headers = [
45
+ 'host:' + host,
46
+ 'x-amz-date:' + amzdate].join("\n") + "\n"
47
+
48
+ canonical_request = [method, canonical_uri, request_parameters, canonical_headers, signed_headers, payload_hash].join("\n")
49
+
50
+ # Task 2: Create a String to Sign for Signature Version 4
51
+ # http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html
52
+ algorithm = 'AWS4-HMAC-SHA256'
53
+ credential_scope = [datestamp, region, service, 'aws4_request'].join("/")
54
+ string_to_sign = [
55
+ algorithm, amzdate, credential_scope,
56
+ OpenSSL::Digest.new("sha256").hexdigest(canonical_request)
57
+ ].join("\n")
58
+
59
+ # Task 3: Calculate the AWS Signature Version 4
60
+ # http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
61
+ signing_key = getSignatureKey(secret_key, datestamp, region, service)
62
+
63
+ # Task 4: Add the Signing Information to the Request
64
+ # http://docs.aws.amazon.com/general/latest/gr/sigv4-add-signature-to-request.html
65
+ signature = OpenSSL::HMAC.hexdigest('sha256', signing_key, string_to_sign)
66
+ uri = URI.parse(endpoint)
67
+ https = Net::HTTP.new(uri.host, uri.port)
68
+ https.use_ssl = true
69
+
70
+ request_parameters_str = request_parameters.present? ? ('?' + request_parameters) : ''
71
+
72
+ request = "Net::HTTP::#{method.titlecase}".constantize.new("#{canonical_uri}#{request_parameters_str}")
73
+
74
+ auth = "#{algorithm} Credential=#{access_key + '/' + credential_scope}, SignedHeaders=#{signed_headers}, Signature=#{signature}"
75
+
76
+ request.add_field 'Content-Type', "json"
77
+ request.add_field 'X-Amz-Date', amzdate
78
+ request.add_field 'X-Amz-Content-Sha256', payload_hash
79
+ request.add_field 'Authorization', auth
80
+ request.add_field 'Accept', 'json'
81
+ request.body = body
82
+
83
+ begin
84
+ tries ||= 3
85
+
86
+ res = https.request(request)
87
+
88
+ case res.code.to_i
89
+ when 500..599
90
+ sleep 0.5
91
+ fail res.body
92
+ when 400..499
93
+ tries = 1
94
+ fail res.body
95
+ end
96
+
97
+ json(res.body)
98
+ rescue StandardError => e
99
+ Dal.config.logger.error({message: e.message})
100
+
101
+ retry unless (tries -= 1).zero?
102
+ nil
103
+ end
104
+ end
105
+ end
106
+
@@ -0,0 +1,24 @@
1
+ module Dal
2
+ require 'ostruct'
3
+
4
+ class << self
5
+
6
+ def config
7
+ @config ||= OpenStruct.new(default_params)
8
+ end
9
+
10
+ def configure
11
+ yield config
12
+ end
13
+
14
+ private
15
+
16
+ def default_params
17
+ if defined?(Rails)
18
+ YAML.load_file(File.join(Rails.root, 'config', 'printos.yml')) rescue {}
19
+ else
20
+ {}
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,140 @@
1
+ class DeviceClient < BaseClient
2
+ DEVICES_URL = '/api/v1/devices/_search-by-devices'
3
+
4
+ def self.get_devices_by_ids(device_ids)
5
+ url = DEVICES_URL
6
+ post_body = {
7
+ 'aaa-device-ids' => device_ids
8
+ }.to_json
9
+ # res_hash = api_request 'POST', url, {}, post_body
10
+ res_hash = {
11
+ devices: [{
12
+ "aaa_device_id": "749883ec-641c-456a-9bda-fd9ccd4107cd",
13
+ "aaa_organization_id": "dcbeab71-dc2a-4fcb-aba0-2ba5a07feeb1",
14
+ "activity": "Printing",
15
+ "alerts": [{
16
+ "area": "/IDS/CARTRIDGES/CARTRIDGE_fusing_black_0/",
17
+ "cardinal_name": "/IDS/CARTRIDGES/CARTRIDGE_%s_%s_%d/LOW",
18
+ "id": "161092183422018",
19
+ "is_hidden": "false",
20
+ "name": "LOW",
21
+ "severity": "Warning",
22
+ "timestamp": "2019-03-06T11:57:47.000Z"
23
+ }, {
24
+ "area": "/MAINTENANCE/WASTE_CONTAINER_0/",
25
+ "cardinal_name": "/MAINTENANCE/WASTE_CONTAINER_%d/REPLACEMENT_LEVEL_REACHED",
26
+ "id": "161092183422999",
27
+ "is_hidden": "false",
28
+ "name": "REPLACEMENT_LEVEL_REACHED",
29
+ "severity": "Error",
30
+ "timestamp": "2019-03-07T16:20:58.000Z"
31
+ }, {
32
+ "area": "/MAINTENANCE/LIQUID_TANK_abc_5/",
33
+ "cardinal_name": "/MAINTENANCE/LIQUID_TANK_%s_%d/NOT_PRESENT",
34
+ "id": "161092183422999",
35
+ "is_hidden": "false",
36
+ "name": "NOT_PRESENT",
37
+ "severity": "Error",
38
+ "timestamp": "2019-03-10T16:20:58.000Z"
39
+ }, {
40
+ "area": "/MAINTENANCE/FILTER_front_3/",
41
+ "cardinal_name": "/MAINTENANCE/FILTER_%s_%d/ERROR",
42
+ "id": "161092183422999",
43
+ "is_hidden": "false",
44
+ "name": "ERROR",
45
+ "severity": "Error",
46
+ "timestamp": "2019-03-08T16:20:58.000Z"
47
+ }],
48
+ "command_center_version": "CC_0.1",
49
+ "current_job_id": "31643c1c-d397-477f-9809-2bd0a478a49d",
50
+ "error_code": nil,
51
+ "fw_version": "TATDAG_14_18_05.49",
52
+ "last_updated": "2019-03-07T14:37:52.000Z",
53
+ "last_heartbeat": "2019-03-07T14:37:52.000Z",
54
+ "most_relevant_status": "WithAlerts",
55
+ "part_number": "2YG73A",
56
+ "serial_number": "SG84534001",
57
+ "severity": "Warning",
58
+ "status": "printing",
59
+ "total_jobs": 2,
60
+ "trolley_uuid": "bb9f50c3-6153-6390-2ac0-9a6b5c121f33",
61
+ "links": [{
62
+ "rel": "current_job",
63
+ "href": "https://<jobDAL>/api/v1/jobs/31643c1c-d397-477f-9809-2bd0a478a49d"
64
+ }]
65
+ }, {
66
+ "aaa_device_id": "b377a474-608d-4a0d-a6d8-63c4c1ee3561",
67
+ "aaa_organization_id": "dcbeab71-dc2a-4fcb-aba0-2ba5a07feeb1",
68
+ "activity": "Printing",
69
+ "alerts": [{
70
+ "area": "/IDS/PRINTHEADS/PRINTHEAD_33/",
71
+ "cardinal_name": "/IDS/PRINTHEADS/PRINTHEAD_%d/RESEAT",
72
+ "id": "161092183422018",
73
+ "is_hidden": "false",
74
+ "name": "LOW",
75
+ "severity": "Warning",
76
+ "timestamp": "2019-03-06T11:57:47.000Z"
77
+ }, {
78
+ "area": "/TOP_LAMPS/LAMP_1/",
79
+ "cardinal_name": "/TOP_LAMPS/LAMP_%d/FUSED",
80
+ "id": "161092183422999",
81
+ "is_hidden": "false",
82
+ "name": "REPLACEMENT_LEVEL_REACHED",
83
+ "severity": "Error",
84
+ "timestamp": "2019-03-07T16:20:58.000Z"
85
+ }, {
86
+ "area": "/IDS/CARTRIDGES/CARTRIDGE_fusing_blue_5/",
87
+ "cardinal_name": "/IDS/CARTRIDGES/CARTRIDGE_%s_%s_%d/LOW",
88
+ "id": "161092183422018",
89
+ "is_hidden": "false",
90
+ "name": "LOW",
91
+ "severity": "Warning",
92
+ "timestamp": "2019-03-09T11:57:47.000Z"
93
+ }, {
94
+ "area": "/IDS/PRINTHEADS/PRINTHEAD_1/",
95
+ "cardinal_name": "/IDS/PRINTHEADS/PRINTHEAD_%d/TEST_SEPARATELY",
96
+ "id": "161092183422018",
97
+ "is_hidden": "false",
98
+ "name": "LOW",
99
+ "severity": "Warning",
100
+ "timestamp": "2019-03-12T11:57:47.000Z"
101
+ }, {
102
+ "area": "/MAINTENANCE/FILTER_front_3/",
103
+ "cardinal_name": "/MAINTENANCE/FILTER_%s_%d/ERROR",
104
+ "id": "161092183422999",
105
+ "is_hidden": "false",
106
+ "name": "ERROR",
107
+ "severity": "Error",
108
+ "timestamp": "2019-03-10T16:20:58.000Z"
109
+ }, {
110
+ "area": "/MAINTENANCE/LIQUID_TANK_xyz_1/",
111
+ "cardinal_name": "/MAINTENANCE/LIQUID_TANK_%s_%d/ERROR",
112
+ "id": "161092183422999",
113
+ "is_hidden": "false",
114
+ "name": "ERROR",
115
+ "severity": "Error",
116
+ "timestamp": "2019-03-10T16:20:58.000Z"
117
+ }],
118
+ "command_center_version": "CC_0.1",
119
+ "current_job_id": "31643c1c-d397-477f-9809-2bd0a478a49d",
120
+ "error_code": nil,
121
+ "fw_version": "TATDAG_14_18_05.49",
122
+ "last_updated": "2019-03-07T14:37:52.000Z",
123
+ "last_heartbeat": "2019-03-07T14:37:52.000Z",
124
+ "most_relevant_status": "WithAlerts",
125
+ "part_number": "2YG73A",
126
+ "serial_number": "SG84534001",
127
+ "severity": "Warning",
128
+ "status": "printing",
129
+ "total_jobs": 2,
130
+ "trolley_uuid": "bb9f50c3-6153-6390-2ac0-9a6b5c121f33",
131
+ "links": [{
132
+ "rel": "current_job",
133
+ "href": "https://<jobDAL>/api/v1/jobs/31643c1c-d397-477f-9809-2bd0a478a49d"
134
+ }]
135
+ }]
136
+ }
137
+ res_hash.present? ? res_hash[:devices] : nil
138
+ end
139
+ end
140
+
@@ -0,0 +1,30 @@
1
+ class JobClient < BaseClient
2
+ JOBS_BY_DEVICE_IDS = '/api/v1/jobs/_search-by-devices'
3
+ JOB_BY_ID_URL = '/api/v1/jobs/%{job_id}'
4
+ JOBS_LIST_BY_ID_URL = '/api/v1/jobs/_search-by-jobs'
5
+
6
+ def self.get_jobs(device_ids, start_day, end_day)
7
+ device_ids = [device_ids] unless device_ids.is_a?(Array)
8
+ url = JOBS_BY_DEVICE_IDS
9
+ post_body = {
10
+ "aaa-device-ids": device_ids,
11
+ "start": start_day.iso8601(3),
12
+ "end": end_day.iso8601(3)
13
+ }.to_json
14
+ res_hash = api_request 'POST', url, {}, post_body
15
+ res_hash.present? ? res_hash[:data] : nil
16
+ end
17
+
18
+ def self.get_job_by_id(job_id)
19
+ url = JOB_BY_ID_URL % {job_id: job_id}
20
+ res_hash = api_request 'GET', url, {}
21
+ res_hash.present? ? res_hash[:data] : nil
22
+ end
23
+
24
+ def self.get_jobs_by_id(job_ids)
25
+ job_ids = [job_ids] unless job_ids.is_a?(Array)
26
+ post_body = {'job-ids': job_ids}.to_json
27
+ res_hash = api_request 'POST', JOBS_LIST_BY_ID_URL, {}, post_body
28
+ res_hash.present? ? res_hash[:data] : nil
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ class UsageClient < BaseClient
2
+ USAGE_URL = '/api/v1/usage/_search-by-devices'
3
+
4
+ def self.get_usage(devices, start_day, end_day, unit = 'day')
5
+ url = USAGE_URL
6
+ post_body = {
7
+ "aaa-device-ids": devices,
8
+ "start": start_day.iso8601(3),
9
+ "end": end_day.iso8601(3),
10
+ "unit": unit
11
+ }.to_json
12
+ res_hash = api_request 'POST', url, {}, post_body
13
+ res_hash.present? ? res_hash[:data] : nil
14
+ end
15
+ end
16
+
@@ -0,0 +1,3 @@
1
+ module Dal
2
+ VERSION = "0.1.9"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9
5
+ platform: ruby
6
+ authors:
7
+ - Josh Humphrey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ description: Dal Client Library
84
+ email:
85
+ - joshua.humphrey@hp.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - dal.gemspec
101
+ - lib/dal.rb
102
+ - lib/dal/base_client.rb
103
+ - lib/dal/configuration.rb
104
+ - lib/dal/device_client.rb
105
+ - lib/dal/job_client.rb
106
+ - lib/dal/usage_client.rb
107
+ - lib/dal/version.rb
108
+ homepage: https://github.azc.ext.hp.com/3DSoftware/dal
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.13
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Dal Client Library
131
+ test_files: []