communicator 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- communicator (0.1.0)
4
+ communicator (0.1.1)
5
5
  activerecord (< 3.0.0)
6
6
  httparty (>= 0.6.1)
7
7
  json (>= 1.4.0)
8
8
  sinatra (~> 1.1.0)
9
- sinatra-basic-auth
10
9
 
11
10
  GEM
12
11
  remote: http://rubygems.org/
@@ -26,8 +25,6 @@ GEM
26
25
  sinatra (1.1.0)
27
26
  rack (~> 1.1)
28
27
  tilt (~> 1.1)
29
- sinatra-basic-auth (0.1.0)
30
- sinatra
31
28
  sqlite3-ruby (1.3.2)
32
29
  tilt (1.1)
33
30
 
@@ -44,5 +41,4 @@ DEPENDENCIES
44
41
  rack-test (>= 0.5.6)
45
42
  shoulda (= 2.10.3)
46
43
  sinatra (~> 1.1.0)
47
- sinatra-basic-auth
48
44
  sqlite3-ruby (>= 1.3.0)
@@ -20,8 +20,38 @@ migrations from the gem:
20
20
  $ rake communicator:update_migrations
21
21
  $ rake db:migrate
22
22
 
23
- After doing these steps, you can proceed to configure either the server or client
24
- side as specified in the following subsections.
23
+ After doing these steps, you can proceed to configure either the server or client.
24
+ On both sides, you'll have to configure the client and server. You can do so
25
+ by placing a configuration file in Rails.root/config/communicator.yml that looks
26
+ somewhat like this:
27
+
28
+ defaults: &defaults
29
+ username: communicator
30
+ password: verysecret
31
+ base_uri: localhost:3001 # Can be ommitted for server config
32
+
33
+ test:
34
+ <<: *defaults
35
+
36
+ development:
37
+ <<: *defaults
38
+
39
+ production:
40
+ <<: *defaults
41
+ password: Uber!Secret
42
+ base_uri: 192.168.0.104:4000 # Can be ommitted for server config
43
+
44
+ The configuration for the current `Rails.env` will then be automatically loaded
45
+ when you `require 'communicator'`.
46
+
47
+ You can also skip the YAML configuration and set up the credentials programmatically:
48
+
49
+ Communicator::Server.username = 'foo'
50
+ Communicator::Server.password = 'bar'
51
+
52
+ Communicator::Client.username = 'foo'
53
+ Communicator::Client.password = 'bar'
54
+ Communicator::Client.base_uri 'localhost:1234'
25
55
 
26
56
  == Server side
27
57
 
@@ -29,8 +59,6 @@ On the server side, you can mount the server component in a Rails 2.3 app
29
59
  as a rack middleware inside environment.rb:
30
60
 
31
61
  require 'communicator'
32
- Communicator::Server.username = 'foo'
33
- Communicator::Server.password = 'bar'
34
62
  config.middleware.use 'Communicator::Server'
35
63
 
36
64
  It will then be mounted at /messages.json for GET and POST requests, requesting
@@ -42,9 +70,6 @@ Tell the client the server url and port as well as the auth credentials inside
42
70
  your environment.rb:
43
71
 
44
72
  require 'communicator'
45
- Communicator::Client.username = 'test'
46
- Communicator::Client.password = 'test'
47
- Communicator::Client.base_uri 'localhost:3001'
48
73
 
49
74
  When everything's fine, you should be able to push and pull using the client:
50
75
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{communicator}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Christoph Olszowka"]
12
- s.date = %q{2010-11-03}
12
+ s.date = %q{2010-11-04}
13
13
  s.description = %q{Data push/pull between apps with local inbound/outbound queue and easy publish/process interface}
14
14
  s.email = %q{christoph at olszowka de}
15
15
  s.extra_rdoc_files = [
@@ -51,4 +51,16 @@ require 'communicator/server'
51
51
  require 'communicator/client'
52
52
  require 'communicator/active_record_integration'
53
53
  require 'communicator/outbound_message'
54
- require 'communicator/inbound_message'
54
+ require 'communicator/inbound_message'
55
+
56
+ # Autoload config when present for rails
57
+ if defined?(Rails)
58
+ config_path = File.join(Rails.root, 'config', 'communicator.yml')
59
+ if File.exist?(config_path)
60
+ config = YAML.load_file(config_path).with_indifferent_access[Rails.env]
61
+ puts "Config file for communicator found, but does not have configuration for env #{Rails.env}" unless config.kind_of?(Hash)
62
+ Communicator::Server.username = Communicator::Client.username = config[:username]
63
+ Communicator::Server.password = Communicator::Client.password = config[:password]
64
+ Communicator::Client.base_uri config[:base_uri]
65
+ end
66
+ end
@@ -16,10 +16,6 @@ class Communicator::Server < Sinatra::Base
16
16
  end
17
17
  end
18
18
 
19
- # use Rack::Auth::Basic do |username, password|
20
- # [username, password] == [Communicator::Server.username, Communicator::Server.password]
21
- # end
22
-
23
19
  helpers do
24
20
  def protected!
25
21
  unless authorized?
@@ -27,7 +23,7 @@ class Communicator::Server < Sinatra::Base
27
23
  throw(:halt, [401, "Not authorized\n"])
28
24
  end
29
25
  end
30
-
26
+
31
27
  def authorized?
32
28
  @auth ||= Rack::Auth::Basic::Request.new(request.env)
33
29
  @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [Communicator::Server.username, Communicator::Server.password]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: communicator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christoph Olszowka
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-03 00:00:00 +01:00
18
+ date: 2010-11-04 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency