trogdir_api_client 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c84869f5c27f1d6ff0e6b6c542f0066bf0c41fd5
4
+ data.tar.gz: 5140f152412bf8030873d74c07b54408b318f18c
5
+ SHA512:
6
+ metadata.gz: b3f7af1b5cb00fb77e0e9cf1f4a4a2b9efc8ee254248423357f17956c1c8d5a71da35fd39560fcbab9c76a0120499d6a538aacf27c1f22f3aa01b7dbf678a7a1
7
+ data.tar.gz: 6878a454c3674445e8fd68326bb78a8f1c70400312e6276fd376e0990472a6b267c960a5f9b98311e56eb94c4b2c839cc347f1df6971beacf0736da9fa23a756
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
@@ -0,0 +1,17 @@
1
+ Trogdir API Client [![Build Status](https://travis-ci.org/biola/trogdir-api-client.svg?branch=master)](https://travis-ci.org/biola/trogdir-api-client)
2
+ ==================
3
+
4
+ Installing
5
+ ----------
6
+
7
+ Add `gem 'trogdir_api_client'` to your `Gemfile` and run `bundle`
8
+
9
+ Usage
10
+ -----
11
+
12
+ TODO
13
+
14
+ License
15
+ -------
16
+
17
+ MIT
@@ -0,0 +1,23 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class Addresses < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
6
+
7
+ get :index, '/people/{uuid}/addresses'
8
+
9
+ get :show, '/people/{uuid}/addresses/{address_id}'
10
+
11
+ post :create, '/people/{uuid}/addresses' do |resource|
12
+ resource.required :type, :street_1
13
+ resource.optional :street_2, :city, :state, :zip, :country
14
+ end
15
+
16
+ put :update, '/people/{uuid}/addresses/{address_id}' do |resource|
17
+ resource.optional :type, :street_1, :street_2, :city, :state, :zip, :country
18
+ end
19
+
20
+ delete :destroy, '/people/{uuid}/addresses/{address_id}'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class ChangeSyncs < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
6
+
7
+ put :start, '/change_syncs/start'
8
+
9
+ put :error, '/change_syncs/error/{sync_log_id}' do |resource|
10
+ resource.required :message
11
+ end
12
+
13
+ put :finish, '/change_syncs/finish/{sync_log_id}' do |resource|
14
+ resource.required :action
15
+ resource.optional :message
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class Emails < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
6
+
7
+ get :index, '/people/{uuid}/emails'
8
+
9
+ get :show, '/people/{uuid}/emails/{email_id}'
10
+
11
+ post :create, '/people/{uuid}/emails' do |resource|
12
+ resource.required :type, :address
13
+ resource.optional :primary
14
+ end
15
+
16
+ put :update, '/people/{uuid}/emails/{email_id}' do |resource|
17
+ resource.optional :type, :address, :primary
18
+ end
19
+
20
+ delete :destroy, '/people/{uuid}/emails/{email_id}'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class IDs < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ # use Weary::Middleware::ContentType
6
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
7
+
8
+ get :index, '/people/{uuid}/ids'
9
+
10
+ get :show, '/people/{uuid}/ids/{id_id}'
11
+
12
+ post :create, '/people/{uuid}/ids' do |resource|
13
+ resource.required :type, :identifier
14
+ end
15
+
16
+ put :update, '/people/{uuid}/ids/{id_id}' do |resource|
17
+ resource.optional :type, :identifier
18
+ end
19
+
20
+ delete :destroy, '/people/{uuid}/ids/{id_id}'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class People < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ # use Weary::Middleware::ContentType
6
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
7
+
8
+ get :index, '/people' do |resource|
9
+ resource.optional :affiliation
10
+ end
11
+
12
+ get :show, '/people/{uuid}'
13
+
14
+ get :by_id, '/people/by_id/{id}' do |resource|
15
+ resource.optional :type
16
+ end
17
+
18
+ post :create, '/people' do |resource|
19
+ resource.required :first_name, :last_name
20
+ resource.optional(
21
+ :preferred_name, :middle_name, :display_name, # Names
22
+ :gender, :partial_ssn, :birth_date, # Demographic
23
+ :entitlements, :affiliations, # Groups and permissions
24
+
25
+ # STUDENT INFO #
26
+ :residence, :floor, :wing, # On-Campus Residence
27
+ :majors, # Academic
28
+ :privacy, # FERPA
29
+
30
+ # EMPLOYEE INFO #
31
+ :department, :title, :employee_type, :full_time, :pay_type
32
+ )
33
+ end
34
+
35
+ put :update, '/people/{uuid}' do |resource|
36
+ resource.optional(
37
+ :first_name, :last_name, :preferred_name, :middle_name, :display_name, # Names
38
+ :gender, :partial_ssn, :birth_date, # Demographic
39
+ :entitlements, :affiliations, # Groups and permissions
40
+
41
+ # STUDENT INFO #
42
+ :residence, :floor, :wing, # On-Campus Residence
43
+ :majors, # Academic
44
+ :privacy, # FERPA
45
+
46
+ # EMPLOYEE INFO #
47
+ :department, :title, :employee_type, :full_time, :pay_type
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class Phones < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
6
+
7
+ get :index, '/people/{uuid}/phones'
8
+
9
+ get :show, '/people/{uuid}/phones/{phone_id}'
10
+
11
+ post :create, '/people/{uuid}/phones' do |resource|
12
+ resource.required :type, :number
13
+ resource.optional :primary
14
+ end
15
+
16
+ put :update, '/people/{uuid}/phones/{phone_id}' do |resource|
17
+ resource.optional :type, :number, :primary
18
+ end
19
+
20
+ delete :destroy, '/people/{uuid}/phones/{phone_id}'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module Trogdir
2
+ module APIClient
3
+ class Photos < Weary::Client
4
+ domain TrogdirAPIClient.config.base_url
5
+ use Weary::Middleware::HMACAuth, [TrogdirAPIClient.config.credentials]
6
+
7
+ get :index, '/people/{uuid}/photos'
8
+
9
+ get :show, '/people/{uuid}/photos/{photo_id}'
10
+
11
+ post :create, '/people/{uuid}/photos' do |resource|
12
+ resource.required :type, :url, :height, :width
13
+ end
14
+
15
+ put :update, '/people/{uuid}/photos/{photo_id}' do |resource|
16
+ resource.optional :type, :url, :width, :height
17
+ end
18
+
19
+ delete :destroy, '/people/{uuid}/photos/{photo_id}'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'weary'
2
+
3
+ module TrogdirAPIClient
4
+ require 'trogdir_api_client/configuration'
5
+
6
+ def self.configure
7
+ yield config
8
+ end
9
+
10
+ def self.config
11
+ @config ||= Configuration.new
12
+ end
13
+ end
14
+
15
+ module Trogdir
16
+ module APIClient
17
+ autoload :People, 'trogdir/api_client/people'
18
+ autoload :IDs, 'trogdir/api_client/ids'
19
+ autoload :Emails, 'trogdir/api_client/emails'
20
+ autoload :Phones, 'trogdir/api_client/phones'
21
+ autoload :Photos, 'trogdir/api_client/photos'
22
+ autoload :Addresses, 'trogdir/api_client/addresses'
23
+ autoload :ChangeSyncs, 'trogdir/api_client/change_syncs'
24
+ end
25
+ end
26
+
27
+ module Weary
28
+ module Middleware
29
+ autoload :HMACAuth, 'weary/middleware/hmac_auth'
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ require 'uri'
2
+
3
+ module TrogdirAPIClient
4
+ class Configuration
5
+ attr_accessor :access_id
6
+ attr_accessor :secret_key
7
+
8
+ attr_accessor :scheme
9
+ attr_accessor :host
10
+ attr_accessor :script_name
11
+ attr_accessor :version
12
+
13
+ def initialize
14
+ @scheme = 'https'
15
+ @host = 'api.biola.edu'
16
+ @script_name = 'directory'
17
+ @version = 'v1'
18
+ end
19
+
20
+ def base_url
21
+ URI.join(root_url, "/#{script_name}/", version).to_s
22
+ end
23
+
24
+ def credentials
25
+ {access_id: access_id, secret_key: secret_key}
26
+ end
27
+
28
+ private
29
+
30
+ def root_url
31
+ URI::Generic.build(scheme: scheme, host: host)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module TrogdirAPIClient
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'api_auth'
2
+
3
+ module Weary
4
+ module Middleware
5
+ class HMACAuth
6
+
7
+ def initialize(app, config = {})
8
+ @app = app
9
+ @access_id = config[:access_id]
10
+ @secret_key = config[:secret_key]
11
+ end
12
+
13
+ def call(env)
14
+ set_content_type! env
15
+ sign! env
16
+ @app.call env
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :access_id, :secret_key
22
+
23
+ def set_content_type!(env)
24
+ env.tap do |e|
25
+ # Weary::Middleware::ContentType is dynamically injected after
26
+ # this middleware is called and since Content-Type is used to
27
+ # sign HMAC signatures, we have to mimic that behavior so that
28
+ # there's no difference in the headers when it's authenticated.
29
+ if ['POST', 'PUT'].include? e['REQUEST_METHOD']
30
+ e.update 'CONTENT_TYPE' => 'application/x-www-form-urlencoded'
31
+ end
32
+ end
33
+ end
34
+
35
+ def signed_request(env)
36
+ Rack::Request.new(env).tap do |r|
37
+ ApiAuth.sign! r, access_id, secret_key
38
+ end
39
+ end
40
+
41
+ def sign!(env)
42
+ req = signed_request(env)
43
+
44
+ env.tap do |e|
45
+ # Weary wants all headers to be in HTTP_[UPCASE] format for Rack env compatibility
46
+ e.update(
47
+ 'HTTP_AUTHORIZATION' => req.env['Authorization'],
48
+ 'HTTP_DATE' => req.env['DATE']
49
+ )
50
+
51
+ if md5 = req.env['Content-MD5']
52
+ e.update 'HTTP_CONTENT_MD5' => md5
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trogdir_api_client
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-09 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: weary
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.17'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.17'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faker
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: trogdir_api
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-stack_explorer
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.4'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.4'
139
+ description: API consuming models for the Trogdir directory project
140
+ email: adam.crownoble@biola.edu
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - MIT-LICENSE
146
+ - README.md
147
+ - lib/trogdir/api_client/addresses.rb
148
+ - lib/trogdir/api_client/change_syncs.rb
149
+ - lib/trogdir/api_client/emails.rb
150
+ - lib/trogdir/api_client/ids.rb
151
+ - lib/trogdir/api_client/people.rb
152
+ - lib/trogdir/api_client/phones.rb
153
+ - lib/trogdir/api_client/photos.rb
154
+ - lib/trogdir_api_client.rb
155
+ - lib/trogdir_api_client/configuration.rb
156
+ - lib/trogdir_api_client/version.rb
157
+ - lib/weary/middleware/hmac_auth.rb
158
+ homepage: https://github.com/biola/trogdir-api-client
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.2.2
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Client for the Trogdir directory API
182
+ test_files: []