rpi_union 0.2.0

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: ac3aa502ab23e9dbbd6b274196cd1a2702c8aab1
4
+ data.tar.gz: 6e5aa4820cc8175785a21381509e147b9c4059e2
5
+ SHA512:
6
+ metadata.gz: 1860d286e67318a74b509cac51a323fc911fd3be4c84577b797ee878bee2d64e915a454406e7179868d4de3ba2573407576902d4e0bfbc1c99ae00a8079f03b2
7
+ data.tar.gz: 28acf0aa8da6a1d3d6b5f9d21ddeacef0b723d23eb8afcdd32480e7b20978166c38f79b9b25f85eac4552bb91d16fb143224307002f08b4c40565307656ef829
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpi_union.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Noah Goldman
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.
@@ -0,0 +1,25 @@
1
+ # RpiUnion
2
+
3
+ A thin wrapper over the RPI Union API. Accessing the API (and using the gem) requires a key that you recieve from being a union-recognized club.
4
+
5
+ Documentation of the underlying API is at https://clubs.union.rpi.edu/?content_id=260
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rpi_union'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rpi_union
22
+
23
+ ## Usage
24
+
25
+ See documentation at http://www.rubydoc.info/github/noahgoldman/rpi_union
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rpi_union"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,113 @@
1
+ require "rpi_union/version"
2
+ require 'httparty'
3
+
4
+ module RpiUnion
5
+ class Client
6
+ include HTTParty
7
+
8
+ API_BASE_URI = 'http://api.union.rpi.edu/query.php'
9
+ base_uri API_BASE_URI
10
+
11
+ GET_USER_TASK = 'GetUser'
12
+ LIST_ALL_ORGANIZATIONS_TASK = 'ListAllOrganizations'
13
+ GET_ORGANIZATION_TASK = 'GetOrganization'
14
+ GET_USER_ORGS_TASK = 'GetUserOrgs'
15
+
16
+ # Initialize a new Client with the specified API key
17
+ def initialize(api_key)
18
+ @api_key = api_key
19
+ end
20
+
21
+ # Get the properties of a specific user.
22
+ #
23
+ # @param options [Hash] Must contain one of: `:rin`, `:id` (API/database ID), or `rcsid`
24
+ # @return [Hash] The output of the API call. This is of the form:
25
+ # `{"name": ..., "rin": ..., "phone": ..., "class": ...}`
26
+ def get_user(options = {})
27
+ opts = {}
28
+ opts[:query] = {}
29
+
30
+ if options.key?(:rin)
31
+ opts[:query][:rin] = options[:rin]
32
+ elsif options.key?(:rcsid)
33
+ opts[:query][:rcsid] = options[:rcsid]
34
+ elsif options.key?(:id)
35
+ opts[:query][:dbid] = options[:id]
36
+ else
37
+ raise "You must pass one of the following as an option to get_user(): "+
38
+ "'rin', 'rcsid', or 'id'"
39
+ end
40
+
41
+ # Set middlename if it was pass in options
42
+ if options.key?(:middlename)
43
+ opts[:query][:middlename] = options[:middlename]
44
+ end
45
+
46
+ get_with_key_task(GET_USER_TASK, opts)
47
+ end
48
+
49
+ # Get all of the Union clubs
50
+ #
51
+ # @return [Array] An array of hashes of the form `{"club_id": ..., "club_name": ...}`
52
+ def list_all_organizations
53
+ get_with_key_task(LIST_ALL_ORGANIZATIONS_TASK)
54
+ end
55
+
56
+ # Get information about a club
57
+ #
58
+ # @param id [Int] The ID of the club
59
+ # @return [Hash] The result of the API call. Send an example request to see the format.
60
+ def get_organization(id)
61
+ opts = { :query => { :id => id } }
62
+ get_with_key_task(GET_ORGANIZATION_TASK, opts)
63
+ end
64
+
65
+ # Get the IDs of all the clubs of which the user is an officer
66
+ #
67
+ # @param rin [Int] The RIN of the user to search for.
68
+ def get_user_orgs(rin)
69
+ opts = { :query => { :rin => rin } }
70
+ get_with_key_task(GET_USER_ORGS_TASK, opts)
71
+ end
72
+
73
+ private
74
+
75
+ def get_with_key_task(task, options = {})
76
+ # Add the api key to the request
77
+ options[:query] ||= {}
78
+ options[:query].merge!({ :apikey => @api_key, :task => task })
79
+
80
+ res = self.class.get('', options)
81
+ data = JSON.parse(res.body)
82
+
83
+ raise ApiError.new(data['status']) unless data['status']['statusCode'] == 0
84
+
85
+ data['result']
86
+ end
87
+ end
88
+
89
+ class ApiError < StandardError
90
+ ERROR_TYPES = {
91
+ 2 => "Task Not Found",
92
+ 3 => "Database Error",
93
+ 4 => "Invalid API Key",
94
+ 5 => "Unauthorized Origin",
95
+ 10 => "Validation Error",
96
+ 11 => "Data Not Found",
97
+ }
98
+
99
+ def initialize(status_obj)
100
+ @code = status_obj['code']
101
+ @text = status_obj['text']
102
+ end
103
+
104
+ def get_error_type(code)
105
+ return "API Error" unless ERROR_TYPES.key?(code)
106
+ ERROR_TYPES[code]
107
+ end
108
+
109
+ def message
110
+ return "#{get_error_type(@code)}: #{@text}"
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,3 @@
1
+ module RpiUnion
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rpi_union/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rpi_union"
8
+ spec.version = RpiUnion::VERSION
9
+ spec.authors = ["Noah Goldman"]
10
+ spec.email = ["noah@phaaze.com"]
11
+
12
+ spec.summary = %q{A thin wrapper for the RPI Union API}
13
+ spec.description = "A tiny API to access the RPI Union API for clubs. " +
14
+ "Access to the API Requires a key from a union-sponsored " +
15
+ "club."
16
+ spec.homepage = "https://github.com/noahgoldman/rpi_union"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "httparty", "~> 0.13"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 0"
29
+ spec.add_development_dependency "webmock", "~> 0"
30
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpi_union
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Goldman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-08 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.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
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: webmock
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
+ description: A tiny API to access the RPI Union API for clubs. Access to the API Requires
84
+ a key from a union-sponsored club.
85
+ email:
86
+ - noah@phaaze.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/rpi_union.rb
100
+ - lib/rpi_union/version.rb
101
+ - rpi_union.gemspec
102
+ homepage: https://github.com/noahgoldman/rpi_union
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.4.8
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A thin wrapper for the RPI Union API
126
+ test_files: []
127
+ has_rdoc: