pachuber 0.1.0
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.
- data/MIT-LICENSE +21 -0
- data/README.textile +11 -0
- data/Rakefile +70 -0
- data/lib/pachuber.rb +32 -0
- data/resources/005.xsd +134 -0
- data/resources/key.rb +3 -0
- data/test/pachuber_test.rb +35 -0
- metadata +80 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2009 kitplummer@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.textile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
h1. First whack at a Ruby API for interacting with "Pachube":http://www.pachube.com
|
2
|
+
|
3
|
+
h2. Work in progress at this point
|
4
|
+
|
5
|
+
Requires version 0.2.0 or greater of the eeml-simple EEML wrapper library. Thanks to James Smith for including my changes upstream.
|
6
|
+
|
7
|
+
Take a peek at the test cases for examples of how to consume/contribute to Pachube in either EEML XML or EEML objects.
|
8
|
+
|
9
|
+
h2. Wants
|
10
|
+
|
11
|
+
To support the whole API, I don't need it all yet. So...if you're interested fork away or let me know how I can help.
|
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/packagetask'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
8
|
+
require 'pachuber'
|
9
|
+
|
10
|
+
PKG_NAME = 'pachuber'
|
11
|
+
PKG_VERSION = Pachube::VERSION
|
12
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
13
|
+
|
14
|
+
desc 'Default: run unit tests.'
|
15
|
+
task :default => :test
|
16
|
+
|
17
|
+
desc "Clean generated files"
|
18
|
+
task :clean do
|
19
|
+
#rm FileList['test/']
|
20
|
+
rm_rf 'pkg'
|
21
|
+
rm_rf 'rdoc'
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Test the pachuber gem.'
|
25
|
+
Rake::TestTask.new(:test) do |t|
|
26
|
+
t.libs << 'lib'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = true
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Generate documentation for the pachuber gem.'
|
32
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = 'pachuber'
|
35
|
+
rdoc.options << '--line-numbers'
|
36
|
+
rdoc.rdoc_files.include('README.textile')
|
37
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Create compressed packages
|
42
|
+
spec = Gem::Specification.new do |s|
|
43
|
+
s.platform = Gem::Platform::RUBY
|
44
|
+
s.name = PKG_NAME
|
45
|
+
s.summary = "Interact with the Pachube API via HTTParty."
|
46
|
+
s.description = %q{Just a simple Ruby library to provides Ruby-style abstraction around the HTTP API at Pachube.}
|
47
|
+
s.version = PKG_VERSION
|
48
|
+
|
49
|
+
s.author = "Kit Plummer"
|
50
|
+
s.email = "kitplummer@gmail.com"
|
51
|
+
s.rubyforge_project = PKG_NAME
|
52
|
+
s.homepage = "http://github.com/kitplummer/pachuber"
|
53
|
+
|
54
|
+
s.has_rdoc = true
|
55
|
+
s.requirements << 'none'
|
56
|
+
s.require_path = 'lib'
|
57
|
+
#s.autorequire = 'pachuber'
|
58
|
+
s.add_dependency("httparty", ">= 0.4.5")
|
59
|
+
s.add_dependency("eeml-simple", ">= 0.2.0")
|
60
|
+
s.files = [ "Rakefile", "README.textile", "MIT-LICENSE" ]
|
61
|
+
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
62
|
+
s.files = s.files + Dir.glob( "resources/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
63
|
+
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) || item.include?("\.png") }
|
64
|
+
end
|
65
|
+
|
66
|
+
Rake::GemPackageTask.new(spec) do |p|
|
67
|
+
p.gem_spec = spec
|
68
|
+
p.need_tar = false
|
69
|
+
p.need_zip = true
|
70
|
+
end
|
data/lib/pachuber.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'eeml'
|
4
|
+
|
5
|
+
class Pachube
|
6
|
+
VERSION = '0.1.0'
|
7
|
+
class PachubeError < RuntimeError; end
|
8
|
+
|
9
|
+
include HTTParty
|
10
|
+
base_uri 'http://www.pachube.com/api'
|
11
|
+
|
12
|
+
def initialize(key)
|
13
|
+
@key = key
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_xml(feed_url)
|
17
|
+
options = { :format => "xml", :headers => {"X-PachubeApiKey" => @key} }
|
18
|
+
self.class.get(feed_url, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_eeml(feed_url)
|
22
|
+
xml = self.get_xml(feed_url)
|
23
|
+
eeml = EEML::Environment.from_eeml(xml)
|
24
|
+
end
|
25
|
+
|
26
|
+
def update(feed_url, eeml)
|
27
|
+
options = { :headers => {"X-PachubeApiKey" => @key},
|
28
|
+
:body => eeml
|
29
|
+
}
|
30
|
+
self.class.put(feed_url, options)
|
31
|
+
end
|
32
|
+
end
|
data/resources/005.xsd
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<xsd:schema xmlns="http://www.eeml.org/xsd/005" elementFormDefault="qualified" targetNamespace="http://www.eeml.org/xsd/005" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
3
|
+
<xsd:element name="eeml">
|
4
|
+
<xsd:complexType>
|
5
|
+
<xsd:choice>
|
6
|
+
<xsd:element maxOccurs="unbounded" name="environment">
|
7
|
+
<xsd:complexType>
|
8
|
+
<xsd:sequence>
|
9
|
+
<xsd:element minOccurs="0" name="title" type="xsd:string" />
|
10
|
+
<xsd:element minOccurs="0" name="feed" type="xsd:anyURI" />
|
11
|
+
<xsd:element minOccurs="0" name="status">
|
12
|
+
<xsd:simpleType>
|
13
|
+
<xsd:restriction base="xsd:string">
|
14
|
+
<xsd:enumeration value="frozen" />
|
15
|
+
<xsd:enumeration value="live" />
|
16
|
+
</xsd:restriction>
|
17
|
+
</xsd:simpleType>
|
18
|
+
</xsd:element>
|
19
|
+
<xsd:element minOccurs="0" name="description" type="xsd:string" />
|
20
|
+
<xsd:element minOccurs="0" name="icon" type="xsd:anyURI" />
|
21
|
+
<xsd:element minOccurs="0" name="website" type="xsd:anyURI" />
|
22
|
+
<xsd:element minOccurs="0" name="email" type="xsd:string" />
|
23
|
+
<xsd:element minOccurs="0" name="location">
|
24
|
+
<xsd:complexType>
|
25
|
+
<xsd:sequence>
|
26
|
+
<xsd:element minOccurs="0" name="name" type="xsd:string" />
|
27
|
+
<xsd:element name="lat">
|
28
|
+
<xsd:simpleType>
|
29
|
+
<xsd:restriction base="xsd:double">
|
30
|
+
<xsd:minInclusive value="-90" />
|
31
|
+
<xsd:maxInclusive value="90" />
|
32
|
+
</xsd:restriction>
|
33
|
+
</xsd:simpleType>
|
34
|
+
</xsd:element>
|
35
|
+
<xsd:element name="lon">
|
36
|
+
<xsd:simpleType>
|
37
|
+
<xsd:restriction base="xsd:double">
|
38
|
+
<xsd:minInclusive value="-180" />
|
39
|
+
<xsd:maxInclusive value="180" />
|
40
|
+
</xsd:restriction>
|
41
|
+
</xsd:simpleType>
|
42
|
+
</xsd:element>
|
43
|
+
<xsd:element minOccurs="0" maxOccurs="1" name="ele" type="xsd:double" />
|
44
|
+
</xsd:sequence>
|
45
|
+
<xsd:attribute name="exposure" use="optional">
|
46
|
+
<xsd:simpleType>
|
47
|
+
<xsd:restriction base="xsd:string">
|
48
|
+
<xsd:enumeration value="indoor" />
|
49
|
+
<xsd:enumeration value="outdoor" />
|
50
|
+
</xsd:restriction>
|
51
|
+
</xsd:simpleType>
|
52
|
+
</xsd:attribute>
|
53
|
+
<xsd:attribute name="domain" use="required">
|
54
|
+
<xsd:simpleType>
|
55
|
+
<xsd:restriction base="xsd:string">
|
56
|
+
<xsd:enumeration value="physical" />
|
57
|
+
<xsd:enumeration value="virtual" />
|
58
|
+
</xsd:restriction>
|
59
|
+
</xsd:simpleType>
|
60
|
+
</xsd:attribute>
|
61
|
+
<xsd:attribute name="disposition" use="optional">
|
62
|
+
<xsd:simpleType>
|
63
|
+
<xsd:restriction base="xsd:string">
|
64
|
+
<xsd:enumeration value="fixed" />
|
65
|
+
<xsd:enumeration value="mobile" />
|
66
|
+
</xsd:restriction>
|
67
|
+
</xsd:simpleType>
|
68
|
+
</xsd:attribute>
|
69
|
+
</xsd:complexType>
|
70
|
+
</xsd:element>
|
71
|
+
<xsd:element minOccurs="1" maxOccurs="unbounded" name="data">
|
72
|
+
<xsd:complexType>
|
73
|
+
<xsd:sequence>
|
74
|
+
<xsd:element minOccurs="0" maxOccurs="unbounded" name="tag" type="xsd:string" />
|
75
|
+
<xsd:element name="value">
|
76
|
+
<xsd:complexType>
|
77
|
+
<xsd:simpleContent>
|
78
|
+
<xsd:extension base="xsd:string">
|
79
|
+
<xsd:attribute name="minValue" type="xsd:string" use="optional" />
|
80
|
+
<xsd:attribute name="maxValue" type="xsd:string" use="optional" />
|
81
|
+
</xsd:extension>
|
82
|
+
</xsd:simpleContent>
|
83
|
+
</xsd:complexType>
|
84
|
+
</xsd:element>
|
85
|
+
<xsd:element minOccurs="0" maxOccurs="1" name="unit">
|
86
|
+
<xsd:complexType>
|
87
|
+
<xsd:simpleContent>
|
88
|
+
<xsd:extension base="xsd:string">
|
89
|
+
<xsd:attribute name="symbol" type="xsd:string" use="optional">
|
90
|
+
</xsd:attribute>
|
91
|
+
<xsd:attribute name="type" use="optional">
|
92
|
+
<xsd:simpleType>
|
93
|
+
<xsd:restriction base="xsd:string">
|
94
|
+
<xsd:enumeration value="basicSI" />
|
95
|
+
<xsd:enumeration value="derivedSI" />
|
96
|
+
<xsd:enumeration value="conversionBasedUnits" />
|
97
|
+
<xsd:enumeration value="derivedUnits" />
|
98
|
+
<xsd:enumeration value="contextDependentUnits" />
|
99
|
+
</xsd:restriction>
|
100
|
+
</xsd:simpleType>
|
101
|
+
</xsd:attribute>
|
102
|
+
</xsd:extension>
|
103
|
+
</xsd:simpleContent>
|
104
|
+
</xsd:complexType>
|
105
|
+
</xsd:element>
|
106
|
+
</xsd:sequence>
|
107
|
+
<xsd:attribute name="id" type="xsd:nonNegativeInteger" use="required" />
|
108
|
+
</xsd:complexType>
|
109
|
+
</xsd:element>
|
110
|
+
</xsd:sequence>
|
111
|
+
<xsd:attribute name="updated" use="optional">
|
112
|
+
<xsd:simpleType>
|
113
|
+
<xsd:restriction base="xsd:dateTime" />
|
114
|
+
</xsd:simpleType>
|
115
|
+
</xsd:attribute>
|
116
|
+
<xsd:attribute fixed="http://www.haque.co.uk" name="creator" use="optional">
|
117
|
+
<xsd:simpleType>
|
118
|
+
<xsd:restriction base="xsd:string" />
|
119
|
+
</xsd:simpleType>
|
120
|
+
</xsd:attribute>
|
121
|
+
<xsd:attribute name="id" type="xsd:nonNegativeInteger" use="optional" />
|
122
|
+
</xsd:complexType>
|
123
|
+
</xsd:element>
|
124
|
+
</xsd:choice>
|
125
|
+
<xsd:attribute name="version" use="optional">
|
126
|
+
<xsd:simpleType>
|
127
|
+
<xsd:restriction base="xsd:positiveInteger">
|
128
|
+
<xsd:enumeration value="5" />
|
129
|
+
</xsd:restriction>
|
130
|
+
</xsd:simpleType>
|
131
|
+
</xsd:attribute>
|
132
|
+
</xsd:complexType>
|
133
|
+
</xsd:element>
|
134
|
+
</xsd:schema>
|
data/resources/key.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), '../lib/pachuber.rb')
|
6
|
+
# The pachube_api_key needs to be your Pachube API key.
|
7
|
+
# I happen to store mine in a key.rb file in resources/.
|
8
|
+
require File.join(File.dirname(__FILE__), '../resources/key.rb')
|
9
|
+
class PachubeTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_pachube_get_xml
|
12
|
+
pach = Pachube.new(pachube_api_key)
|
13
|
+
xml = pach.get_xml("/504.xml")
|
14
|
+
assert xml
|
15
|
+
assert_equal "Pachube Office environment",
|
16
|
+
Nokogiri::XML.parse(xml).css('title').text.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_pachube_get_eeml
|
20
|
+
pach = Pachube.new(pachube_api_key)
|
21
|
+
eeml = pach.get_eeml("/504.xml")
|
22
|
+
assert eeml
|
23
|
+
assert_equal "EEML::Environment", eeml.class.name
|
24
|
+
assert_equal "office", eeml.location.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_pachube_update_post
|
28
|
+
env = EEML::Environment.new
|
29
|
+
env << EEML::Data.new(42, :id => "ABC123")
|
30
|
+
pach = Pachube.new(pachube_api_key)
|
31
|
+
resp = pach.update("/4078.xml", env.to_eeml)
|
32
|
+
assert_equal 200, resp.code
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pachuber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kit Plummer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.5
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: eeml-simple
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
version:
|
35
|
+
description: Just a simple Ruby library to provides Ruby-style abstraction around the HTTP API at Pachube.
|
36
|
+
email: kitplummer@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- Rakefile
|
45
|
+
- README.textile
|
46
|
+
- MIT-LICENSE
|
47
|
+
- lib/pachuber.rb
|
48
|
+
- resources/005.xsd
|
49
|
+
- resources/key.rb
|
50
|
+
- test/pachuber_test.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/kitplummer/pachuber
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements:
|
73
|
+
- none
|
74
|
+
rubyforge_project: pachuber
|
75
|
+
rubygems_version: 1.3.5
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Interact with the Pachube API via HTTParty.
|
79
|
+
test_files: []
|
80
|
+
|