rapidash 0.3.0.beta → 0.3.0.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c189f614b87a9f1d01e06b573191ab55cfc5304
4
- data.tar.gz: 4e105da2de17bca6c15e66055e9cae54f9f2e502
3
+ metadata.gz: bd496716b730c32050d32bea5b8092915374d854
4
+ data.tar.gz: b388a6b91ef8848c8ae1e0c9fa2dbf2d78df1994
5
5
  SHA512:
6
- metadata.gz: cf3736b55a2373d1f29addff7e56904f3a7eed7c457797f984de95f7447a451e1f8d6f097e7e17125da7c0ac3dd9a65cab232090e24ac55c7b02f6290936fbb1
7
- data.tar.gz: 2917f78dda7987f293c15d95cc760d901f597aec9d8a300552257f68720cf466d304a239b2dfadbbef07ebed9741c375985c273e5ba271ba8032c891c1d61ebe
6
+ metadata.gz: be5b2ac379f1ecc80f461ae35f7528e7a5076b7797c14b228035e380c66a930c8c0bc8dbd82fe2046058e3b41a6c953dd6c8b9132501fde6ce34b7047359876e
7
+ data.tar.gz: d5a3f16209b48f83d1f24c04b8e4c2a04815ea4909d592d0348328fae946021e40beb4fc37ecb978071d1855ae00265a59981f57776cb914e9f43f70e03afdd3
@@ -63,6 +63,25 @@ module Rapidash
63
63
  end
64
64
  end
65
65
  end
66
+
67
+ def collection(name, attrs = {})
68
+ path = attrs[:path] || name.to_s
69
+ path.gsub!(/^\//, '')
70
+
71
+ method = attrs[:method] || :get
72
+
73
+ define_method("#{name}!") do
74
+ original_url = @url
75
+
76
+ @url += "/#{path}"
77
+ @options[:method] = method
78
+ result = call!
79
+
80
+ @url = original_url
81
+
82
+ result
83
+ end
84
+ end
66
85
  end
67
86
  end
68
87
  end
@@ -55,12 +55,10 @@ module Rapidash
55
55
  @method = response[:method].to_s.upcase
56
56
  @url = response[:url]
57
57
 
58
- super(message)
58
+ super
59
59
  end
60
60
 
61
- private
62
-
63
- def message
61
+ def to_s
64
62
  msg = "#{status} #{method} #{url}"
65
63
 
66
64
  if respond_to?(:errors) && !(errors.blank?)
@@ -1,3 +1,3 @@
1
1
  module Rapidash
2
- VERSION = "0.3.0.beta"
2
+ VERSION = "0.3.0.beta2"
3
3
  end
@@ -99,7 +99,7 @@ describe Rapidash::Client do
99
99
 
100
100
  it "should set encoder for valid argument" do
101
101
  klass.encode_request_with(:json)
102
- expect(klass.encoder).to eq :json
102
+ expect(klass.encoder).to eq :multi_json
103
103
  end
104
104
 
105
105
  it "should raise exception for invalid argument" do
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ module CollectionTest; end
3
+
4
+ class CollectionTest::User < Rapidash::Base
5
+ collection :active
6
+ end
7
+
8
+ class CollectionTest::Person < Rapidash::Base
9
+ collection :suspend_all, :path => 'deactivate', :method => :post
10
+ end
11
+
12
+ class CollectionTest::Client < Rapidash::Client
13
+ method :http
14
+ site 'http://acme.com'
15
+
16
+ resource :users, :class_name => "CollectionTest::User"
17
+ resource :people, :class_name => "CollectionTest::Person"
18
+ end
19
+
20
+ describe Rapidash::Client do
21
+ let(:client) { CollectionTest::Client.new }
22
+
23
+ context "standand collection" do
24
+ let(:resource) { client.users }
25
+
26
+ it "should define a new method" do
27
+ expect(resource).to respond_to(:active!)
28
+ end
29
+
30
+ it "should call with the updated URL" do
31
+ client.should_receive(:get).with('users/active', { :headers => { "content-type" => "application/json" }})
32
+ resource.active!
33
+ end
34
+
35
+ it "should not update the URL on the resource" do
36
+ resource.active!
37
+ expect(resource.url).to eq 'users'
38
+ end
39
+ end
40
+
41
+ context "additional options" do
42
+ let(:resource) { client.people }
43
+
44
+ it "should define a new method" do
45
+ expect(resource).to respond_to(:suspend_all!)
46
+ end
47
+
48
+ it "should call with the updated URL" do
49
+ client.should_receive(:post).with('people/deactivate', { :headers => { "content-type" => "application/json" }})
50
+ resource.suspend_all!
51
+ end
52
+
53
+ it "should not update the URL on the resource" do
54
+ resource.suspend_all!
55
+ expect(resource.url).to eq 'people'
56
+ end
57
+ end
58
+ end
@@ -55,16 +55,12 @@ describe Rapidash::Resourceable do
55
55
  it "should include the resource method" do
56
56
  Rapidash::ClientTester.methods.map { |m| m.to_sym }.should include(:resource)
57
57
  end
58
-
59
58
  end
60
59
 
61
-
62
60
  describe "instance methods" do
63
61
  let(:client) { ClientTester.new }
64
62
 
65
63
  describe ".resource" do
66
-
67
-
68
64
  it "should create a Rapidash::Base" do
69
65
  client.resource(:users, 1).class.should eql(Rapidash::Base)
70
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapidash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.beta
4
+ version: 0.3.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary 'Gazler' Rennie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,6 +197,7 @@ files:
197
197
  - spec/rapidash/http_client_spec.rb
198
198
  - spec/rapidash/integration/test_client_spec.rb
199
199
  - spec/rapidash/oauth_client_spec.rb
200
+ - spec/rapidash/resourceable/collection_spec.rb
200
201
  - spec/rapidash/resourceable_spec.rb
201
202
  - spec/rapidash/response_error_spec.rb
202
203
  - spec/rapidash/test_client_spec.rb
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  version: 1.3.1
223
224
  requirements: []
224
225
  rubyforge_project:
225
- rubygems_version: 2.0.2
226
+ rubygems_version: 2.0.0
226
227
  signing_key:
227
228
  specification_version: 4
228
229
  summary: An opinionated core for creating clients for RESTful APIs quickly
@@ -233,6 +234,7 @@ test_files:
233
234
  - spec/rapidash/http_client_spec.rb
234
235
  - spec/rapidash/integration/test_client_spec.rb
235
236
  - spec/rapidash/oauth_client_spec.rb
237
+ - spec/rapidash/resourceable/collection_spec.rb
236
238
  - spec/rapidash/resourceable_spec.rb
237
239
  - spec/rapidash/response_error_spec.rb
238
240
  - spec/rapidash/test_client_spec.rb