portals_api 0.0.0

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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +1 -0
  3. data/README.md +37 -0
  4. data/bin/portals_run +64 -0
  5. data/lib/portals_api.rb +53 -0
  6. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 978e30dd5d37062734eefc4901c69be201a9e20d
4
+ data.tar.gz: 96bdc6b9fe354ac38fe55f1318d521e42b9ad4c4
5
+ SHA512:
6
+ metadata.gz: 3f00e0244805b0e44791a4cf17f3037c17a6fcffcabdc82ba30a673bd505d9745710aaf6e35eb84d2d956fa1ac5ee0a6f43ee88c57a52b1772e7a326ef204f50
7
+ data.tar.gz: d8fe5aaac1aa0d12cfe25b56caece0cdfa98cab1cbec35e0bf8ad6e3ffa11887c24b770c4804abc57ad660d1604d5f790e56ac93e4ae1975a6e9a5a060121645
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gem 'trollop'
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Portals Run and Portals API
2
+ # Portals API.rb
3
+ `portals_api.rb`
4
+
5
+ portals_api.rb Ruby file is provides the interface to the portals API. It contains the following Class info:
6
+ class PortalsAPI
7
+ @access_token - the instance attribute the access_token provided to the constructor
8
+ #initialize - constructor that sets access_token
9
+ #retrieve_portal_status - provides the portal status
10
+ #start_stop_portal - toggles the portal from started or stopped to the opposite
11
+ #retrieve_checkedout_patchset - gets the name of the checked out patchset, else false
12
+ #checkout_patchset - sends the command to checkout a specific patchset
13
+ #cancel_portal_request - cancels whatever request has been send, if any
14
+ private
15
+ #get_request - uses HTTP GET request to make the calls to the API
16
+
17
+ ## Portals Run Command
18
+ `portals_run`
19
+
20
+ portals_run is a Ruby tool that provides a command line interface to the portals API (via portals_api.rb). Here is the usages for portals_run:
21
+ portal_api.rb is an awesome program starts and stops portals
22
+ Usage:
23
+ portal_api.rb [options] <filenames>+
24
+ where [options] are:
25
+
26
+ -a, --accesstoken=<s> Portals Access Token
27
+ -p, --portalstat Retrieve portal status
28
+ -s, --startportal Start Portal
29
+ -t, --stopportal Stop portal
30
+ --psstat Retrieve patchset status
31
+ -c, --checkoutps=<s> Checkout Patchset xx.xxxxx.x format (default: master)
32
+ -u, --user=<s> Portal User (default: rkuss2)
33
+ -h, --phost=<s> Portal Host (default: https://portal2-beta.instructure.com/)
34
+ -d, --dbcreate Drop and recreate db
35
+ -n, --cancelportal Cancel Portal Request
36
+ -v, --version Print version and exit
37
+ -e, --help Show this message
data/bin/portals_run ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'trollop'
5
+ require 'portals_api'
6
+
7
+ opts = Trollop.options do
8
+ version '1.0'
9
+ banner <<-EOS
10
+ portal_api.rb is an awesome program starts and stops portals
11
+
12
+ Usage:
13
+ portal_api.rb [options] <filenames>+
14
+ where [options] are:
15
+ EOS
16
+
17
+ opt :accesstoken, 'Portals Access Token', type: :string
18
+ opt :portalstat, 'Retrieve portal status'
19
+ opt :startportal, 'Start Portal'
20
+ opt :stopportal, 'Stop portal'
21
+ opt :psstat, 'Retrieve patchset status'
22
+ opt :checkoutps, 'Checkout Patchset xx.xxxxx.x format', default: 'master'
23
+ opt :user, 'Portal User', default: 'rkuss2'
24
+ opt :phost, 'Portal Host', default: 'https://portal2-beta.instructure.com/'
25
+ opt :dbcreate, 'Drop and recreate db'
26
+ opt :cancelportal, 'Cancel Portal Request'
27
+ end
28
+
29
+ Trollop.die :accesstoken, 'Access Token for portal must be provided' \
30
+ unless opts[:accesstoken_given]
31
+ Trollop.die :portalstat, 'Cannot check portal status and perform activity at the same time' \
32
+ if opts[:portalstat] && (opts[:startportal_given] || opts[:stopportal_given] || opts[:checkoutps_given])
33
+ Trollop.die :psstat, 'Cannot check patchset status and perform activity at the same time' \
34
+ if opts[:psstat] && (opts[:startportal_given] || opts[:stopportal_given] || opts[:checkoutps_given])
35
+ Trollop.die :startportal, 'cannot start portal and checkout ps at same time' \
36
+ if opts[:startportal_given] && opts[:stopportal_given]
37
+ Trollop.die :startportal, 'cannot start portal and checkout ps at same time' \
38
+ if opts[:startportal_given] && opts[:checkoutps_given]
39
+ Trollop.die :stopportal, 'cannot start portal and checkout ps at same time' \
40
+ if opts[:stopportal_given] && opts[:checkoutps_given]
41
+
42
+ portal_api = PortalsAPI.new(opts[:accesstoken])
43
+
44
+ if opts[:portalstat]
45
+ puts portal_api.retrieve_portal_status(opts[:phost], opts[:user])
46
+ end
47
+
48
+ if opts[:startportal] && portal_api.retrieve_portal_status(opts[:phost], opts[:user])
49
+ portal_api.start_stop_portal(opts[:phost], opts[:user])
50
+ end
51
+
52
+ portal_api.start_stop_portal(opts[:phost], opts[:user]) if opts[:stopportal]
53
+
54
+ if opts[:psstat]
55
+ puts portal_api.retrieve_checkedout_patchset(opts[:phost], opts[:user])
56
+ end
57
+
58
+ if opts[:checkoutps_given]
59
+ portal_api.checkout_patchset(opts[:checkoutps], opts[:dbcreate], opts[:phost], opts[:user])
60
+ end
61
+
62
+ if opts[:cancelportal]
63
+ portal_api.cancel_portal_request(opts[:phost], opts[:user])
64
+ end
@@ -0,0 +1,53 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'trollop'
4
+ class PortalsAPI
5
+ attr_accessor :access_token
6
+
7
+ PORTALS_HOST = 'https://portal2-beta.instructure.com/'.freeze
8
+ PORTALS_USER = 'rkuss2'.freeze
9
+
10
+ def initialize(portal_access_token)
11
+ @access_token = portal_access_token
12
+ end
13
+
14
+ def retrieve_portal_status(portals_host = PORTALS_HOST, portals_user = PORTALS_USER)
15
+ portal_endpoint = portals_host + 'canvas/isStarted/' + portals_user
16
+ get_request(portal_endpoint).body
17
+ end
18
+
19
+ def start_stop_portal(portals_host = PORTALS_HOST, portals_user = PORTALS_USER)
20
+ portal_endpoint = portals_host + 'canvas/startStopPortal/' + portals_user
21
+ get_request(portal_endpoint).body
22
+ end
23
+
24
+ def retrieve_checkedout_patchset(portals_host = PORTALS_HOST, portals_user = PORTALS_USER)
25
+ portal_endpoint = portals_host + 'canvas/isCheckedOut/' + portals_user
26
+ get_request(portal_endpoint).body
27
+ end
28
+
29
+ def checkout_patchset(patchset_name = 'master', dbcreate = false,
30
+ portals_host = PORTALS_HOST, portals_user = PORTALS_USER)
31
+ portal_endpoint = portals_host + 'canvas/checkoutPatchset?user=' + portals_user + '&patchset=' + patchset_name
32
+ portal_endpoint += '&db_created=0' if dbcreate
33
+ get_request(portal_endpoint).body
34
+ end
35
+
36
+ def cancel_portal_request(portals_host = PORTALS_HOST, portals_user = PORTALS_USER)
37
+ portal_endpoint = portals_host + 'canvas/cancelRequest?user=' + portals_user
38
+ get_request(portal_endpoint).body
39
+ end
40
+
41
+ private
42
+
43
+ def get_request(endpoint)
44
+ uri = URI.parse(endpoint)
45
+ http = Net::HTTP.new(uri.host, uri.port)
46
+ http.use_ssl = true
47
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
48
+
49
+ request = Net::HTTP::Get.new(uri.request_uri)
50
+ request['Access_token'] = @access_token
51
+ http.request(request)
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: portals_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Robin Kuss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple gem to access Portals
14
+ email: rkuss@instructure.com
15
+ executables:
16
+ - portals_run
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Gemfile
21
+ - README.md
22
+ - bin/portals_run
23
+ - lib/portals_api.rb
24
+ homepage: http://rubygems.org/gems/portals_api
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.6.11
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: API for Canvas Portals
48
+ test_files: []