Floppy-amee 0.2.1 → 0.2.3
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/README +2 -1
- data/examples/create_profile.rb +27 -0
- data/lib/amee.rb +2 -0
- data/lib/amee/connection.rb +26 -1
- data/lib/amee/data_category.rb +1 -1
- data/lib/amee/data_item.rb +1 -1
- data/lib/amee/data_item_value.rb +3 -3
- data/lib/amee/data_object.rb +9 -0
- data/lib/amee/object.rb +0 -4
- data/lib/amee/profile.rb +46 -6
- data/lib/amee/profile_object.rb +9 -0
- metadata +6 -3
data/README
CHANGED
@@ -20,7 +20,8 @@ Homepage: http://github.com/Floppy/amee-ruby
|
|
20
20
|
|
21
21
|
Currently, you can read DataCategories, DataItems and DataItemValues. See
|
22
22
|
examples/view_data_*.rb for simple usage examples. You can also get the list
|
23
|
-
of available Profiles. See examples/list_profiles.rb
|
23
|
+
of available Profiles and create new ones. See examples/list_profiles.rb and
|
24
|
+
examples/create_profile.rb for details.
|
24
25
|
|
25
26
|
The gem will use the AMEE JSON API if the JSON gem is installed on the local
|
26
27
|
system. Otherwise the XML API will be used.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
dir = File.dirname(__FILE__) + '/../lib'
|
2
|
+
$LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
|
3
|
+
|
4
|
+
#require 'rubygems'
|
5
|
+
require 'amee'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
# Command-line options - get username, password, and server
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.on("-u", "--username USERNAME", "AMEE username") do |u|
|
12
|
+
options[:username] = u
|
13
|
+
end
|
14
|
+
opts.on("-p", "--password PASSWORD", "AMEE password") do |p|
|
15
|
+
options[:password] = p
|
16
|
+
end
|
17
|
+
opts.on("-s", "--server SERVER", "AMEE server") do |s|
|
18
|
+
options[:server] = s
|
19
|
+
end
|
20
|
+
end.parse!
|
21
|
+
|
22
|
+
# Connect
|
23
|
+
connection = AMEE::Connection.new(options[:server], options[:username], options[:password])
|
24
|
+
|
25
|
+
# Create a new profile
|
26
|
+
profile = AMEE::Profile.create(connection)
|
27
|
+
puts "#{profile.uid} created"
|
data/lib/amee.rb
CHANGED
@@ -17,6 +17,8 @@ require 'amee/version'
|
|
17
17
|
require 'amee/exceptions'
|
18
18
|
require 'amee/connection'
|
19
19
|
require 'amee/object'
|
20
|
+
require 'amee/data_object'
|
21
|
+
require 'amee/profile_object'
|
20
22
|
require 'amee/data_category'
|
21
23
|
require 'amee/data_item'
|
22
24
|
require 'amee/data_item_value'
|
data/lib/amee/connection.rb
CHANGED
@@ -52,7 +52,32 @@ module AMEE
|
|
52
52
|
response.body
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
def post(path, data = {})
|
56
|
+
response = nil
|
57
|
+
post = Net::HTTP::Post.new(path)
|
58
|
+
post['authToken'] = @auth_token
|
59
|
+
post['Accept'] = content_type
|
60
|
+
# Add data params to body
|
61
|
+
body = []
|
62
|
+
data.each_pair do |key, value|
|
63
|
+
body << "#{key}=#{value}"
|
64
|
+
end
|
65
|
+
post.body = body.join '&'
|
66
|
+
# Send request
|
67
|
+
response = @http.request(post)
|
68
|
+
# Handle 404s
|
69
|
+
raise AMEE::NotFound.new("URL doesn't exist on server.") if response.code == '404'
|
70
|
+
# If request fails, authenticate and try again
|
71
|
+
if authentication_failed?(response)
|
72
|
+
authenticate
|
73
|
+
post['authToken'] = @auth_token
|
74
|
+
response = @http.request(post)
|
75
|
+
end
|
76
|
+
yield response.body if block_given?
|
77
|
+
response.body
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
56
81
|
|
57
82
|
def content_type
|
58
83
|
(@use_json_if_available && defined?(JSON)) ? 'application/json' : 'application/xml'
|
data/lib/amee/data_category.rb
CHANGED
data/lib/amee/data_item.rb
CHANGED
data/lib/amee/data_item_value.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module AMEE
|
2
2
|
module Data
|
3
|
-
class ItemValue < AMEE::
|
3
|
+
class ItemValue < AMEE::DataObject
|
4
4
|
|
5
5
|
def initialize(data = {})
|
6
6
|
@value = data ? data[:value] : nil
|
@@ -37,7 +37,7 @@ module AMEE
|
|
37
37
|
data[:created] = DateTime.parse(doc['created'])
|
38
38
|
data[:modified] = DateTime.parse(doc['modified'])
|
39
39
|
data[:name] = doc['name']
|
40
|
-
data[:path] = path
|
40
|
+
data[:path] = path.gsub(/^\/data/, '')
|
41
41
|
data[:value] = doc['value']
|
42
42
|
data[:type] = doc['itemValueDefinition']['valueDefinition']['valueType']
|
43
43
|
# Create object
|
@@ -54,7 +54,7 @@ module AMEE
|
|
54
54
|
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@Created").to_s)
|
55
55
|
data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@Modified").to_s)
|
56
56
|
data[:name] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/Name').text
|
57
|
-
data[:path] = path
|
57
|
+
data[:path] = path.gsub(/^\/data/, '')
|
58
58
|
data[:value] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/Value').text
|
59
59
|
data[:type] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/ValueDefinition/ValueType').text
|
60
60
|
data[:from_profile] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/FromProfile').text == "true" ? true : false
|
data/lib/amee/object.rb
CHANGED
data/lib/amee/profile.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module AMEE
|
2
|
-
class Profile < AMEE::
|
2
|
+
class Profile < AMEE::ProfileObject
|
3
3
|
|
4
4
|
def self.list(connection)
|
5
5
|
# Load data from path
|
@@ -15,11 +15,9 @@ module AMEE
|
|
15
15
|
data[:created] = DateTime.parse(p['created'])
|
16
16
|
data[:modified] = DateTime.parse(p['modified'])
|
17
17
|
data[:name] = p['name']
|
18
|
-
data[:path] = p['path']
|
18
|
+
data[:path] = "/#{p['path']}"
|
19
19
|
# Create profile
|
20
20
|
profile = AMEE::Profile.new(data)
|
21
|
-
# Store connection in object for future use
|
22
|
-
profile.connection = connection
|
23
21
|
# Store in array
|
24
22
|
profiles << profile
|
25
23
|
end
|
@@ -32,10 +30,10 @@ module AMEE
|
|
32
30
|
data[:created] = DateTime.parse(p.attributes['created'].to_s)
|
33
31
|
data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
|
34
32
|
data[:name] = p.elements['Name'].text || data[:uid]
|
35
|
-
data[:path] = p.elements['Path'].text || data[:uid]
|
33
|
+
data[:path] = "/#{p.elements['Path'].text || data[:uid]}"
|
36
34
|
# Create profile
|
37
35
|
profile = AMEE::Profile.new(data)
|
38
|
-
# Store connection in object
|
36
|
+
# Store connection in profile object
|
39
37
|
profile.connection = connection
|
40
38
|
# Store in array
|
41
39
|
profiles << profile
|
@@ -45,5 +43,47 @@ module AMEE
|
|
45
43
|
return profiles
|
46
44
|
end
|
47
45
|
|
46
|
+
def self.create(connection)
|
47
|
+
# Create new profile
|
48
|
+
response = connection.post('/profiles', :profile => true)
|
49
|
+
# Parse data from response
|
50
|
+
if response.is_json?
|
51
|
+
# Read JSON
|
52
|
+
doc = JSON.parse(response)
|
53
|
+
p = doc['profile']
|
54
|
+
data = {}
|
55
|
+
data[:uid] = p['uid']
|
56
|
+
data[:created] = DateTime.parse(p['created'])
|
57
|
+
data[:modified] = DateTime.parse(p['modified'])
|
58
|
+
data[:name] = p['name']
|
59
|
+
data[:path] = p['path']
|
60
|
+
# Create profile
|
61
|
+
profile = AMEE::Profile.new(data)
|
62
|
+
# Done
|
63
|
+
return profile
|
64
|
+
else
|
65
|
+
# Read XML
|
66
|
+
doc = REXML::Document.new(response)
|
67
|
+
p = REXML::XPath.first(doc, '/Resources/ProfilesResource/Profile')
|
68
|
+
data = {}
|
69
|
+
data[:uid] = p.attributes['uid'].to_s
|
70
|
+
data[:created] = DateTime.parse(p.attributes['created'].to_s)
|
71
|
+
data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
|
72
|
+
data[:name] = p.elements['Name'].text || data[:uid]
|
73
|
+
data[:path] = p.elements['Path'].text || data[:uid]
|
74
|
+
# Create profile
|
75
|
+
profile = AMEE::Profile.new(data)
|
76
|
+
# Store connection in profile object
|
77
|
+
profile.connection = connection
|
78
|
+
# Done
|
79
|
+
return profile
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def delete
|
84
|
+
# Create new profile
|
85
|
+
response = connection.delete(full_path)
|
86
|
+
end
|
87
|
+
|
48
88
|
end
|
49
89
|
end
|
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.2.
|
4
|
+
version: 0.2.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-08-
|
12
|
+
date: 2008-08-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -29,16 +29,19 @@ files:
|
|
29
29
|
- lib/amee/data_item.rb
|
30
30
|
- lib/amee/exceptions.rb
|
31
31
|
- lib/amee/profile.rb
|
32
|
+
- lib/amee/profile_object.rb
|
32
33
|
- lib/amee/version.rb
|
33
34
|
- lib/amee/data_category.rb
|
34
35
|
- lib/amee/data_item_value.rb
|
36
|
+
- lib/amee/data_object.rb
|
35
37
|
- lib/amee/object.rb
|
36
38
|
- lib/amee/shell.rb
|
37
39
|
- bin/ameesh
|
38
40
|
- examples/list_profiles.rb
|
41
|
+
- examples/create_profile.rb
|
39
42
|
- examples/view_data_category.rb
|
40
43
|
- examples/view_data_item.rb
|
41
|
-
has_rdoc:
|
44
|
+
has_rdoc: true
|
42
45
|
homepage: http://github.com/Floppy/amee-ruby
|
43
46
|
post_install_message:
|
44
47
|
rdoc_options: []
|