capacity 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/Manifest +6 -1
- data/Rakefile +1 -1
- data/capacity.gemspec +3 -3
- data/lib/capacity/resource.rb +35 -0
- data/spec/api_spec.rb +10 -0
- data/spec/helper.rb +1 -0
- data/spec/resource_spec.rb +15 -0
- data/spec/response_spec.rb +51 -0
- metadata +9 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/Manifest
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('capacity', '0.0.
|
5
|
+
Echoe.new('capacity', '0.0.9') do |p|
|
6
6
|
p.summary = "Driver for the Capacity API"
|
7
7
|
p.description = 'Not even alpha, not for production use, and not much use to anyone but us at the moment!'
|
8
8
|
p.url = 'http://getcapacity.com/'
|
data/capacity.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{capacity}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Peat Bakke"]
|
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.date = %q{2010-10-29}
|
11
11
|
s.description = %q{Not even alpha, not for production use, and not much use to anyone but us at the moment!}
|
12
12
|
s.email = %q{peat@getcapacity.com}
|
13
|
-
s.extra_rdoc_files = ["lib/capacity.rb", "lib/capacity/api.rb", "lib/capacity/response.rb"]
|
14
|
-
s.files = ["
|
13
|
+
s.extra_rdoc_files = ["lib/capacity.rb", "lib/capacity/api.rb", "lib/capacity/resource.rb", "lib/capacity/response.rb"]
|
14
|
+
s.files = ["Rakefile", "lib/capacity.rb", "lib/capacity/api.rb", "lib/capacity/resource.rb", "lib/capacity/response.rb", "spec/api_spec.rb", "spec/helper.rb", "spec/resource_spec.rb", "spec/response_spec.rb", "Manifest", "capacity.gemspec"]
|
15
15
|
s.homepage = %q{http://getcapacity.com/}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Capacity"]
|
17
17
|
s.require_paths = ["lib"]
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Capacity
|
2
|
+
class Resource
|
3
|
+
|
4
|
+
def initialize( name, token = nil )
|
5
|
+
@name = name.to_sym
|
6
|
+
@api = API.new
|
7
|
+
@api.token = token
|
8
|
+
end
|
9
|
+
|
10
|
+
def token=( t )
|
11
|
+
@api.token = t
|
12
|
+
end
|
13
|
+
|
14
|
+
def token
|
15
|
+
@api.token
|
16
|
+
end
|
17
|
+
|
18
|
+
def get( params = {} )
|
19
|
+
@api.get( @name, params )
|
20
|
+
end
|
21
|
+
|
22
|
+
def put( params = {} )
|
23
|
+
@api.put( @name, params )
|
24
|
+
end
|
25
|
+
|
26
|
+
def post( params = {} )
|
27
|
+
@api.post( @name, params )
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete( params = {} )
|
31
|
+
@api.delete( @name, params )
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/spec/api_spec.rb
ADDED
data/spec/helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'lib', 'capacity' )
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe "A Resource" do
|
5
|
+
|
6
|
+
it "should wrap an API object for accessing a specific Capacity resource" do
|
7
|
+
account = Capacity::Resource.new( :account )
|
8
|
+
|
9
|
+
name = "something#{rand}"
|
10
|
+
resp = account.post( :name => name )
|
11
|
+
resp.error?.should be_false
|
12
|
+
resp.data[:name].should == name
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
describe "A Response" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@hash_data = {'status' => 'OK', 'thing' => { 'shoe' => 'adidas', 'shirt' => 'american apparel' }}
|
8
|
+
@hash_response = Capacity::Response.new( @hash_data )
|
9
|
+
|
10
|
+
@array_data = {'status' => 'OK', 'things' => [ {'foo' => 'bar'}, {'quux' => 'zed'} ]}
|
11
|
+
@array_response = Capacity::Response.new( @array_data )
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should correctly detect an error response" do
|
15
|
+
errors = [ 'NOT FOUND', 'ERROR', 'EXCEPTION', 'UNKNOWN', 'ADSFINI*@#*RY@' ]
|
16
|
+
errors.each do |e|
|
17
|
+
raw = { 'status' => e }
|
18
|
+
resp = Capacity::Response.new( raw )
|
19
|
+
resp.error?.should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
@array_response.error?.should be_false
|
23
|
+
@hash_response.error?.should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should provide the raw status string" do
|
27
|
+
Capacity::Response.new( 'status' => 'SOMETHING' ).status.should == 'SOMETHING'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should preserve a hash response as a hash" do
|
31
|
+
@hash_response.data[:shoe].should == 'adidas'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should preserve an array response as an array" do
|
35
|
+
@array_response.data.length == 2
|
36
|
+
@array_response.data[0]['foo'].should == 'bar'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should provide hash keys as symbols" do
|
40
|
+
@hash_response.data[:shoe].should == 'adidas' # converted to symbol
|
41
|
+
@hash_response.data['shoe'].should be_nil # original; dropped
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should reveal if it's conveying an array or a hash" do
|
45
|
+
@hash_response.hash?.should be_true
|
46
|
+
@hash_response.array?.should be_false
|
47
|
+
@array_response.array?.should be_true
|
48
|
+
@array_response.hash?.should be_false
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Peat Bakke
|
@@ -48,13 +48,19 @@ extensions: []
|
|
48
48
|
extra_rdoc_files:
|
49
49
|
- lib/capacity.rb
|
50
50
|
- lib/capacity/api.rb
|
51
|
+
- lib/capacity/resource.rb
|
51
52
|
- lib/capacity/response.rb
|
52
53
|
files:
|
53
|
-
- Manifest
|
54
54
|
- Rakefile
|
55
55
|
- lib/capacity.rb
|
56
56
|
- lib/capacity/api.rb
|
57
|
+
- lib/capacity/resource.rb
|
57
58
|
- lib/capacity/response.rb
|
59
|
+
- spec/api_spec.rb
|
60
|
+
- spec/helper.rb
|
61
|
+
- spec/resource_spec.rb
|
62
|
+
- spec/response_spec.rb
|
63
|
+
- Manifest
|
58
64
|
- capacity.gemspec
|
59
65
|
has_rdoc: true
|
60
66
|
homepage: http://getcapacity.com/
|
metadata.gz.sig
CHANGED
Binary file
|