courier 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
data/courier.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{courier}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Danil Pismenny"]
12
- s.date = %q{2011-04-05}
12
+ s.date = %q{2011-04-19}
13
13
  s.description = %q{Система управления пользовательскими оповещениями и подписками}
14
14
  s.email = %q{danil@orionet.ru}
15
15
  s.extra_rdoc_files = [
@@ -67,7 +67,7 @@ Gem::Specification.new do |s|
67
67
  s.homepage = %q{http://github.com/dapi/courier}
68
68
  s.licenses = ["MIT"]
69
69
  s.require_paths = ["lib"]
70
- s.rubygems_version = %q{1.6.1}
70
+ s.rubygems_version = %q{1.6.2}
71
71
  s.summary = %q{Система управления пользовательскими оповещениями и подписками}
72
72
  s.test_files = [
73
73
  "spec/controllers/courier_settings_controller_spec.rb",
@@ -26,7 +26,7 @@ class Courier::Config
26
26
 
27
27
  def get_service name
28
28
  name=name.to_sym
29
- services_hash[name] or raise "No such service '#{name}'"
29
+ services_hash[name] or raise "No such service '#{name}'. Specify it by Courier.init in ./config/initializers/courier.rb"
30
30
  end
31
31
 
32
32
  def template name, *sets
@@ -42,7 +42,7 @@ class Courier::Config
42
42
  end
43
43
 
44
44
  def get_template key
45
- templates_hash[key.to_sym] or raise "No such template '#{key}'"
45
+ templates_hash[key.to_sym] or raise "No such template '#{key}'. Specify it by Courier.init in ./config/initializers/courier.rb"
46
46
  end
47
47
 
48
48
  def class_of_service(name)
data/lib/courier/owner.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
-
4
- # # Courier::Sender (extenstion для AR-модели пользователя-отправителя)
5
-
6
- # Подключается через `acts_as_sender` дает модели метод `message(key, options)`. Пример вызова:
7
-
3
+ # Подключается через `has_courier` дает модели метод `message(key, options)`. Пример вызова:
4
+ #
8
5
  # @@@
9
- # user.notify :comments_in_my_plan, :comments=>@comments, :level=>:success
10
- # user.notify_failure :cant_import_plans, :provider=>:facebook
6
+ # user.message :comments_in_my_plan, :comments=>@comments, :level=>:success
11
7
  # @@@
12
8
 
13
9
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  class Courier::Service::Facebook < Courier::Service::Base
4
4
 
5
+ FACEBOOK_PROPERTY_ATTRS = [:from, :to, :picture, :link, :name, :caption, :description, :message,
6
+ :source, :icon, :attribution, :actions, :privacy, :targeting]
7
+
5
8
  def initialize
6
9
  raise "No Koala defined. Add gem 'koala' to your Gemfile. " unless defined? Koala
7
10
  attr_accessor={}
@@ -13,15 +16,22 @@ class Courier::Service::Facebook < Courier::Service::Base
13
16
  # http://developers.facebook.com/docs/reference/api/post/
14
17
  #
15
18
  def deliver_message(message)
16
- message.owner.respond_to?(:facebook_token) or
17
- raise "method facebook_token is not defined in your owner's model #{owner.class}"
18
- token = message.owner.facebook_token or raise "owner's facebook_token is empty"
19
-
20
- unless args = message.options[:facebook_properties]
21
- args = message.options.slice(:from, :to, :picture, :link, :name, :caption, :message,
22
- :description, :source, :icon, :attribution, :actions, :privacy, :targeting)
23
- end
24
- args[:message] ||= message.options[:text] || Courier.template(message.template).get_text(message.service, message.options)
25
- Koala::Facebook::GraphAPI.new(token).put_object(args[:to] || 'me', "feed", args)
19
+ return true unless message.owner.facebook_id
20
+
21
+ args = message.options[:facebook_properties] || message.options.slice(FACEBOOK_PROPERTY_ATTRS)
22
+
23
+ args[:message] ||= message.options[:text] || Courier.template(message.template).
24
+ get_text(message.service, message.options)
25
+
26
+ token = args[:token]
27
+ token ||= message.owner.facebook_token if message.owner.respond_to?(:facebook_token)
28
+
29
+ return nil unless token
30
+
31
+ to = args[:to] || (message.owner.respond_to?(:facebook_id) ? message.owner.facebook_id : nil) || 'me'
32
+
33
+ # Settings.omniauth.facebook.app_id, Settings.omniauth.facebook.secret
34
+ # Это post_on_wall
35
+ Koala::Facebook::GraphAPI.new(token).put_object(to, "feed", args)
26
36
  end
27
37
  end
@@ -8,10 +8,4 @@ describe Courier::Message do
8
8
  it { should validate_presence_of(:owner) }
9
9
  it { should validate_presence_of(:service) }
10
10
  it { should validate_presence_of(:template) }
11
-
12
- describe do
13
- before do
14
- pending
15
- end
16
- end
17
11
  end
@@ -3,19 +3,30 @@ require 'spec_helper'
3
3
 
4
4
  describe Courier::Service::Facebook do
5
5
  describe '#deliver!' do
6
+ before do
7
+ @owner = mock_owner :facebook_id=>123
8
+ end
9
+ let(:owner) { @owner }
10
+ let(:message) { mock_message :owner=>owner, :options=>{:text=>'text'} }
11
+
6
12
  it 'posts messages with Koala' do
7
- owner = mock_owner :facebook_token=>'fbtoken'
13
+ owner.stub(:facebook_token) { 'fbtoken' }
8
14
 
9
- message = mock_message :owner=>owner, :options=>{:text=>'text'}
10
15
  message.should_receive(:mark_as_delivered!)
11
16
 
12
17
  graph = double
13
- graph.should_receive(:put_object).
14
- with('me','feed',{:message=>'text'}) { true }
18
+ graph.should_receive(:put_object).with(123,'feed',{:message=>'text'}) { true }
15
19
  Koala::Facebook::GraphAPI.should_receive(:new).with('fbtoken') { graph }
16
20
 
17
21
  subject.stub_chain('messages.fresh') { [message] }
18
22
  subject.deliver_all!
19
23
  end
24
+
25
+ it 'do nothing if there is no token' do
26
+ Koala::Facebook::GraphAPI.should_not_receive(:new)
27
+
28
+ subject.stub_chain('messages.fresh') { [message] }
29
+ subject.deliver_all!
30
+ end
20
31
  end
21
32
  end
@@ -5,7 +5,8 @@ module GritterNotices end
5
5
 
6
6
  module Koala
7
7
  module Facebook
8
- module GraphAPI end
8
+ class GraphAPI
9
9
  end
10
+ end
10
11
  end
11
12
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: courier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Danil Pismenny
@@ -15,10 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-05 00:00:00 +04:00
18
+ date: 2011-04-19 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ type: :runtime
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -29,11 +30,11 @@ dependencies:
29
30
  - 3
30
31
  - 0
31
32
  version: "3.0"
32
- version_requirements: *id001
33
33
  name: rails
34
+ version_requirements: *id001
34
35
  prerelease: false
35
- type: :runtime
36
36
  - !ruby/object:Gem::Dependency
37
+ type: :runtime
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
@@ -45,11 +46,11 @@ dependencies:
45
46
  - 10
46
47
  - 2
47
48
  version: 0.10.2
48
- version_requirements: *id002
49
49
  name: state_machine
50
+ version_requirements: *id002
50
51
  prerelease: false
51
- type: :runtime
52
52
  - !ruby/object:Gem::Dependency
53
+ type: :development
53
54
  requirement: &id003 !ruby/object:Gem::Requirement
54
55
  none: false
55
56
  requirements:
@@ -59,11 +60,11 @@ dependencies:
59
60
  segments:
60
61
  - 0
61
62
  version: "0"
62
- version_requirements: *id003
63
63
  name: pg
64
+ version_requirements: *id003
64
65
  prerelease: false
65
- type: :development
66
66
  - !ruby/object:Gem::Dependency
67
+ type: :development
67
68
  requirement: &id004 !ruby/object:Gem::Requirement
68
69
  none: false
69
70
  requirements:
@@ -73,11 +74,11 @@ dependencies:
73
74
  segments:
74
75
  - 0
75
76
  version: "0"
76
- version_requirements: *id004
77
77
  name: ruby-debug
78
+ version_requirements: *id004
78
79
  prerelease: false
79
- type: :development
80
80
  - !ruby/object:Gem::Dependency
81
+ type: :development
81
82
  requirement: &id005 !ruby/object:Gem::Requirement
82
83
  none: false
83
84
  requirements:
@@ -87,11 +88,11 @@ dependencies:
87
88
  segments:
88
89
  - 0
89
90
  version: "0"
90
- version_requirements: *id005
91
91
  name: watchr
92
+ version_requirements: *id005
92
93
  prerelease: false
93
- type: :development
94
94
  - !ruby/object:Gem::Dependency
95
+ type: :development
95
96
  requirement: &id006 !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
@@ -101,11 +102,11 @@ dependencies:
101
102
  segments:
102
103
  - 0
103
104
  version: "0"
104
- version_requirements: *id006
105
105
  name: sqlite3
106
+ version_requirements: *id006
106
107
  prerelease: false
107
- type: :development
108
108
  - !ruby/object:Gem::Dependency
109
+ type: :development
109
110
  requirement: &id007 !ruby/object:Gem::Requirement
110
111
  none: false
111
112
  requirements:
@@ -115,11 +116,11 @@ dependencies:
115
116
  segments:
116
117
  - 0
117
118
  version: "0"
118
- version_requirements: *id007
119
119
  name: factory_girl
120
+ version_requirements: *id007
120
121
  prerelease: false
121
- type: :development
122
122
  - !ruby/object:Gem::Dependency
123
+ type: :development
123
124
  requirement: &id008 !ruby/object:Gem::Requirement
124
125
  none: false
125
126
  requirements:
@@ -129,11 +130,11 @@ dependencies:
129
130
  segments:
130
131
  - 0
131
132
  version: "0"
132
- version_requirements: *id008
133
133
  name: shoulda
134
+ version_requirements: *id008
134
135
  prerelease: false
135
- type: :development
136
136
  - !ruby/object:Gem::Dependency
137
+ type: :development
137
138
  requirement: &id009 !ruby/object:Gem::Requirement
138
139
  none: false
139
140
  requirements:
@@ -144,11 +145,11 @@ dependencies:
144
145
  - 2
145
146
  - 5
146
147
  version: "2.5"
147
- version_requirements: *id009
148
148
  name: rspec
149
+ version_requirements: *id009
149
150
  prerelease: false
150
- type: :development
151
151
  - !ruby/object:Gem::Dependency
152
+ type: :development
152
153
  requirement: &id010 !ruby/object:Gem::Requirement
153
154
  none: false
154
155
  requirements:
@@ -158,11 +159,11 @@ dependencies:
158
159
  segments:
159
160
  - 0
160
161
  version: "0"
161
- version_requirements: *id010
162
162
  name: rspec-rails
163
+ version_requirements: *id010
163
164
  prerelease: false
164
- type: :development
165
165
  - !ruby/object:Gem::Dependency
166
+ type: :development
166
167
  requirement: &id011 !ruby/object:Gem::Requirement
167
168
  none: false
168
169
  requirements:
@@ -174,11 +175,11 @@ dependencies:
174
175
  - 0
175
176
  - 0
176
177
  version: 1.0.0
177
- version_requirements: *id011
178
178
  name: bundler
179
+ version_requirements: *id011
179
180
  prerelease: false
180
- type: :development
181
181
  - !ruby/object:Gem::Dependency
182
+ type: :development
182
183
  requirement: &id012 !ruby/object:Gem::Requirement
183
184
  none: false
184
185
  requirements:
@@ -190,11 +191,11 @@ dependencies:
190
191
  - 5
191
192
  - 2
192
193
  version: 1.5.2
193
- version_requirements: *id012
194
194
  name: jeweler
195
+ version_requirements: *id012
195
196
  prerelease: false
196
- type: :development
197
197
  - !ruby/object:Gem::Dependency
198
+ type: :development
198
199
  requirement: &id013 !ruby/object:Gem::Requirement
199
200
  none: false
200
201
  requirements:
@@ -204,10 +205,9 @@ dependencies:
204
205
  segments:
205
206
  - 0
206
207
  version: "0"
207
- version_requirements: *id013
208
208
  name: rcov
209
+ version_requirements: *id013
209
210
  prerelease: false
210
- type: :development
211
211
  description: !binary |
212
212
  0KHQuNGB0YLQtdC80LAg0YPQv9GA0LDQstC70LXQvdC40Y8g0L/QvtC70YzQ
213
213
  t9C+0LLQsNGC0LXQu9GM0YHQutC40LzQuCDQvtC/0L7QstC10YnQtdC90LjR
@@ -298,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  requirements: []
299
299
 
300
300
  rubyforge_project:
301
- rubygems_version: 1.6.1
301
+ rubygems_version: 1.6.2
302
302
  signing_key:
303
303
  specification_version: 3
304
304
  summary: !binary |