ties 0.2.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.
- data/Gemfile +8 -0
- data/LICENSE +22 -0
- data/README +3 -0
- data/lib/ties/base.rb +86 -0
- data/lib/ties/my_view.rb +10 -0
- data/lib/ties/schedule.rb +28 -0
- data/lib/ties/schools.rb +13 -0
- data/lib/ties/students.rb +13 -0
- data/lib/ties/teachers.rb +13 -0
- data/lib/ties.rb +21 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/ties/base_spec.rb +12 -0
- data/spec/ties/my_view_spec.rb +10 -0
- data/spec/ties/schedule_spec.rb +28 -0
- data/spec/ties/schools_spec.rb +16 -0
- data/spec/ties/students_spec.rb +15 -0
- data/spec/ties/ties_spec.rb +7 -0
- data/ties.gemspec +34 -0
- metadata +73 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 2011 Naiku Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/lib/ties/base.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
class TIES::Base
|
3
|
+
attr_accessor :api_key, :secret_key, :endpoint, :district_number
|
4
|
+
attr_accessor :total_pages, :total_count
|
5
|
+
|
6
|
+
# options should contain
|
7
|
+
# :api_key
|
8
|
+
# :secret_key
|
9
|
+
# :district_number
|
10
|
+
def initialize(options)
|
11
|
+
self.api_key, self.secret_key = options["api_key"], options["secret_key"]
|
12
|
+
self.district_number = options["district_number"]
|
13
|
+
self.endpoint = options["endpoint"] || TIES::ENDPOINT
|
14
|
+
end
|
15
|
+
|
16
|
+
def each(options = {})
|
17
|
+
page = 1
|
18
|
+
begin
|
19
|
+
self.get(page, options).each do |element|
|
20
|
+
yield(element)
|
21
|
+
end
|
22
|
+
page += 1
|
23
|
+
end until self.total_pages.nil? || self.total_pages <= page
|
24
|
+
end
|
25
|
+
|
26
|
+
def all(options = {})
|
27
|
+
@results = []
|
28
|
+
page = 1
|
29
|
+
begin
|
30
|
+
@results.concat self.get(page, options)
|
31
|
+
page += 1
|
32
|
+
end until self.total_pages.nil? || self.total_pages <= page
|
33
|
+
@results
|
34
|
+
end
|
35
|
+
|
36
|
+
def send_request(uri, options = {})
|
37
|
+
if self.api_key.nil? || self.secret_key.nil? || self.district_number.nil?
|
38
|
+
raise 'not enough data to send request'
|
39
|
+
end
|
40
|
+
result = request_over_http(options, endpoint, uri)
|
41
|
+
if !result
|
42
|
+
raise 'Request to TIES api "%s" failed' % uri
|
43
|
+
end
|
44
|
+
case result.code.to_i
|
45
|
+
when 400
|
46
|
+
return false
|
47
|
+
when 200
|
48
|
+
return JSON.parse(result.body)
|
49
|
+
else
|
50
|
+
raise 'unknown error status code %s for uri "%s"' % [result.code, uri]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def authentication(http_method, time, request_uri)
|
55
|
+
data = [http_method, time, request_uri].join('\n')
|
56
|
+
'TIES ' + [api_key, Base64.encode64(OpenSSL::HMAC.digest('sha1', self.secret_key, data))].join(':')
|
57
|
+
end
|
58
|
+
|
59
|
+
def schools(); @schools ||= TIES::Schools.new(self); end
|
60
|
+
def students(); @students ||= TIES::Students.new(self); end
|
61
|
+
def teachers(); @teachers ||= TIES::Teachers.new(self); end
|
62
|
+
def classes(); @classes ||= TIES::Schedule::Classes.new(self); end
|
63
|
+
def requested_classes(); @requested_classes ||= TIES::Schedule::RequestedClasses.new(self); end
|
64
|
+
def reimbursements(); @reimbursements ||= TIES::MyView::Reimbursements.new(self); end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
# For easier testing. You can mock this method with a XML file you're expecting to receive
|
69
|
+
def request_over_http(options, endpoint, uri)
|
70
|
+
uri = URI.parse([endpoint, uri].join('/') + '?' + options.collect{|k,v| "%s=%s" % [k,v]}.join('&'))
|
71
|
+
|
72
|
+
http = Net::HTTP.new(uri.host, 443)
|
73
|
+
http.use_ssl = true
|
74
|
+
# http.set_debug_output $stderr
|
75
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
76
|
+
request.initialize_http_header({
|
77
|
+
'Accept' => 'application/json',
|
78
|
+
'Content-Type' => 'application/json',
|
79
|
+
'User-Agent' => 'TIEScloud ruby %s' % TIES::VERSION,
|
80
|
+
'ties-date' => (time = Time.now).utc.to_s,
|
81
|
+
'Authorization' => authentication('GET', time, uri.request_uri),
|
82
|
+
'DistrictNumber' => self.district_number.to_s
|
83
|
+
})
|
84
|
+
http.request(request)
|
85
|
+
end
|
86
|
+
end
|
data/lib/ties/my_view.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class TIES::Schedule
|
2
|
+
class Classes < TIES::Base
|
3
|
+
def initialize(ties)
|
4
|
+
@ties = ties
|
5
|
+
end
|
6
|
+
def get(page = 1, options = {})
|
7
|
+
result = @ties.send_request('Schedule/Classes/%i' % page, options)
|
8
|
+
return [] unless result
|
9
|
+
self.total_pages = result['TotalPages']
|
10
|
+
self.total_count = result['TotalCount']
|
11
|
+
return result['Return']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class RequestedClasses < TIES::Base
|
15
|
+
def initialize(ties)
|
16
|
+
@ties = ties
|
17
|
+
end
|
18
|
+
def get(page = 1, options = {})
|
19
|
+
raise 'Missing student id' if options["StudentId"].nil?
|
20
|
+
options.merge!({'IsScheduled' => 'true'})
|
21
|
+
result = @ties.send_request('Schedule/RequestedClasses/%i' % page, options)
|
22
|
+
return [] unless result
|
23
|
+
self.total_pages = result['TotalPages']
|
24
|
+
self.total_count = result['TotalCount']
|
25
|
+
return result['Return']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ties/schools.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class TIES::Schools < TIES::Base
|
2
|
+
def initialize(ties)
|
3
|
+
@ties = ties
|
4
|
+
end
|
5
|
+
def get(page = 1, options = {})
|
6
|
+
options.merge!({"DistrictNumber" => @ties.district_number})
|
7
|
+
result = @ties.send_request('Schools/%i' % page, options)
|
8
|
+
return [] unless result
|
9
|
+
self.total_pages = result['TotalPages']
|
10
|
+
self.total_count = result['TotalCount']
|
11
|
+
return result['Return']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class TIES::Students < TIES::Base
|
2
|
+
attr_accessor :total_pages, :total_count
|
3
|
+
def initialize(ties)
|
4
|
+
@ties = ties
|
5
|
+
end
|
6
|
+
def get(page = 1, options = {})
|
7
|
+
result = @ties.send_request('Students/%i' % page, options)
|
8
|
+
return [] unless result
|
9
|
+
self.total_pages = result['TotalPages']
|
10
|
+
self.total_count = result['TotalCount']
|
11
|
+
return result['Return']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class TIES::Teachers < TIES::Base
|
2
|
+
attr_accessor :total_pages, :total_count
|
3
|
+
def initialize(ties)
|
4
|
+
@ties = ties
|
5
|
+
end
|
6
|
+
def get(page = 1, options = {})
|
7
|
+
result = @ties.send_request('Staff/Teachers/%i' % page, options)
|
8
|
+
return [] unless result
|
9
|
+
self.total_pages = result['TotalPages']
|
10
|
+
self.total_count = result['TotalCount']
|
11
|
+
return result['Return']
|
12
|
+
end
|
13
|
+
end
|
data/lib/ties.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
require 'cgi'
|
5
|
+
require 'uri'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module TIES
|
9
|
+
ENDPOINT = 'https://api.tiescloud.net/v1.0'
|
10
|
+
VERSION = '0.2'
|
11
|
+
def self.new(*options)
|
12
|
+
TIES::Base.new(*options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'ties/base'
|
17
|
+
require 'ties/schools'
|
18
|
+
require 'ties/students'
|
19
|
+
require 'ties/teachers'
|
20
|
+
require 'ties/schedule'
|
21
|
+
require 'ties/my_view'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec'
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
5
|
+
require 'ties'
|
6
|
+
|
7
|
+
module TiesHelper
|
8
|
+
def ties
|
9
|
+
TIES.new("api_key" => "4a29d0e61cd0", "secret_key" => "4a29d0e61cd047d78f233ea99f62a3b3", "endpoint" => 'https://apitest.tiescloud.net/v1.0', "district_number" => '8999')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |c|
|
14
|
+
c.include TiesHelper
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe TIES::Base do
|
4
|
+
describe ".new" do
|
5
|
+
it "should initialize" do
|
6
|
+
ties.should be_a(TIES::Base)
|
7
|
+
end
|
8
|
+
it "should have default endpoint" do
|
9
|
+
TIES.new({}).endpoint.should == TIES::ENDPOINT
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe TIES::MyView::Reimbursements do
|
4
|
+
it "should be reimbursements object" do
|
5
|
+
ties.reimbursements.should be_a(TIES::MyView::Reimbursements)
|
6
|
+
end
|
7
|
+
it "retrieve reimbursements" do
|
8
|
+
ties.reimbursements.get
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe TIES::Schedule::Classes do
|
4
|
+
it "should be classes object" do
|
5
|
+
ties.classes.should be_a(TIES::Schedule::Classes)
|
6
|
+
end
|
7
|
+
it "should retrieve classes" do
|
8
|
+
classes = ties.classes
|
9
|
+
result = classes.get(1, {SchoolYear: "2010", StudentId: "2010"})
|
10
|
+
result.should_not be_empty
|
11
|
+
result.should be_a(Array)
|
12
|
+
classes.total_pages.should_not be_nil
|
13
|
+
classes.total_count.should_not be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe TIES::Schedule::RequestedClasses do
|
17
|
+
it "should be a RequestedClasses object" do
|
18
|
+
ties.requested_classes.should be_a(TIES::Schedule::RequestedClasses)
|
19
|
+
end
|
20
|
+
it "should require StudentId" do
|
21
|
+
ties.requested_classes.get(1, 'SchoolYear' => '2010')
|
22
|
+
end
|
23
|
+
it "retrieve requested classes" do
|
24
|
+
classes = ties.requested_classes.get(1, 'StudentId' => '698090', 'SchoolYear' => '2010')
|
25
|
+
classes.should be_a(Array)
|
26
|
+
classes.should_not be_empty
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe TIES::Schools do
|
4
|
+
|
5
|
+
it "should be schools object" do
|
6
|
+
ties.schools.should be_a(TIES::Schools)
|
7
|
+
end
|
8
|
+
it "should retrieve schools" do
|
9
|
+
schools = ties.schools
|
10
|
+
result = schools.get()
|
11
|
+
result.should_not be_empty
|
12
|
+
result.should be_a(Array)
|
13
|
+
schools.total_pages.should_not be_nil
|
14
|
+
schools.total_count.should_not be_nil
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe TIES::Students do
|
4
|
+
it "should be students object" do
|
5
|
+
ties.students.should be_a(TIES::Students)
|
6
|
+
end
|
7
|
+
it "should retrieve students" do
|
8
|
+
students = ties.students
|
9
|
+
result = students.get(1, "SchoolId" => "0121", "SchoolYear" => "2010")
|
10
|
+
result.should_not be_empty
|
11
|
+
result.should be_a(Array)
|
12
|
+
students.total_pages.should_not be_nil
|
13
|
+
students.total_count.should_not be_nil
|
14
|
+
end
|
15
|
+
end
|
data/ties.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "ties"
|
3
|
+
s.version = "0.2.1"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Thomas R. Koll"]
|
7
|
+
s.date = "2011-09-26"
|
8
|
+
s.description = "Provides a ruby interface to the TIEScloud API"
|
9
|
+
s.summary = "Provides a ruby interface to the TIEScloud API"
|
10
|
+
s.email = "info@ananasblau.com"
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"README"
|
13
|
+
]
|
14
|
+
s.files = [
|
15
|
+
"Gemfile",
|
16
|
+
"LICENSE",
|
17
|
+
"README",
|
18
|
+
"lib/ties.rb",
|
19
|
+
"lib/ties/base.rb",
|
20
|
+
"lib/ties/schedule.rb",
|
21
|
+
"lib/ties/my_view.rb",
|
22
|
+
"lib/ties/schools.rb",
|
23
|
+
"lib/ties/students.rb",
|
24
|
+
"lib/ties/teachers.rb",
|
25
|
+
"spec/spec_helper.rb",
|
26
|
+
"spec/ties/base_spec.rb",
|
27
|
+
"spec/ties/schedule_spec.rb",
|
28
|
+
"spec/ties/my_view_spec.rb",
|
29
|
+
"spec/ties/schools_spec.rb",
|
30
|
+
"spec/ties/students_spec.rb",
|
31
|
+
"spec/ties/ties_spec.rb",
|
32
|
+
"ties.gemspec"
|
33
|
+
]
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ties
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas R. Koll
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-26 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Provides a ruby interface to the TIEScloud API
|
18
|
+
email: info@ananasblau.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- Gemfile
|
27
|
+
- LICENSE
|
28
|
+
- README
|
29
|
+
- lib/ties.rb
|
30
|
+
- lib/ties/base.rb
|
31
|
+
- lib/ties/schedule.rb
|
32
|
+
- lib/ties/my_view.rb
|
33
|
+
- lib/ties/schools.rb
|
34
|
+
- lib/ties/students.rb
|
35
|
+
- lib/ties/teachers.rb
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- spec/ties/base_spec.rb
|
38
|
+
- spec/ties/schedule_spec.rb
|
39
|
+
- spec/ties/my_view_spec.rb
|
40
|
+
- spec/ties/schools_spec.rb
|
41
|
+
- spec/ties/students_spec.rb
|
42
|
+
- spec/ties/ties_spec.rb
|
43
|
+
- ties.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage:
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.6.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Provides a ruby interface to the TIEScloud API
|
72
|
+
test_files: []
|
73
|
+
|