trogdir_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +19 -0
- data/README.md +3 -0
- data/config/environment.rb +5 -0
- data/config/mongoid.yml +13 -0
- data/config/mongoid.yml.example +35 -0
- data/config.ru +8 -0
- data/lib/trogdir/api.rb +5 -0
- data/lib/trogdir/helpers/authentication_helpers.rb +24 -0
- data/lib/trogdir/helpers/request_helpers.rb +8 -0
- data/lib/trogdir/helpers/response_helpers.rb +11 -0
- data/lib/trogdir/versions/v1/addresses_api.rb +52 -0
- data/lib/trogdir/versions/v1/api.rb +29 -0
- data/lib/trogdir/versions/v1/change_syncs_api.rb +46 -0
- data/lib/trogdir/versions/v1/emails_api.rb +44 -0
- data/lib/trogdir/versions/v1/entities/address.rb +13 -0
- data/lib/trogdir/versions/v1/entities/email.rb +9 -0
- data/lib/trogdir/versions/v1/entities/id.rb +8 -0
- data/lib/trogdir/versions/v1/entities/person.rb +52 -0
- data/lib/trogdir/versions/v1/entities/phone.rb +9 -0
- data/lib/trogdir/versions/v1/entities/photo.rb +10 -0
- data/lib/trogdir/versions/v1/entities/sync_log.rb +12 -0
- data/lib/trogdir/versions/v1/entities/sync_log_with_changeset.rb +13 -0
- data/lib/trogdir/versions/v1/ids_api.rb +43 -0
- data/lib/trogdir/versions/v1/people_api.rb +127 -0
- data/lib/trogdir/versions/v1/phones_api.rb +44 -0
- data/lib/trogdir/versions/v1/photos_api.rb +46 -0
- data/lib/trogdir/versions/v1.rb +20 -0
- data/lib/trogdir_api/version.rb +3 -0
- data/lib/trogdir_api.rb +22 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c0461f30e10661b43c4d43250326dcc5c135eff
|
4
|
+
data.tar.gz: 9edfd9a1b18c4ed633841d2821c595ec89d75df4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee5b4c1468f78d401e0c55afe48a0359e5b111d3e8b17c6f9b497f37809d50e285bd2eb5a7570f3920e14fde7a141659880847e0f59563fe8d50590c604e50e9
|
7
|
+
data.tar.gz: a5c94365037a666d4ebc73f4836874416e96f6ea02fe98073aa09dd1359c686dbc09cb23ece5408df2d82e00dbf5572f28e9a151126a18c0acba71541009d798
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 by Biola University
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/config/mongoid.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
development:
|
2
|
+
sessions:
|
3
|
+
default:
|
4
|
+
database: trogdir_development
|
5
|
+
hosts:
|
6
|
+
- localhost:27017
|
7
|
+
|
8
|
+
test:
|
9
|
+
sessions:
|
10
|
+
default:
|
11
|
+
database: trogdir_test
|
12
|
+
hosts:
|
13
|
+
- localhost:27017
|
14
|
+
|
15
|
+
staging:
|
16
|
+
sessions:
|
17
|
+
default:
|
18
|
+
database: trogdir
|
19
|
+
hosts:
|
20
|
+
- mongo1.staging.biola.edu:27017
|
21
|
+
- mongo2.staging.biola.edu:27017
|
22
|
+
- mongo3.staging.biola.edu:27017
|
23
|
+
username: trogdir
|
24
|
+
password: "*************"
|
25
|
+
|
26
|
+
production:
|
27
|
+
sessions:
|
28
|
+
default:
|
29
|
+
database: trogdir
|
30
|
+
hosts:
|
31
|
+
- mongo1.prod.biola.edu:27017
|
32
|
+
- mongo2.prod.biola.edu:27017
|
33
|
+
- mongo3.prod.biola.edu:27017
|
34
|
+
username: trogdir
|
35
|
+
password: "*************"
|
data/config.ru
ADDED
data/lib/trogdir/api.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module AuthenticationHelpers
|
2
|
+
def rack_request
|
3
|
+
Rack::Request.new(@env)
|
4
|
+
end
|
5
|
+
|
6
|
+
def current_syncinator
|
7
|
+
access_id = ApiAuth.access_id(rack_request)
|
8
|
+
Syncinator.where(access_id: access_id).first
|
9
|
+
end
|
10
|
+
|
11
|
+
def authentic?
|
12
|
+
secret_key = current_syncinator.try(:secret_key)
|
13
|
+
|
14
|
+
ApiAuth.authentic? rack_request, secret_key
|
15
|
+
end
|
16
|
+
|
17
|
+
def authenticate!
|
18
|
+
unauthorized! unless authentic?
|
19
|
+
end
|
20
|
+
|
21
|
+
def unauthorized!
|
22
|
+
error!('401 Unauthorized', 401)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class AddressesAPI < Grape::API
|
4
|
+
resource :addresses do
|
5
|
+
get do
|
6
|
+
present Person.find_by(uuid: params[:person_id]).addresses, with: AddressEntity
|
7
|
+
end
|
8
|
+
|
9
|
+
params do
|
10
|
+
requires :address_id, type: String
|
11
|
+
end
|
12
|
+
get ':address_id' do
|
13
|
+
present Person.find_by(uuid: params[:person_id]).addresses.find(params[:address_id]), with: AddressEntity
|
14
|
+
end
|
15
|
+
|
16
|
+
params do
|
17
|
+
requires :type, type: Symbol, values: Address::TYPES
|
18
|
+
requires :street_1, type: String
|
19
|
+
optional :street_1, type: String
|
20
|
+
optional :city, type: String
|
21
|
+
optional :state, type: String
|
22
|
+
optional :zip, type: String
|
23
|
+
optional :contry, type: String
|
24
|
+
end
|
25
|
+
post do
|
26
|
+
Person.find_by(uuid: params[:person_id]).addresses.create! clean_params(except: :person_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
params do
|
30
|
+
requires :address_id, type: String
|
31
|
+
optional :type, type: Symbol, values: Address::TYPES
|
32
|
+
optional :street_1, type: String
|
33
|
+
optional :street_1, type: String
|
34
|
+
optional :city, type: String
|
35
|
+
optional :state, type: String
|
36
|
+
optional :zip, type: String
|
37
|
+
optional :contry, type: String
|
38
|
+
end
|
39
|
+
put ':address_id' do
|
40
|
+
Person.find_by(uuid: params[:person_id]).addresses.find(params[:address_id]).update_attributes! clean_params(except: [:person_id, :address_id])
|
41
|
+
end
|
42
|
+
|
43
|
+
params do
|
44
|
+
requires :address_id, type: String
|
45
|
+
end
|
46
|
+
delete ':address_id' do
|
47
|
+
Person.find_by(uuid: params[:person_id]).addresses.find(params[:address_id]).destroy
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class API < Grape::API
|
4
|
+
version 'v1', using: :path
|
5
|
+
|
6
|
+
format :json
|
7
|
+
helpers RequestHelpers
|
8
|
+
helpers ResponseHelpers
|
9
|
+
helpers AuthenticationHelpers
|
10
|
+
|
11
|
+
before { authenticate! }
|
12
|
+
|
13
|
+
rescue_from Mongoid::Errors::DocumentNotFound do |e|
|
14
|
+
error! "404 Not Found", 404
|
15
|
+
end
|
16
|
+
|
17
|
+
mount PeopleAPI
|
18
|
+
mount ChangeSyncsAPI
|
19
|
+
|
20
|
+
resource 'people/:person_id' do
|
21
|
+
mount IDsAPI
|
22
|
+
mount EmailsAPI
|
23
|
+
mount PhotosAPI
|
24
|
+
mount PhonesAPI
|
25
|
+
mount AddressesAPI
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class ChangeSyncsAPI < Grape::API
|
4
|
+
resource :change_syncs do
|
5
|
+
desc "Return and starts change_syncs that haven't been started"
|
6
|
+
put :start do
|
7
|
+
syncinator = current_syncinator
|
8
|
+
changesets = syncinator.startable_changesets
|
9
|
+
|
10
|
+
sync_logs = changesets.map do |changeset|
|
11
|
+
syncinator.start! changeset
|
12
|
+
end
|
13
|
+
|
14
|
+
present sync_logs, with: SyncLogWithChangesetEntity
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Return a sync_log and mark it as errored"
|
18
|
+
params do
|
19
|
+
requires :sync_log_id, type: String
|
20
|
+
requires :message, type: String
|
21
|
+
end
|
22
|
+
put 'error/:sync_log_id' do
|
23
|
+
sync_log = SyncLog.find_through_parents(params[:sync_log_id])
|
24
|
+
|
25
|
+
unauthorized! unless sync_log.syncinator == current_syncinator
|
26
|
+
|
27
|
+
current_syncinator.error! sync_log, params[:message]
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Return a sync_log and mark it as succeeded"
|
31
|
+
params do
|
32
|
+
requires :sync_log_id, type: String
|
33
|
+
requires :action, type: String
|
34
|
+
optional :message, type: String
|
35
|
+
end
|
36
|
+
put 'finish/:sync_log_id' do
|
37
|
+
sync_log = SyncLog.find_through_parents(params[:sync_log_id])
|
38
|
+
|
39
|
+
unauthorized! unless sync_log.syncinator == current_syncinator
|
40
|
+
|
41
|
+
current_syncinator.finish! sync_log, params[:action], params[:message]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class EmailsAPI < Grape::API
|
4
|
+
resource :emails do
|
5
|
+
get do
|
6
|
+
present Person.find_by(uuid: params[:person_id]).emails, with: EmailEntity
|
7
|
+
end
|
8
|
+
|
9
|
+
params do
|
10
|
+
requires :email_id, type: String
|
11
|
+
end
|
12
|
+
get ':email_id' do
|
13
|
+
present Person.find_by(uuid: params[:person_id]).emails.find(params[:email_id]), with: EmailEntity
|
14
|
+
end
|
15
|
+
|
16
|
+
params do
|
17
|
+
requires :type, type: Symbol, values: Email::TYPES
|
18
|
+
requires :address, type: String
|
19
|
+
optional :primary, type: Boolean
|
20
|
+
end
|
21
|
+
post do
|
22
|
+
Person.find_by(uuid: params[:person_id]).emails.create! clean_params(except: :person_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
params do
|
26
|
+
requires :email_id, type: String
|
27
|
+
optional :type, type: Symbol, values: Email::TYPES
|
28
|
+
optional :address, type: String
|
29
|
+
optional :primary, type: Boolean
|
30
|
+
end
|
31
|
+
put ':email_id' do
|
32
|
+
Person.find_by(uuid: params[:person_id]).emails.find(params[:email_id]).update_attributes! clean_params(except: [:person_id, :email_id])
|
33
|
+
end
|
34
|
+
|
35
|
+
params do
|
36
|
+
requires :email_id, type: String
|
37
|
+
end
|
38
|
+
delete ':email_id' do
|
39
|
+
Person.find_by(uuid: params[:person_id]).emails.find(params[:email_id]).destroy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class PersonEntity < Grape::Entity
|
4
|
+
expose :ids, using: IDEntity, as: :ids
|
5
|
+
expose :emails, using: EmailEntity, as: :emails
|
6
|
+
expose :photos, using: PhotoEntity, as: :photos
|
7
|
+
expose :phones, using: PhoneEntity, as: :phones
|
8
|
+
expose :addresses, using: AddressEntity, as: :addresses
|
9
|
+
|
10
|
+
expose :uuid
|
11
|
+
|
12
|
+
# Names
|
13
|
+
expose :first_name
|
14
|
+
expose :preferred_name
|
15
|
+
expose :middle_name
|
16
|
+
expose :last_name
|
17
|
+
expose :display_name
|
18
|
+
|
19
|
+
# Demographic
|
20
|
+
expose :gender
|
21
|
+
expose :partial_ssn
|
22
|
+
expose :birth_date
|
23
|
+
|
24
|
+
# Groups and permissions
|
25
|
+
expose :entitlements
|
26
|
+
expose :affiliations
|
27
|
+
|
28
|
+
# Options
|
29
|
+
expose :enabled
|
30
|
+
|
31
|
+
# STUDENT INFO #
|
32
|
+
|
33
|
+
# On-Campus Residence
|
34
|
+
expose :residence
|
35
|
+
expose :floor
|
36
|
+
expose :wing
|
37
|
+
|
38
|
+
# Academic
|
39
|
+
expose :majors
|
40
|
+
|
41
|
+
# FERPA
|
42
|
+
expose :privacy
|
43
|
+
|
44
|
+
# EMPLOYEE INFO #
|
45
|
+
expose :department
|
46
|
+
expose :title
|
47
|
+
expose :employee_type
|
48
|
+
expose :full_time
|
49
|
+
expose :pay_type
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class SyncLogWithChangesetEntity < Grape::Entity
|
4
|
+
expose(:sync_log_id) { |sync_log| sync_log.id }
|
5
|
+
expose(:action) { |sync_log| sync_log.changeset.action }
|
6
|
+
expose(:person_id) { |sync_log| sync_log.changeset.person.uuid }
|
7
|
+
expose(:scope) { |sync_log| sync_log.changeset.scope }
|
8
|
+
expose(:original) { |sync_log| sync_log.changeset.original }
|
9
|
+
expose(:modified) { |sync_log| sync_log.changeset.modified }
|
10
|
+
expose(:created_at) { |sync_log| sync_log.changeset.created_at }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class IDsAPI < Grape::API
|
4
|
+
resource :ids do
|
5
|
+
get do
|
6
|
+
present Person.find_by(uuid: params[:person_id]).ids, with: IDEntity
|
7
|
+
end
|
8
|
+
|
9
|
+
params do
|
10
|
+
# Stupid name. I know. But you get the idea.
|
11
|
+
requires :id_id, type: String
|
12
|
+
end
|
13
|
+
get ':id_id' do
|
14
|
+
present Person.find_by(uuid: params[:person_id]).ids.find(params[:id_id]), with: IDEntity
|
15
|
+
end
|
16
|
+
|
17
|
+
params do
|
18
|
+
requires :type, type: Symbol, values: ID::TYPES
|
19
|
+
requires :identifier
|
20
|
+
end
|
21
|
+
post do
|
22
|
+
Person.find_by(uuid: params[:person_id]).ids.create! clean_params(except: :person_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
params do
|
26
|
+
requires :id_id, type: String
|
27
|
+
optional :type, type: Symbol, values: ID::TYPES
|
28
|
+
optional :identifier
|
29
|
+
end
|
30
|
+
put ':id_id' do
|
31
|
+
Person.find_by(uuid: params[:person_id]).ids.find(params[:id_id]).update_attributes! clean_params(except: [:person_id, :id_id])
|
32
|
+
end
|
33
|
+
|
34
|
+
params do
|
35
|
+
requires :id_id, type: String
|
36
|
+
end
|
37
|
+
delete ':id_id' do
|
38
|
+
Person.find_by(uuid: params[:person_id]).ids.find(params[:id_id]).destroy
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class PeopleAPI < Grape::API
|
4
|
+
UUID_REGEXP = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
|
5
|
+
|
6
|
+
resource :people do
|
7
|
+
desc 'Get a list of people'
|
8
|
+
params do
|
9
|
+
optional :affiliation, type: String
|
10
|
+
end
|
11
|
+
get do
|
12
|
+
conditions = {}
|
13
|
+
|
14
|
+
conditions[:affiliations] = params[:affiliation].to_s if params[:affiliation]
|
15
|
+
|
16
|
+
present Person.where(conditions), with: PersonEntity
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Return a person by associated id', {params: PersonEntity.documentation.except(:enabled)}
|
20
|
+
params do
|
21
|
+
requires :identifier, type: String, desc: 'Associated identifier'
|
22
|
+
optional :type, type: Symbol, values: ID::TYPES, default: ID::DEFAULT_TYPE
|
23
|
+
end
|
24
|
+
get 'by_id/:identifier', requirements: {identifier: /[0-9a-zA-Z\._-]+/} do
|
25
|
+
conditions = {ids: {type: params[:type], identifier: params[:identifier]}}
|
26
|
+
|
27
|
+
present elem_match_or_404(Person, conditions), with: PersonEntity
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Return a person', {params: PersonEntity.documentation.except(:enabled)}
|
31
|
+
params do
|
32
|
+
requires :person_id, desc: 'Person ID'
|
33
|
+
end
|
34
|
+
get ':person_id', requirements: {person_id: UUID_REGEXP} do
|
35
|
+
present Person.find_by(uuid: params[:person_id]), with: PersonEntity
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Create a person'
|
39
|
+
params do
|
40
|
+
# Names
|
41
|
+
requires :first_name, type: String
|
42
|
+
optional :preferred_name, type: String
|
43
|
+
optional :middle_name, type: String
|
44
|
+
requires :last_name, type: String
|
45
|
+
optional :display_name, type: String
|
46
|
+
|
47
|
+
# Demographic
|
48
|
+
optional :gender, type: Symbol, values: Person::GENDERS
|
49
|
+
optional :partial_ssn, type: String
|
50
|
+
optional :birth_date, type: Date
|
51
|
+
|
52
|
+
# Groups and permissions
|
53
|
+
optional :entitlements, type: Array
|
54
|
+
optional :affiliations, type: Array
|
55
|
+
|
56
|
+
# STUDENT INFO #
|
57
|
+
|
58
|
+
# On-Campus Residence
|
59
|
+
optional :residence, type: String
|
60
|
+
optional :floor, type: Integer
|
61
|
+
optional :wing, type: String
|
62
|
+
|
63
|
+
# Academic
|
64
|
+
optional :majors, type: Array
|
65
|
+
|
66
|
+
# FERPA
|
67
|
+
optional :privacy, type: Boolean
|
68
|
+
|
69
|
+
# EMPLOYEE INFO #
|
70
|
+
optional :department, type: String
|
71
|
+
optional :title, type: String
|
72
|
+
optional :employee_type, type: Symbol
|
73
|
+
optional :full_time, type: Boolean
|
74
|
+
optional :pay_type, type: Symbol
|
75
|
+
end
|
76
|
+
post do
|
77
|
+
present Person.create!(clean_params), with: PersonEntity
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'Update a person'
|
81
|
+
params do
|
82
|
+
# Names
|
83
|
+
optional :first_name, type: String
|
84
|
+
optional :preferred_name, type: String
|
85
|
+
optional :middle_name, type: String
|
86
|
+
optional :last_name, type: String
|
87
|
+
optional :display_name, type: String
|
88
|
+
|
89
|
+
# Demographic
|
90
|
+
optional :gender, type: Symbol, values: Person::GENDERS
|
91
|
+
optional :partial_ssn, type: String
|
92
|
+
optional :birth_date, type: Date
|
93
|
+
|
94
|
+
# Groups and permissions
|
95
|
+
optional :entitlements, type: Array
|
96
|
+
optional :affiliations, type: Array
|
97
|
+
|
98
|
+
# STUDENT INFO #
|
99
|
+
|
100
|
+
# On-Campus Residence
|
101
|
+
optional :residence, type: String
|
102
|
+
optional :floor, type: Integer
|
103
|
+
optional :wing, type: String
|
104
|
+
|
105
|
+
# Academic
|
106
|
+
optional :majors, type: Array
|
107
|
+
|
108
|
+
# FERPA
|
109
|
+
optional :privacy, type: Boolean
|
110
|
+
|
111
|
+
# EMPLOYEE INFO #
|
112
|
+
optional :department, type: String
|
113
|
+
optional :title, type: String
|
114
|
+
optional :employee_type, type: Symbol
|
115
|
+
optional :full_time, type: Boolean
|
116
|
+
optional :pay_type, type: Symbol
|
117
|
+
end
|
118
|
+
put ':person_id', requirements: {person_id: UUID_REGEXP} do
|
119
|
+
person = Person.find_by(uuid: params[:person_id])
|
120
|
+
person.update_attributes! clean_params(except: :person_id)
|
121
|
+
|
122
|
+
present person, with: PersonEntity
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class PhonesAPI < Grape::API
|
4
|
+
resource :phones do
|
5
|
+
get do
|
6
|
+
present Person.find_by(uuid: params[:person_id]).phones, with: PhoneEntity
|
7
|
+
end
|
8
|
+
|
9
|
+
params do
|
10
|
+
requires :phone_id, type: String
|
11
|
+
end
|
12
|
+
get ':phone_id' do
|
13
|
+
present Person.find_by(uuid: params[:person_id]).phones.find(params[:phone_id]), with: PhoneEntity
|
14
|
+
end
|
15
|
+
|
16
|
+
params do
|
17
|
+
requires :type, type: Symbol, values: Phone::TYPES
|
18
|
+
requires :number, type: String
|
19
|
+
optional :primary, type: Boolean
|
20
|
+
end
|
21
|
+
post do
|
22
|
+
Person.find_by(uuid: params[:person_id]).phones.create! clean_params(except: :person_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
params do
|
26
|
+
requires :phone_id, type: String
|
27
|
+
optional :type, type: Symbol, values: Phone::TYPES
|
28
|
+
optional :number, type: String
|
29
|
+
optional :primary, type: Boolean
|
30
|
+
end
|
31
|
+
put ':phone_id' do
|
32
|
+
Person.find_by(uuid: params[:person_id]).phones.find(params[:phone_id]).update_attributes! clean_params(except: [:person_id, :phone_id])
|
33
|
+
end
|
34
|
+
|
35
|
+
params do
|
36
|
+
requires :phone_id, type: String
|
37
|
+
end
|
38
|
+
delete ':phone_id' do
|
39
|
+
Person.find_by(uuid: params[:person_id]).phones.find(params[:phone_id]).destroy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
class PhotosAPI < Grape::API
|
4
|
+
resource :photos do
|
5
|
+
get do
|
6
|
+
present Person.find_by(uuid: params[:person_id]).photos, with: PhotoEntity
|
7
|
+
end
|
8
|
+
|
9
|
+
params do
|
10
|
+
requires :photo_id, type: String
|
11
|
+
end
|
12
|
+
get ':photo_id' do
|
13
|
+
present Person.find_by(uuid: params[:person_id]).photos.find(params[:photo_id]), with: PhotoEntity
|
14
|
+
end
|
15
|
+
|
16
|
+
params do
|
17
|
+
requires :type, type: Symbol, values: Photo::TYPES
|
18
|
+
requires :url, type: String
|
19
|
+
optional :height, type: Integer
|
20
|
+
optional :width, type: Integer
|
21
|
+
end
|
22
|
+
post do
|
23
|
+
Person.find_by(uuid: params[:person_id]).photos.create! clean_params(except: :person_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
params do
|
27
|
+
requires :photo_id, type: String
|
28
|
+
optional :type, type: Symbol, values: Photo::TYPES
|
29
|
+
optional :url, type: String
|
30
|
+
optional :height, type: Integer
|
31
|
+
optional :width, type: Integer
|
32
|
+
end
|
33
|
+
put ':photo_id' do
|
34
|
+
Person.find_by(uuid: params[:person_id]).photos.find(params[:photo_id]).update_attributes! clean_params(except: [:person_id, :photo_id])
|
35
|
+
end
|
36
|
+
|
37
|
+
params do
|
38
|
+
requires :photo_id, type: String
|
39
|
+
end
|
40
|
+
delete ':photo_id' do
|
41
|
+
Person.find_by(uuid: params[:person_id]).photos.find(params[:photo_id]).destroy
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Trogdir
|
2
|
+
module V1
|
3
|
+
autoload :API, File.expand_path('../v1/api', __FILE__)
|
4
|
+
autoload :ChangeSyncsAPI, File.expand_path('../v1/change_syncs_api', __FILE__)
|
5
|
+
autoload :PeopleAPI, File.expand_path('../v1/people_api', __FILE__)
|
6
|
+
autoload :IDsAPI, File.expand_path('../v1/ids_api', __FILE__)
|
7
|
+
autoload :EmailsAPI, File.expand_path('../v1/emails_api', __FILE__)
|
8
|
+
autoload :PhotosAPI, File.expand_path('../v1/photos_api', __FILE__)
|
9
|
+
autoload :PhonesAPI, File.expand_path('../v1/phones_api', __FILE__)
|
10
|
+
autoload :AddressesAPI, File.expand_path('../v1/addresses_api', __FILE__)
|
11
|
+
autoload :SyncLogEntity, File.expand_path('../v1/entities/sync_log', __FILE__)
|
12
|
+
autoload :SyncLogWithChangesetEntity, File.expand_path('../v1/entities/sync_log_with_changeset', __FILE__)
|
13
|
+
autoload :PersonEntity, File.expand_path('../v1/entities/person', __FILE__)
|
14
|
+
autoload :IDEntity, File.expand_path('../v1/entities/id', __FILE__)
|
15
|
+
autoload :EmailEntity, File.expand_path('../v1/entities/email', __FILE__)
|
16
|
+
autoload :PhotoEntity, File.expand_path('../v1/entities/photo', __FILE__)
|
17
|
+
autoload :PhoneEntity, File.expand_path('../v1/entities/phone', __FILE__)
|
18
|
+
autoload :AddressEntity, File.expand_path('../v1/entities/address', __FILE__)
|
19
|
+
end
|
20
|
+
end
|
data/lib/trogdir_api.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'grape'
|
2
|
+
require 'grape-entity'
|
3
|
+
require 'api_auth'
|
4
|
+
require 'trogdir_models'
|
5
|
+
|
6
|
+
module TrogdirAPI
|
7
|
+
def self.initialize!
|
8
|
+
ENV['RACK_ENV'] ||= 'development'
|
9
|
+
|
10
|
+
mongoid_yml_path = File.expand_path('../../config/mongoid.yml', __FILE__)
|
11
|
+
mongoid_yml_path = "#{mongoid_yml_path}.example" if !File.exists? mongoid_yml_path
|
12
|
+
Mongoid.load! mongoid_yml_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Trogdir
|
17
|
+
autoload :AuthenticationHelpers, File.expand_path('../trogdir/helpers/authentication_helpers', __FILE__)
|
18
|
+
autoload :ResponseHelpers, File.expand_path('../trogdir/helpers/response_helpers', __FILE__)
|
19
|
+
autoload :RequestHelpers, File.expand_path('../trogdir/helpers/request_helpers', __FILE__)
|
20
|
+
autoload :API, File.expand_path('../trogdir/api', __FILE__)
|
21
|
+
autoload :V1, File.expand_path('../trogdir/versions/v1', __FILE__)
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trogdir_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Crownoble
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: api-auth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: grape
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: grape-entity
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.4'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: trogdir_models
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: API for the Trogdir directory project
|
70
|
+
email: adam.crownoble@biola.edu
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- MIT-LICENSE
|
76
|
+
- README.md
|
77
|
+
- config.ru
|
78
|
+
- config/environment.rb
|
79
|
+
- config/mongoid.yml
|
80
|
+
- config/mongoid.yml.example
|
81
|
+
- lib/trogdir/api.rb
|
82
|
+
- lib/trogdir/helpers/authentication_helpers.rb
|
83
|
+
- lib/trogdir/helpers/request_helpers.rb
|
84
|
+
- lib/trogdir/helpers/response_helpers.rb
|
85
|
+
- lib/trogdir/versions/v1.rb
|
86
|
+
- lib/trogdir/versions/v1/addresses_api.rb
|
87
|
+
- lib/trogdir/versions/v1/api.rb
|
88
|
+
- lib/trogdir/versions/v1/change_syncs_api.rb
|
89
|
+
- lib/trogdir/versions/v1/emails_api.rb
|
90
|
+
- lib/trogdir/versions/v1/entities/address.rb
|
91
|
+
- lib/trogdir/versions/v1/entities/email.rb
|
92
|
+
- lib/trogdir/versions/v1/entities/id.rb
|
93
|
+
- lib/trogdir/versions/v1/entities/person.rb
|
94
|
+
- lib/trogdir/versions/v1/entities/phone.rb
|
95
|
+
- lib/trogdir/versions/v1/entities/photo.rb
|
96
|
+
- lib/trogdir/versions/v1/entities/sync_log.rb
|
97
|
+
- lib/trogdir/versions/v1/entities/sync_log_with_changeset.rb
|
98
|
+
- lib/trogdir/versions/v1/ids_api.rb
|
99
|
+
- lib/trogdir/versions/v1/people_api.rb
|
100
|
+
- lib/trogdir/versions/v1/phones_api.rb
|
101
|
+
- lib/trogdir/versions/v1/photos_api.rb
|
102
|
+
- lib/trogdir_api.rb
|
103
|
+
- lib/trogdir_api/version.rb
|
104
|
+
homepage: https://github.com/biola/trogdir-api
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Trogdir directory API
|
128
|
+
test_files: []
|