messenger_platform_rails 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/messenger_platform/contact.rb +6 -1
- data/lib/messenger_platform/engine.rb +7 -0
- data/lib/messenger_platform/message_base.rb +21 -0
- data/lib/messenger_platform/message_sender.rb +21 -0
- data/lib/messenger_platform/subscriber.rb +1 -1
- data/lib/messenger_platform/text_message.rb +20 -0
- data/lib/messenger_platform/version.rb +1 -1
- data/lib/messenger_platform.rb +3 -0
- data/test/dummy/config/application.rb +1 -15
- data/test/dummy/config/environments/development.rb +0 -6
- data/test/dummy/config/environments/production.rb +0 -2
- data/test/dummy/config/environments/test.rb +0 -1
- metadata +5 -4
- data/test/dummy/config/database.yml +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 226331ea0922373301bd50f6d4ca1e183a4fbdd9
|
4
|
+
data.tar.gz: b6f6318982efc531cf9f53632aa343da086ca85c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5b146c2b466b85bcbebba06d41a1969a89f9046808b5215b96469052be76e892c376ca6cf47d1e85f9fefde9606fbb3e2f229eb6e02d1a3669c8567351050f9
|
7
|
+
data.tar.gz: 143e9f23b605e3484f2b00407aea596c7bed660c101dd0582c8cf24bda871901290b33c6e1a0ba99818ba01aae60273f311ad5c0aaa874756e74d1c0e34fe5c8
|
@@ -1,9 +1,14 @@
|
|
1
1
|
class MessengerPlatform::Contact
|
2
2
|
|
3
|
-
attr_reader :id
|
3
|
+
attr_reader :id, :phone_number
|
4
4
|
|
5
5
|
def initialize(hash)
|
6
6
|
@id = hash.fetch(:id)
|
7
|
+
@phone_number = hash.fetch(:phone_number)
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize
|
11
|
+
id.present? ? { id: id } : { phone_number: phone_number }
|
7
12
|
end
|
8
13
|
|
9
14
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module MessengerPlatform
|
2
|
+
|
2
3
|
class Engine < ::Rails::Engine
|
3
4
|
isolate_namespace MessengerPlatform
|
4
5
|
end
|
@@ -13,4 +14,10 @@ module MessengerPlatform
|
|
13
14
|
yield self
|
14
15
|
end
|
15
16
|
|
17
|
+
def self.facebook_api_base_url(api_method)
|
18
|
+
uri = URI("https://graph.facebook.com/v2.6/me/#{ api_method }")
|
19
|
+
uri.query = URI.encode_www_form({ access_token: MessengerPlatform.access_token })
|
20
|
+
uri.to_s
|
21
|
+
end
|
22
|
+
|
16
23
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class MessengerPlatform::MessageBase
|
2
|
+
|
3
|
+
attr_reader :recipient, :notification_type
|
4
|
+
|
5
|
+
def initialize(recipient, notification_type = :regular)
|
6
|
+
@recipient = recipient
|
7
|
+
@notification_type = notification_type
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize
|
11
|
+
{
|
12
|
+
recipient: recipient.serialize,
|
13
|
+
notification_type: notification_type.to_s.upcase
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def deliver
|
18
|
+
MessengerPlatform::MessageSender.deliver(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class MessengerPlatform::MessageSender
|
4
|
+
|
5
|
+
def self.deliver(message)
|
6
|
+
HTTParty.post(messages_url, {
|
7
|
+
body: message.serialize.to_json,
|
8
|
+
headers: {
|
9
|
+
'Content-Type' => 'application/json',
|
10
|
+
'Accept' => 'application/json'
|
11
|
+
}
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.messages_url
|
18
|
+
MessengerPlatform.facebook_api_base_url("messages")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class MessengerPlatform::TextMessage < MessengerPlatform::MessageBase
|
2
|
+
|
3
|
+
MAX_MESSAGE_LENGTH = 320
|
4
|
+
|
5
|
+
attr_reader :message
|
6
|
+
|
7
|
+
def initialize(recipient, message, notification_type = :regular)
|
8
|
+
super(recipient, notification_type)
|
9
|
+
@message = message.slice(0, MAX_MESSAGE_LENGTH)
|
10
|
+
end
|
11
|
+
|
12
|
+
def serialize
|
13
|
+
super.merge({
|
14
|
+
message: {
|
15
|
+
text: message
|
16
|
+
}
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/messenger_platform.rb
CHANGED
@@ -2,3 +2,6 @@ require "messenger_platform/engine"
|
|
2
2
|
require "messenger_platform/subscriber"
|
3
3
|
require "messenger_platform/inbound_message"
|
4
4
|
require "messenger_platform/contact"
|
5
|
+
require "messenger_platform/message_base"
|
6
|
+
require "messenger_platform/text_message"
|
7
|
+
require "messenger_platform/message_sender"
|
@@ -1,26 +1,12 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'action_controller/railtie'
|
4
4
|
|
5
5
|
Bundler.require(*Rails.groups)
|
6
6
|
require "messenger_platform"
|
7
7
|
|
8
8
|
module Dummy
|
9
9
|
class Application < Rails::Application
|
10
|
-
# Settings in config/environments/* take precedence over those specified here.
|
11
|
-
# Application configuration should go into files in config/initializers
|
12
|
-
# -- all .rb files in that directory are automatically loaded.
|
13
|
-
|
14
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
-
|
18
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
-
# config.i18n.default_locale = :de
|
21
|
-
|
22
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
23
|
-
config.active_record.raise_in_transactional_callbacks = true
|
24
10
|
end
|
25
11
|
end
|
26
12
|
|
@@ -13,15 +13,9 @@ Rails.application.configure do
|
|
13
13
|
config.consider_all_requests_local = true
|
14
14
|
config.action_controller.perform_caching = false
|
15
15
|
|
16
|
-
# Don't care if the mailer can't send.
|
17
|
-
config.action_mailer.raise_delivery_errors = false
|
18
|
-
|
19
16
|
# Print deprecation notices to the Rails logger.
|
20
17
|
config.active_support.deprecation = :log
|
21
18
|
|
22
|
-
# Raise an error on page load if there are pending migrations.
|
23
|
-
config.active_record.migration_error = :page_load
|
24
|
-
|
25
19
|
# Debug mode disables concatenation and preprocessing of assets.
|
26
20
|
# This option may cause significant delays in view rendering with a large
|
27
21
|
# number of complex assets.
|
@@ -74,6 +74,4 @@ Rails.application.configure do
|
|
74
74
|
# Use default logging formatter so that PID and timestamp are not suppressed.
|
75
75
|
config.log_formatter = ::Logger::Formatter.new
|
76
76
|
|
77
|
-
# Do not dump schema after migrations.
|
78
|
-
config.active_record.dump_schema_after_migration = false
|
79
77
|
end
|
@@ -29,7 +29,6 @@ Rails.application.configure do
|
|
29
29
|
# Tell Action Mailer not to deliver emails to the real world.
|
30
30
|
# The :test delivery method accumulates sent emails in the
|
31
31
|
# ActionMailer::Base.deliveries array.
|
32
|
-
config.action_mailer.delivery_method = :test
|
33
32
|
|
34
33
|
# Randomize the order test cases are executed.
|
35
34
|
config.active_support.test_order = :random
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messenger_platform_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FxN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,7 +53,10 @@ files:
|
|
53
53
|
- lib/messenger_platform/contact.rb
|
54
54
|
- lib/messenger_platform/engine.rb
|
55
55
|
- lib/messenger_platform/inbound_message.rb
|
56
|
+
- lib/messenger_platform/message_base.rb
|
57
|
+
- lib/messenger_platform/message_sender.rb
|
56
58
|
- lib/messenger_platform/subscriber.rb
|
59
|
+
- lib/messenger_platform/text_message.rb
|
57
60
|
- lib/messenger_platform/version.rb
|
58
61
|
- lib/tasks/messenger_platform_tasks.rake
|
59
62
|
- test/controllers/messenger_platform/webhook_controller_test.rb
|
@@ -72,7 +75,6 @@ files:
|
|
72
75
|
- test/dummy/config.ru
|
73
76
|
- test/dummy/config/application.rb
|
74
77
|
- test/dummy/config/boot.rb
|
75
|
-
- test/dummy/config/database.yml
|
76
78
|
- test/dummy/config/environment.rb
|
77
79
|
- test/dummy/config/environments/development.rb
|
78
80
|
- test/dummy/config/environments/production.rb
|
@@ -136,7 +138,6 @@ test_files:
|
|
136
138
|
- test/dummy/bin/setup
|
137
139
|
- test/dummy/config/application.rb
|
138
140
|
- test/dummy/config/boot.rb
|
139
|
-
- test/dummy/config/database.yml
|
140
141
|
- test/dummy/config/environment.rb
|
141
142
|
- test/dummy/config/environments/development.rb
|
142
143
|
- test/dummy/config/environments/production.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# SQLite version 3.x
|
2
|
-
# gem install sqlite3
|
3
|
-
#
|
4
|
-
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
-
# gem 'sqlite3'
|
6
|
-
#
|
7
|
-
default: &default
|
8
|
-
adapter: sqlite3
|
9
|
-
pool: 5
|
10
|
-
timeout: 5000
|
11
|
-
|
12
|
-
development:
|
13
|
-
<<: *default
|
14
|
-
database: db/development.sqlite3
|
15
|
-
|
16
|
-
# Warning: The database defined as "test" will be erased and
|
17
|
-
# re-generated from your development database when you run "rake".
|
18
|
-
# Do not set this db to the same as development or production.
|
19
|
-
test:
|
20
|
-
<<: *default
|
21
|
-
database: db/test.sqlite3
|
22
|
-
|
23
|
-
production:
|
24
|
-
<<: *default
|
25
|
-
database: db/production.sqlite3
|