communicator 0.1.5 → 0.1.6

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- communicator (0.1.2)
4
+ communicator (0.1.5)
5
5
  activerecord (< 3.0.0)
6
6
  httparty (>= 0.6.1)
7
7
  json (>= 1.4.0)
@@ -15,12 +15,21 @@ GEM
15
15
  activesupport (2.3.10)
16
16
  crack (0.1.8)
17
17
  factory_girl (1.3.2)
18
+ gemcutter (0.6.1)
19
+ git (1.2.5)
18
20
  httparty (0.6.1)
19
21
  crack (= 0.1.8)
22
+ jeweler (1.4.0)
23
+ gemcutter (>= 0.1.0)
24
+ git (>= 1.2.5)
25
+ rubyforge (>= 2.0.0)
20
26
  json (1.4.6)
27
+ json_pure (1.4.6)
21
28
  rack (1.2.1)
22
29
  rack-test (0.5.6)
23
30
  rack (>= 1.0)
31
+ rubyforge (2.0.4)
32
+ json_pure (>= 1.1.7)
24
33
  shoulda (2.10.3)
25
34
  sinatra (1.1.0)
26
35
  rack (~> 1.1)
@@ -37,6 +46,7 @@ DEPENDENCIES
37
46
  communicator!
38
47
  factory_girl (>= 1.2.3)
39
48
  httparty (>= 0.6.1)
49
+ jeweler (>= 1.4.0)
40
50
  json (>= 1.4.0)
41
51
  rack-test (>= 0.5.6)
42
52
  shoulda (= 2.10.3)
data/Rakefile CHANGED
@@ -14,7 +14,6 @@ begin
14
14
  gem.add_dependency 'activerecord', "< 3.0.0"
15
15
  gem.add_dependency 'httparty', '>= 0.6.1'
16
16
  gem.add_dependency 'json', '>= 1.4.0'
17
-
18
17
  gem.add_development_dependency "shoulda", "2.10.3"
19
18
  gem.add_development_dependency 'factory_girl', ">= 1.2.3"
20
19
  gem.add_development_dependency 'rack-test', ">= 0.5.6"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
data/communicator.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{communicator}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
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"]
data/lib/communicator.rb CHANGED
@@ -11,7 +11,20 @@ module Communicator
11
11
  # Error to be raised when no credentials were given
12
12
  class MissingCredentials < StandardError; end;
13
13
 
14
+ # Fake logger to be returned as Communicator.logger when Rails is unavailable
15
+ class FakeLogger
16
+ class << self
17
+ def method_missing(*args, &blk)
18
+ true
19
+ end
20
+ end
21
+ end
22
+
14
23
  class << self
24
+ def logger
25
+ defined?(Rails) ? Rails.logger : Communicator::FakeLogger
26
+ end
27
+
15
28
  # Hash containing all receivers
16
29
  def receivers
17
30
  @recevers ||= {}.with_indifferent_access
@@ -25,6 +38,7 @@ module Communicator
25
38
  target.send(:include, Communicator::ActiveRecordIntegration::InstanceMethods)
26
39
 
27
40
  target.skip_remote_attributes(*options[:except]) if options[:except]
41
+ Communicator.logger.info "Registered #{target} as receiver for messages from #{source}"
28
42
 
29
43
  target
30
44
  end
@@ -62,5 +76,6 @@ if defined?(Rails)
62
76
  Communicator::Server.username = Communicator::Client.username = config[:username]
63
77
  Communicator::Server.password = Communicator::Client.password = config[:password]
64
78
  Communicator::Client.base_uri config[:base_uri]
79
+ Communicator.logger.info "Set up communicator from yaml config"
65
80
  end
66
81
  end
@@ -30,12 +30,15 @@ module Communicator::ActiveRecordIntegration
30
30
 
31
31
  # Publishes this instance as an OutboundMessage with json representation as body
32
32
  def publish
33
- Communicator::OutboundMessage.create!(:body => {self.class.to_s.underscore => attributes}.to_json)
33
+ msg = Communicator::OutboundMessage.create!(:body => {self.class.to_s.underscore => attributes}.to_json)
34
+ Communicator.logger.info "Publishing updates for #{self.class} ##{id}"
35
+ msg
34
36
  end
35
37
 
36
38
  # Processes the given message body by applying all contained attributes and their values
37
39
  # and saving. When the setter instance method is missing on the local record, skip that attribute.
38
40
  def process_message(input)
41
+ Communicator.logger.info "Processing json message content on #{self.class} ##{id}"
39
42
  # When the input is still json, parse it. Otherwise we're assuming it's already a demarshalled hash
40
43
  input = JSON.parse(input) if input.kind_of?(String)
41
44
  input.each do |attr_name, value|
@@ -16,6 +16,7 @@ class Communicator::InboundMessage < ActiveRecord::Base
16
16
  inbound_msg = Communicator::InboundMessage.new(:body => json_message["body"])
17
17
  inbound_msg.id = json_message["id"]
18
18
  inbound_msg.save!
19
+ Communicator.logger.info "Created inbound message from json, local id is #{inbound_msg.id}"
19
20
  inbound_msg
20
21
  end
21
22
 
@@ -37,15 +38,19 @@ class Communicator::InboundMessage < ActiveRecord::Base
37
38
  end
38
39
 
39
40
  def message_content
40
- JSON.parse(body).with_indifferent_access
41
+ @message_content ||= JSON.parse(body).with_indifferent_access
41
42
  end
42
43
 
43
44
  # Figure out who is the receiver of this message and process the message
44
45
  def process!
45
- return if processed_at.present? # Do not process if already processed!
46
+ if processed_at.present? # Do not process if already processed!
47
+ Communicator.logger.info "InboundMessage #{id} has already been processed, not processing again!"
48
+ return false
49
+ end
46
50
  source, content = message_content.first
47
51
  Communicator.receiver_for(source).find_or_initialize_by_id(content["id"]).process_message(content)
48
52
  self.processed_at = Time.now
49
53
  self.save!
54
+ Communicator.logger.info "Processed inbound message #{id} successfully"
50
55
  end
51
56
  end
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: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christoph Olszowka