trogdir_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c0461f30e10661b43c4d43250326dcc5c135eff
4
- data.tar.gz: 9edfd9a1b18c4ed633841d2821c595ec89d75df4
3
+ metadata.gz: 94a2d90b3c249f0b5eecb43e9cbe7122582b9570
4
+ data.tar.gz: 3ac808217184e16102e5ca11555c9bd7ef7707d2
5
5
  SHA512:
6
- metadata.gz: ee5b4c1468f78d401e0c55afe48a0359e5b111d3e8b17c6f9b497f37809d50e285bd2eb5a7570f3920e14fde7a141659880847e0f59563fe8d50590c604e50e9
7
- data.tar.gz: a5c94365037a666d4ebc73f4836874416e96f6ea02fe98073aa09dd1359c686dbc09cb23ece5408df2d82e00dbf5572f28e9a151126a18c0acba71541009d798
6
+ metadata.gz: d5e189f20a678f1880920e53b5970daaa6127d94e678e9abb4af7861df9cc7ffba8fdbc4abf15126657333064b95696f03fe18430317d3d2f435492db30ce1f1
7
+ data.tar.gz: 0d4cd9d6477690cbaf5889100bb2b14417f260922ccb395a4e24c13fe08cfd8b72ca3d16bd0ca72b000b689e2c199c9aa9b556c495c7cf8e250ddadae62ba787
@@ -2,15 +2,20 @@ module Trogdir
2
2
  module V1
3
3
  class AddressesAPI < Grape::API
4
4
  resource :addresses do
5
+ before do
6
+ @person = Person.find_by(uuid: params[:person_id]) if params[:person_id]
7
+ @address = @person.addresses.find(params[:address_id]) if params[:address_id]
8
+ end
9
+
5
10
  get do
6
- present Person.find_by(uuid: params[:person_id]).addresses, with: AddressEntity
11
+ present @person.addresses, with: AddressEntity
7
12
  end
8
13
 
9
14
  params do
10
15
  requires :address_id, type: String
11
16
  end
12
17
  get ':address_id' do
13
- present Person.find_by(uuid: params[:person_id]).addresses.find(params[:address_id]), with: AddressEntity
18
+ present @address, with: AddressEntity
14
19
  end
15
20
 
16
21
  params do
@@ -23,7 +28,7 @@ module Trogdir
23
28
  optional :contry, type: String
24
29
  end
25
30
  post do
26
- Person.find_by(uuid: params[:person_id]).addresses.create! clean_params(except: :person_id)
31
+ present @person.addresses.create!(clean_params(except: :person_id)), with: AddressEntity
27
32
  end
28
33
 
29
34
  params do
@@ -37,14 +42,18 @@ module Trogdir
37
42
  optional :contry, type: String
38
43
  end
39
44
  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])
45
+ @address.update_attributes! clean_params(except: [:person_id, :address_id])
46
+
47
+ present @address, with: AddressEntity
41
48
  end
42
49
 
43
50
  params do
44
51
  requires :address_id, type: String
45
52
  end
46
53
  delete ':address_id' do
47
- Person.find_by(uuid: params[:person_id]).addresses.find(params[:address_id]).destroy
54
+ @address.destroy
55
+
56
+ present @address, with: AddressEntity
48
57
  end
49
58
  end
50
59
  end
@@ -2,6 +2,14 @@ module Trogdir
2
2
  module V1
3
3
  class ChangeSyncsAPI < Grape::API
4
4
  resource :change_syncs do
5
+ before do
6
+ if params[:sync_log_id]
7
+ @sync_log = SyncLog.find_through_parents(params[:sync_log_id])
8
+
9
+ unauthorized! unless @sync_log.syncinator == current_syncinator
10
+ end
11
+ end
12
+
5
13
  desc "Return and starts change_syncs that haven't been started"
6
14
  put :start do
7
15
  syncinator = current_syncinator
@@ -20,11 +28,7 @@ module Trogdir
20
28
  requires :message, type: String
21
29
  end
22
30
  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]
31
+ current_syncinator.error! @sync_log, params[:message]
28
32
  end
29
33
 
30
34
  desc "Return a sync_log and mark it as succeeded"
@@ -34,11 +38,7 @@ module Trogdir
34
38
  optional :message, type: String
35
39
  end
36
40
  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]
41
+ current_syncinator.finish! @sync_log, params[:action], params[:message]
42
42
  end
43
43
  end
44
44
  end
@@ -2,15 +2,20 @@ module Trogdir
2
2
  module V1
3
3
  class EmailsAPI < Grape::API
4
4
  resource :emails do
5
+ before do
6
+ @person = Person.find_by(uuid: params[:person_id]) if params[:person_id]
7
+ @email = @person.emails.find(params[:email_id]) if params[:email_id]
8
+ end
9
+
5
10
  get do
6
- present Person.find_by(uuid: params[:person_id]).emails, with: EmailEntity
11
+ present @person.emails, with: EmailEntity
7
12
  end
8
13
 
9
14
  params do
10
15
  requires :email_id, type: String
11
16
  end
12
17
  get ':email_id' do
13
- present Person.find_by(uuid: params[:person_id]).emails.find(params[:email_id]), with: EmailEntity
18
+ present @email, with: EmailEntity
14
19
  end
15
20
 
16
21
  params do
@@ -19,7 +24,7 @@ module Trogdir
19
24
  optional :primary, type: Boolean
20
25
  end
21
26
  post do
22
- Person.find_by(uuid: params[:person_id]).emails.create! clean_params(except: :person_id)
27
+ present @person.emails.create!(clean_params(except: :person_id)), with: EmailEntity
23
28
  end
24
29
 
25
30
  params do
@@ -29,14 +34,18 @@ module Trogdir
29
34
  optional :primary, type: Boolean
30
35
  end
31
36
  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])
37
+ @email.update_attributes! clean_params(except: [:person_id, :email_id])
38
+
39
+ present @email, with: EmailEntity
33
40
  end
34
41
 
35
42
  params do
36
43
  requires :email_id, type: String
37
44
  end
38
45
  delete ':email_id' do
39
- Person.find_by(uuid: params[:person_id]).emails.find(params[:email_id]).destroy
46
+ @email.destroy
47
+
48
+ present @email, with: EmailEntity
40
49
  end
41
50
  end
42
51
  end
@@ -1,6 +1,7 @@
1
1
  module Trogdir
2
2
  module V1
3
3
  class AddressEntity < Grape::Entity
4
+ expose :id
4
5
  expose :type
5
6
  expose :street_1
6
7
  expose :street_2
@@ -1,6 +1,7 @@
1
1
  module Trogdir
2
2
  module V1
3
3
  class EmailEntity < Grape::Entity
4
+ expose :id
4
5
  expose :type
5
6
  expose :address
6
7
  expose :primary
@@ -1,6 +1,7 @@
1
1
  module Trogdir
2
2
  module V1
3
3
  class IDEntity < Grape::Entity
4
+ expose :id
4
5
  expose :type
5
6
  expose :identifier
6
7
  end
@@ -1,6 +1,7 @@
1
1
  module Trogdir
2
2
  module V1
3
3
  class PhoneEntity < Grape::Entity
4
+ expose :id
4
5
  expose :type
5
6
  expose :number
6
7
  expose :primary
@@ -1,6 +1,7 @@
1
1
  module Trogdir
2
2
  module V1
3
3
  class PhotoEntity < Grape::Entity
4
+ expose :id
4
5
  expose :type
5
6
  expose :url
6
7
  expose :height
@@ -2,8 +2,13 @@ module Trogdir
2
2
  module V1
3
3
  class IDsAPI < Grape::API
4
4
  resource :ids do
5
+ before do
6
+ @person = Person.find_by(uuid: params[:person_id])
7
+ @id = @person.ids.find(params[:id_id]) if params[:id_id]
8
+ end
9
+
5
10
  get do
6
- present Person.find_by(uuid: params[:person_id]).ids, with: IDEntity
11
+ present @person.ids, with: IDEntity
7
12
  end
8
13
 
9
14
  params do
@@ -11,7 +16,7 @@ module Trogdir
11
16
  requires :id_id, type: String
12
17
  end
13
18
  get ':id_id' do
14
- present Person.find_by(uuid: params[:person_id]).ids.find(params[:id_id]), with: IDEntity
19
+ present @id, with: IDEntity
15
20
  end
16
21
 
17
22
  params do
@@ -19,7 +24,7 @@ module Trogdir
19
24
  requires :identifier
20
25
  end
21
26
  post do
22
- Person.find_by(uuid: params[:person_id]).ids.create! clean_params(except: :person_id)
27
+ present @person.ids.create!(clean_params(except: :person_id)), with: IDEntity
23
28
  end
24
29
 
25
30
  params do
@@ -28,14 +33,18 @@ module Trogdir
28
33
  optional :identifier
29
34
  end
30
35
  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])
36
+ @id.update_attributes! clean_params(except: [:person_id, :id_id])
37
+
38
+ present @id, with: IDEntity
32
39
  end
33
40
 
34
41
  params do
35
42
  requires :id_id, type: String
36
43
  end
37
44
  delete ':id_id' do
38
- Person.find_by(uuid: params[:person_id]).ids.find(params[:id_id]).destroy
45
+ @id.destroy
46
+
47
+ present @id, with: IDEntity
39
48
  end
40
49
  end
41
50
  end
@@ -4,6 +4,10 @@ module Trogdir
4
4
  UUID_REGEXP = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
5
5
 
6
6
  resource :people do
7
+ before do
8
+ @person = Person.find_by(uuid: params[:person_id]) if params[:person_id]
9
+ end
10
+
7
11
  desc 'Get a list of people'
8
12
  params do
9
13
  optional :affiliation, type: String
@@ -32,7 +36,7 @@ module Trogdir
32
36
  requires :person_id, desc: 'Person ID'
33
37
  end
34
38
  get ':person_id', requirements: {person_id: UUID_REGEXP} do
35
- present Person.find_by(uuid: params[:person_id]), with: PersonEntity
39
+ present @person, with: PersonEntity
36
40
  end
37
41
 
38
42
  desc 'Create a person'
@@ -116,10 +120,9 @@ module Trogdir
116
120
  optional :pay_type, type: Symbol
117
121
  end
118
122
  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)
123
+ @person.update_attributes! clean_params(except: :person_id)
121
124
 
122
- present person, with: PersonEntity
125
+ present @person, with: PersonEntity
123
126
  end
124
127
  end
125
128
  end
@@ -2,15 +2,20 @@ module Trogdir
2
2
  module V1
3
3
  class PhonesAPI < Grape::API
4
4
  resource :phones do
5
+ before do
6
+ @person = Person.find_by(uuid: params[:person_id]) if params[:person_id]
7
+ @phone = @person.phones.find(params[:phone_id]) if params[:phone_id]
8
+ end
9
+
5
10
  get do
6
- present Person.find_by(uuid: params[:person_id]).phones, with: PhoneEntity
11
+ present @person.phones, with: PhoneEntity
7
12
  end
8
13
 
9
14
  params do
10
15
  requires :phone_id, type: String
11
16
  end
12
17
  get ':phone_id' do
13
- present Person.find_by(uuid: params[:person_id]).phones.find(params[:phone_id]), with: PhoneEntity
18
+ present @phone, with: PhoneEntity
14
19
  end
15
20
 
16
21
  params do
@@ -19,7 +24,7 @@ module Trogdir
19
24
  optional :primary, type: Boolean
20
25
  end
21
26
  post do
22
- Person.find_by(uuid: params[:person_id]).phones.create! clean_params(except: :person_id)
27
+ present @person.phones.create!(clean_params(except: :person_id)), with: PhoneEntity
23
28
  end
24
29
 
25
30
  params do
@@ -29,14 +34,18 @@ module Trogdir
29
34
  optional :primary, type: Boolean
30
35
  end
31
36
  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])
37
+ @phone.update_attributes! clean_params(except: [:person_id, :phone_id])
38
+
39
+ present @phone, with: PhoneEntity
33
40
  end
34
41
 
35
42
  params do
36
43
  requires :phone_id, type: String
37
44
  end
38
45
  delete ':phone_id' do
39
- Person.find_by(uuid: params[:person_id]).phones.find(params[:phone_id]).destroy
46
+ @phone.destroy
47
+
48
+ present @phone, with: PhoneEntity
40
49
  end
41
50
  end
42
51
  end
@@ -2,15 +2,20 @@ module Trogdir
2
2
  module V1
3
3
  class PhotosAPI < Grape::API
4
4
  resource :photos do
5
+ before do
6
+ @person = Person.find_by(uuid: params[:person_id]) if params[:person_id]
7
+ @photo = @person.photos.find(params[:photo_id]) if params[:photo_id]
8
+ end
9
+
5
10
  get do
6
- present Person.find_by(uuid: params[:person_id]).photos, with: PhotoEntity
11
+ present @person.photos, with: PhotoEntity
7
12
  end
8
13
 
9
14
  params do
10
15
  requires :photo_id, type: String
11
16
  end
12
17
  get ':photo_id' do
13
- present Person.find_by(uuid: params[:person_id]).photos.find(params[:photo_id]), with: PhotoEntity
18
+ present @photo, with: PhotoEntity
14
19
  end
15
20
 
16
21
  params do
@@ -20,7 +25,7 @@ module Trogdir
20
25
  optional :width, type: Integer
21
26
  end
22
27
  post do
23
- Person.find_by(uuid: params[:person_id]).photos.create! clean_params(except: :person_id)
28
+ present @person.photos.create!(clean_params(except: :person_id)), with: PhotoEntity
24
29
  end
25
30
 
26
31
  params do
@@ -31,14 +36,18 @@ module Trogdir
31
36
  optional :width, type: Integer
32
37
  end
33
38
  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])
39
+ @photo.update_attributes! clean_params(except: [:person_id, :photo_id])
40
+
41
+ present @photo, with: PhotoEntity
35
42
  end
36
43
 
37
44
  params do
38
45
  requires :photo_id, type: String
39
46
  end
40
47
  delete ':photo_id' do
41
- Person.find_by(uuid: params[:person_id]).photos.find(params[:photo_id]).destroy
48
+ @photo.destroy
49
+
50
+ present @photo, with: PhotoEntity
42
51
  end
43
52
  end
44
53
  end
@@ -1,3 +1,3 @@
1
1
  module TrogdirAPI
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trogdir_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-08 00:00:00.000000000 Z
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api-auth