relax 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/relax/request.rb CHANGED
@@ -45,6 +45,16 @@ module Relax
45
45
  to_query.to_s
46
46
  end
47
47
 
48
+ # Checks the validity of the property values in this request.
49
+ def valid?
50
+ self.class.parameters.each do |key, options|
51
+ if options[:required]
52
+ value = send(key)
53
+ raise Relax::MissingParameter if value.nil?
54
+ end
55
+ end
56
+ end
57
+
48
58
  # Converts a key when the Request is converted to a query. By default, no
49
59
  # conversion actually takes place, but this method can be overridden by
50
60
  # child classes to perform standard manipulations, such as replacing
data/lib/relax/service.rb CHANGED
@@ -66,6 +66,7 @@ module Relax
66
66
  # the body of the response is used to instantiate the response class, and
67
67
  # this response object is returned.
68
68
  def call(request, response_class)
69
+ request.valid?
69
70
  uri = @endpoint.clone
70
71
  uri.query = query(request).to_s
71
72
  response = request(uri)
data/spec/request_spec.rb CHANGED
@@ -8,7 +8,7 @@ class Amount < Relax::Request
8
8
  end
9
9
 
10
10
  class TestRequest < Relax::Request
11
- parameter :action
11
+ parameter :action, :required => true
12
12
  parameter :token_id
13
13
  parameter :user_id
14
14
  parameter :amount, :type => Amount
@@ -50,6 +50,12 @@ end
50
50
  describe 'a normal request' do
51
51
  it_should_behave_like 'a request that converts to a query'
52
52
  it_should_behave_like 'an option initialized request'
53
+
54
+ it 'should raise an exception if a required parameter is missing' do
55
+ lambda {
56
+ TestRequest.new(:token_id => 123).valid?
57
+ }.should raise_error(Relax::MissingParameter)
58
+ end
53
59
  end
54
60
 
55
61
  describe 'a template request' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Hunt
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-03 00:00:00 -05:00
12
+ date: 2009-04-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency