courier 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -3
- data/VERSION +1 -1
- data/courier.gemspec +1 -1
- data/lib/courier/message.rb +12 -0
- data/lib/courier/service/base.rb +2 -4
- data/lib/courier/service/facebook.rb +15 -14
- data/lib/courier/service/gritter_notice.rb +13 -3
- data/lib/courier/template/base.rb +2 -3
- data/spec/courier/service/facebook_spec.rb +4 -5
- data/spec/courier/service/gritter_notice_spec.rb +1 -1
- data/spec/courier/template/base_spec.rb +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -48,7 +48,11 @@ Gemfile:
|
|
48
48
|
отправил, а если сообщения собираются для дальнейшей отправки, то
|
49
49
|
осуществляется эта доставка так:
|
50
50
|
|
51
|
-
Courier.deliver_all!
|
51
|
+
Courier.deliver_all! # Запускает доставку по всем сервисам
|
52
|
+
|
53
|
+
Для каждого сервиса можно запускать доставку отдельно:
|
54
|
+
|
55
|
+
Courier.service(:facebook).deliver_all!
|
52
56
|
|
53
57
|
== Сервисы
|
54
58
|
|
@@ -74,7 +78,7 @@ Gemfile:
|
|
74
78
|
|
75
79
|
def deliver_all!
|
76
80
|
messages.fresh.each do |message|
|
77
|
-
send_message_my_way(message.owner, message.text) and message.
|
81
|
+
send_message_my_way(message.owner, message.text) and message.mark_as_delivered!
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
@@ -94,7 +98,6 @@ Gemfile:
|
|
94
98
|
end
|
95
99
|
|
96
100
|
|
97
|
-
|
98
101
|
== Contributing to courier
|
99
102
|
|
100
103
|
* Yes, please.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/courier.gemspec
CHANGED
data/lib/courier/message.rb
CHANGED
@@ -22,4 +22,16 @@ class Courier::Message < ActiveRecord::Base
|
|
22
22
|
transition :fresh => :delivered
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
def destroy_when_delivered?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def mark_as_delivered!
|
31
|
+
if destroy_when_delivered?
|
32
|
+
destroy
|
33
|
+
else
|
34
|
+
set_delivered
|
35
|
+
end
|
36
|
+
end
|
25
37
|
end
|
data/lib/courier/service/base.rb
CHANGED
@@ -35,9 +35,7 @@ class Courier::Service::Base
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def check_args owner, template, args
|
38
|
-
args[:
|
39
|
-
args[:service]||=self
|
40
|
-
args[:text] ||=template.get_text(args)
|
38
|
+
# args[:text]||=template.get_text(self, args)
|
41
39
|
end
|
42
40
|
|
43
41
|
def message(owner, template, args)
|
@@ -63,7 +61,7 @@ class Courier::Service::Base
|
|
63
61
|
|
64
62
|
def deliver_all!
|
65
63
|
messages.fresh.each do |message|
|
66
|
-
deliver_message(message) and message.
|
64
|
+
deliver_message(message) and message.mark_as_delivered!
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
@@ -1,26 +1,27 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
class Courier::Service::Facebook < Courier::Service::Base
|
4
|
+
|
4
5
|
def initialize
|
5
6
|
raise "No Koala defined. Add gem 'koala' to your Gemfile. " unless defined? Koala
|
7
|
+
attr_accessor={}
|
6
8
|
super
|
7
9
|
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
#
|
12
|
+
# message.options[:facebook_properties] are all available options from
|
13
|
+
# http://developers.facebook.com/docs/reference/api/post/
|
14
|
+
#
|
15
|
+
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"
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
message.owner.respond_to?(:facebook_token) or
|
19
|
-
raise "method facebook_token is not defined in your owner's model #{owner.class}"
|
20
|
-
token = message.owner.facebook_token or raise "owner's facebook_token is empty"
|
21
|
-
graph = cache[token] ||= Koala::Facebook::GraphAPI.new(token)
|
22
|
-
graph.put_wall_post(message.options[:text], message.options[:attachment], message.options[:to] || 'me') and
|
23
|
-
message.set_delivered
|
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)
|
24
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)
|
25
26
|
end
|
26
27
|
end
|
@@ -6,10 +6,20 @@ class Courier::Service::GritterNotice < Courier::Service::Base
|
|
6
6
|
super
|
7
7
|
end
|
8
8
|
|
9
|
+
#
|
10
|
+
# В локале создается хеш всех параметров принимаемых GritterNotice
|
11
|
+
#
|
12
|
+
# template_key:
|
13
|
+
# title: Внимание!
|
14
|
+
# text: Ва прошли на новый уровень
|
15
|
+
# level: warning
|
16
|
+
# image: /images/warning.png
|
17
|
+
#
|
18
|
+
#
|
19
|
+
|
9
20
|
def message(owner, template, options)
|
10
|
-
options[:scope]=[:courier
|
11
|
-
|
12
|
-
owner.gritter_notice template.name, options
|
21
|
+
options[:scope]=[:courier, :gritter_notice] unless options[:scope]
|
22
|
+
owner.gritter_notice template.name, I18n::translate(template.name, options )
|
13
23
|
end
|
14
24
|
|
15
25
|
def deliver!
|
@@ -8,9 +8,8 @@ class Courier::Template::Base
|
|
8
8
|
self.defaults={}
|
9
9
|
end
|
10
10
|
|
11
|
-
def get_text(args)
|
12
|
-
|
13
|
-
args[:scope]=[:courier, args[:service].name] unless args[:scope]
|
11
|
+
def get_text(service, args)
|
12
|
+
args[:scope]=[:courier, service.to_s] unless args[:scope]
|
14
13
|
args[:cascade]=true unless args.has_key? :cascade
|
15
14
|
I18n::translate(name, args )
|
16
15
|
end
|
@@ -6,13 +6,12 @@ describe Courier::Service::Facebook do
|
|
6
6
|
it 'posts messages with Koala' do
|
7
7
|
owner = mock_owner :facebook_token=>'fbtoken'
|
8
8
|
|
9
|
-
message = mock_message :owner=>owner, :options=>{:text=>'text'
|
10
|
-
message.should_receive(:
|
11
|
-
message.should_receive(:set_delivered)
|
9
|
+
message = mock_message :owner=>owner, :options=>{:text=>'text'}
|
10
|
+
message.should_receive(:mark_as_delivered!)
|
12
11
|
|
13
12
|
graph = double
|
14
|
-
graph.should_receive(:
|
15
|
-
with(
|
13
|
+
graph.should_receive(:put_object).
|
14
|
+
with('me','feed',{:message=>'text'}) { true }
|
16
15
|
Koala::Facebook::GraphAPI.should_receive(:new).with('fbtoken') { graph }
|
17
16
|
|
18
17
|
subject.stub_chain('messages.fresh') { [message] }
|
@@ -7,7 +7,7 @@ describe Courier::Service::GritterNotice do
|
|
7
7
|
args={:a=>1}
|
8
8
|
owner = double
|
9
9
|
template = double :name=>:template_key
|
10
|
-
owner.should_receive(:gritter_notice).with(template.name,
|
10
|
+
owner.should_receive(:gritter_notice).with(template.name, "translation missing: en.courier.gritter_notice.template_key")
|
11
11
|
subject.message owner, template, args
|
12
12
|
end
|
13
13
|
end
|
@@ -11,7 +11,7 @@ describe Courier::Template::Base do
|
|
11
11
|
it 'should return text with localized tranlation' do
|
12
12
|
subject.should_receive(:name) { 'template_key' }
|
13
13
|
subject.
|
14
|
-
get_text(
|
14
|
+
get_text(mock_service(:to_s=>'facebook'), :some_option=>123).should ==
|
15
15
|
'translation missing: en.courier.facebook.template_key'
|
16
16
|
end
|
17
17
|
end
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Danil Pismenny
|