Floppy-amee 0.1.1 → 0.1.2

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 CHANGED
@@ -18,5 +18,13 @@ Homepage: http://github.com/Floppy/amee-ruby
18
18
 
19
19
  == USAGE
20
20
 
21
- Currently, you can only read data categories, items and itemvalues. See
22
- examples/view_data_*.rb for simple usage examples.
21
+ Currently, you can read DataCategories, DataItems and DataItemValues. See
22
+ examples/view_data_*.rb for simple usage examples. You can also get the list
23
+ of available Profiles. See examples/list_profiles.rb for details.
24
+
25
+ == INTERACTIVE SHELL
26
+
27
+ You can use the 'ameesh' app to interactively explore the AMEE data area. Run
28
+ 'ameesh -u USERNAME -p PASSWORD -s SERVER' to try it out. Source code for this
29
+ tool is in bin/ameesh and lib/amee/shell.rb. Profiles are not accessible through
30
+ this interface yet.
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'amee'
3
+ require 'optparse'
4
+
5
+ # Command-line options - get username, password, and server
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.on("-u", "--username USERNAME", "AMEE username") do |u|
9
+ options[:username] = u
10
+ end
11
+ opts.on("-p", "--password PASSWORD", "AMEE password") do |p|
12
+ options[:password] = p
13
+ end
14
+ opts.on("-s", "--server SERVER", "AMEE server") do |s|
15
+ options[:server] = s
16
+ end
17
+ end.parse!
18
+
19
+ # Connect
20
+ connection = AMEE::Connection.new(options[:server], options[:username], options[:password])
21
+
22
+ # List all available profiles
23
+ profiles = AMEE::Profile.list(connection)
24
+ puts "#{profiles.size} #{profiles.size == 1 ? "profile" : "profiles"} available in AMEE:"
25
+ profiles.each do |p|
26
+ puts p.uid
27
+ end
28
+
29
+
data/lib/amee.rb CHANGED
@@ -5,13 +5,14 @@ require 'amee/object'
5
5
  require 'amee/data_category'
6
6
  require 'amee/data_item'
7
7
  require 'amee/data_item_value'
8
+ require 'amee/profile'
8
9
 
9
10
  module AMEE
10
11
 
11
12
  module VERSION #:nodoc:
12
13
  MAJOR = 0
13
14
  MINOR = 1
14
- TINY = 1
15
+ TINY = 2
15
16
  STRING = [MAJOR, MINOR, TINY].join('.')
16
17
  end
17
18
 
@@ -9,6 +9,16 @@ module AMEE
9
9
  @password = password
10
10
  @auth_token = nil
11
11
  raise "Must specify both username and password for authenticated access" if (@username || @password) && !valid?
12
+ # Make connection to server
13
+ @http = Net::HTTP.new(@server)
14
+ #@http.set_debug_output($stdout)
15
+ @http.start
16
+ rescue SocketError
17
+ raise AMEE::ConnectionFailed.new("Connection failed. Check server name or network connection.")
18
+ end
19
+
20
+ def finalize
21
+ @http.finish
12
22
  end
13
23
 
14
24
  def valid?
@@ -25,26 +35,20 @@ module AMEE
25
35
 
26
36
  def get(path)
27
37
  response = nil
28
- http = Net::HTTP.new(@server)
29
- #http.set_debug_output($stdout)
30
- http.start do
31
- get = Net::HTTP::Get.new(path)
38
+ get = Net::HTTP::Get.new(path)
39
+ get['authToken'] = @auth_token
40
+ get['Accept'] = 'application/xml'
41
+ response = @http.request(get)
42
+ # Handle 404s
43
+ raise AMEE::NotFound.new("URL doesn't exist on server.") if response.code == '404'
44
+ # If request fails, authenticate and try again
45
+ if authentication_failed?(response)
46
+ authenticate
32
47
  get['authToken'] = @auth_token
33
- get['Accept'] = 'application/xml'
34
- response = http.request(get)
35
- # Handle 404s
36
- raise AMEE::NotFound.new("URL doesn't exist on server.") if response.code == '404'
37
- # If request fails, authenticate and try again
38
- if authentication_failed?(response)
39
- authenticate
40
- get['authToken'] = @auth_token
41
- response = http.request(get)
42
- end
48
+ response = @http.request(get)
43
49
  end
44
50
  yield response.body if block_given?
45
51
  response.body
46
- rescue SocketError
47
- raise AMEE::ConnectionFailed.new("Connection failed. Check server name or network connection.")
48
52
  end
49
53
 
50
54
  protected
@@ -58,17 +62,12 @@ module AMEE
58
62
  raise AMEE::AuthRequired.new("Authentication required. Please provide your username and password.")
59
63
  end
60
64
  response = nil
61
- http = Net::HTTP.new(@server)
62
- http.start do
63
- post = Net::HTTP::Post.new("/auth")
64
- post.body = "username=#{@username}&password=#{@password}"
65
- post['Accept'] = 'application/xml'
66
- response = http.request(post)
67
- @auth_token = response['authToken']
68
- raise AMEE::AuthFailed.new("Authentication failed. Please check your username and password.") unless authenticated?
69
- end
70
- rescue SocketError
71
- raise AMEE::ConnectionFailed.new("Connection failed. Check server name or network connection.")
65
+ post = Net::HTTP::Post.new("/auth")
66
+ post.body = "username=#{@username}&password=#{@password}"
67
+ post['Accept'] = 'application/xml'
68
+ response = @http.request(post)
69
+ @auth_token = response['authToken']
70
+ raise AMEE::AuthFailed.new("Authentication failed. Please check your username and password.") unless authenticated?
72
71
  end
73
72
 
74
73
  end
@@ -0,0 +1,29 @@
1
+ module AMEE
2
+ class Profile < AMEE::Object
3
+
4
+ def self.list(connection)
5
+ # Load data from path
6
+ response = connection.get('/profiles')
7
+ # Parse data from response into hash
8
+ doc = REXML::Document.new(response)
9
+ profiles = []
10
+ REXML::XPath.each(doc, '/Resources/ProfilesResource/Profiles/Profile') do |p|
11
+ data = {}
12
+ data[:uid] = p.attributes['uid'].to_s
13
+ data[:created] = DateTime.parse(p.attributes['created'].to_s)
14
+ data[:modified] = DateTime.parse(p.attributes['modified'].to_s)
15
+ data[:name] = p.elements['Name'].text || data[:uid]
16
+ data[:path] = p.elements['Path'].text || data[:uid]
17
+ # Create profile
18
+ profile = AMEE::Profile.new(data)
19
+ # Store connection in object for future use
20
+ profile.connection = connection
21
+ # Store in array
22
+ profiles << profile
23
+ end
24
+ # Done
25
+ return profiles
26
+ end
27
+
28
+ end
29
+ 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.1.1
4
+ version: 0.1.2
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-20 00:00:00 -07:00
12
+ date: 2008-07-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,7 +32,9 @@ files:
32
32
  - lib/amee/data_item_value.rb
33
33
  - lib/amee/exceptions.rb
34
34
  - lib/amee/object.rb
35
+ - lib/amee/profile.rb
35
36
  - lib/amee/shell.rb
37
+ - examples/list_profiles.rb
36
38
  - examples/view_data_category.rb
37
39
  - examples/view_data_item.rb
38
40
  has_rdoc: false