capacity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +2 -0
- data/Manifest +3 -0
- data/Rakefile +12 -0
- data/capacity.gemspec +32 -0
- data/lib/capacity.rb +75 -0
- metadata +92 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('capacity', '0.0.1') do |p|
|
6
|
+
p.description = 'A handy class for interacting with the Capacity API'
|
7
|
+
p.url = 'http://getcapacity.com/'
|
8
|
+
p.author = 'Peat Bakke'
|
9
|
+
p.email = 'peat@getcapacity.com'
|
10
|
+
p.ignore_pattern = ['tmp/*', 'script/*', 'capacity.gemspec']
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
data/capacity.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{capacity}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Peat Bakke"]
|
9
|
+
s.cert_chain = ["/Users/peat/.ssh/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-10-20}
|
11
|
+
s.description = %q{A handy class for interacting with the Capacity API}
|
12
|
+
s.email = %q{peat@getcapacity.com}
|
13
|
+
s.extra_rdoc_files = ["lib/capacity.rb"]
|
14
|
+
s.files = ["Rakefile", "lib/capacity.rb", "Manifest", "capacity.gemspec"]
|
15
|
+
s.homepage = %q{http://getcapacity.com/}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Capacity"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{capacity}
|
19
|
+
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/Users/peat/.ssh/gem-private_key.pem}
|
21
|
+
s.summary = %q{A handy class for interacting with the Capacity API}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
data/lib/capacity.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# talks with the Capcity API
|
7
|
+
class Capacity
|
8
|
+
|
9
|
+
SERVER = 'http://localhost:8080/'
|
10
|
+
VERSION = 'v1'
|
11
|
+
|
12
|
+
@@token = nil
|
13
|
+
|
14
|
+
def self.token=( token )
|
15
|
+
@@token = token
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get( resource, query = {} )
|
19
|
+
request( :get, resource, query )
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.post( resource, query = {} )
|
23
|
+
request( :post, resource, query )
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.put( resource, query = {} )
|
27
|
+
request( :put, resource, query )
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.delete( resource, query = {} )
|
31
|
+
request( :delete, resource, query )
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def self.request( http_method, resource, query = {} )
|
37
|
+
query.merge!( { :token => @@token } ) if @@token
|
38
|
+
|
39
|
+
url = URI.parse("#{SERVER}#{VERSION}/#{resource}")
|
40
|
+
|
41
|
+
# hack for query parameter in GETs
|
42
|
+
if http_method == :get
|
43
|
+
if query.empty?
|
44
|
+
get_path = url.path
|
45
|
+
else
|
46
|
+
query_array = []
|
47
|
+
query.each do |k,v|
|
48
|
+
if v.is_a?(Hash) # sub-key/value pairs, eg: query[foo]=abcdef query[bar]=zed
|
49
|
+
v.each do |subKey, subVal|
|
50
|
+
query_array << URI.escape( "#{k.to_s}[" + subKey.to_s + "]" ) + "=" + URI.escape( subVal.to_s )
|
51
|
+
end
|
52
|
+
else
|
53
|
+
query_array << "#{URI.escape( k.to_s )}=#{URI.escape( v.to_s )}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
get_path = url.path + "?" + query_array.join("&");
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
req = case http_method
|
61
|
+
when :get then Net::HTTP::Get.new( get_path )
|
62
|
+
when :put then Net::HTTP::Put.new( url.path )
|
63
|
+
when :post then Net::HTTP::Post.new( url.path )
|
64
|
+
when :delete then Net::HTTP::Delete.new( url.path )
|
65
|
+
end
|
66
|
+
|
67
|
+
res = Net::HTTP.start( url.host, url.port ) { |http|
|
68
|
+
req.set_form_data( query ) if http_method != :get
|
69
|
+
http.request( req )
|
70
|
+
}
|
71
|
+
|
72
|
+
JSON.parse( res.body )
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capacity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Peat Bakke
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMQ0wCwYDVQQDDARwZWF0
|
19
|
+
MRswGQYKCZImiZPyLGQBGRYLZ2V0Y2FwYWNpdHkxEzARBgoJkiaJk/IsZAEZFgNj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OPgxnhO2eSP7mO6mefBZ13J6IfLaEyXgWU4ttz
|
35
|
+
xMeJ822ms/e03A==
|
36
|
+
-----END CERTIFICATE-----
|
37
|
+
|
38
|
+
date: 2010-10-20 00:00:00 -07:00
|
39
|
+
default_executable:
|
40
|
+
dependencies: []
|
41
|
+
|
42
|
+
description: A handy class for interacting with the Capacity API
|
43
|
+
email: peat@getcapacity.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files:
|
49
|
+
- lib/capacity.rb
|
50
|
+
files:
|
51
|
+
- Rakefile
|
52
|
+
- lib/capacity.rb
|
53
|
+
- Manifest
|
54
|
+
- capacity.gemspec
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://getcapacity.com/
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --line-numbers
|
62
|
+
- --inline-source
|
63
|
+
- --title
|
64
|
+
- Capacity
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 2
|
83
|
+
version: "1.2"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: capacity
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: A handy class for interacting with the Capacity API
|
91
|
+
test_files: []
|
92
|
+
|
metadata.gz.sig
ADDED
Binary file
|