buweb_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: 2af5fcbeeb57b207ede3c883aeb56dd60e44a3e9
4
+ data.tar.gz: c251217e972003da03fb1621f2c2b1b0a2cba234
5
+ SHA512:
6
+ metadata.gz: 28b34086f53040e91ebcac82895209103fa9a09b464ca34c72d4fc4d16ecbac7e9bd7c5a9b3567eac8235e7874a64a893b18685299ae7ff08b8f39665b81339b
7
+ data.tar.gz: 2c236feec572c2cf8d5e2a6df61183bd7871e7236391a8928dbbfde998a984d8c8eab49b552709f56ea6b47169fc13dfe8a6ec2f672145fb3a359b7f85dede6a
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
+ BU Web API Client [![Build Status](https://travis-ci.org/biola/buweb-api-client.svg?branch=master)](https://travis-ci.org/biola/buweb-api-client)
2
+ ==================
3
+
4
+ Installing
5
+ ----------
6
+
7
+ Add `gem 'buweb_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,14 @@
1
+ module BUWeb
2
+ module APIClient
3
+ class Departments < Weary::Client
4
+ domain BUWebAPIClient.config.base_url
5
+ use Weary::Middleware::HMACAuth, [BUWebAPIClient.config.credentials]
6
+
7
+ get :index, '/departments/' do |resource|
8
+ resource.optional :location
9
+ end
10
+
11
+ get :show, '/departments/{id}'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module BUWeb
2
+ module APIClient
3
+ class People < Weary::Client
4
+ domain BUWebAPIClient.config.base_url
5
+ # use Weary::Middleware::ContentType
6
+ use Weary::Middleware::HMACAuth, [BUWebAPIClient.config.credentials]
7
+
8
+ get :index, '/people' do |resource|
9
+ resource.optional :affiliation
10
+ end
11
+
12
+ get :by_id, '/people/{id}' do |resource|
13
+ resource.optional :type
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ require 'uri'
2
+
3
+ module BUWebAPIClient
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 = 'web'
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 BUWebAPIClient
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'weary'
2
+
3
+ module BUWebAPIClient
4
+ require 'buweb_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 BUWeb
16
+ module APIClient
17
+ autoload :People, 'buweb/api_client/people'
18
+ autoload :Departments, 'buweb/api_client/departments'
19
+ end
20
+ end
21
+
22
+ module Weary
23
+ module Middleware
24
+ autoload :HMACAuth, 'weary/middleware/hmac_auth'
25
+ end
26
+ 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,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buweb_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Devin Hanlon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-23 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: biola_web_api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.17'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.17'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faker
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
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 Biola Web API project
140
+ email: devin.hanlon@biola.edu
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - MIT-LICENSE
146
+ - README.md
147
+ - lib/buweb/api_client/departments.rb
148
+ - lib/buweb/api_client/people.rb
149
+ - lib/buweb_api_client.rb
150
+ - lib/buweb_api_client/configuration.rb
151
+ - lib/buweb_api_client/version.rb
152
+ - lib/weary/middleware/hmac_auth.rb
153
+ homepage: https://github.com/biola/buweb-api-client
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.2.2
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Client for the Biola Web API
177
+ test_files: []