ait_connect 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/LICENSE +23 -0
- data/Rakefile +1 -0
- data/ait_connect.gemspec +27 -0
- data/lib/.DS_Store +0 -0
- data/lib/active_in_time.rb +32 -0
- data/lib/ait_connect/base.rb +148 -0
- data/lib/ait_connect/facility.rb +35 -0
- data/lib/ait_connect/facility_type.rb +27 -0
- data/lib/ait_connect/facility_type_category.rb +24 -0
- data/lib/ait_connect/instructor.rb +18 -0
- data/lib/ait_connect/level.rb +18 -0
- data/lib/ait_connect/site.rb +132 -0
- data/lib/ait_connect/site_proxy.rb +44 -0
- data/lib/ait_connect/term_type.rb +18 -0
- data/lib/ait_connect/test.rb +1 -0
- data/lib/ait_connect/timetable.rb +27 -0
- data/lib/ait_connect/timetable_entry.rb +76 -0
- data/lib/ait_connect/timetable_entry_proxy.rb +27 -0
- data/lib/ait_connect/timetable_proxy.rb +21 -0
- data/lib/ait_connect/timetable_session.rb +23 -0
- data/lib/ait_connect/timetable_session_category.rb +18 -0
- data/lib/ait_connect/version.rb +3 -0
- data/lib/ait_connect.rb +29 -0
- data/lib/test.rb +38 -0
- data/spec/base_spec.rb +18 -0
- data/spec/site_proxy_spec.rb +72 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/timetable_proxy_spec.rb +41 -0
- metadata +43 -7
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
(The MIT-License)
|
2
|
+
|
3
|
+
Copyright (c) 2011 GroupMe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ait_connect.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ait_connect/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ait_connect"
|
7
|
+
s.version = AITConnect::VERSION
|
8
|
+
s.authors = ["Daniel Morgan"]
|
9
|
+
s.email = ["danmorgz@googlemail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = "Write a gem summary"
|
12
|
+
s.description = "Write a gem description"
|
13
|
+
|
14
|
+
s.rubyforge_project = "ait_connect"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
|
25
|
+
s.add_dependency(%q<typhoeus>, [">= 0"])
|
26
|
+
s.add_dependency(%q<json>, [">= 0"])
|
27
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class Error < StandardError ; end
|
3
|
+
class InvalidAuth < ActiveInTime::Error; end
|
4
|
+
class ServiceUnavailable < ActiveInTime::Error; end
|
5
|
+
class EndPointMissing < ActiveInTime::Error; end
|
6
|
+
|
7
|
+
def self.verbose=(setting)
|
8
|
+
@verbose = setting
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.verbose?
|
12
|
+
@verbose
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.log(msg)
|
16
|
+
return unless verbose?
|
17
|
+
puts "[activeintime] #{msg}"
|
18
|
+
end
|
19
|
+
|
20
|
+
ERRORS = {
|
21
|
+
"invalid_auth" => "OAuth token was not provided or was invalid.",
|
22
|
+
"param_error" => "A required parameter was missing or a parameter was malformed. This is also used if the resource ID in the path is incorrect.",
|
23
|
+
"endpoint_error" => "The requested path does not exist.",
|
24
|
+
"not_authorized" => "Although authentication succeeded, the acting user is not allowed to see this information due to privacy restrictions.",
|
25
|
+
"rate_limit_exceeded" => "Rate limit for this hour exceeded.",
|
26
|
+
"deprecated" => "Something about this request is using deprecated functionality, or the response format may be about to change.",
|
27
|
+
"server_error" => "Server is currently experiencing issues. Check status.activeintime.com for udpates.",
|
28
|
+
"other" => "Some other type of error occurred."
|
29
|
+
}
|
30
|
+
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class Base
|
3
|
+
API = "https://api.activeintime.com/v1/"
|
4
|
+
#API = "http://api.lvh.me:3000/v1/"
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
case args.size
|
8
|
+
when 1
|
9
|
+
@access_token = args.first
|
10
|
+
when 2
|
11
|
+
@key, @secret = args
|
12
|
+
else
|
13
|
+
raise ArgumentError, "You need to pass either an access_token or key and secret"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# def users
|
18
|
+
# ActiveInTime::UserProxy.new(self)
|
19
|
+
# end
|
20
|
+
|
21
|
+
# def checkins
|
22
|
+
# ActiveInTime::CheckinProxy.new(self)
|
23
|
+
# end
|
24
|
+
|
25
|
+
def sites
|
26
|
+
ActiveInTime::SiteProxy.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def timetables
|
30
|
+
ActiveInTime::TimetableProxy.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def timetable_entries
|
34
|
+
ActiveInTime::TimetableEntryProxy.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
# def settings
|
38
|
+
# @settings ||= ActiveInTime::Settings.new(self)
|
39
|
+
# end
|
40
|
+
|
41
|
+
def get(path, params={})
|
42
|
+
params = camelize(params)
|
43
|
+
ActiveInTime.log("GET #{API + path}")
|
44
|
+
ActiveInTime.log("PARAMS: #{params.inspect}")
|
45
|
+
merge_auth_params(params)
|
46
|
+
response = JSON.parse(Typhoeus::Request.get(API + path + '.json', :params => params).body)
|
47
|
+
ActiveInTime.log(response.inspect)
|
48
|
+
error(response) || response["response"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def post(path, params={})
|
52
|
+
params = camelize(params)
|
53
|
+
ActiveInTime.log("POST #{API + path}")
|
54
|
+
ActiveInTime.log("PARAMS: #{params.inspect}")
|
55
|
+
merge_auth_params(params)
|
56
|
+
response = JSON.parse(Typhoeus::Request.post(API + path, :params => params).body)
|
57
|
+
ActiveInTime.log(response.inspect)
|
58
|
+
error(response) || response["response"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def authorize_url(redirect_uri)
|
62
|
+
# http://developer.foursquare.com/docs/oauth.html
|
63
|
+
|
64
|
+
# check params
|
65
|
+
raise "you need to define a client id before" if @key.blank?
|
66
|
+
raise "no callback url provided" if redirect_uri.blank?
|
67
|
+
|
68
|
+
# params
|
69
|
+
params = {}
|
70
|
+
params["key"] = @key
|
71
|
+
params["response_type"] = "code"
|
72
|
+
params["redirect_uri"] = redirect_uri
|
73
|
+
|
74
|
+
# url
|
75
|
+
oauth2_url('authenticate', params)
|
76
|
+
end
|
77
|
+
|
78
|
+
def access_token(code, redirect_uri)
|
79
|
+
# http://developer.foursquare.com/docs/oauth.html
|
80
|
+
|
81
|
+
# check params
|
82
|
+
raise "you need to define a client id before" if @key.blank?
|
83
|
+
raise "you need to define a client secret before" if @secret.blank?
|
84
|
+
raise "no code provided" if code.blank?
|
85
|
+
raise "no redirect_uri provided" if redirect_uri.blank?
|
86
|
+
|
87
|
+
# params
|
88
|
+
params = {}
|
89
|
+
params["key"] = @key
|
90
|
+
params["secret"] = @secret
|
91
|
+
params["grant_type"] = "authorization_code"
|
92
|
+
params["redirect_uri"] = redirect_uri
|
93
|
+
params["code"] = code
|
94
|
+
|
95
|
+
# url
|
96
|
+
url = oauth2_url('access_token', params)
|
97
|
+
|
98
|
+
# response
|
99
|
+
# http://developer.foursquare.com/docs/oauth.html
|
100
|
+
response = JSON.parse(Typhoeus::Request.get(url).body)
|
101
|
+
response["access_token"]
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# def oauth2_url(method_name, params)
|
107
|
+
# "https://foursquare.com/oauth2/#{method_name}?#{params.to_query}"
|
108
|
+
# end
|
109
|
+
|
110
|
+
def camelize(params)
|
111
|
+
params.inject({}) { |o, (k, v)|
|
112
|
+
o[k.to_s.gsub(/(_[a-z])/) { |m| m[1..1].upcase }] = v
|
113
|
+
o
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
def error(response)
|
118
|
+
case response["meta"]["error"]
|
119
|
+
when nil
|
120
|
+
# It's all good.
|
121
|
+
when "deprecated"
|
122
|
+
ActiveInTime.log(ActiveInTime::ERRORS[response['meta']['error']])
|
123
|
+
nil
|
124
|
+
else
|
125
|
+
code = response['meta']['status']
|
126
|
+
error = response['meta']['error']['error_message']
|
127
|
+
case code
|
128
|
+
when 403
|
129
|
+
raise ActiveInTime::InvalidAuth.new(error)
|
130
|
+
when 501
|
131
|
+
raise ActiveInTime::ServiceUnavailable.new(error)
|
132
|
+
when 404
|
133
|
+
raise ActiveInTime::EndPointMissing.new(error)
|
134
|
+
else
|
135
|
+
raise ActiveInTime::Error.new(error)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def merge_auth_params(params)
|
141
|
+
if @access_token
|
142
|
+
params.merge!(:oauth_token => @access_token)
|
143
|
+
else
|
144
|
+
params.merge!(:key => @key, :secret => @secret)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class Facility
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
# def fetch
|
10
|
+
# @json = @active_in_time.get("timetables/#{id}")["timetable"]
|
11
|
+
# self
|
12
|
+
# end
|
13
|
+
|
14
|
+
def id
|
15
|
+
@json["id"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@json["primary_name"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def tldc_approved
|
23
|
+
@json['tldc_approved']
|
24
|
+
end
|
25
|
+
|
26
|
+
def length
|
27
|
+
@json['length']
|
28
|
+
end
|
29
|
+
|
30
|
+
def facility_type
|
31
|
+
ActiveInTime::FacilityType.new(@active_in_time, @json['facility_type'])
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class FacilityType
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
# def fetch
|
10
|
+
# @json = @active_in_time.get("timetables/#{id}")["timetable"]
|
11
|
+
# self
|
12
|
+
# end
|
13
|
+
|
14
|
+
def id
|
15
|
+
@json["id"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@json["name"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def facility_type_category
|
23
|
+
ActiveInTime::FacilityTypeCategory.new(@active_in_time, @json)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class FacilityTypeCategory
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
# def fetch
|
10
|
+
# @json = @active_in_time.get("timetables/#{id}")["timetable"]
|
11
|
+
# self
|
12
|
+
# end
|
13
|
+
|
14
|
+
def id
|
15
|
+
@json["id"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@json["name"]
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class Site
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
def fetch
|
10
|
+
@json = @active_in_time.get("sites/#{id}")
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
@json["id"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def tldc_approved
|
19
|
+
@json['tldc_approved']
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@json["name"]
|
24
|
+
end
|
25
|
+
|
26
|
+
#####
|
27
|
+
##
|
28
|
+
## Contact info
|
29
|
+
|
30
|
+
def contact
|
31
|
+
@json["contact"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def post_town
|
35
|
+
self.contact['post_town']
|
36
|
+
end
|
37
|
+
|
38
|
+
def country
|
39
|
+
self.contact['country']
|
40
|
+
end
|
41
|
+
|
42
|
+
def borough
|
43
|
+
self.contact['borough']
|
44
|
+
end
|
45
|
+
|
46
|
+
def address_line_1
|
47
|
+
self.contact['address_line_1']
|
48
|
+
end
|
49
|
+
|
50
|
+
def address_line_2
|
51
|
+
self.contact['address_line_2']
|
52
|
+
end
|
53
|
+
|
54
|
+
def post_code
|
55
|
+
self.contact['post_code']
|
56
|
+
end
|
57
|
+
|
58
|
+
def latitude
|
59
|
+
self.contact['latitude']
|
60
|
+
end
|
61
|
+
|
62
|
+
def longitude
|
63
|
+
self.contact['longitude']
|
64
|
+
end
|
65
|
+
|
66
|
+
def telephone
|
67
|
+
self.contact['telephone']
|
68
|
+
end
|
69
|
+
|
70
|
+
def email
|
71
|
+
self.contact['email']
|
72
|
+
end
|
73
|
+
|
74
|
+
def website
|
75
|
+
self.contact['website']
|
76
|
+
end
|
77
|
+
|
78
|
+
def timetables
|
79
|
+
return [] if !@json["timetables"] || @json["timetables"].empty?
|
80
|
+
timetables = []
|
81
|
+
@json['timetables'].each do |timetable|
|
82
|
+
timetables << ActiveInTime::Timetable.new(@active_in_time, timetable)
|
83
|
+
end
|
84
|
+
timetables
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
def facilities
|
89
|
+
return [] if !@json["facilities"] || @json["facilities"].empty?
|
90
|
+
|
91
|
+
facilities = []
|
92
|
+
json['facilities'].each do |facility|
|
93
|
+
facilities << ActiveInTime::Facility.new(@active_in_time, facility)
|
94
|
+
end
|
95
|
+
facilities
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# # not all photos may be present here (but we try to avoid one extra API call)
|
101
|
+
# # if you want to get all the photos, try all_photos
|
102
|
+
# def photos
|
103
|
+
# return all_photos if @json["photos"].blank?
|
104
|
+
# @json["photos"]["groups"].select { |g| g["type"] == "venue" }.first["items"].map do |item|
|
105
|
+
# Foursquare::Photo.new(@foursquare, item)
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# # https://developer.foursquare.com/docs/venues/photos.html
|
110
|
+
# def all_photos(options={:group => "venue"})
|
111
|
+
# @foursquare.get("venues/#{id}/photos", options)["photos"]["items"].map do |item|
|
112
|
+
# Foursquare::Photo.new(@foursquare, item)
|
113
|
+
# end
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# # count the people who have checked-in at the venue in the last two hours
|
117
|
+
# def here_now_count
|
118
|
+
# fetch unless @json.has_key?("hereNow")
|
119
|
+
# @json["hereNow"]["count"]
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
# # returns a list of checkins (only if a valid oauth token from a user is provided)
|
123
|
+
# # https://developer.foursquare.com/docs/venues/herenow.html
|
124
|
+
# # options: limit, offset, aftertimestamp
|
125
|
+
# def here_now_checkins(options={:limit => "50"})
|
126
|
+
# @foursquare.get("venues/#{id}/herenow", options)["hereNow"]["items"].map do |item|
|
127
|
+
# Foursquare::Checkin.new(@foursquare, item)
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class SiteProxy
|
3
|
+
def initialize(active_in_time)
|
4
|
+
@active_in_time = active_in_time
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
ActiveInTime::Site.new(@active_in_time, @active_in_time.get("sites/#{id}"))
|
9
|
+
end
|
10
|
+
|
11
|
+
def nearby(options={})
|
12
|
+
raise ArgumentError, "You must include :ll" unless options[:ll]
|
13
|
+
|
14
|
+
sites = []
|
15
|
+
response = @active_in_time.get('sites', options).each do |site_json|
|
16
|
+
sites << ActiveInTime::Site.new(@active_in_time, site_json)
|
17
|
+
end
|
18
|
+
|
19
|
+
sites
|
20
|
+
end
|
21
|
+
|
22
|
+
# def trending(options={})
|
23
|
+
# search_group("trending", options)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# def favorites(options={})
|
27
|
+
# search_group("favorites", options)
|
28
|
+
# end
|
29
|
+
|
30
|
+
#def nearby(options={})
|
31
|
+
# search_group("nearby", options)
|
32
|
+
#end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# def search_group(name, options)
|
37
|
+
# raise ArgumentError, "You must include :ll" unless options[:ll]
|
38
|
+
# response = @foursquare.get('venues/search', options)["groups"].detect { |group| group["type"] == name }
|
39
|
+
# response ? response["items"].map do |json|
|
40
|
+
# Foursquare::Venue.new(@foursquare, json)
|
41
|
+
# end : []
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test.rb
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class Timetable
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
def fetch
|
10
|
+
@json = @active_in_time.get("timetables/#{id}")["timetable"]
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
@json["id"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@json["name"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def timetable_entries(options = {})
|
23
|
+
@active_in_time.timetable_entries.find(self.id,options)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module ActiveInTime
|
5
|
+
class TimetableEntry
|
6
|
+
attr_reader :json
|
7
|
+
|
8
|
+
def initialize(active_in_time, json)
|
9
|
+
@active_in_time, @json = active_in_time, json
|
10
|
+
end
|
11
|
+
|
12
|
+
# def fetch
|
13
|
+
# @json = @active_in_time.get("timetables/#{timetable_id}/timetable_entries/#{id}")["timetable_entry"]
|
14
|
+
# self
|
15
|
+
# end
|
16
|
+
|
17
|
+
def id
|
18
|
+
@json["id"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def start_time
|
22
|
+
Time.parse(@json["start_time"])
|
23
|
+
end
|
24
|
+
|
25
|
+
def end_time
|
26
|
+
Time.parse(@json["end_time"])
|
27
|
+
end
|
28
|
+
|
29
|
+
def date
|
30
|
+
Date.parse(@json["date"])
|
31
|
+
end
|
32
|
+
|
33
|
+
def facility
|
34
|
+
return nil if !@json['facility']
|
35
|
+
ActiveInTime::Facility.new(@active_in_time,@json['facility'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def term_type
|
39
|
+
ActiveInTime::TermType.new(@active_in_time,@json['term_type'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def timetable_session
|
43
|
+
return nil if !@json['timetable_session']
|
44
|
+
ActiveInTime::TimetableSession.new(@active_in_time,@json['timetable_session'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def instructor
|
48
|
+
return nil if !@json['instructor']
|
49
|
+
ActiveInTime::Instructor.new(@active_in_time,@json['instructor'])
|
50
|
+
end
|
51
|
+
|
52
|
+
def level
|
53
|
+
return nil if !@json['level']
|
54
|
+
ActiveInTime::Level.new(@active_in_time,@json['level'])
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def timetable_id
|
60
|
+
@json["timetable_id"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def name
|
64
|
+
@json["name"]
|
65
|
+
end
|
66
|
+
|
67
|
+
def is_cancelled
|
68
|
+
@json["is_cancelled"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def cancellation_reason
|
72
|
+
@json["cancellation_reason"]
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class TimetableEntryProxy
|
3
|
+
def initialize(active_in_time)
|
4
|
+
@active_in_time = active_in_time
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(id, options = {})
|
8
|
+
|
9
|
+
entries = []
|
10
|
+
@active_in_time.get("timetables/#{id}/timetable_entries", options).each { |te|
|
11
|
+
entries << ActiveInTime::TimetableEntry.new(@active_in_time,te)
|
12
|
+
}
|
13
|
+
entries
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# def search_group(name, options)
|
20
|
+
# raise ArgumentError, "You must include :ll" unless options[:ll]
|
21
|
+
# response = @foursquare.get('venues/search', options)["groups"].detect { |group| group["type"] == name }
|
22
|
+
# response ? response["items"].map do |json|
|
23
|
+
# Foursquare::Venue.new(@foursquare, json)
|
24
|
+
# end : []
|
25
|
+
# end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class TimetableProxy
|
3
|
+
def initialize(active_in_time)
|
4
|
+
@active_in_time = active_in_time
|
5
|
+
end
|
6
|
+
|
7
|
+
def find(id)
|
8
|
+
ActiveInTime::Timetable.new(@active_in_time, @active_in_time.get("timetables/#{id}"))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# def search_group(name, options)
|
14
|
+
# raise ArgumentError, "You must include :ll" unless options[:ll]
|
15
|
+
# response = @foursquare.get('venues/search', options)["groups"].detect { |group| group["type"] == name }
|
16
|
+
# response ? response["items"].map do |json|
|
17
|
+
# Foursquare::Venue.new(@foursquare, json)
|
18
|
+
# end : []
|
19
|
+
# end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class TimetableSession
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
@json["id"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@json["name"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def timetable_session_category
|
18
|
+
return nil if !@json['timetable_session_category']
|
19
|
+
ActiveInTime::TimetableSessionCategory.new(@active_in_time,@json['timetable_session_category'])
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ActiveInTime
|
2
|
+
class TimetableSessionCategory
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(active_in_time, json)
|
6
|
+
@active_in_time, @json = active_in_time, json
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
@json["id"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@json["name"]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/ait_connect.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "typhoeus"
|
5
|
+
require "json"
|
6
|
+
require "cgi"
|
7
|
+
require "ait_connect/base"
|
8
|
+
# require "ait_connect/checkin_proxy"
|
9
|
+
# require "ait_connect/checkin"
|
10
|
+
# require "ait_connect/user_proxy"
|
11
|
+
# require "ait_connect/user"
|
12
|
+
require "ait_connect/site_proxy"
|
13
|
+
require "ait_connect/site"
|
14
|
+
require "ait_connect/timetable"
|
15
|
+
require "ait_connect/timetable_proxy"
|
16
|
+
require "ait_connect/timetable_entry_proxy"
|
17
|
+
require "ait_connect/timetable_entry"
|
18
|
+
|
19
|
+
require "ait_connect/term_type"
|
20
|
+
require "ait_connect/timetable_session"
|
21
|
+
require "ait_connect/instructor"
|
22
|
+
require "ait_connect/level"
|
23
|
+
require "ait_connect/timetable_session_category"
|
24
|
+
|
25
|
+
require "ait_connect/facility"
|
26
|
+
require "ait_connect/facility_type"
|
27
|
+
require "ait_connect/facility_type_category"
|
28
|
+
|
29
|
+
require 'active_in_time'
|
data/lib/test.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "ait_connect")
|
2
|
+
|
3
|
+
##Localhost
|
4
|
+
API_KEY = ''
|
5
|
+
API_SECRET = ''
|
6
|
+
##activeintime.com
|
7
|
+
ait = ActiveInTime::Base.new(API_KEY,API_SECRET) #localhost
|
8
|
+
|
9
|
+
# With activities and facility_types
|
10
|
+
#response = ait.sites.nearby(:ll => "51.5,-0.09", :facility_types => "1,2,3,4,5,35", :activity_type_categories => '1')
|
11
|
+
|
12
|
+
#Just plain long lat
|
13
|
+
#response = ait.sites.nearby(:ll => "51.5,-0.09")
|
14
|
+
|
15
|
+
#With a radius
|
16
|
+
#response = ait.sites.nearby(:ll => "51.5,-0.09", :radius => 20)
|
17
|
+
|
18
|
+
#With pagination
|
19
|
+
response = ait.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :page => 1, :per_page => 1).first.fetch
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
##############
|
24
|
+
##
|
25
|
+
## Timetables
|
26
|
+
##
|
27
|
+
#response = ait.timetable_entries.find(response.first.timetables.first.id)
|
28
|
+
#response = response.first.timetables
|
29
|
+
|
30
|
+
|
31
|
+
#response = ait.sites.find(1)
|
32
|
+
|
33
|
+
puts response.inspect
|
34
|
+
|
35
|
+
#puts 'NOW UPDATING'
|
36
|
+
|
37
|
+
#puts response.fetch.inspect
|
38
|
+
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe ActiveInTime::Base do
|
5
|
+
|
6
|
+
it "should not pass through sites without a valid API key testing sites" do
|
7
|
+
response = lambda {invalid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20)}.should raise_error(ActiveInTime::InvalidAuth)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not pass through timetables without a valid API key testing sites" do
|
11
|
+
response = lambda {invalid_api_client.timetables.find(1)}.should raise_error(ActiveInTime::InvalidAuth)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not pass through timetable_entries without a valid API key testing sites" do
|
15
|
+
response = lambda {invalid_api_client.timetable_entries.find(1)}.should raise_error(ActiveInTime::InvalidAuth)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveInTime::SiteProxy do
|
4
|
+
|
5
|
+
it "should raise an argument error withouta longitude and latitude param" do
|
6
|
+
response = lambda {valid_api_client.sites.nearby(:radius => 20)}.should raise_error(ArgumentError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "searching Central London should return a list of sites with valid longitude and latitude" do
|
10
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20)
|
11
|
+
response.is_a?([].class).should == true
|
12
|
+
response.size.should > 1
|
13
|
+
response.first.is_a?(ActiveInTime::Site).should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "searching for a single site should bring back a single site with matching id" do
|
17
|
+
response = valid_api_client.sites.find(1)
|
18
|
+
response.is_a?(ActiveInTime::Site).should == true
|
19
|
+
response.id.should == 1
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
it "fetching updating information on a single site should bring back a single site with matching id" do
|
24
|
+
response = valid_api_client.sites.find(1)
|
25
|
+
site_id = response.id
|
26
|
+
|
27
|
+
#Use our conveinence method to fetch updated details
|
28
|
+
response = response.fetch
|
29
|
+
response.is_a?(ActiveInTime::Site).should == true
|
30
|
+
response.id.should == site_id
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
it "searching with pagination (1 per page) should bring back 1 result only" do
|
37
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :per_page => 1)
|
38
|
+
response.is_a?([].class).should == true
|
39
|
+
response.size.should == 1
|
40
|
+
response.first.is_a?(ActiveInTime::Site).should == true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "searching with pagination (1 per page) should bring back 2 different results on 2 pages" do
|
44
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :per_page => 1, :page => 1)
|
45
|
+
first_site = response.first
|
46
|
+
|
47
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :per_page => 1, :page => 2)
|
48
|
+
second_site = response.first
|
49
|
+
|
50
|
+
first_site.should_not == second_site
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return facilities if they exist" do
|
55
|
+
response = valid_api_client.sites.find(1)
|
56
|
+
response.facilities.is_a?([].class).should == true
|
57
|
+
response.facilities.first.is_a?(ActiveInTime::Facility).should == true
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
it "if a facility exists it should bring back a facility type" do
|
62
|
+
response = valid_api_client.sites.find(1)
|
63
|
+
|
64
|
+
facility = response.facilities.first
|
65
|
+
facility.facility_type.is_a?(ActiveInTime::FacilityType).should == true
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'ait_connect' # and any other gems you need
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# some (optional) config here
|
8
|
+
|
9
|
+
def invalid_api_client
|
10
|
+
ActiveInTime::Base.new("bollocks key","pizza is goood")
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid_api_client
|
14
|
+
#ActiveInTime::Base.new("","") #production
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe ActiveInTime::TimetableProxy do
|
5
|
+
|
6
|
+
it "searching for a single site should bring back timetables in the json" do
|
7
|
+
response = valid_api_client.sites.find(1)
|
8
|
+
response.timetables.is_a?([].class).should == true
|
9
|
+
response.timetables.size > 0
|
10
|
+
response.timetables.first.is_a?(ActiveInTime::Timetable).should == true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "searching for a single timetable should bring back a single timetables" do
|
14
|
+
response = valid_api_client.timetables.find(1)
|
15
|
+
response.is_a?(ActiveInTime::Timetable).should == true
|
16
|
+
response.id.should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "searching with pagination (1 per page) should bring back 1 result only" do
|
20
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :per_page => 1)
|
21
|
+
response.is_a?([].class).should == true
|
22
|
+
response.size.should == 1
|
23
|
+
response.first.is_a?(ActiveInTime::Site).should == true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "searching with pagination (1 per page) should bring back 2 different results on 2 pages" do
|
27
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :per_page => 1, :page => 1)
|
28
|
+
first_site = response.first
|
29
|
+
|
30
|
+
response = valid_api_client.sites.nearby(:ll => "51.5,-0.09", :radius => 20, :per_page => 1, :page => 2)
|
31
|
+
second_site = response.first
|
32
|
+
|
33
|
+
first_site.should_not == second_site
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ait_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-25 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
16
|
-
requirement: &
|
16
|
+
requirement: &70097647504840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70097647504840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70097647504320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,14 +32,46 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70097647504320
|
36
36
|
description: Write a gem description
|
37
37
|
email:
|
38
38
|
- danmorgz@googlemail.com
|
39
39
|
executables: []
|
40
40
|
extensions: []
|
41
41
|
extra_rdoc_files: []
|
42
|
-
files:
|
42
|
+
files:
|
43
|
+
- .DS_Store
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- Rakefile
|
49
|
+
- ait_connect.gemspec
|
50
|
+
- lib/.DS_Store
|
51
|
+
- lib/active_in_time.rb
|
52
|
+
- lib/ait_connect.rb
|
53
|
+
- lib/ait_connect/base.rb
|
54
|
+
- lib/ait_connect/facility.rb
|
55
|
+
- lib/ait_connect/facility_type.rb
|
56
|
+
- lib/ait_connect/facility_type_category.rb
|
57
|
+
- lib/ait_connect/instructor.rb
|
58
|
+
- lib/ait_connect/level.rb
|
59
|
+
- lib/ait_connect/site.rb
|
60
|
+
- lib/ait_connect/site_proxy.rb
|
61
|
+
- lib/ait_connect/term_type.rb
|
62
|
+
- lib/ait_connect/test.rb
|
63
|
+
- lib/ait_connect/timetable.rb
|
64
|
+
- lib/ait_connect/timetable_entry.rb
|
65
|
+
- lib/ait_connect/timetable_entry_proxy.rb
|
66
|
+
- lib/ait_connect/timetable_proxy.rb
|
67
|
+
- lib/ait_connect/timetable_session.rb
|
68
|
+
- lib/ait_connect/timetable_session_category.rb
|
69
|
+
- lib/ait_connect/version.rb
|
70
|
+
- lib/test.rb
|
71
|
+
- spec/base_spec.rb
|
72
|
+
- spec/site_proxy_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/timetable_proxy_spec.rb
|
43
75
|
homepage: ''
|
44
76
|
licenses: []
|
45
77
|
post_install_message:
|
@@ -64,4 +96,8 @@ rubygems_version: 1.8.6
|
|
64
96
|
signing_key:
|
65
97
|
specification_version: 3
|
66
98
|
summary: Write a gem summary
|
67
|
-
test_files:
|
99
|
+
test_files:
|
100
|
+
- spec/base_spec.rb
|
101
|
+
- spec/site_proxy_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/timetable_proxy_spec.rb
|