restpack_user_service 0.0.4 → 0.0.5

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: 0fdd6e9e5ea385023ee95d8ca4fe6374255a4b20
4
- data.tar.gz: dde09dfcf8e9b9e76673aeb8e984c17d5ee0a462
3
+ metadata.gz: c0c271281a82e716ca91f3f90867b30ddd94d30a
4
+ data.tar.gz: 0c129e97bebd4f6552aec4fdb2b9f4fb26fc3d10
5
5
  SHA512:
6
- metadata.gz: 950120dce2af643bd5ec69d923d08edcbd20e9e74c255dbf78b1e9bb27aab07a92ea8a2fb154170585e6e129ce8d283e89a015422f5fee825f3c60323dc52462
7
- data.tar.gz: 1f1462758a45abe54380a2abebc7033f4cf62e2944b712c2c24a39e4ca5383497d81372c6bcef867e6d29c1408355a4cdc131e36edec3421487f1569c01f9c4d
6
+ metadata.gz: 27c4036f51ca0c80f49252a0946332f45180777534a7a0ec770cc4dc8bdda331ba082da76cb713d1f6a848bb7dc6192a5ffdb3018a18340d0380c9e5bad40309
7
+ data.tar.gz: 92e5baf3af87b2beb187c22212b5cd30ca43932cd9137b46ce1eac9bce93a376b4b41680fcbedb8b053e844bd9dff8a682ef239d9add77ac9bb8f1cded21245d
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in restpack_user_service.gemspec
4
3
  gemspec
@@ -1,6 +1,6 @@
1
1
  class CreateUsers < ActiveRecord::Migration
2
2
  def change
3
- create_table :restpack_users do |t|
3
+ create_table :restpack_user_users do |t|
4
4
  t.string :name, :limit => 128
5
5
  t.string :nickname, :limit => 128
6
6
  t.string :email, :limit => 512
@@ -1,6 +1,6 @@
1
1
  class CreateAuthentications < ActiveRecord::Migration
2
2
  def change
3
- create_table :restpack_authentications do |t|
3
+ create_table :restpack_user_authentications do |t|
4
4
  t.string :provider, :limit => 128, :null => false
5
5
  t.string :uid, :limit => 1024, :null => false
6
6
  t.json :omniauth, :null => false
@@ -1,2 +1,2 @@
1
1
  require 'restpack_service'
2
- RestPack::Service::Loader.load 'user', Dir.pwd
2
+ RestPack::Service::Loader.load 'restpack_user_service', 'Users'
@@ -1,25 +1,8 @@
1
- module RestPack::User::Service::Commands
2
- module User
3
- class Get < RestPack::Service::Command
4
- required do
5
- integer :id
6
- integer :application_id
7
- end
8
-
9
- def execute
10
- #TODO: GJ: remove the :application_id scope when we can specify custom serializer filters
11
- # https://github.com/RestPack/restpack_serializer/issues/42
12
- result = Serializers::User.resource(
13
- inputs,
14
- Models::User.where(application_id: inputs[:application_id])
15
- )
16
-
17
- if result[:users].empty?
18
- status :not_found
19
- else
20
- result
21
- end
22
- end
1
+ module Commands::Users::User
2
+ class Get < RestPack::Service::Commands::Get
3
+ required do
4
+ integer :id
5
+ integer :application_id
23
6
  end
24
7
  end
25
8
  end
@@ -0,0 +1,15 @@
1
+ module Commands::Users::User
2
+ class List < RestPack::Service::Commands::List
3
+ required do
4
+ integer :application_id
5
+ end
6
+
7
+ optional do
8
+ integer :account_id
9
+ string :email
10
+ string :include
11
+ integer :page
12
+ integer :page_size
13
+ end
14
+ end
15
+ end
@@ -1,34 +1,48 @@
1
- module RestPack::User::Service::Commands
2
- module User
3
- class OmniAuthenticate < RestPack::Service::Command
4
- required do
5
- integer :application_id
6
- hash :omniauth_response do
7
- required do
8
- string :provider
9
- string :uid
10
- hash :info
11
- end
1
+ require 'restpack_service_messaging'
2
+
3
+ module Commands::Users::User
4
+ class OmniAuthenticate < RestPack::Service::Command
5
+ required do
6
+ integer :application_id
7
+ hash :omniauth_response do
8
+ required do
9
+ string :provider
10
+ string :uid
11
+ hash :info
12
12
  end
13
13
  end
14
+ end
14
15
 
15
- optional do
16
- integer :user_id
17
- end
16
+ optional do
17
+ integer :user_id
18
+ end
18
19
 
19
- def execute
20
- user = Models::User.authenticate(
21
- user_id,
22
- application_id,
23
- raw_inputs[:omniauth_response]
24
- )
20
+ def execute
21
+ user = Models::Users::User.authenticate(
22
+ user_id,
23
+ application_id,
24
+ raw_inputs[:omniauth_response]
25
+ )
25
26
 
26
- if user
27
- return Serializers::User.resource(user)
28
- else
29
- status :unauthorized
30
- end
27
+ if user
28
+ record_activity(user, inputs)
29
+ return Serializers::Users::User.resource(user)
30
+ else
31
+ status :unauthorized
31
32
  end
32
33
  end
34
+
35
+ private
36
+
37
+ def record_activity(user, inputs)
38
+ provider = inputs[:omniauth_response][:provider]
39
+ type = 'login' #TODO: GJ: differentiate between login and signup
40
+ Messaging::Activity::Create.run({
41
+ application_id: inputs[:application_id],
42
+ user_id: user.id,
43
+ content: "#{user.name} logged in via #{inputs[:omniauth_response][:provider]}",
44
+ tags: "service:users,auth:#{type},provider:#{provider}"
45
+ })
46
+ end
33
47
  end
34
48
  end
@@ -1,7 +1,6 @@
1
-
2
- module RestPack::User::Service::Models
1
+ module Models::Users
3
2
  class Authentication < ActiveRecord::Base
4
- self.table_name = :restpack_authentications
3
+ self.table_name = :restpack_user_authentications
5
4
 
6
5
  attr_accessible :application_id, :oauth, :provider, :uid, :user_id, :omniauth
7
6
  serialize :oauth, JSON
@@ -1,6 +1,6 @@
1
- module RestPack::User::Service::Models
1
+ module Models::Users
2
2
  class User < ActiveRecord::Base
3
- self.table_name = :restpack_users
3
+ self.table_name = :restpack_user_users
4
4
  attr_accessible :application_id, :description, :email, :image, :location, :name, :nickname
5
5
 
6
6
  validates_presence_of :application_id
@@ -0,0 +1,11 @@
1
+ module Serializers::Users
2
+ class Authentication
3
+ include RestPack::Serializer
4
+
5
+ self.model_class = Models::Users::Authentication
6
+ self.key = :authentications
7
+
8
+ attributes :id, :provider, :uid
9
+ can_include :user
10
+ end
11
+ end
@@ -1,12 +1,14 @@
1
- module RestPack::User::Service::Serializers
1
+ module Serializers::Users
2
2
  class User
3
3
  include RestPack::Serializer
4
4
 
5
- self.model_class = Models::User
5
+ self.model_class = Models::Users::User
6
6
  self.key = :users
7
7
 
8
8
  attributes :id, :application_id, :description, :email,
9
9
  :image, :avatar, :location, :name, :nickname, :href
10
+ can_include :authentications
11
+ can_filter_by :application_id
10
12
 
11
13
  def avatar
12
14
  image || "http://robohash.org/#{id}.png?size=200x200"
@@ -1,7 +1,7 @@
1
1
  module RestPack
2
2
  module User
3
3
  module Service
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
6
6
  end
7
7
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "restpack_service"
22
+ spec.add_dependency "restpack_service_messaging"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.3"
24
25
  spec.add_development_dependency "database_cleaner", "~> 1.0.1"
@@ -1,6 +1,6 @@
1
- require_relative '../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Commands::User::Get do
3
+ describe Commands::Users::User::Get do
4
4
  is_required :id, :application_id
5
5
 
6
6
  let(:response) { subject.class.run(params) }
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commands::Users::User::List do
4
+ is_required :application_id
5
+ is_optional :account_id, :email, :include, :page, :page_size
6
+
7
+ pending
8
+ end
@@ -1,11 +1,11 @@
1
- require_relative '../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe Commands::User::OmniAuthenticate do
3
+ describe Commands::Users::User::OmniAuthenticate do
4
4
  is_required :application_id, :omniauth_response
5
5
  is_optional :user_id
6
6
 
7
- User = Models::User
8
- Authentication = Models::Authentication
7
+ User = Models::Users::User
8
+ Authentication = Models::Users::Authentication
9
9
 
10
10
  let(:response) { subject.class.run(params) }
11
11
 
@@ -23,7 +23,7 @@ describe Commands::User::OmniAuthenticate do
23
23
  context 'existing authentication' do
24
24
  it 'returns the existing user' do
25
25
  response.success?.should == true
26
- response.result.should == Serializers::User.resource(@authentication.user)
26
+ response.result.should == Serializers::Users::User.resource(@authentication.user)
27
27
  end
28
28
  end
29
29
 
@@ -35,7 +35,7 @@ describe Commands::User::OmniAuthenticate do
35
35
 
36
36
  it 'returns the existing user' do
37
37
  response.success?.should == true
38
- response.result.should == Serializers::User.resource(@authentication.user)
38
+ response.result.should == Serializers::Users::User.resource(@authentication.user)
39
39
  @authentication.user.authentications.length.should == 2
40
40
  end
41
41
  end
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
- factory :authentication, :class => Models::Authentication do
2
+ factory :authentication, :class => Models::Users::Authentication do
3
3
  user
4
4
  application_id { user.application_id }
5
5
  provider 'twitter'
@@ -1,5 +1,5 @@
1
1
  FactoryGirl.define do
2
- factory :user, :class => Models::User do
2
+ factory :user, :class => Models::Users::User do
3
3
  sequence(:application_id)
4
4
  sequence(:description) {|n| "Description ##{n}" }
5
5
  sequence(:email) {|n| "email ##{n}" }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Models::Authentication do
3
+ describe Models::Users::Authentication do
4
4
  it { should validate_presence_of(:application_id) }
5
5
  it { should validate_presence_of(:omniauth) }
6
6
  it { should validate_presence_of(:provider) }
@@ -11,7 +11,6 @@ describe Models::Authentication do
11
11
  it { should ensure_length_of(:uid).is_at_most(1024) }
12
12
 
13
13
  it { should belong_to(:user) }
14
- it { subject.class.table_name.should == 'restpack_authentications' }
15
14
 
16
15
  let(:application_id) { 123 }
17
16
  let(:omniauth) { {
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Models::User do
3
+ describe Models::Users::User do
4
4
  it { should validate_presence_of(:application_id) }
5
5
  it { should ensure_length_of(:name).is_at_most(128) }
6
6
  it { should ensure_length_of(:nickname).is_at_most(128) }
@@ -8,7 +8,6 @@ describe Models::User do
8
8
  it { should ensure_length_of(:image).is_at_most(1024) }
9
9
  it { should ensure_length_of(:location).is_at_most(512) }
10
10
  it { should ensure_length_of(:description).is_at_most(1024) }
11
- it { subject.class.table_name.should == 'restpack_users' }
12
11
 
13
12
  describe "#authenticate" do
14
13
  pending
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_user_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-21 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: restpack_service
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: restpack_service_messaging
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -137,20 +151,23 @@ files:
137
151
  - README.md
138
152
  - Rakefile
139
153
  - config/database.yml
140
- - db/migrate/20130807130942_create_users.rb
141
- - db/migrate/20130807130949_create_authentications.rb
154
+ - db/migrate/20130807130943_create_users.rb
155
+ - db/migrate/20130807130950_create_authentications.rb
142
156
  - lib/restpack_user_service.rb
143
157
  - lib/restpack_user_service/commands/user/get.rb
158
+ - lib/restpack_user_service/commands/user/list.rb
144
159
  - lib/restpack_user_service/commands/user/omni_authenticate.rb
145
160
  - lib/restpack_user_service/configuration.rb
146
161
  - lib/restpack_user_service/models/authentication.rb
147
162
  - lib/restpack_user_service/models/user.rb
163
+ - lib/restpack_user_service/serializers/authentication.rb
148
164
  - lib/restpack_user_service/serializers/user.rb
149
165
  - lib/restpack_user_service/tasks/db.rake
150
166
  - lib/restpack_user_service/tasks/tasks.rb
151
167
  - lib/restpack_user_service/version.rb
152
168
  - restpack_user_service.gemspec
153
169
  - spec/commands/user/get_spec.rb
170
+ - spec/commands/user/list_spec.rb
154
171
  - spec/commands/user/omni_authenticate_spec.rb
155
172
  - spec/factories/authentication_factory.rb
156
173
  - spec/factories/user_factory.rb
@@ -177,12 +194,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
194
  version: '0'
178
195
  requirements: []
179
196
  rubyforge_project:
180
- rubygems_version: 2.0.5
197
+ rubygems_version: 2.0.7
181
198
  signing_key:
182
199
  specification_version: 4
183
200
  summary: Users and Authentications
184
201
  test_files:
185
202
  - spec/commands/user/get_spec.rb
203
+ - spec/commands/user/list_spec.rb
186
204
  - spec/commands/user/omni_authenticate_spec.rb
187
205
  - spec/factories/authentication_factory.rb
188
206
  - spec/factories/user_factory.rb