g5-jobbing 0.0.1

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
+ SHA1:
3
+ metadata.gz: 55652a2298d944b826ddea6b131b8f274361764a
4
+ data.tar.gz: 2282b5b732157ec4c93e7eebaecc501ee2b0ba81
5
+ SHA512:
6
+ metadata.gz: cac1729f614604cd32927778b448d1b838f4b48363209a29d0a0d69f488675be5436eaae5185ef113ee6766c43035e77ff53cd3fa7232cad142ab0ba193c40ed
7
+ data.tar.gz: dadda9985bea16ea44eee5888ec31c81cf72cc19e9e5a92bde10b638ba6e62404fc1114a0855f110091d56784c6d170a039f571fe5dab82b44ead37703e32fb0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.4
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
4
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in g5-jobbing.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Perry Hertler
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # G5::Jobbing
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'g5-jobbing'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install g5-jobbing
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/g5-jobbing/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'g5/jobbing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "g5-jobbing"
8
+ spec.version = G5::Jobbing::VERSION
9
+ spec.authors = ["Perry Hertler"]
10
+ spec.email = ["perry@hertler.org"]
11
+ spec.summary = %q{Uses the g5-jobs service to manage and organize jobs.}
12
+ spec.description = %q{Uses the g5-jobs service to manage and organize jobs.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", ">= 3.1"
24
+ spec.add_development_dependency "rspec-its"
25
+ spec.add_development_dependency "pry-nav"
26
+
27
+ spec.add_dependency "activesupport"
28
+ spec.add_dependency "httparty"
29
+ spec.add_dependency "virtus"
30
+ spec.add_dependency "g5_authentication_client", ">= 0.2"
31
+ end
32
+
@@ -0,0 +1,5 @@
1
+ module G5::Jobbing::AccessToken
2
+ def get_access_token
3
+ @access_token ||= G5AuthenticationClient::Client.new.get_access_token
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ class G5::Jobbing::Job
2
+ include Virtus.model
3
+
4
+ attribute :uid, String
5
+ attribute :urn, String
6
+ attribute :state, String
7
+ attribute :created_at, DateTime
8
+ attribute :updated_at, DateTime
9
+ attribute :integration_setting_uid, String
10
+ attribute :message, String
11
+
12
+ def logs_url
13
+ return 'ENV[LOGS_BY_JOB_URL] not set!' if logs_by_job_url.blank?
14
+ logs_by_job_url.gsub('{{JOB_ID}}', "#{self.urn}")
15
+ end
16
+
17
+ def logs_by_job_url
18
+ ENV['LOGS_BY_JOB_URL']
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ class G5::Jobbing::JobRetriever
2
+ include G5::Jobbing::AccessToken
3
+ attr_accessor :locations_integration_setting_uids
4
+
5
+ def initialize(params={})
6
+ self.locations_integration_setting_uids = params[:locations_integration_setting_uids]
7
+ end
8
+
9
+ def perform
10
+ response = HTTParty.get(jobs_url_for_locations,
11
+ {query: {access_token: get_access_token},
12
+ headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'}}
13
+ )
14
+ JSON.parse(response.body)['jobs'].collect { |job_hash| G5::Jobbing::Job.new(job_hash) }
15
+ end
16
+
17
+ def jobs_url_for_locations
18
+ "#{ENV['JOBS_URL']}/api/v1/jobs?current=true&integration_setting_uid=#{CGI.escape(locations_as_parameter)}"
19
+ end
20
+
21
+ def locations_as_parameter
22
+ "[#{self.locations_integration_setting_uids.join(',')}]"
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ class G5::Jobbing::JobStarter
2
+ include G5::Jobbing::AccessToken
3
+ attr_accessor :locations_integration_setting_uid
4
+
5
+ def initialize(params={})
6
+ self.locations_integration_setting_uid = params[:locations_integration_setting_uid]
7
+ end
8
+
9
+ def perform
10
+ response = HTTParty.post(start_job_url,
11
+ {query: {access_token: get_access_token},
12
+ headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'}}
13
+ )
14
+ 201 == response.code
15
+ end
16
+
17
+ def start_job_url
18
+ "#{ENV['JOBS_URL']}/api/v1/job_runners?integration_setting_uid=#{CGI.escape(self.locations_integration_setting_uid)}"
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module G5
2
+ module Jobbing
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/g5/jobbing.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'g5/jobbing/version'
3
+ require 'g5_authentication_client'
4
+ require 'httparty'
5
+ require 'virtus'
6
+
7
+ module G5
8
+ module Jobbing
9
+
10
+ end
11
+ end
12
+
13
+ require 'g5/jobbing/access_token'
14
+ require 'g5/jobbing/job'
15
+ require 'g5/jobbing/job_retriever'
16
+ require 'g5/jobbing/job_starter'
@@ -0,0 +1,20 @@
1
+ {"jobs": [
2
+ {
3
+ "uid": "http://localhost:5778/api/v1/jobs/g5-job-6i4h4jo",
4
+ "urn": "g5-job-6i4h4jo",
5
+ "state": "started",
6
+ "created_at": "2014-11-10T14:57:49.216-08:00",
7
+ "updated_at": "2014-11-10T15:12:23.111-08:00",
8
+ "integration_setting_uid": "http://localhost/clients/g5-c-6i4h3un-ethan-bode/locations/g5-cl-6i4h3uo-zoe-krajcik/locations_integration_settings/g5-lis-6i4h3uo",
9
+ "message": null
10
+ },
11
+ {
12
+ "uid": "http://localhost:5778/api/v1/jobs/g5-job-6i4h4bb",
13
+ "urn": "g5-job-6i4h4bb",
14
+ "state": "started",
15
+ "created_at": "2014-11-10T14:57:19.546-08:00",
16
+ "updated_at": "2014-11-10T15:12:23.103-08:00",
17
+ "integration_setting_uid": "http://localhost/clients/g5-c-6i4h3un-ethan-bode/locations/g5-cl-6i4h3un-retha-hane/locations_integration_settings/g5-lis-6i4h3un",
18
+ "message": null
19
+ }
20
+ ]}
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5::Jobbing::JobRetriever do
4
+ let!(:locations_integration_setting_uid_1) { 'uid1' }
5
+ let!(:locations_integration_setting_uid_2) { 'uid2' }
6
+
7
+ subject { G5::Jobbing::JobRetriever.new(locations_integration_setting_uids: [locations_integration_setting_uid_1, locations_integration_setting_uid_2]) }
8
+
9
+ describe :perform do
10
+ let(:body) { fixture('jobs.json') }
11
+ let(:body_hash) { JSON.parse(body)[:jobs] }
12
+ let(:token) { 'the toke' }
13
+ before do
14
+ expect(G5AuthenticationClient::Client).to receive(:new).and_return(double(:token, get_access_token: token))
15
+ expect(HTTParty).to receive(:get).with(subject.jobs_url_for_locations,
16
+ {query: {access_token: token},
17
+ headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'}}).
18
+ and_return(double(:response, body: body))
19
+ end
20
+ it 'returns array of jobs' do
21
+ result = subject.perform
22
+ expect(result.length).to eq(2)
23
+ expect(result.all? { |job| G5::Jobbing::Job == job.class }).to be_truthy
24
+ expect(result.collect(&:integration_setting_uid)).to eq(%w(http://localhost/clients/g5-c-6i4h3un-ethan-bode/locations/g5-cl-6i4h3uo-zoe-krajcik/locations_integration_settings/g5-lis-6i4h3uo http://localhost/clients/g5-c-6i4h3un-ethan-bode/locations/g5-cl-6i4h3un-retha-hane/locations_integration_settings/g5-lis-6i4h3un))
25
+ end
26
+ end
27
+
28
+ its (:locations_as_parameter) { is_expected.to eq("[#{locations_integration_setting_uid_1},#{locations_integration_setting_uid_2}]") }
29
+
30
+ describe :jobs_url_for_locations do
31
+ it 'filters by current and locations_integration_setting UIDs' do
32
+ expect(subject).to receive(:locations_as_parameter).and_return('loc_param')
33
+ expect(subject.jobs_url_for_locations).to match(/\/api\/v1\/jobs\?current=true&integration_setting_uid=loc_param/)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5::Jobbing::Job do
4
+ let(:uid) { 'uid' }
5
+ let(:urn) { 'urn' }
6
+ let(:state) { 'state' }
7
+ let(:integration_setting_uid) { 'isuid' }
8
+ let(:message) { 'message' }
9
+ let(:created_at) { DateTime.new(2012, 11, 11) }
10
+ let(:updated_at) { DateTime.new(2013, 10, 10) }
11
+
12
+ subject { G5::Jobbing::Job.new(uid: uid, urn: urn, state: state,
13
+ integration_setting_uid: integration_setting_uid,
14
+ message: message, created_at: created_at, updated_at: updated_at) }
15
+
16
+ its(:uid) { is_expected.to eq(uid) }
17
+ its(:urn) { is_expected.to eq(urn) }
18
+ its(:state) { is_expected.to eq(state) }
19
+ its(:integration_setting_uid) { is_expected.to eq(integration_setting_uid) }
20
+ its(:message) { is_expected.to eq(message) }
21
+ its(:created_at) { is_expected.to eq(created_at) }
22
+ its(:updated_at) { is_expected.to eq(updated_at) }
23
+
24
+ describe 'logs_url' do
25
+ subject { G5::Jobbing::Job.new(urn: 3) }
26
+
27
+ context 'LOGS_BY_JOB_URL set' do
28
+ it 'generates proper url' do
29
+ expect(subject).to receive(:logs_by_job_url).at_least(:once).and_return('http://splunk.com?external_id={{JOB_ID}}')
30
+ expect(subject.logs_url).to eq('http://splunk.com?external_id=3')
31
+ end
32
+ end
33
+
34
+ context 'LOGS_BY_JOB_URL NOT set' do
35
+ it 'generates proper url' do
36
+ expect(subject).to receive(:logs_by_job_url).and_return(nil)
37
+ expect(subject.logs_url).to eq('ENV[LOGS_BY_JOB_URL] not set!')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5::Jobbing::JobStarter do
4
+ let(:locations_integration_setting_uid) { 'a-uid' }
5
+ let(:token) { 'the toke' }
6
+ subject { G5::Jobbing::JobStarter.new(locations_integration_setting_uid: locations_integration_setting_uid) }
7
+
8
+ describe :perform do
9
+ before do
10
+ expect(G5AuthenticationClient::Client).to receive(:new).and_return(double(:token, get_access_token: token))
11
+ expect(HTTParty).to receive(:post).with(subject.start_job_url,
12
+ {query: {access_token: token},
13
+ headers: {'Content-Type' => 'application/json', 'Accept' => 'application/json'}}).
14
+ and_return(double(:response, code: code))
15
+ end
16
+ describe 'success' do
17
+ let(:code) { 201 }
18
+ its(:perform) { is_expected.to be_truthy }
19
+ end
20
+
21
+ describe 'failure' do
22
+ let(:code) { 404 }
23
+ its(:perform) { is_expected.to be_falsey }
24
+ end
25
+ end
26
+
27
+ its(:start_job_url) { is_expected.to match(/\/api\/v1\/job_runners\?integration_setting_uid=/) }
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'g5/jobbing'
2
+ require 'pry'
3
+ require 'rspec/its'
4
+
5
+ module FixturesHelper
6
+ def fixture(fixture_path)
7
+ open(File.join("spec", "fixtures", fixture_path)).read
8
+ end
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.include FixturesHelper
13
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: g5-jobbing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Perry Hertler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
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: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: virtus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: g5_authentication_client
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0.2'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0.2'
139
+ description: Uses the g5-jobs service to manage and organize jobs.
140
+ email:
141
+ - perry@hertler.org
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".ruby-version"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - g5-jobbing.gemspec
154
+ - lib/g5/jobbing.rb
155
+ - lib/g5/jobbing/access_token.rb
156
+ - lib/g5/jobbing/job.rb
157
+ - lib/g5/jobbing/job_retriever.rb
158
+ - lib/g5/jobbing/job_starter.rb
159
+ - lib/g5/jobbing/version.rb
160
+ - spec/fixtures/jobs.json
161
+ - spec/lib/g5/jobbing/job_retriever_spec.rb
162
+ - spec/lib/g5/jobbing/job_spec.rb
163
+ - spec/lib/g5/jobbing/job_starter_spec.rb
164
+ - spec/spec_helper.rb
165
+ homepage: ''
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.2.2
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Uses the g5-jobs service to manage and organize jobs.
189
+ test_files:
190
+ - spec/fixtures/jobs.json
191
+ - spec/lib/g5/jobbing/job_retriever_spec.rb
192
+ - spec/lib/g5/jobbing/job_spec.rb
193
+ - spec/lib/g5/jobbing/job_starter_spec.rb
194
+ - spec/spec_helper.rb