pennstudyspaces 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.
@@ -0,0 +1,19 @@
1
+ token.dat
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ examples.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pennstudyspaces.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,99 @@
1
+ # Ruby gem to interface with v1 of the pennstudyspaces api
2
+ require 'json'
3
+ require 'open-uri'
4
+
5
+ class PennStudySpaces
6
+ def initialize(api_root = "http://pennstudyspaces.com/api?")
7
+ @api_root = api_root
8
+ end
9
+
10
+ def query(args)
11
+ # Return array of buildings
12
+ if args.is_a? Hash
13
+ api_url = "#{@api_root}capacity=#{args['capacity']}&shr=#{args['shr']}&smin=#{args['smin']}&ehr=#{args['ehr']}&emin=#{args['emin']}&date=#{args['date']}&format=json"
14
+ elsif args.is_a? String
15
+ api_url = @api_root + args
16
+ end
17
+
18
+ response = JSON.parse(open(api_url).read)
19
+ buildings = []
20
+ response['buildings'].each do |building_json|
21
+ buildings << Building.new(building_json)
22
+ end
23
+ buildings
24
+ end
25
+
26
+ def json(args)
27
+ if args.is_a? Hash
28
+ api_url = "#{@api_root}capacity=#{args['capacity']}&shr=#{args['shr']}&smin=#{args['smin']}&ehr=#{args['ehr']}&emin=#{args['emin']}&date=#{args['date']}&format=json"
29
+ elsif args.is_a? String
30
+ api_url = @api_root + args
31
+ end
32
+
33
+ JSON.pretty_generate(JSON.parse(open(api_url).read))
34
+ end
35
+ end
36
+
37
+ class Building
38
+ attr_accessor :latitude, :longitude, :name, :roomkinds
39
+
40
+ def initialize(building_json)
41
+ @latitude = building_json['latitude']
42
+ @longitude = building_json['longitude']
43
+ @name = building_json['name']
44
+ @roomkinds = []
45
+ building_json['roomkinds'].each do |roomkind_json|
46
+ @roomkinds << RoomKind.new(roomkind_json)
47
+ end
48
+ end
49
+
50
+ def rooms()
51
+ rooms = []
52
+ @roomkinds.each do |rk|
53
+ rk.rooms.each do |r|
54
+ rooms << r
55
+ end
56
+ end
57
+ rooms
58
+ end
59
+ end
60
+
61
+ class RoomKind
62
+ attr_accessor :has_big_screen, :reserve_type, :has_computer, :name, :privacy, :has_whiteboard, :max_occupancy, :comments, :rooms
63
+
64
+ def initialize(roomkind_json)
65
+ attrs = %w(has_big_screen reserve_type has_computer name privacy has_whiteboard max_occupancy comments)
66
+ attrs.each do |attr|
67
+ self.instance_variable_set("@#{attr}", roomkind_json[attr])
68
+ end
69
+
70
+ @rooms = []
71
+ roomkind_json['rooms'].each do |room_json|
72
+ @rooms << Room.new(room_json)
73
+ end
74
+ end
75
+ end
76
+
77
+ class Room
78
+ attr_accessor :availabilities, :name, :id
79
+
80
+ def initialize(room_json)
81
+ @name = room_json['name']
82
+ @id = room_json['id']
83
+ @availabilities = []
84
+ room_json['availabilities'].each do |date, avail_array|
85
+ @availabilities << Availability.new(date, avail_array)
86
+ end
87
+ end
88
+ end
89
+
90
+ class Availability
91
+ attr_accessor :date, :hours, :free_times
92
+
93
+ def initialize(date, avail_array)
94
+ # avail_array = [hours, [availabilities]]
95
+ @date = Date.parse(date)
96
+ @hours = avail_array[0]
97
+ @free_times = avail_array[1]
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ module PennStudySpaces
2
+ module Ruby
3
+ VERSION = "0.1"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/pennstudyspaces/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = "Matt Parmett"
6
+ gem.email = "mparmett@wharton.upenn.edu"
7
+ gem.description = %q{Ruby wrapper for the Penn Study Spaces API}
8
+ gem.summary = %q{Ruby wrapper for the Penn Study Spaces API}
9
+ gem.homepage = "http://github.com/mattparmett/pennstudyspaces.rb"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "pennstudyspaces"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = PennStudySpaces::Ruby::VERSION
17
+
18
+ gem.add_dependency "json"
19
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pennstudyspaces
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Parmett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Ruby wrapper for the Penn Study Spaces API
31
+ email: mparmett@wharton.upenn.edu
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - Rakefile
39
+ - lib/pennstudyspaces.rb
40
+ - lib/pennstudyspaces/version.rb
41
+ - pennstudyspaces.gemspec
42
+ homepage: http://github.com/mattparmett/pennstudyspaces.rb
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.23
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ruby wrapper for the Penn Study Spaces API
66
+ test_files: []