bobot 4.4.1 → 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d390e6b0114f6f9c5711d4cf4a1de653b31dc65b7bd5205c7be5ef3069da2648
4
- data.tar.gz: 6b6cd9ffc4ebef23a2d738a5bbfff534fd5652609410ea89f2da704d6e5d396d
3
+ metadata.gz: d093e3ccb5910f8a8427770a9dd8c62cd23a3e1bca8edcf04e46060d057bb048
4
+ data.tar.gz: 37b0b720425ce522449ddcd7563d05a37f82da50efcaa780abe48bba4f22db21
5
5
  SHA512:
6
- metadata.gz: 22bb577ef33b1f30d213f1323102f48d83ac6e33e9cdadb7af0c056eb944f6fbe817dd5b522c490f300a25b4b794345ef8a4a088f3f95ce3b13f87cca563098c
7
- data.tar.gz: 16d0f211b6e24d48b3252d6e45f5ac6c108e6fbbd9c1f89397bd7edd9361e2a85f77a3db99349133300a6323c003d08a7a713a8b3180ec9d135badc0d9afdd87
6
+ metadata.gz: 4e7b089446483cde8685cab259ebff4e8868f6685bc72563f1957dc36f7e75de0e8396496265f821af52ecb8ddfe6b47c5933d3b940b45c4297f98ddfddcfaf2
7
+ data.tar.gz: ad4f5447c8c509f82195fa05a2fde2bcee17ad8e1b891b39eab6e5e3186ffc5ec037374986f98b973e853101ac24f79513e9f9fc5a5abb332e34ba23909052f0
data/README.md CHANGED
@@ -82,8 +82,6 @@ gem 'bobot'
82
82
  - `page.update_facebook_setup!`
83
83
 
84
84
  Or one by one in a Rails console:
85
- - `page.subscribe_to_facebook_page!`
86
- - `page.unsubscribe_to_facebook_page!`
87
85
  - `page.unset_greeting_text!`
88
86
  - `page.set_greeting_text!`
89
87
  - `page.unset_whitelist_domains!`
data/lib/bobot.rb CHANGED
@@ -3,7 +3,6 @@ require 'bobot/exceptions'
3
3
  require 'bobot/error_parser'
4
4
  require 'bobot/graph_facebook'
5
5
  require 'bobot/configuration'
6
- require 'bobot/subscription'
7
6
  require 'bobot/profile'
8
7
  require 'bobot/user'
9
8
  require 'bobot/buttons'
@@ -34,6 +34,8 @@ module Bobot
34
34
 
35
35
  def receive(payload)
36
36
  event = Bobot::Event.parse(payload)
37
+ return if event.page.present?
38
+
37
39
  hooks.fetch(Bobot::Event::EVENTS.invert[event.class].to_sym)
38
40
  event.mark_as_seen
39
41
  Bobot::CommanderJob.send(
@@ -46,6 +48,8 @@ module Bobot
46
48
 
47
49
  def trigger(payload)
48
50
  event = Bobot::Event.parse(payload)
51
+ return if event.page.present?
52
+
49
53
  hook = hooks.fetch(Bobot::Event::EVENTS.invert[event.class].to_sym)
50
54
  hook.call(event)
51
55
  rescue KeyError
data/lib/bobot/page.rb CHANGED
@@ -256,20 +256,6 @@ module Bobot
256
256
  rescue => e
257
257
  Rails.logger.error(e.message)
258
258
  end
259
- begin
260
- puts "- unsubscribe_to_facebook_page! [....]"
261
- unsubscribe_to_facebook_page!
262
- puts "- unsubscribe_to_facebook_page! [DONE]"
263
- rescue => e
264
- Rails.logger.error(e.message)
265
- end
266
- begin
267
- puts "- subscribe_to_facebook_page! [....]"
268
- subscribe_to_facebook_page!
269
- puts "- subscribe_to_facebook_page! [DONE]"
270
- rescue => e
271
- Rails.logger.error(e.message)
272
- end
273
259
  end
274
260
 
275
261
  def get_facebook_setup
@@ -301,13 +287,6 @@ module Bobot
301
287
  rescue => e
302
288
  Rails.logger.error(e.message)
303
289
  end
304
- begin
305
- puts "- subscribed_facebook_pages [....]"
306
- puts subscribed_facebook_pages.inspect
307
- puts "- subscribed_facebook_pages [DONE]"
308
- rescue => e
309
- Rails.logger.error(e.message)
310
- end
311
290
  end
312
291
 
313
292
  ## == Set bot description (only displayed on first time). ==
@@ -479,42 +458,5 @@ module Bobot
479
458
  query: { access_token: page_access_token, fields: %w[persistent_menu] },
480
459
  )
481
460
  end
482
-
483
- ## == Subcribe your bot to your page ==
484
- def subscribe_to_facebook_page!(subscription_fields: [])
485
- raise Bobot::FieldFormat.new("page_id is required") unless page_id.present?
486
- raise Bobot::FieldFormat.new("access_token is required") unless page_access_token.present?
487
- raise Bobot::FieldFormat.new("subscription_fields is required") if subscription_fields.nil?
488
- raise Bobot::FieldFormat.new("subscription_fields has to be an array") unless subscription_fields.is_a?(Array)
489
- Bobot::Subscription.set(
490
- query: {
491
- page_id: page_id,
492
- access_token: page_access_token,
493
- subscription_fields: subscription_fields,
494
- },
495
- )
496
- end
497
-
498
- ## == Unsubcribe your bot from your page ==
499
- def unsubscribe_to_facebook_page!
500
- raise Bobot::FieldFormat.new("page_id is required") unless page_id.present?
501
- raise Bobot::FieldFormat.new("access_token is required") unless page_access_token.present?
502
- Bobot::Subscription.unset(
503
- query: {
504
- page_id: page_id,
505
- access_token: page_access_token,
506
- },
507
- )
508
- end
509
-
510
- ## == Subcribed pages for your bot ==
511
- def subscribed_facebook_pages
512
- raise Bobot::FieldFormat.new("access_token is required") unless page_access_token.present?
513
- Bobot::Subscription.get(
514
- query: {
515
- access_token: page_access_token,
516
- },
517
- )
518
- end
519
461
  end
520
462
  end
data/lib/bobot/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Bobot
2
2
  class Version
3
3
  MAJOR = 4
4
- MINOR = 4
5
- PATCH = 1
4
+ MINOR = 5
5
+ PATCH = 0
6
6
  PRE = nil
7
7
 
8
8
  class << self
@@ -1,48 +1,38 @@
1
- bobot_config_path = Rails.root.join("config", "secrets.yml")
2
- bobot_config = YAML.safe_load(ERB.new(File.read(bobot_config_path)).result, [], [], true)[Rails.env]["bobot"]
3
-
1
+ bobot_config = Rails.application.config_for(:bobot).with_indifferent_access
4
2
  if bobot_config.present?
5
- unless bobot_config.key?("pages")
6
- raise "Bobot: #{bobot_config_path} required an array key :pages (cf. https://github.com/navidemad/bobot)"
7
- end
8
3
  Bobot.configure do |config|
9
- config.app_id = bobot_config["app_id"]
10
- config.app_secret = bobot_config["app_secret"]
11
- config.verify_token = bobot_config["verify_token"]
12
- config.skip_code = bobot_config["skip_code"]
13
- config.domains = bobot_config["domains"]
14
- config.async = bobot_config["async"]
15
- config.commander_queue_name = bobot_config["commander_queue_name"]
16
- bobot_config["pages"].each do |page|
4
+ config.app_id = bobot_config[:app_id]
5
+ config.app_secret = bobot_config[:app_secret]
6
+ config.verify_token = bobot_config[:verify_token]
7
+ config.skip_code = bobot_config[:skip_code]
8
+ config.domains = bobot_config[:domains]
9
+ config.async = bobot_config[:async]
10
+ config.commander_queue_name = bobot_config[:commander_queue_name]
11
+ bobot_config[:pages].each do |page|
12
+ next if page[:slug].nil? || page[:page_id].nil? || page[:page_access_token].nil? || page[:get_started_payload].nil?
17
13
  config.pages << Bobot::Page.new(
18
- slug: page["slug"],
19
- language: page["language"],
20
- page_id: page["page_id"],
21
- page_access_token: page["page_access_token"],
22
- get_started_payload: page["get_started_payload"],
14
+ slug: page[:slug],
15
+ language: page[:language],
16
+ page_id: page[:page_id],
17
+ page_access_token: page[:page_access_token],
18
+ get_started_payload: page[:get_started_payload],
23
19
  )
24
20
  end
25
21
  end
26
- else
27
- warn "#{bobot_config_path} not configured yet in #{Rails.env} environment."
28
- end
29
-
30
- unless Rails.env.production?
31
- bot_files = Dir[Rails.root.join("app", "bobot", "**", "*.rb")]
32
- bot_reloader = ActiveSupport::FileUpdateChecker.new(bot_files) do
22
+ unless Rails.env.production?
23
+ bot_files = Dir[Rails.root.join("app", "bobot", "**", "*.rb")]
24
+ bot_reloader = ActiveSupport::FileUpdateChecker.new(bot_files) do
25
+ bot_files.each { |file| require_dependency file }
26
+ end
27
+ ActiveSupport::Reloader.to_prepare do
28
+ bot_reloader.execute_if_updated
29
+ end
33
30
  bot_files.each { |file| require_dependency file }
34
31
  end
35
-
36
- ActiveSupport::Reloader.to_prepare do
37
- bot_reloader.execute_if_updated
38
- end
39
-
40
- bot_files.each { |file| require_dependency file }
41
- end
42
-
43
- if defined?(Rails::Server)
44
- Rails.application.config.after_initialize do
45
- Rails.application.config.paths.add File.join("app", "bobot"), glob: File.join("**", "*.rb")
46
- Rails.application.config.autoload_paths += Dir[Rails.root.join("app", "bobot", "*")]
32
+ if defined?(Rails::Server)
33
+ Rails.application.config.after_initialize do
34
+ Rails.application.config.paths.add File.join("app", "bobot"), glob: File.join("**", "*.rb")
35
+ Rails.application.config.autoload_paths += Dir[Rails.root.join("app", "bobot", "*")]
36
+ end
47
37
  end
48
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Navid EMAD
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-15 00:00:00.000000000 Z
11
+ date: 2018-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -99,7 +99,6 @@ files:
99
99
  - lib/bobot/graph_facebook.rb
100
100
  - lib/bobot/page.rb
101
101
  - lib/bobot/profile.rb
102
- - lib/bobot/subscription.rb
103
102
  - lib/bobot/user.rb
104
103
  - lib/bobot/version.rb
105
104
  - lib/generators/bobot/install_generator.rb
@@ -125,7 +124,6 @@ files:
125
124
  - spec/bobot/install_generator_spec.rb
126
125
  - spec/bobot/page_spec.rb
127
126
  - spec/bobot/profile_spec.rb
128
- - spec/bobot/subscription_spec.rb
129
127
  - spec/bobot/user_spec.rb
130
128
  - spec/controllers/bobot/application_controller_spec.rb
131
129
  - spec/controllers/bobot/webhook_controller_spec.rb
@@ -241,7 +239,6 @@ test_files:
241
239
  - spec/bobot/install_generator_spec.rb
242
240
  - spec/bobot/bobot_spec.rb
243
241
  - spec/bobot/page_spec.rb
244
- - spec/bobot/subscription_spec.rb
245
242
  - spec/bobot/event_spec.rb
246
243
  - spec/bobot/profile_spec.rb
247
244
  - spec/bobot/user_spec.rb
@@ -1,20 +0,0 @@
1
- module Bobot
2
- module Subscription
3
- include Bobot::GraphFacebook
4
-
5
- def get(query:)
6
- graph_get "/me/subscribed_apps", query: query
7
- end
8
- module_function :get
9
-
10
- def set(query:)
11
- graph_post "/#{query.fetch(:page_id)}/subscribed_apps", query: query
12
- end
13
- module_function :set
14
-
15
- def unset(query:)
16
- graph_delete "/#{query.fetch(:page_id)}/subscribed_apps", query: query
17
- end
18
- module_function :unset
19
- end
20
- end
@@ -1,140 +0,0 @@
1
- require 'rails_helper'
2
- require 'helpers/graph_api_helpers'
3
-
4
- RSpec.describe Bobot::Subscription do
5
- let(:access_token) { 'access token' }
6
- let(:page_id) { 'page-id' }
7
-
8
- let(:subscription_url) do
9
- File.join(
10
- described_class::GRAPH_FB_URL,
11
- "/#{page_id}",
12
- '/subscribed_apps?include_headers=false',
13
- )
14
- end
15
-
16
- before do
17
- Bobot.config.pages << Bobot::Page.new(
18
- page_access_token: access_token,
19
- page_id: page_id,
20
- )
21
- end
22
-
23
- describe '.set' do
24
- context 'with a successful response' do
25
- before do
26
- stub_request(:post, subscription_url)
27
- .with(query: { access_token: access_token})
28
- .to_return(
29
- body: ActiveSupport::JSON.encode(
30
- success: true,
31
- ),
32
- status: :ok,
33
- headers: default_graph_api_response_headers
34
- )
35
- end
36
-
37
- it 'returns hash' do
38
- expect(
39
- subject.set(
40
- query: {
41
- page_id: page_id,
42
- access_token: access_token,
43
- }
44
- )
45
- ).to include('success' => true)
46
- end
47
- end
48
-
49
- context 'with an unsuccessful response' do
50
- let(:error_message) { 'Invalid OAuth access token.' }
51
-
52
- before do
53
- stub_request(:post, subscription_url)
54
- .with(query: { access_token: access_token })
55
- .to_return(
56
- body: {
57
- 'error' => {
58
- 'message' => error_message,
59
- 'type' => 'OAuthException',
60
- 'code' => 190,
61
- 'fbtrace_id' => 'Hlssg2aiVlN'
62
- }
63
- }.to_json,
64
- status: :ok,
65
- headers: default_graph_api_response_headers
66
- )
67
- end
68
-
69
- it 'raises an error' do
70
- expect do
71
- subject.set(
72
- query: {
73
- page_id: page_id,
74
- access_token: access_token,
75
- }
76
- )
77
- end.to raise_error(Bobot::AccessTokenError)
78
- end
79
- end
80
- end
81
-
82
- describe '.unset' do
83
- context 'with a successful response' do
84
- before do
85
- stub_request(:delete, subscription_url)
86
- .with(query: { access_token: access_token })
87
- .to_return(
88
- body: ActiveSupport::JSON.encode(
89
- success: true,
90
- ),
91
- status: :ok,
92
- headers: default_graph_api_response_headers
93
- )
94
- end
95
-
96
- it 'returns hash' do
97
- expect(
98
- subject.unset(
99
- query: {
100
- page_id: page_id,
101
- access_token: access_token,
102
- }
103
- )
104
- ).to include('success' => true)
105
- end
106
- end
107
-
108
- context 'with an unsuccessful response' do
109
- let(:error_message) { 'Invalid OAuth access token.' }
110
-
111
- before do
112
- stub_request(:delete, subscription_url)
113
- .with(query: { access_token: access_token })
114
- .to_return(
115
- body: {
116
- 'error' => {
117
- 'message' => error_message,
118
- 'type' => 'OAuthException',
119
- 'code' => 190,
120
- 'fbtrace_id' => 'Hlssg2aiVlN'
121
- }
122
- }.to_json,
123
- status: :ok,
124
- headers: default_graph_api_response_headers
125
- )
126
- end
127
-
128
- it 'raises an error' do
129
- expect do
130
- subject.unset(
131
- query: {
132
- page_id: page_id,
133
- access_token: access_token,
134
- }
135
- )
136
- end.to raise_error(Bobot::AccessTokenError)
137
- end
138
- end
139
- end
140
- end