amiando 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'multi_json'
23
23
 
24
24
  s.add_development_dependency 'minitest', '2.9.0'
25
- s.add_development_dependency 'webmock'
25
+ s.add_development_dependency 'webmock', '~> 1.7.6'
26
26
  s.add_development_dependency 'rake'
27
27
  end
@@ -27,7 +27,7 @@ module Amiando
27
27
  def self.create(attributes)
28
28
  object = new
29
29
  post object, '/api/event/create',
30
- :params => map_params(attributes),
30
+ :params => attributes,
31
31
  :populate_method => :populate_create
32
32
 
33
33
  object
@@ -39,10 +39,10 @@ module Amiando
39
39
  # @param id
40
40
  # @param [Hash] attributes
41
41
  #
42
- # @return [Boolean] if it was successful or not.
42
+ # @return [Result] if it was successful or not.
43
43
  def self.update(id, attributes)
44
44
  object = Result.new
45
- post object, "/api/event/#{id}", :params => map_params(attributes)
45
+ post object, "/api/event/#{id}", :params => attributes
46
46
 
47
47
  object
48
48
  end
@@ -19,7 +19,7 @@ module Amiando
19
19
  def self.create(attributes)
20
20
  object = new
21
21
  post object, '/api/partner/create',
22
- :params => map_params(attributes),
22
+ :params => attributes,
23
23
  :populate_method => :populate_create
24
24
 
25
25
  object
@@ -34,7 +34,7 @@ module Amiando
34
34
  # @return [Result] saying if the update was successful
35
35
  def self.update(id, attributes)
36
36
  object = Result.new
37
- post object, "/api/partner/#{id}", :params => map_params(attributes)
37
+ post object, "/api/partner/#{id}", :params => attributes
38
38
 
39
39
  object
40
40
  end
@@ -57,7 +57,7 @@ module Amiando
57
57
  private
58
58
 
59
59
  def do_request(object, verb, path, options = {})
60
- req = Request.new(object, verb, path, options[:params] || {})
60
+ req = Request.new(object, verb, path, map_params(options[:params] || {}))
61
61
  object.request = req
62
62
 
63
63
  req.log_request
@@ -49,7 +49,7 @@ module Amiando
49
49
  # @return [Boolean] deferred object indicating the result of the update.
50
50
  def self.update(event_id, attributes)
51
51
  object = Boolean.new('success')
52
- post object, "/api/event/#{event_id}/ticketShop", :params => map_params(attributes)
52
+ post object, "/api/event/#{event_id}/ticketShop", :params => attributes
53
53
 
54
54
  object
55
55
  end
@@ -42,7 +42,7 @@ module Amiando
42
42
  def self.create(attributes)
43
43
  object = new
44
44
  post object, '/api/user/create',
45
- :params => map_params(attributes),
45
+ :params => attributes,
46
46
  :populate_method => :populate_create
47
47
 
48
48
  object
@@ -56,7 +56,7 @@ module Amiando
56
56
  # @param [String] username
57
57
  def self.update(user_id, attributes)
58
58
  object = Boolean.new('success')
59
- post object, "/api/user/#{user_id}", :params => map_params(attributes)
59
+ post object, "/api/user/#{user_id}", :params => attributes
60
60
 
61
61
  object
62
62
  end
@@ -1,3 +1,3 @@
1
1
  module Amiando
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -6,11 +6,23 @@ describe Amiando::Resource do
6
6
  map :last_name , :lastName
7
7
  map :creation, :creation, :type => :time
8
8
 
9
- def self.create
9
+ def self.create(params = {})
10
10
  object = new
11
- post object, 'somewhere', :populate_method => :populate_create
11
+ post object, 'somewhere', :params => params, :populate_method => :populate_create
12
12
  object
13
13
  end
14
+
15
+ def self.find(id)
16
+ object = new
17
+ get object, 'somewhere', :populate_method => :populate_test
18
+ object
19
+ end
20
+
21
+ private
22
+
23
+ def populate_test(body)
24
+ extract_attributes_from(body, 'wadus')
25
+ end
14
26
  end
15
27
 
16
28
  it 'raises error when amiando is down' do
@@ -68,6 +80,19 @@ describe Amiando::Resource do
68
80
  Wadus.reverse_map_params(:creation => '1970-01-01T00:00:00Z').must_equal expected
69
81
  end
70
82
 
83
+ it 'automatically maps attributes for a request' do
84
+ result = Wadus.create :first_name => 'George'
85
+ result.request.params.must_equal(:firstName => 'George')
86
+ end
87
+
88
+ it 'automatically reverse maps attributes on responses' do
89
+ stub_request(:any, /somewhere/).to_return(:status => 200, :body => '{"wadus":{"firstName":"George"}}')
90
+ result = Wadus.find(1)
91
+ Amiando.run
92
+
93
+ result.attributes.must_equal(:first_name => "George")
94
+ end
95
+
71
96
  describe 'synchronous calls' do
72
97
  it 'accepts synchronous calls' do
73
98
  stub_request(:post, /somewhere/).to_return(:status => 200, :body => '{"success":true}')
@@ -0,0 +1,11 @@
1
+ Typhoeus::Hydra.class_eval do
2
+ alias_method :run_without_monkeys, :run
3
+
4
+ def run_with_monkeys
5
+ run_without_monkeys
6
+ ensure
7
+ @active_stubs = []
8
+ end
9
+
10
+ alias_method :run, :run_with_monkeys
11
+ end
@@ -16,6 +16,7 @@ rescue LoadError; end
16
16
 
17
17
  require 'support/hydra_cache'
18
18
  require 'support/factory'
19
+ require 'support/hydra_monkey_patch'
19
20
 
20
21
  Amiando.hydra.cache_setter &HydraCache.method(:setter)
21
22
  Amiando.hydra.cache_getter &HydraCache.method(:getter)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amiando
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jorge Dias
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-15 00:00:00 +01:00
20
- default_executable:
19
+ date: 2011-12-19 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: typhoeus
@@ -69,12 +68,14 @@ dependencies:
69
68
  requirement: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
72
- - - ">="
71
+ - - ~>
73
72
  - !ruby/object:Gem::Version
74
- hash: 3
73
+ hash: 7
75
74
  segments:
76
- - 0
77
- version: "0"
75
+ - 1
76
+ - 7
77
+ - 6
78
+ version: 1.7.6
78
79
  type: :development
79
80
  version_requirements: *id004
80
81
  - !ruby/object:Gem::Dependency
@@ -222,8 +223,8 @@ files:
222
223
  - test/fixtures/User/efb3543620c2a1753972b79b1a747b00.yml
223
224
  - test/support/factory.rb
224
225
  - test/support/hydra_cache.rb
226
+ - test/support/hydra_monkey_patch.rb
225
227
  - test/test_helper.rb
226
- has_rdoc: true
227
228
  homepage: ""
228
229
  licenses: []
229
230
 
@@ -253,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
254
  requirements: []
254
255
 
255
256
  rubyforge_project: amiando
256
- rubygems_version: 1.6.2
257
+ rubygems_version: 1.8.10
257
258
  signing_key:
258
259
  specification_version: 3
259
260
  summary: A ruby client for the amiando REST API
@@ -356,4 +357,5 @@ test_files:
356
357
  - test/fixtures/User/efb3543620c2a1753972b79b1a747b00.yml
357
358
  - test/support/factory.rb
358
359
  - test/support/hydra_cache.rb
360
+ - test/support/hydra_monkey_patch.rb
359
361
  - test/test_helper.rb