g5_authentication_client 0.2.1 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9da8c28deb98850c7e6b1174c64163c2dc694104
4
- data.tar.gz: b8530a5eb42cab81dc1ceb2c3cc32a6010f56115
3
+ metadata.gz: 631343ac9b439ce2f1e1cbad1e8fa52999ff30ad
4
+ data.tar.gz: 903d0901198ef0057473475b33eeb74a13b61317
5
5
  SHA512:
6
- metadata.gz: d3a70a125ba261f7580db5ba0873c21a3b6c9b12857b80908ee45ed5a6b1324a610261056c3dfb57eb6752ae34597b73bd7a641ffbf23a6ed94d60ec8082c7ad
7
- data.tar.gz: 0a5f34d64d22f3194ad5e7b9ec90383c15e305e3c3668125360929b118aa70b2245f667b6561dc54a80dc710b146d92f69461fbd59a1e0432661d91b5ad0e256
6
+ metadata.gz: 08bb76c84e52b228ff9790d83dc7282869e7128a72ecd855a97255a396ac8cdf241866dd9a5b194e0d96a7fed589f71eba8cc42ed74faaae35babf8eb90888c8
7
+ data.tar.gz: 8ab1e14d06f37eb166c15d05b921d8b8be1bb2bfe60dc1a239ae45b035c732f5c8961f0db63c3b6cb77b9abc437d1832df17b56dae10aeac59ca3f2d9bd44eec
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## v0.2.3 (2014-07-31)
2
+ * remove id from body in create/update user
3
+
1
4
  ## v0.2.0 (2014-03-10)
2
5
 
3
6
  * First open source release to [RubyGems](http://rubygems.org/)
@@ -98,7 +98,7 @@ module G5AuthenticationClient
98
98
  def create_user(options={})
99
99
  user=User.new(options)
100
100
  user.validate_for_create!
101
- response=oauth_access_token.post('/v1/users', params: {user: user.to_hash})
101
+ response=oauth_access_token.post('/v1/users', body: user_hash(user.to_hash))
102
102
  User.new(response.parsed)
103
103
  end
104
104
 
@@ -111,10 +111,22 @@ module G5AuthenticationClient
111
111
  def update_user(options={})
112
112
  user=User.new(options)
113
113
  user.validate!
114
- response=oauth_access_token.put("/v1/users/#{user.id}", params: {user: user.to_hash})
114
+ response=oauth_access_token.put("/v1/users/#{user.id}", body: user_hash(user.to_hash))
115
115
  User.new(response.parsed)
116
116
  end
117
117
 
118
+ # Find a user by email
119
+ # @param [String] email address
120
+ # @return [G5AuthenticationClient::User]
121
+ def find_user_by_email(email)
122
+ response = oauth_access_token.get('/v1/users', params: { email: email })
123
+ user = response.parsed.first
124
+ if user
125
+ user=User.new(user)
126
+ end
127
+ user
128
+ end
129
+
118
130
  # Get a user
119
131
  # @param [Integer] id the user ID in the remote service
120
132
  # @return [G5AuthenticationClient::User]
@@ -158,6 +170,11 @@ module G5AuthenticationClient
158
170
  end
159
171
 
160
172
  private
173
+
174
+ def user_hash(h)
175
+ { user: h.reject{ |k,v| k == 'id' } }
176
+ end
177
+
161
178
  def oauth_client
162
179
  OAuth2::Client.new(client_id, client_secret, site: endpoint)
163
180
  end
@@ -54,5 +54,6 @@ module G5AuthenticationClient
54
54
  validate!
55
55
  raise ArgumentError.new("Password required for new user.") unless !password.nil?
56
56
  end
57
+
57
58
  end
58
59
  end
@@ -1,3 +1,3 @@
1
1
  module G5AuthenticationClient
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -45,6 +45,19 @@ describe G5AuthenticationClient::Client do
45
45
  id: user_id}
46
46
  end
47
47
 
48
+ let(:new_user_request) do
49
+ {
50
+ "email"=>email,
51
+ "first_name"=>"",
52
+ "last_name"=>"",
53
+ "organization_name"=>"",
54
+ "password"=>"#{password}x",
55
+ "password_confirmation"=>"",
56
+ "phone_number"=>"",
57
+ "title"=>""
58
+ }
59
+ end
60
+
48
61
  let(:email){'foo@blah.com'}
49
62
  let(:password){'mybigtestpasswored'}
50
63
  let(:user_id){1}
@@ -273,8 +286,8 @@ describe G5AuthenticationClient::Client do
273
286
  subject(:create_user) { client.create_user(new_user_options) }
274
287
 
275
288
  before do
276
- stub_request(:post, /#{endpoint}\/v1\/users/).
277
- with(headers: {'Authorization' => auth_header_value}).
289
+ stub_request(:post, "#{endpoint}/v1/users").
290
+ with(:body => {"user"=>new_user_request}, headers: {'Authorization' => auth_header_value}).
278
291
  to_return(status: 200,
279
292
  body: returned_user.to_json,
280
293
  headers: {'Content-Type' => 'application/json'})
@@ -288,7 +301,7 @@ describe G5AuthenticationClient::Client do
288
301
 
289
302
  before do
290
303
  stub_request(:put, /#{endpoint}\/v1\/users\/#{user_id}/).
291
- with(headers: {'Authorization' => auth_header_value}).
304
+ with(:body => { "user" => new_user_request }, headers: {'Authorization' => auth_header_value}).
292
305
  to_return(status: 200,
293
306
  body: returned_user.to_json,
294
307
  headers: {'Content-Type' => 'application/json'})
@@ -297,6 +310,30 @@ describe G5AuthenticationClient::Client do
297
310
  it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::User
298
311
  end
299
312
 
313
+ describe '#find_user_by_email' do
314
+ subject(:find_user_by_email) { client.find_user_by_email(email) }
315
+
316
+ let(:response_body) { [returned_user].to_json}
317
+
318
+ before do
319
+ stub_request(:get, /#{endpoint}\/v1\/users/).
320
+ with(query: {'email' => email}, headers: {'Authorization' => auth_header_value}).
321
+ to_return(status: 200,
322
+ body: response_body,
323
+ headers: {'Content-Type' => 'application/json'})
324
+ end
325
+
326
+ context 'when there is no user' do
327
+ let(:response_body) { [].to_json }
328
+
329
+ it 'should return nil' do
330
+ expect(find_user_by_email).to be_nil
331
+ end
332
+ end
333
+
334
+ it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::User
335
+ end
336
+
300
337
  describe '#get_user' do
301
338
  subject(:get_user) { client.get_user(user_id) }
302
339
 
@@ -181,4 +181,36 @@ describe G5AuthenticationClient::User do
181
181
  end
182
182
  end
183
183
  end
184
+
185
+ describe '#to_hash' do
186
+ subject(:to_hash) { user.to_hash }
187
+
188
+ it 'should have a first name' do
189
+ expect(to_hash['first_name']).to eq(first_name)
190
+ end
191
+
192
+ it 'should have a last name' do
193
+ expect(to_hash['last_name']).to eq(last_name)
194
+ end
195
+
196
+ it 'should have an email' do
197
+ expect(to_hash['email']).to eq(email)
198
+ end
199
+
200
+ it 'should have a title ' do
201
+ expect(to_hash['title']).to eq(title)
202
+ end
203
+
204
+ it 'should have an organization name' do
205
+ expect(to_hash['organization_name']).to eq(organization_name)
206
+ end
207
+
208
+ it 'should have an phone_number' do
209
+ expect(to_hash['phone_number']).to eq(phone_number)
210
+ end
211
+
212
+ it 'should have an id' do
213
+ expect(to_hash['id']).to eq(id)
214
+ end
215
+ end
184
216
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g5_authentication_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Revels
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-08 00:00:00.000000000 Z
12
+ date: 2014-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: modelish
@@ -203,7 +203,6 @@ extra_rdoc_files: []
203
203
  files:
204
204
  - ".gitignore"
205
205
  - ".rspec"
206
- - ".ruby-gemset"
207
206
  - ".ruby-version"
208
207
  - CHANGELOG.md
209
208
  - Gemfile
@@ -244,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
243
  version: '0'
245
244
  requirements: []
246
245
  rubyforge_project: g5_authentication_client
247
- rubygems_version: 2.1.11
246
+ rubygems_version: 2.2.2
248
247
  signing_key:
249
248
  specification_version: 4
250
249
  summary: Client for the G5 Auth service
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- g5_authentication_client