restpack_activity_service 0.0.12 → 0.0.13
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 +4 -4
- data/db/migrate/{20130630145408_create_activity_table.rb → 20130630145409_create_activity_table.rb} +1 -1
- data/lib/restpack_activity_service.rb +1 -1
- data/lib/restpack_activity_service/commands/activity/create.rb +25 -32
- data/lib/restpack_activity_service/commands/activity/destroy.rb +16 -18
- data/lib/restpack_activity_service/commands/activity/get.rb +5 -20
- data/lib/restpack_activity_service/commands/activity/list.rb +21 -23
- data/lib/restpack_activity_service/commands/activity/update.rb +26 -28
- data/lib/restpack_activity_service/jobs/activity/create.rb +15 -0
- data/lib/restpack_activity_service/models/activity.rb +5 -2
- data/lib/restpack_activity_service/serializers/activity.rb +2 -2
- data/lib/restpack_activity_service/version.rb +1 -1
- data/spec/factories/activity_factory.rb +6 -17
- data/spec/factories/api_activity_factory.rb +10 -0
- data/spec/services/create_spec.rb +4 -2
- data/spec/services/destroy_spec.rb +4 -4
- data/spec/services/get_spec.rb +4 -4
- data/spec/services/list_spec.rb +12 -12
- data/spec/spec_helper.rb +4 -2
- metadata +6 -4
- data/lib/restpack_activity_service/services.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d6a465f44d89c820a690574414c948640888cce
|
4
|
+
data.tar.gz: 5e3e1b20e053755f267fbb0db17d6f287995f622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0fad183aa52e01eeaad4f8bc2fe915f8742d95ba80f974dc2a6056a8aa9e0728f1c2c8ae5764f15a83ba6ea9a2a6d3dac05f49ad575433af6a84f8537abd412
|
7
|
+
data.tar.gz: 5c971b677f18023bfd64121df732e250c1f8997018f7cdf51a7aba97da575c8b0e5d9ab74f85ffb26525e271196452ab9d2fbc0f4214984e9861b13e092eb614
|
@@ -1,41 +1,34 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
optional do
|
11
|
-
string :title, empty: true
|
12
|
-
string :tags, empty: true
|
13
|
-
string :access, empty: true
|
14
|
-
float :latitude
|
15
|
-
float :longitude
|
16
|
-
end
|
17
|
-
|
18
|
-
def init
|
19
|
-
inputs[:data] = raw_inputs[:data] if raw_inputs[:data]
|
1
|
+
module Commands::Activities::Activity
|
2
|
+
class Create < RestPack::Service::Commands::SingleCreate
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
integer :user_id
|
6
|
+
string :content
|
7
|
+
end
|
20
8
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
9
|
+
optional do
|
10
|
+
string :title, empty: true
|
11
|
+
string :tags, empty: true
|
12
|
+
string :access, empty: true
|
13
|
+
float :latitude
|
14
|
+
float :longitude
|
15
|
+
model :data, class: Hash
|
16
|
+
end
|
26
17
|
|
27
|
-
|
28
|
-
|
18
|
+
def init
|
19
|
+
if latitude.present? || longitude.present?
|
20
|
+
if latitude.present? != longitude.present?
|
21
|
+
service_error "Both Latitude and Longitude are required"
|
29
22
|
end
|
23
|
+
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
#TEMP: GJ: some example service errors
|
26
|
+
if title == "error"
|
27
|
+
service_error "This is a service error"
|
34
28
|
end
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
Serializers::Activity.as_json(activity)
|
30
|
+
if title == "custom"
|
31
|
+
field_error :title, "Title should not be 'custom'"
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
@@ -1,23 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module Commands::Activities::Activity
|
2
|
+
class Destroy < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :id
|
5
|
+
integer :application_id
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def execute
|
9
|
+
activity = Models::Activities::Activity.find_by_id_and_application_id(
|
10
|
+
inputs[:id],
|
11
|
+
inputs[:application_id]
|
12
|
+
)
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
14
|
+
if activity
|
15
|
+
activity.destroy
|
16
|
+
nil
|
17
|
+
else
|
18
|
+
status :not_found
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
@@ -1,23 +1,8 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
integer :application_id
|
7
|
-
end
|
8
|
-
|
9
|
-
def execute
|
10
|
-
activity = Models::Activity.find_by_id_and_application_id(
|
11
|
-
inputs[:id],
|
12
|
-
inputs[:application_id]
|
13
|
-
)
|
14
|
-
|
15
|
-
if activity
|
16
|
-
Serializers::Activity.as_json(activity)
|
17
|
-
else
|
18
|
-
status :not_found
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module Commands::Activities::Activity
|
2
|
+
class Get < RestPack::Service::Commands::Get
|
3
|
+
required do
|
4
|
+
integer :id
|
5
|
+
integer :application_id
|
21
6
|
end
|
22
7
|
end
|
23
8
|
end
|
@@ -1,30 +1,28 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
module Commands::Activities::Activity
|
2
|
+
class List < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :application_id
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
optional do
|
8
|
+
integer :user_id
|
9
|
+
integer :page
|
10
|
+
integer :page_size
|
11
|
+
string :tags
|
12
|
+
string :access
|
13
|
+
string :query
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def execute
|
17
|
+
scope = Models::Activities::Activity.all
|
18
|
+
scope = scope.where(application_id: application_id)
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
scope = scope.where(user_id: user_id) if user_id
|
21
|
+
scope = scope.all_tags_csv(tags) if tags
|
22
|
+
scope = scope.any_tags_csv(access, :access) if access
|
23
|
+
scope = scope.search(query) if query
|
25
24
|
|
26
|
-
|
27
|
-
end
|
25
|
+
Serializers::Activities::Activity.resource(inputs, scope)
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -1,35 +1,33 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module Commands::Activities::Activity
|
2
|
+
class Update < RestPack::Service::Command
|
3
|
+
required do
|
4
|
+
integer :id
|
5
|
+
integer :application_id
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
optional do
|
9
|
+
string :title, empty: true
|
10
|
+
string :content
|
11
|
+
string :tags, empty: true
|
12
|
+
string :access, empty: true
|
13
|
+
float :latitude
|
14
|
+
float :longitude
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def init
|
18
|
+
inputs[:data] = raw_inputs[:data] if raw_inputs[:data]
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def execute
|
22
|
+
activity = Models::Activities::Activity.find_by_id_and_application_id(
|
23
|
+
inputs[:id], inputs[:application_id]
|
24
|
+
)
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
26
|
+
if activity
|
27
|
+
activity.update_attributes(inputs)
|
28
|
+
Serializers::Activities::Activity.as_json(activity)
|
29
|
+
else
|
30
|
+
status :not_found
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -1,6 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module Models::Activities
|
2
2
|
class Activity < ActiveRecord::Base
|
3
|
-
self.table_name = :
|
3
|
+
self.table_name = :restpack_activity_activities
|
4
|
+
|
5
|
+
attr_accessible :application_id, :user_id, :title, :content,
|
6
|
+
:latitude, :longitude, :data, :tags, :access
|
4
7
|
|
5
8
|
def self.search(query)
|
6
9
|
conditions = <<-EOS
|
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
1
|
+
module Serializers::Activities
|
2
2
|
class Activity
|
3
3
|
include RestPack::Serializer
|
4
4
|
|
5
|
-
self.model_class = Models::Activity
|
5
|
+
self.model_class = Models::Activities::Activity
|
6
6
|
self.key = :activities
|
7
7
|
|
8
8
|
attributes :id, :application_id, :user_id, :title, :content, :latitude, :longitude,
|
@@ -1,19 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
})
|
8
|
-
|
9
|
-
Commands::Activity::Create.run!(params)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def self.sequence
|
15
|
-
@@sequence ||= 0
|
16
|
-
@@sequence += 1
|
17
|
-
@@sequence
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :activity, :class => Models::Activities::Activity do
|
3
|
+
sequence(:application_id)
|
4
|
+
sequence(:user_id)
|
5
|
+
sequence(:title) {|n| "Title ##{n}" }
|
6
|
+
sequence(:content) {|n| "Content ##{n}" }
|
18
7
|
end
|
19
8
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Commands::Activities::Activity::Create do
|
4
|
+
it_acts_as_single_create_command(:activities, :activity)
|
2
5
|
|
3
|
-
describe Commands::Activity::Create do
|
4
6
|
is_required :application_id, :user_id, :content
|
5
7
|
is_optional :title, :tags, :access, :latitude, :longitude
|
6
8
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Commands::Activity::Destroy do
|
3
|
+
describe Commands::Activities::Activity::Destroy do
|
4
4
|
is_required :id, :application_id
|
5
5
|
|
6
6
|
let(:response) { subject.class.run(params) }
|
7
7
|
let(:params) { {} }
|
8
8
|
|
9
9
|
before do
|
10
|
-
@activity =
|
10
|
+
@activity = create(:activity, application_id: 100, title: 'test activity' )
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'with valid params' do
|
@@ -19,7 +19,7 @@ describe Commands::Activity::Destroy do
|
|
19
19
|
it 'deletes the activity' do
|
20
20
|
response.success?.should == true
|
21
21
|
response.result.should == {}
|
22
|
-
Commands::Activity::Get.run(params).status.should == :not_found
|
22
|
+
Commands::Activities::Activity::Get.run(params).status.should == :not_found
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/spec/services/get_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Commands::Activity::Get do
|
3
|
+
describe Commands::Activities::Activity::Get do
|
4
4
|
is_required :id, :application_id
|
5
5
|
|
6
6
|
let(:response) { subject.class.run(params) }
|
7
7
|
let(:params) { {} }
|
8
8
|
|
9
9
|
before do
|
10
|
-
@activity =
|
10
|
+
@activity = create(:activity)
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'with valid params' do
|
@@ -18,7 +18,7 @@ describe Commands::Activity::Get do
|
|
18
18
|
|
19
19
|
it 'returns the correct activity' do
|
20
20
|
response.success?.should == true
|
21
|
-
response.result.should == @activity
|
21
|
+
response.result.should == Serializers::Activities::Activity.resource(@activity)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/spec/services/list_spec.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Commands::Activity::List do
|
3
|
+
describe Commands::Activities::Activity::List do
|
4
4
|
is_required :application_id
|
5
5
|
is_optional :user_id, :page, :page_size, :tags, :access, :query
|
6
6
|
|
7
7
|
before do
|
8
|
-
|
8
|
+
create(:activity,
|
9
9
|
application_id: 100, user_id: 200, title: 'Achievement Unlocked 1',
|
10
10
|
content: 'Three in a row! You have unlocked the "three-in-a-row" achievement.',
|
11
11
|
tags: 'achievement,three in a row',
|
12
12
|
access: 'user:100,group:300'
|
13
|
-
|
13
|
+
)
|
14
14
|
|
15
|
-
|
15
|
+
create(:activity,
|
16
16
|
application_id: 100, user_id: 200, title: 'Achievement Unlocked 2',
|
17
17
|
content: 'Five in a row! You have unlocked the "five-in-a-row" achievement.',
|
18
18
|
tags: 'achievement,five in a row',
|
19
19
|
access: 'user:100,group:300'
|
20
|
-
|
20
|
+
)
|
21
21
|
|
22
|
-
|
22
|
+
create(:activity,
|
23
23
|
application_id: 100, user_id: 200, title: '3 Photos Uploaded',
|
24
24
|
content: '3 photos have been uploaded',
|
25
25
|
tags: 'photos',
|
@@ -27,16 +27,16 @@ describe Commands::Activity::List do
|
|
27
27
|
data: {
|
28
28
|
photos: ['1.png', '2.png', '3.png']
|
29
29
|
}
|
30
|
-
|
30
|
+
)
|
31
31
|
|
32
|
-
|
32
|
+
create(:activity,
|
33
33
|
application_id: 100, user_id: 200, title: 'Check In: Eatery120',
|
34
34
|
content: 'You checked in to Eatery 130, Ranelagh, Dublin 6',
|
35
35
|
tags: 'checkin,eatery120,ranelagh,dublin',
|
36
36
|
access: 'user:100,public',
|
37
37
|
latitude: 53.324577,
|
38
38
|
longitude: -6.254193
|
39
|
-
|
39
|
+
)
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'listing activities' do
|
@@ -46,7 +46,7 @@ describe Commands::Activity::List do
|
|
46
46
|
context 'valid' do
|
47
47
|
let(:params) { { application_id: 100 } }
|
48
48
|
it 'retuns activities' do
|
49
|
-
response.result[:meta][:activities][:count].should == Models::Activity.count
|
49
|
+
response.result[:meta][:activities][:count].should == Models::Activities::Activity.count
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -63,7 +63,7 @@ describe Commands::Activity::List do
|
|
63
63
|
let(:params) { { application_id: 100, user_id: 200 }}
|
64
64
|
|
65
65
|
it 'returns activities' do
|
66
|
-
response.result[:meta][:activities][:count].should == Models::Activity.count
|
66
|
+
response.result[:meta][:activities][:count].should == Models::Activities::Activity.count
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'restpack_service/support/spec_helper'
|
2
2
|
require 'restpack_activity_service'
|
3
3
|
|
4
|
-
require_relative 'factories/activity_factory'
|
5
|
-
|
6
4
|
require 'coveralls'
|
7
5
|
Coveralls.wear!
|
8
6
|
|
@@ -13,9 +11,13 @@ migrations_path = File.dirname(__FILE__) + "/../db/migrate"
|
|
13
11
|
migrator = ActiveRecord::Migrator.new(:up, migrations_path)
|
14
12
|
migrator.migrate
|
15
13
|
|
14
|
+
FactoryGirl.find_definitions
|
15
|
+
|
16
16
|
DatabaseCleaner.strategy = :transaction
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
19
|
+
config.include FactoryGirl::Syntax::Methods
|
20
|
+
|
19
21
|
config.before(:each) do
|
20
22
|
DatabaseCleaner.start
|
21
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restpack_activity_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
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-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: restpack_service
|
@@ -136,7 +136,7 @@ files:
|
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
138
|
- config/database.yml
|
139
|
-
- db/migrate/
|
139
|
+
- db/migrate/20130630145409_create_activity_table.rb
|
140
140
|
- lib/restpack_activity_service.rb
|
141
141
|
- lib/restpack_activity_service/api/activity.rb
|
142
142
|
- lib/restpack_activity_service/commands/activity/create.rb
|
@@ -145,14 +145,15 @@ files:
|
|
145
145
|
- lib/restpack_activity_service/commands/activity/list.rb
|
146
146
|
- lib/restpack_activity_service/commands/activity/update.rb
|
147
147
|
- lib/restpack_activity_service/configuration.rb
|
148
|
+
- lib/restpack_activity_service/jobs/activity/create.rb
|
148
149
|
- lib/restpack_activity_service/models/activity.rb
|
149
150
|
- lib/restpack_activity_service/serializers/activity.rb
|
150
|
-
- lib/restpack_activity_service/services.rb
|
151
151
|
- lib/restpack_activity_service/tasks/db.rake
|
152
152
|
- lib/restpack_activity_service/tasks/tasks.rb
|
153
153
|
- lib/restpack_activity_service/version.rb
|
154
154
|
- restpack_activity_service.gemspec
|
155
155
|
- spec/factories/activity_factory.rb
|
156
|
+
- spec/factories/api_activity_factory.rb
|
156
157
|
- spec/services/create_spec.rb
|
157
158
|
- spec/services/destroy_spec.rb
|
158
159
|
- spec/services/get_spec.rb
|
@@ -184,6 +185,7 @@ specification_version: 4
|
|
184
185
|
summary: Simple Activity Streams
|
185
186
|
test_files:
|
186
187
|
- spec/factories/activity_factory.rb
|
188
|
+
- spec/factories/api_activity_factory.rb
|
187
189
|
- spec/services/create_spec.rb
|
188
190
|
- spec/services/destroy_spec.rb
|
189
191
|
- spec/services/get_spec.rb
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module RestPack::Activity::Service::Commands
|
2
|
-
|
3
|
-
end
|
4
|
-
|
5
|
-
require "restpack_activity_service/services/activity/list"
|
6
|
-
require "restpack_activity_service/services/activity/create"
|
7
|
-
require "restpack_activity_service/services/activity/get"
|
8
|
-
require "restpack_activity_service/services/activity/update"
|
9
|
-
require "restpack_activity_service/services/activity/destroy"
|