ssedap-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.2-p290@ssedap-client"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ # if command -v bundle && [[ -s Gemfile ]]
51
+ # then
52
+ # bundle install
53
+ # fi
54
+
55
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ssedap-client.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # SSEDAP Client
2
+
3
+ Client gem for consuming web services exposed by [SSEDAP](/codykrieger/ssedap).
4
+
5
+ ## Dependencies
6
+
7
+ Patron ([https://github.com/toland/patron](https://github.com/toland/patron))
8
+
9
+ ## Usage
10
+
11
+
12
+ ```ruby
13
+ client = SSEDAP::Client.new "https://ssedap.local"
14
+
15
+ client.authorize user, pass
16
+ #=> {"status"=>200, "data"=>{"success"=>true, "user"=>"cjk7752", "user_info"=>{"role"=>"Admin"}}}
17
+ ```
18
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module SSEDAP
2
+ class Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,59 @@
1
+ require 'patron'
2
+ require 'json'
3
+
4
+ module SSEDAP
5
+ class Client
6
+ @host = "https://ssedap.se.rit.edu"
7
+
8
+ def initialize(host=nil)
9
+ @host = host unless host.nil?
10
+ end
11
+
12
+ def authorize(username, password)
13
+ ps = session
14
+
15
+ # url encode parameters
16
+ username = CGI::unescape username
17
+ password = CGI::unescape password
18
+
19
+ # make the request
20
+ resp = ps.post("/api/authorize", "username=#{username}&password=#{password}")
21
+
22
+ retval = {}
23
+ retval["status"] = resp.status
24
+ retval["data"] = JSON.parse resp.body
25
+
26
+ retval
27
+ end
28
+
29
+ def userinfo(username, password, lookup)
30
+ ps = session
31
+
32
+ # url encode parameters
33
+ username = CGI::unescape username
34
+ password = CGI::unescape password
35
+ lookup = CGI::unescape lookup
36
+
37
+ # make the request
38
+ resp = ps.post("/api/userinfo", "username=#{username}&password=#{password}&lookup=#{lookup}")
39
+
40
+ retval = {}
41
+ retval["status"] = resp.status
42
+ retval["data"] = JSON.parse resp.body
43
+
44
+ retval
45
+ end
46
+
47
+ private
48
+
49
+ def session
50
+ ps = Patron::Session.new
51
+ ps.timeout = 10
52
+ ps.base_url = @host
53
+ ps.headers['User-Agent'] = 'ssedap/1.0'
54
+
55
+ ps
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ssedap/client/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sean Barkley", "Cody Krieger"]
6
+ gem.email = ["sean@seanbarkley.com", "cody@codykrieger.com"]
7
+ gem.description = %q{A gem for authenticating and interfacing with an SSEDAP interface.}
8
+ gem.summary = %q{A gem for authenticating and interfacing with an SSEDAP interface.}
9
+ gem.homepage = "http://sse.se.rit.edu"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "ssedap-client"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SSEDAP::Client::VERSION
17
+
18
+ gem.requirements << 'Patron, for HTTPS requests'
19
+ gem.requirements << 'JSON, for decoding response bodies'
20
+ gem.add_dependency "patron"
21
+ gem.add_dependency "json"
22
+ end
data/test.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'ssedap/client'
2
+
3
+ host = "http://ssedap.dev"
4
+ user = ""
5
+ pass = ""
6
+ lookup = ""
7
+
8
+ puts <<-EOF
9
+ ################
10
+ SSEDAP Tester
11
+ ################
12
+
13
+ EOF
14
+
15
+ printf "Host [#{host}]: "
16
+ input = gets.chomp
17
+ host = input.empty? ? host : input
18
+
19
+ printf "Authenticating user: "
20
+ user = gets.chomp
21
+
22
+ printf "Password: "
23
+ pass = gets.chomp
24
+
25
+ printf "User to look up: "
26
+ lookup = gets.chomp
27
+
28
+ puts "\nTesting API methods..."
29
+ puts
30
+
31
+ client = SSEDAP::Client.new host
32
+ puts client.authorize user, pass
33
+ puts client.userinfo user, pass, lookup
34
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssedap-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Barkley
9
+ - Cody Krieger
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-10-28 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: patron
17
+ requirement: &70129456296040 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70129456296040
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: &70129456295620 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70129456295620
37
+ description: A gem for authenticating and interfacing with an SSEDAP interface.
38
+ email:
39
+ - sean@seanbarkley.com
40
+ - cody@codykrieger.com
41
+ executables: []
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - .gitignore
46
+ - .rvmrc
47
+ - Gemfile
48
+ - README.md
49
+ - Rakefile
50
+ - lib/ssedap/client.rb
51
+ - lib/ssedap/client/version.rb
52
+ - ssedap-client.gemspec
53
+ - test.rb
54
+ homepage: http://sse.se.rit.edu
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements:
73
+ - Patron, for HTTPS requests
74
+ - JSON, for decoding response bodies
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.10
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: A gem for authenticating and interfacing with an SSEDAP interface.
80
+ test_files: []