restpack_service 0.0.64 → 0.0.65

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: 8c13378bcbc9ae398e75165b4ea00a432382175d
4
- data.tar.gz: 14c11ae436bd300d79b4c75dd5fdd3ac4ded7752
3
+ metadata.gz: 49137a729f5b2c815e7ee9c104520ec36fa6266e
4
+ data.tar.gz: 86451cffa96faae3785f3464827f553bf3511600
5
5
  SHA512:
6
- metadata.gz: c2c34390c50d5928ba3265b81afd9d9087c67092b89844007a72722e6114349f0089b9ec17bf267aa123c3f91e9585d53e89fcca721b07e86527f8ea77795723
7
- data.tar.gz: f5e5fd3b3d24ab020020a41ca5a603218accfeda6e09920d8300334238c12094d57855067c5387b971afa062062cbafd5cbd210418cbf9c0ad42778350b5b8ad
6
+ metadata.gz: 578bdc4ee648100800538dff93e47cc7b46f5f67a1eebdb73d4bc25f0ae974e9b9b230384a980fbb964023c13aa84f77b7f1c2cc475c4aa4e0312c7fb56e3a71
7
+ data.tar.gz: 2644f5878ce6e1484c317b3482f5f2a219a3dc8f13d302787348285414027a808ea5922cbd55490117419bf552e8abaae92bc8e2b930a0a657e66018e2c44316
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Gavin Joyce
1
+ Copyright (c) 2013, 2014 Gavin Joyce
2
2
 
3
3
  MIT License
4
4
 
@@ -1,11 +1,11 @@
1
1
  require 'modularize'
2
2
 
3
- module RestPack::Service
3
+ module RestPack
4
4
  class Command < Mutations::Command
5
5
  attr_accessor :response
6
6
 
7
7
  def run
8
- @response = Response.new
8
+ @response = RestPack::Service::Response.new
9
9
 
10
10
  begin
11
11
  init
@@ -56,41 +56,6 @@ module RestPack::Service
56
56
  add_error key, key, message
57
57
  end
58
58
 
59
- def get
60
- identifier = service_identifiers[:resources]
61
- result = serializer_klass.resource(inputs)
62
-
63
- if result[identifier].empty?
64
- status :not_found
65
- else
66
- result
67
- end
68
- end
69
-
70
- def list
71
- serializer_klass.resource(inputs)
72
- end
73
-
74
- def create!
75
- identifier = service_identifiers[:resources]
76
- models = create_models!(inputs[identifier])
77
- serialize(models)
78
- end
79
-
80
- def single_create!
81
- identifier = service_identifiers[:resources]
82
- model = model_klass.create!(inputs)
83
- as_json(model)
84
- end
85
-
86
- def serialize(models)
87
- serializer_klass.serialize(models)
88
- end
89
-
90
- def as_json(model)
91
- serializer_klass.as_json(model)
92
- end
93
-
94
59
  def self.inherited(command)
95
60
  namespaces = command.to_s.split('::') # eg. GroupService::Commands::Group::Create
96
61
 
@@ -136,6 +101,102 @@ module RestPack::Service
136
101
  namespaces.take(namespaces.length - 1).join('::').safe_constantize #Commands::Group
137
102
  end
138
103
  end
104
+ end
105
+ end
106
+
107
+ #TODO: GJ: remove this legacy class
108
+ module RestPack::Service
109
+ class Command < Mutations::Command
110
+ attr_accessor :response
111
+
112
+ def run
113
+ @response = Response.new
114
+
115
+ begin
116
+ init
117
+ mutation = super
118
+
119
+ if mutation.errors
120
+ mutation.errors.message.each do |error|
121
+ @response.add_error(error[0], error[1].gsub(error[0].capitalize, ''))
122
+ end
123
+
124
+ @response.status ||= :unprocessable_entity
125
+ else
126
+ @response.status ||= :ok
127
+ end
128
+
129
+ if @response.status == :ok
130
+ @response.result = mutation.result if mutation.result
131
+ end
132
+ rescue Exception => e
133
+ puts "---COMMAND EXCEPTION---"
134
+ puts e.message #TODO: GJ: logging
135
+ puts e.backtrace
136
+ puts "-----------------------"
137
+
138
+ @response.add_error(:base, 'Service Error')
139
+ @response.status = :internal_service_error
140
+ end
141
+
142
+ @response
143
+ end
144
+
145
+ def init
146
+ end
147
+
148
+ def status(status)
149
+ @response.status = status
150
+ end
151
+
152
+ def valid?
153
+ !has_errors?
154
+ end
155
+
156
+ def service_error(message)
157
+ field_error :base, message
158
+ end
159
+
160
+ def field_error(key, message)
161
+ add_error key, key, message
162
+ end
163
+
164
+ def get
165
+ identifier = service_identifiers[:resources]
166
+ result = Serializer.resource(inputs)
167
+
168
+ if result[identifier].empty?
169
+ status :not_found
170
+ else
171
+ result
172
+ end
173
+ end
174
+
175
+ def list
176
+ serializer_klass.resource(inputs)
177
+ end
178
+
179
+ def create!
180
+ identifier = service_identifiers[:resources]
181
+ models = create_models!(inputs[identifier])
182
+ serialize(models)
183
+ end
184
+
185
+ def single_create!
186
+ identifier = service_identifiers[:resources]
187
+ model = model_klass.create!(inputs)
188
+ as_json(model)
189
+ end
190
+
191
+ def serialize(models)
192
+ serializer_klass.serialize(models)
193
+ end
194
+
195
+ def as_json(model)
196
+ serializer_klass.as_json(model)
197
+ end
198
+
199
+
139
200
 
140
201
  def create_models!(array)
141
202
  model_klass.create!(array)
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Service
3
- VERSION = "0.0.64"
3
+ VERSION = "0.0.65"
4
4
  end
5
5
  end
@@ -18,16 +18,16 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "mutations", "~> 0.6.0"
22
- spec.add_dependency "yajl-ruby", "~> 1.1.0"
23
- spec.add_dependency "protected_attributes", "~> 1.0.3"
24
- spec.add_dependency "require_all", "~> 1.3.0"
21
+ spec.add_dependency "mutations", "~> 0.7"
22
+ spec.add_dependency "yajl-ruby", "~> 1.2"
23
+ spec.add_dependency "protected_attributes", "~> 1.0"
24
+ spec.add_dependency "require_all", "~> 1.3"
25
25
  spec.add_dependency "restpack_serializer"
26
26
  spec.add_dependency "restpack_gem"
27
27
  spec.add_dependency "modularize"
28
- spec.add_dependency "sinatra", "~> 1.4.3"
29
- spec.add_dependency "pg", "~> 0.16.0"
30
- spec.add_dependency "sidekiq", "~> 2.15.1"
28
+ spec.add_dependency "sinatra", "~> 1.4"
29
+ spec.add_dependency "pg", "~> 0.17"
30
+ spec.add_dependency "sidekiq", "~> 3.2"
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.3"
33
33
  spec.add_development_dependency "rake"
@@ -1,28 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe RestPack::Service::Command do
3
+ describe RestPack::Command do
4
4
  context 'with a commands in a namespace like TextService::Commands::Text::Reverse' do
5
5
  it 'defines sugar methods' do
6
- TextService::Text.respond_to?(:reverse).should == true
7
- TextService::Text.respond_to?(:reverse!).should == true
8
- TextService::Text.reverse!(text: 'gavin').should == 'nivag'
6
+ expect(TextService::Text).to respond_to(:reverse, :reverse!)
7
+ expect(TextService::Text.reverse!(text: 'gavin')).to eq('nivag')
9
8
  end
10
9
 
11
10
  it 'defines aliases' do
12
11
  command = TextService::Commands::Text::Reverse
13
12
 
14
- command::Model.should == TextService::Models::Text
15
- command::Serializer.should == TextService::Serializers::Text
16
- command::Commands.should == TextService::Commands
17
- command::Models.should == TextService::Models
13
+ expect(command::Model).to eq(TextService::Models::Text)
14
+ expect(command::Serializer).to eq(TextService::Serializers::Text)
15
+ expect(command::Commands).to eq(TextService::Commands)
16
+ expect(command::Models).to eq(TextService::Models)
18
17
  end
19
18
  end
20
19
 
21
20
  context 'with a commands in a namespace like Commands::Template::Create' do
22
21
  it 'defines sugar methods' do
23
- Commands::Math.respond_to?(:add).should == true
24
- Commands::Math.respond_to?(:add!).should == true
25
- Commands::Math.add!(a: 1, b: 2).should == 3
22
+ expect(Commands::Math).to respond_to(:add, :add!)
23
+ expect(Commands::Math.add!(a: 1, b: 2)).to eq(3)
26
24
  end
27
25
  end
28
26
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe RestPack::Service::Configuration do
4
4
  subject { RestPack::Service::Configuration.new }
5
5
 
6
- it "has defaults" do
7
- subject.application_id.should == 1
6
+ it 'has defaults' do
7
+ expect(subject.application_id).to eq(1)
8
8
  end
9
9
  end
@@ -1,18 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RestPack::Service::Response do
4
- pending "Write some specs"
5
-
6
- describe "#from_rest" do
7
- it "parses a successful response" do
4
+ describe '#from_rest' do
5
+ it 'parses a successful response' do
8
6
  response = RestPack::Service::Response.from_rest(
9
7
  double(code: 200, body: '{ "key": "value" }')
10
8
  )
11
9
 
12
- response.status.should == :ok
13
- response.code.should == 200
14
- response.success?.should == true
15
- response.result.should == { key: "value" }
10
+ expect(response.status).to eq(:ok)
11
+ expect(response.code).to eq(200)
12
+ expect(response.success?).to eq(true)
13
+ expect(response.result).to eq({ key: "value" })
16
14
  end
17
15
 
18
16
  it "extracts errors from response body" do
@@ -22,26 +20,26 @@ describe RestPack::Service::Response do
22
20
  } }')
23
21
  )
24
22
 
25
- response.success?.should == false
26
- response.result.should == { key: "value" }
27
- response.errors.should == { name: ["error 1", "error 2"] }
23
+ expect(response.success?).to eq(false)
24
+ expect(response.result).to eq({ key: "value" })
25
+ expect(response.errors).to eq({ name: ["error 1", "error 2"] })
28
26
  end
29
27
 
30
28
  end
31
29
 
32
30
  describe RestPack::Service::Response::Status do
33
- describe "#from_code" do
34
- context "valid status" do
35
- it "maps a code to a status" do
36
- RestPack::Service::Response::Status.from_code(200).should == :ok
31
+ describe '#from_code' do
32
+ context 'valid status' do
33
+ it 'maps a code to a status' do
34
+ expect(RestPack::Service::Response::Status.from_code(200)).to eq(:ok)
37
35
  end
38
36
  end
39
37
 
40
- context "invalid status" do
41
- it "raises an exception" do
38
+ context 'invalid status' do
39
+ it 'raises an exception' do
42
40
  expect {
43
41
  RestPack::Service::Response::Status.from_code(999)
44
- }.to raise_exception("Invalid Status Code: 999")
42
+ }.to raise_exception('Invalid Status Code: 999')
45
43
  end
46
44
  end
47
45
  end
@@ -11,7 +11,7 @@ module TextService
11
11
 
12
12
  module Commands
13
13
  module Text
14
- class Reverse < RestPack::Service::Command
14
+ class Reverse < RestPack::Command
15
15
  required do
16
16
  string :text
17
17
  end
@@ -27,7 +27,7 @@ end
27
27
 
28
28
  module Commands
29
29
  module Math
30
- class Add < RestPack::Service::Command
30
+ class Add < RestPack::Command
31
31
  required do
32
32
  integer :a
33
33
  integer :b
metadata CHANGED
@@ -1,209 +1,209 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.64
4
+ version: 0.0.65
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-03 00:00:00.000000000 Z
11
+ date: 2014-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mutations
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yajl-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.0
33
+ version: '1.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.0
40
+ version: '1.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: protected_attributes
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.3
47
+ version: '1.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.3
54
+ version: '1.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: require_all
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.0
61
+ version: '1.3'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.0
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: restpack_serializer
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: restpack_gem
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: modularize
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: sinatra
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 1.4.3
117
+ version: '1.4'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 1.4.3
124
+ version: '1.4'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pg
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.16.0
131
+ version: '0.17'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.16.0
138
+ version: '0.17'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: sidekiq
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 2.15.1
145
+ version: '3.2'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 2.15.1
152
+ version: '3.2'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: bundler
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: '1.3'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.3'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rake
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rspec
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - '>='
185
+ - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - '>='
192
+ - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: bump
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - '>='
199
+ - - ">="
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - '>='
206
+ - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
209
  description: RestPack service base
@@ -213,9 +213,9 @@ executables: []
213
213
  extensions: []
214
214
  extra_rdoc_files: []
215
215
  files:
216
- - .gitignore
217
- - .rspec
218
- - .travis.yml
216
+ - ".gitignore"
217
+ - ".rspec"
218
+ - ".travis.yml"
219
219
  - Gemfile
220
220
  - LICENSE.txt
221
221
  - README.md
@@ -251,17 +251,17 @@ require_paths:
251
251
  - lib
252
252
  required_ruby_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
- - - '>='
254
+ - - ">="
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
257
  required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  requirements:
259
- - - '>='
259
+ - - ">="
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  requirements: []
263
263
  rubyforge_project:
264
- rubygems_version: 2.0.14
264
+ rubygems_version: 2.2.2
265
265
  signing_key:
266
266
  specification_version: 4
267
267
  summary: A base for RestPack services