Floppy-amee 0.2.3 → 0.3.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.
Files changed (5) hide show
  1. data/README +18 -0
  2. data/init.rb +1 -0
  3. data/lib/amee/connection.rb +10 -10
  4. data/rails/init.rb +23 -0
  5. metadata +4 -2
data/README CHANGED
@@ -32,3 +32,21 @@ You can use the 'ameesh' app to interactively explore the AMEE data area. Run
32
32
  'ameesh -u USERNAME -p PASSWORD -s SERVER' to try it out. Source code for this
33
33
  tool is in bin/ameesh and lib/amee/shell.rb. Profiles are not accessible through
34
34
  this interface yet.
35
+
36
+ == RAILS
37
+
38
+ This gem can be used as a Rails plugin. You can either extract it into
39
+ vendor/plugins, or use the new-style config.gem command in environment.rb. For
40
+ example:
41
+
42
+ config.gem "Floppy-amee", :lib => "amee", :source => "http://gems.github.com"
43
+
44
+ The first time you run your app after installing the gem, a config/amee.yml file
45
+ will be created. You should edit this file and add your AMEE username and
46
+ password to it, as well as the server you want to connect to.
47
+
48
+ Once that is all set up, you can use AMEE objects within Rails anywhere you like.
49
+ There is a persistent AMEE connection available called $amee, which you can pass
50
+ into the other objects to fetch data. For instance:
51
+
52
+ data = AMEE::Data::Category.root($amee)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
@@ -77,16 +77,6 @@ module AMEE
77
77
  response.body
78
78
  end
79
79
 
80
- protected
81
-
82
- def content_type
83
- (@use_json_if_available && defined?(JSON)) ? 'application/json' : 'application/xml'
84
- end
85
-
86
- def authentication_failed?(response)
87
- response.code == '401'
88
- end
89
-
90
80
  def authenticate
91
81
  unless can_authenticate?
92
82
  raise AMEE::AuthRequired.new("Authentication required. Please provide your username and password.")
@@ -99,6 +89,16 @@ module AMEE
99
89
  @auth_token = response['authToken']
100
90
  raise AMEE::AuthFailed.new("Authentication failed. Please check your username and password.") unless authenticated?
101
91
  end
92
+
93
+ protected
94
+
95
+ def content_type
96
+ (@use_json_if_available && defined?(JSON)) ? 'application/json' : 'application/xml'
97
+ end
102
98
 
99
+ def authentication_failed?(response)
100
+ response.code == '401'
101
+ end
102
+
103
103
  end
104
104
  end
data/rails/init.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'amee'
2
+
3
+ # Load config/amee.yml
4
+ amee_config = "#{RAILS_ROOT}/config/amee.yml"
5
+ if File.exist?(amee_config)
6
+ # Load config
7
+ AMEE_CONFIG = YAML.load_file(amee_config)[RAILS_ENV]
8
+ # Create a global AMEE connection that we can use from anywhere in this app
9
+ $amee = AMEE::Connection.new(AMEE_CONFIG['server'], AMEE_CONFIG['username'], AMEE_CONFIG['password'])
10
+ # Authenticate now to get it out of the way and to check settings
11
+ $amee.authenticate
12
+ else
13
+ # Create an example AMEE config file and save it to config/amee.yml
14
+ example_config = {}
15
+ example_config['development'] = {'server' => "stage.co2.dgen.net", 'username' => "your_amee_username", 'password' => "your_amee_password"}
16
+ example_config['production'] = {'server' => "stage.co2.dgen.net", 'username' => "your_amee_username", 'password' => "your_amee_password"}
17
+ example_config['test'] = {'server' => "stage.co2.dgen.net", 'username' => "your_amee_username", 'password' => "your_amee_password"}
18
+ File.open(amee_config, 'w') do |out|
19
+ YAML.dump(example_config, out)
20
+ end
21
+ # Inform the user that we've written a file for them
22
+ raise AMEE::ConnectionFailed.new("config/amee.yml doesn't exist. I've created one for you - please add your API keys to it.")
23
+ 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.3
4
+ version: 0.3.0
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-20 00:00:00 -07:00
12
+ date: 2008-08-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,6 +41,8 @@ files:
41
41
  - examples/create_profile.rb
42
42
  - examples/view_data_category.rb
43
43
  - examples/view_data_item.rb
44
+ - init.rb
45
+ - rails/init.rb
44
46
  has_rdoc: true
45
47
  homepage: http://github.com/Floppy/amee-ruby
46
48
  post_install_message: