google_syncinator_api_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6746ed6b42fa2c0bcc67fd6d132e6c13e60a0c5
4
+ data.tar.gz: 17340e693ea0bb4367d6e22fa19d4e46552d3db5
5
+ SHA512:
6
+ metadata.gz: 87eef4b73e1d7090e808c3249a9f2854e160ea3cf35d4e497942e836f3b0b90ed0b6b063abf5b324715fdba91aebdeef6e1e6f24bcdff4012626a1d8ebd6ef8f
7
+ data.tar.gz: 606b106580f8de0c283d53f6f156c80894428b1ba73678d2417a7549b7b10b996818d0eac0b1911131376bce69c124595b3b2bc878fe72c2a783fe0e84abf80d
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 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,66 @@
1
+ GoogleSyncinator API Client [![Build Status](https://travis-ci.org/biola/google-syncinator-api-client.svg?branch=master)](https://travis-ci.org/biola/google-syncinator-api-client)
2
+ ==================
3
+
4
+ Google Syncinator API Client is a client to the [google-syncinator](https://github.com/biola/google-syncinator) API (duh!)
5
+
6
+ Installing
7
+ ----------
8
+
9
+ Add `gem 'google_syncinator_api_client'` to your `Gemfile` and run `bundle`
10
+
11
+ Configuration
12
+ -------------
13
+
14
+ ```ruby
15
+ GoogleSyncinatorAPIClient.configure do |config|
16
+ # Optional:
17
+ # config.scheme = 'http'
18
+ # config.host = 'localhost'
19
+ # config.script_name = nil
20
+ # config.version = 'v1'
21
+
22
+ # Required:
23
+ config.access_id = '**************'
24
+ config.secret_key = '*****************************************'
25
+ end
26
+ ```
27
+
28
+ Getting Credentials
29
+ -------------------
30
+
31
+ To create a google-syncinator client and get an `access_id` and `secret_key`, see the [google-syncinator README](https://github.com/biola/google-syncinator/blob/master/README.md).
32
+
33
+ Usage
34
+ -----
35
+
36
+ ### Example Syncinator
37
+
38
+ ```ruby
39
+ require 'google_syncinator_api_client'
40
+ require 'multi_json'
41
+
42
+ emails_api = GoogleSyncinator::APIClient::Emails.new
43
+ emails = emails_api.index.perform.parse
44
+ emails_api.show(id: emails.first['id']).perform.parse
45
+
46
+ person_emails_api = GoogleSyncinator::APIClient::PersonEmails.new
47
+ person_email = person_emails_api.create(uuid: 'TROGDIR_PERSON_UUID', address: 'test@example.com').perform.parse
48
+ person_emails_api.show(id: person_email['id']).perform
49
+
50
+ alias_emails_api = GoogleSyncinator::APIClient::AliasEmails.new
51
+ alias_email = alias_emails_api.create(account_email_id: person_email['id'], address: 'test@example.com').perform.parse
52
+ alias_emails_api.show(id: alias_email['id']).perform
53
+
54
+ deprovision_schedules_api = GoogleSyncinator::APIClient::DeprovisionSchedules.new
55
+ deprovision_schedule = deprovision_schedules_api.create(email_id: person_email['id'], action: :suspend, scheduled_for: Time.now).perform.parse
56
+ deprovision_schedules_api.update(email_id: person_email['id'], id: deprovision_schedule['id'], canceled: true).perform
57
+ deprovision_schedules_api.destroy(email_id: person_email['id'], id: deprovision_schedule['id']).perform
58
+
59
+ exclusions_api = GoogleSyncinator::APIClient::Exclusions.new
60
+ exclusion_api = exclusions_api.create(email_id: person_email['id'], creator_uuid: 'TROGDIR_PERSON_UUID', starts_at: Time.now).perform.parse
61
+ exclusions_api.destroy(email_id: person_email['id'], id: exclusion_api['id']).perform
62
+ ```
63
+
64
+ License
65
+ -------
66
+ [MIT](https://github.com/biola/google-syncinator-api-client/blob/master/MIT-LICENSE)
@@ -0,0 +1,13 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class AccountEmails < Weary::Client
4
+ include Settings
5
+
6
+ get :search, '/account_emails' do |resource|
7
+ resource.required :q
8
+ end
9
+
10
+ get :show, '/account_emails/{id}'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class AliasEmails < Weary::Client
4
+ include Settings
5
+
6
+ get :show, '/alias_emails/{id}'
7
+
8
+ post :create, '/alias_emails' do |resource|
9
+ resource.required :account_email_id, :address
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class DepartmentEmails < Weary::Client
4
+ include Settings
5
+
6
+ get :show, '/department_emails/{id}'
7
+
8
+ post :create, '/department_emails' do |resource|
9
+ resource.required :address, :uuids, :first_name, :last_name
10
+ resource.optional :password, :department, :title, :privacy
11
+ end
12
+
13
+ put :update, '/department_emails/{id}' do |resource|
14
+ resource.optional :address, :uuids, :password, :first_name, :last_name, :department, :title, :privacy
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class DeprovisionSchedules < Weary::Client
4
+ include Settings
5
+
6
+ post :create, '/emails/{email_id}/deprovision_schedules' do |resource|
7
+ resource.required :action, :scheduled_for
8
+ resource.optional :reason
9
+ end
10
+
11
+ put :update, '/emails/{email_id}/deprovision_schedules/{id}' do |resource|
12
+ # There shouldn't be any reason to update a deprovision schedule other
13
+ # than to cancel it
14
+ resource.required :canceled
15
+ end
16
+
17
+ delete :destroy, '/emails/{email_id}/deprovision_schedules/{id}'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class Emails < Weary::Client
4
+ include Settings
5
+
6
+ get :index, '/emails' do |resource|
7
+ resource.optional :q, :state, :pending, :page, :per_page, :offset
8
+ end
9
+
10
+ get :show, '/emails/{id}'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class Exclusions < Weary::Client
4
+ include Settings
5
+
6
+ post :create, '/emails/{email_id}/exclusions' do |resource|
7
+ resource.required :creator_uuid, :starts_at
8
+ resource.optional :ends_at, :reason
9
+ end
10
+
11
+ delete :destroy, '/emails/{email_id}/exclusions/{id}'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ class PersonEmails < Weary::Client
4
+ include Settings
5
+
6
+ get :show, '/person_emails/{id}'
7
+
8
+ post :create, '/person_emails' do |resource|
9
+ resource.required :uuid, :address
10
+ end
11
+
12
+ put :update, '/person_emails/{id}' do |resource|
13
+ resource.required :address
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module GoogleSyncinator
2
+ module APIClient
3
+ module Settings
4
+ def self.included(base)
5
+ base.send :domain, GoogleSyncinatorAPIClient.config.base_url
6
+ base.send :adapter, Weary::Adapter::NetHttpAdvanced
7
+ base.send :use, Weary::Middleware::HMACAuth, [GoogleSyncinatorAPIClient.config.credentials]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ require 'weary'
2
+
3
+ module GoogleSyncinatorAPIClient
4
+ require 'google_syncinator_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 GoogleSyncinator
16
+ module APIClient
17
+ autoload :Settings, 'google_syncinator/api_client/settings'
18
+ autoload :DeprovisionSchedules, 'google_syncinator/api_client/deprovision_schedules'
19
+ autoload :AccountEmails, 'google_syncinator/api_client/account_emails'
20
+ autoload :AliasEmails, 'google_syncinator/api_client/alias_emails'
21
+ autoload :Emails, 'google_syncinator/api_client/emails'
22
+ autoload :PersonEmails, 'google_syncinator/api_client/person_emails'
23
+ autoload :DepartmentEmails, 'google_syncinator/api_client/department_emails'
24
+ autoload :Exclusions, 'google_syncinator/api_client/exclusions'
25
+ end
26
+ end
27
+
28
+ module Weary
29
+ module Middleware
30
+ autoload :HMACAuth, 'weary/middleware/hmac_auth'
31
+ end
32
+
33
+ module Adapter
34
+ autoload :NetHttpAdvanced, 'weary/adapters/net_http_advanced'
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'uri'
2
+
3
+ module GoogleSyncinatorAPIClient
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 :port
11
+ attr_accessor :script_name
12
+ attr_accessor :version
13
+
14
+ def initialize
15
+ @scheme = 'https'
16
+ @host = 'api.biola.edu'
17
+ @port = nil
18
+ @script_name = 'google-syncinator'
19
+ @version = 'v1'
20
+ end
21
+
22
+ def base_url
23
+ URI.join(root_url.to_s, "/#{script_name}/", version).to_s
24
+ end
25
+
26
+ def credentials
27
+ {access_id: access_id, secret_key: secret_key}
28
+ end
29
+
30
+ private
31
+
32
+ def root_url
33
+ URI::Generic.build(scheme: scheme, host: host, port: port)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module GoogleSyncinatorAPIClient
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,16 @@
1
+ module Weary
2
+ module Adapter
3
+ class NetHttpAdvanced < NetHttp
4
+ class << self
5
+ attr_accessor :timeout
6
+ end
7
+
8
+ def self.connect(request)
9
+ connection = socket(request)
10
+ connection.read_timeout = timeout unless timeout.nil?
11
+ response = connection.request prepare(request)
12
+ Rack::Response.new response.body || "", response.code, normalize_response(response.to_hash)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
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
+ elsif e['REQUEST_METHOD'] == 'GET' && e['CONTENT_TYPE'].to_s == ''
32
+ e.update 'CONTENT_TYPE' => 'text/plain'
33
+ end
34
+ end
35
+ end
36
+
37
+ def signed_request(env)
38
+ Rack::Request.new(env).tap do |r|
39
+ ApiAuth.sign! r, access_id, secret_key
40
+ end
41
+ end
42
+
43
+ def sign!(env)
44
+ req = signed_request(env)
45
+
46
+ env.tap do |e|
47
+ # Weary wants all headers to be in HTTP_[UPCASE] format for Rack env compatibility
48
+ e.update(
49
+ 'HTTP_AUTHORIZATION' => req.env['Authorization'],
50
+ 'HTTP_DATE' => req.env['DATE']
51
+ )
52
+
53
+ if md5 = req.env['Content-MD5']
54
+ e.update 'HTTP_CONTENT_MD5' => md5
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_syncinator_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Biola University
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-21 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: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.4'
125
+ description: API consuming models for the GoogleSyncinator project
126
+ email: appsupport@biola.edu
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - MIT-LICENSE
132
+ - README.md
133
+ - lib/google_syncinator/api_client/account_emails.rb
134
+ - lib/google_syncinator/api_client/alias_emails.rb
135
+ - lib/google_syncinator/api_client/department_emails.rb
136
+ - lib/google_syncinator/api_client/deprovision_schedules.rb
137
+ - lib/google_syncinator/api_client/emails.rb
138
+ - lib/google_syncinator/api_client/exclusions.rb
139
+ - lib/google_syncinator/api_client/person_emails.rb
140
+ - lib/google_syncinator/api_client/settings.rb
141
+ - lib/google_syncinator_api_client.rb
142
+ - lib/google_syncinator_api_client/configuration.rb
143
+ - lib/google_syncinator_api_client/version.rb
144
+ - lib/weary/adapters/net_http_advanced.rb
145
+ - lib/weary/middleware/hmac_auth.rb
146
+ homepage: https://github.com/biola/google-syncinator-api-client
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.2.2
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Client for the GoogleSyncinator API
170
+ test_files: []
171
+ has_rdoc: