Floppy-amee 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -3
- data/lib/amee/connection.rb +12 -3
- data/lib/amee/data_category.rb +2 -0
- data/lib/amee/data_item.rb +2 -0
- data/lib/amee/data_item_value.rb +22 -0
- data/lib/amee.rb +2 -1
- metadata +2 -2
data/README
CHANGED
@@ -10,7 +10,7 @@ Homepage: http://github.com/Floppy/amee-ruby
|
|
10
10
|
|
11
11
|
== INSTALLATION
|
12
12
|
|
13
|
-
1) Enable gems from github, if you haven't already done so:
|
13
|
+
1) Enable gems from github, if you haven't already done so (rubygems >= 1.2):
|
14
14
|
> sudo gem sources -a http://gems.github.com
|
15
15
|
|
16
16
|
2) Install gem
|
@@ -18,5 +18,5 @@ Homepage: http://github.com/Floppy/amee-ruby
|
|
18
18
|
|
19
19
|
== USAGE
|
20
20
|
|
21
|
-
Currently,
|
22
|
-
examples/
|
21
|
+
Currently, you can only read data categories, items and itemvalues. See
|
22
|
+
examples/view_data_*.rb for simple usage examples.
|
data/lib/amee/connection.rb
CHANGED
@@ -32,6 +32,8 @@ module AMEE
|
|
32
32
|
get['authToken'] = @auth_token
|
33
33
|
get['Accept'] = 'application/xml'
|
34
34
|
response = http.request(get)
|
35
|
+
# Handle 404s
|
36
|
+
raise AMEE::NotFound.new("URL doesn't exist on server.") if response.code == '404'
|
35
37
|
# If request fails, authenticate and try again
|
36
38
|
if authentication_failed?(response)
|
37
39
|
authenticate
|
@@ -41,6 +43,8 @@ module AMEE
|
|
41
43
|
end
|
42
44
|
yield response.body if block_given?
|
43
45
|
response.body
|
46
|
+
rescue SocketError
|
47
|
+
raise AMEE::ConnectionFailed.new("Connection failed. Check server name or network connection.")
|
44
48
|
end
|
45
49
|
|
46
50
|
protected
|
@@ -51,15 +55,20 @@ module AMEE
|
|
51
55
|
|
52
56
|
def authenticate
|
53
57
|
unless can_authenticate?
|
54
|
-
raise "
|
58
|
+
raise AMEE::AuthRequired.new("Authentication required. Please provide your username and password.")
|
55
59
|
end
|
56
60
|
response = nil
|
57
61
|
http = Net::HTTP.new(@server)
|
58
62
|
http.start do
|
59
|
-
|
63
|
+
post = Net::HTTP::Post.new("/auth")
|
64
|
+
post.body = "username=#{@username}&password=#{@password}"
|
65
|
+
post['Accept'] = 'application/xml'
|
66
|
+
response = http.request(post)
|
60
67
|
@auth_token = response['authToken']
|
61
|
-
raise "
|
68
|
+
raise AMEE::AuthFailed.new("Authentication failed. Please check your username and password.") unless authenticated?
|
62
69
|
end
|
70
|
+
rescue SocketError
|
71
|
+
raise AMEE::ConnectionFailed.new("Connection failed. Check server name or network connection.")
|
63
72
|
end
|
64
73
|
|
65
74
|
end
|
data/lib/amee/data_category.rb
CHANGED
data/lib/amee/data_item.rb
CHANGED
data/lib/amee/data_item_value.rb
CHANGED
@@ -9,6 +9,28 @@ module AMEE
|
|
9
9
|
|
10
10
|
attr_reader :value
|
11
11
|
|
12
|
+
def self.get(connection, path)
|
13
|
+
# Load data from path
|
14
|
+
response = connection.get(path)
|
15
|
+
# Parse data from response into hash
|
16
|
+
doc = REXML::Document.new(response)
|
17
|
+
data = {}
|
18
|
+
data[:uid] = REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@uid").to_s
|
19
|
+
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@Created").to_s)
|
20
|
+
data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@Modified").to_s)
|
21
|
+
data[:name] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/Name').text
|
22
|
+
data[:path] = path
|
23
|
+
data[:value] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/Value').text
|
24
|
+
# Create item object
|
25
|
+
item = ItemValue.new(data)
|
26
|
+
# Store connection in object for future use
|
27
|
+
item.connection = connection
|
28
|
+
# Done
|
29
|
+
return item
|
30
|
+
rescue
|
31
|
+
raise AMEE::BadData.new("Couldn't load DataItemValue. Check that your URL is correct.")
|
32
|
+
end
|
33
|
+
|
12
34
|
end
|
13
35
|
end
|
14
36
|
end
|
data/lib/amee.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rexml/document'
|
2
|
+
require 'amee/exceptions'
|
2
3
|
require 'amee/connection'
|
3
4
|
require 'amee/object'
|
4
5
|
require 'amee/data_category'
|
@@ -10,7 +11,7 @@ module AMEE
|
|
10
11
|
module VERSION #:nodoc:
|
11
12
|
MAJOR = 0
|
12
13
|
MINOR = 0
|
13
|
-
TINY =
|
14
|
+
TINY = 3
|
14
15
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
15
16
|
end
|
16
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Floppy-amee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-07-
|
12
|
+
date: 2008-07-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|