bobot 3.0.3 → 3.0.5

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
  SHA1:
3
- metadata.gz: b79d3269f2178d1f8a3825912664eb946bae922f
4
- data.tar.gz: 1eb07574a6eddb697bc19ca7be39d7668b00e606
3
+ metadata.gz: 1604e92019fb451807c99f8a6ecaf3ba969a53a5
4
+ data.tar.gz: 62de9467eec07cdeb073421d9f7c212581d62348
5
5
  SHA512:
6
- metadata.gz: f26648d7412c6c182071f26f7916c5bdd6329ff7b641caa21a2ab549ae4313f0689859730369aadebc700d80dd2f11685896d39e48ea02b9e6a7975739081e6d
7
- data.tar.gz: f55c0a78335543bd9fe0b7322a3a430909c9dff7f2e95720c6343783aeaf70bd3b0c4b1f9568ed06ad05b6a24ed1b9d9c7afd219aee5df08253b718fc5153283
6
+ metadata.gz: f8733aef1551529ee91a8869e510676a36ae79e6b3c331317fbf34420dc273ab2fd385d744ebe919d04c6d2b69354a8625c1d5769777439f98b940076959d8de
7
+ data.tar.gz: b640a5c455189c74aca047303b907f37f1262b20f160a9e3de9308c8c67f9510852e97e17e43b05017a8bcfb8a8d344615cce3edad6db8dedca4f0cefbaa9b63
@@ -1,6 +1,5 @@
1
1
  module Bobot
2
2
  class CommanderJob < ApplicationJob
3
-
4
3
  queue_as do
5
4
  if Bobot.config.commander_queue_name.present?
6
5
  Bobot.config.commander_queue_name
@@ -1,6 +1,5 @@
1
1
  module Bobot
2
2
  class DeliverJob < ApplicationJob
3
-
4
3
  queue_as do
5
4
  if Bobot.config.commander_queue_name.present?
6
5
  Bobot.config.commander_queue_name
data/lib/bobot.rb CHANGED
@@ -1,6 +1,3 @@
1
- require 'net/https'
2
- require 'uri'
3
-
4
1
  require 'bobot/engine'
5
2
  require 'bobot/exceptions'
6
3
  require 'bobot/error_parser'
@@ -1,25 +1,24 @@
1
+ require "Typhoeus"
2
+ require "uri"
3
+
1
4
  module Bobot
2
5
  module GraphFacebook
3
- GRAPH_FB_URL = 'https://graph.facebook.com'.freeze
4
- GRAPH_FB_VERSION = 'v2.11'.freeze
6
+ GRAPH_FB_URL = 'https://graph.facebook.com/v2.11/'.freeze
7
+ GRAPH_HEADERS = { Accept: "application/json", "Content-Type" => "application/json; charset=utf-8" }.freeze
5
8
 
6
9
  module ClassMethods
7
10
  def graph_get(path, query: {})
8
- uri = URI.parse(File.join(GRAPH_FB_URL, GRAPH_FB_VERSION, path))
9
- uri.query = URI.encode_www_form(query)
10
- req = Net::HTTP::Get.new(uri.request_uri)
11
- req['Content-Type'] = 'application/json; charset=utf-8'
12
- req['Accept'] = 'application/json'
13
- req['User-Agent'] = nil
14
- req['Accept-Encoding'] = nil
15
- https = Net::HTTP.new(uri.host, uri.port).tap do |http|
16
- http.use_ssl = true
17
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
- http.read_timeout = 300
19
- end
20
- res = https.request(req)
21
- json = ActiveSupport::JSON.decode(res.send(:body) || '{}')
22
- Rails.logger.debug "[GET] >> #{uri.request_uri}"
11
+ url = "#{GRAPH_FB_URL}#{path}".freeze
12
+ req = Typhoeus::Request.new(
13
+ url,
14
+ method: :get,
15
+ params: URI.encode_www_form(query.reverse_merge(include_headers: false)),
16
+ headers: GRAPH_HEADERS,
17
+ ssl_verifypeer: false,
18
+ ).run
19
+ response = req.run
20
+ json = ActiveSupport::JSON.decode(response.send(:body) || '{}')
21
+ Rails.logger.debug "[GET] >> #{url}"
23
22
  Rails.logger.debug "[GET] << #{json}"
24
23
  Bobot::ErrorParser.raise_errors_from(json)
25
24
  json
@@ -27,22 +26,18 @@ module Bobot
27
26
  module_function :graph_get
28
27
 
29
28
  def graph_post(path, query: {}, body: {})
30
- uri = URI.parse(File.join(GRAPH_FB_URL, GRAPH_FB_VERSION, path))
31
- uri.query = URI.encode_www_form(query)
32
- req = Net::HTTP::Post.new(uri.request_uri)
33
- req['Content-Type'] = 'application/json; charset=utf-8'
34
- req['Accept'] = 'application/json'
35
- req['User-Agent'] = nil
36
- req['Accept-Encoding'] = nil
37
- req.body = ActiveSupport::JSON.encode(body)
38
- https = Net::HTTP.new(uri.host, uri.port).tap do |http|
39
- http.use_ssl = true
40
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
- http.read_timeout = 300
42
- end
43
- res = https.request(req)
44
- json = ActiveSupport::JSON.decode(res.send(:body) || '{}')
45
- Rails.logger.debug "[POST] >> #{uri.request_uri}"
29
+ url = "#{GRAPH_FB_URL}#{path}".freeze
30
+ req = Typhoeus::Request.new(
31
+ url,
32
+ method: :post,
33
+ params: URI.encode_www_form(query.reverse_merge(include_headers: false)),
34
+ body: ActiveSupport::JSON.encode(body),
35
+ headers: GRAPH_HEADERS,
36
+ ssl_verifypeer: false,
37
+ )
38
+ response = req.run
39
+ json = ActiveSupport::JSON.decode(response.send(:body) || '{}')
40
+ Rails.logger.debug "[POST] >> #{url}"
46
41
  Rails.logger.debug "[POST] << #{json}"
47
42
  Bobot::ErrorParser.raise_errors_from(json)
48
43
  json
@@ -50,22 +45,18 @@ module Bobot
50
45
  module_function :graph_post
51
46
 
52
47
  def graph_delete(path, query: {}, body: {})
53
- uri = URI.parse(File.join(GRAPH_FB_URL, GRAPH_FB_VERSION, path))
54
- uri.query = URI.encode_www_form(query)
55
- req = Net::HTTP::Delete.new(uri.request_uri)
56
- req['Content-Type'] = 'application/json; charset=utf-8'
57
- req['Accept'] = 'application/json'
58
- req['User-Agent'] = nil
59
- req['Accept-Encoding'] = nil
60
- req.body = ActiveSupport::JSON.encode(body)
61
- https = Net::HTTP.new(uri.host, uri.port).tap do |http|
62
- http.use_ssl = true
63
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
- http.read_timeout = 300
65
- end
66
- res = https.request(req)
67
- json = ActiveSupport::JSON.decode(res.send(:body) || '{}')
68
- Rails.logger.debug "[DELETE] >> #{uri.request_uri}"
48
+ url = "#{GRAPH_FB_URL}#{path}".freeze
49
+ req = Typhoeus::Request.new(
50
+ url,
51
+ method: :delete,
52
+ params: URI.encode_www_form(query.reverse_merge(include_headers: false)),
53
+ body: ActiveSupport::JSON.encode(body),
54
+ headers: GRAPH_HEADERS,
55
+ ssl_verifypeer: false,
56
+ )
57
+ response = req.run
58
+ json = ActiveSupport::JSON.decode(response.send(:body) || '{}')
59
+ Rails.logger.debug "[DELETE] >> #{url}"
69
60
  Rails.logger.debug "[DELETE] << #{json}"
70
61
  Bobot::ErrorParser.raise_errors_from(json)
71
62
  json
data/lib/bobot/version.rb CHANGED
@@ -2,7 +2,7 @@ module Bobot
2
2
  class Version
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- PATCH = 3
5
+ PATCH = 5
6
6
  PRE = nil
7
7
 
8
8
  class << self
@@ -7,8 +7,7 @@ RSpec.describe Bobot::Profile do
7
7
  let(:messenger_profile_url) do
8
8
  File.join(
9
9
  described_class::GRAPH_FB_URL,
10
- described_class::GRAPH_FB_VERSION,
11
- '/me/messenger_profile'
10
+ '/me/messenger_profile?include_headers=false'
12
11
  )
13
12
  end
14
13
 
@@ -8,9 +8,8 @@ RSpec.describe Bobot::Subscription do
8
8
  let(:subscription_url) do
9
9
  File.join(
10
10
  described_class::GRAPH_FB_URL,
11
- described_class::GRAPH_FB_VERSION,
12
11
  "/#{page_id}",
13
- '/subscribed_apps',
12
+ '/subscribed_apps?include_headers=false',
14
13
  )
15
14
  end
16
15
 
@@ -10,8 +10,7 @@ RSpec.describe Bobot::User do
10
10
  let(:user_url) do
11
11
  File.join(
12
12
  described_class::GRAPH_FB_URL,
13
- described_class::GRAPH_FB_VERSION,
14
- "/#{fb_id}"
13
+ "/#{fb_id}?include_headers=false"
15
14
  )
16
15
  end
17
16
 
@@ -43,3 +43,5 @@ Processing by Rails::WelcomeController#index as HTML
43
43
  Completed 200 OK in 8ms (Views: 5.7ms)
44
44
 
45
45
 
46
+ ETHON: Libcurl initialized
47
+ ETHON: performed EASY effective_url=https://graph.facebook.com/v2.11//me/messages response_code=400 return_code=ok total_time=3.42639
@@ -26,3 +26,10 @@
26
26
  [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: e1b4f1e1-13d8-4243-948c-c2bbdab9f212) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
27
27
  [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: 1c5e3b4b-4ae4-4213-bafb-4164a16a0a4c) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
28
28
  [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: 56732598-6966-4ce2-b00c-0b7632f4a14b) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
29
+ [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: 7bdaa668-ea63-4a68-9576-95f2bc8197a9) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
30
+ ETHON: Libcurl initialized
31
+ [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: 6a6034d0-25d7-4aea-93f9-e56f3d212cda) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
32
+ [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: 30f17782-94b0-481e-a3f3-f667225b0ecc) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
33
+ ETHON: Libcurl initialized
34
+ ETHON: Libcurl initialized
35
+ [ActiveJob] Enqueued Bobot::CommanderJob (Job ID: 3128058b-c515-488d-9987-a121b91bfaab) to Test(default) with arguments: {"sender"=>{"id"=>"2"}, "recipient"=>{"id"=>"3"}, "timestamp"=>1457764197627, "message"=>{"mid"=>"mid.1457764197618:41d102a3e1ae206a38", "seq"=>73, "text"=>"Hello, bot!"}}
@@ -6,11 +6,12 @@ if bobot_config.present?
6
6
  raise "Bobot: #{bobot_config_path} required an array key :pages (cf. https://github.com/navidemad/bobot)"
7
7
  end
8
8
  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.domains = bobot_config["domains"],
13
- config.async = bobot_config["async"],
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.domains = bobot_config["domains"]
13
+ config.async = bobot_config["async"]
14
+ config.commander_queue_name = bobot_config["commander_queue_name"]
14
15
  bobot_config["pages"].each do |page|
15
16
  config.pages << Bobot::Page.new(
16
17
  slug: page["slug"],
@@ -10,17 +10,17 @@ en:
10
10
  persistent_menu:
11
11
  composer_input_disabled: false
12
12
  call_to_actions:
13
- - title: "My Account"
14
- type: "nested"
13
+ - type: "nested"
14
+ title: "My Account"
15
15
  call_to_actions:
16
- - title: "What is a chatbot?"
17
- type: "postback"
16
+ - type: "postback"
17
+ title: "What is a chatbot?"
18
18
  payload: "WHAT_IS_A_CHATBOT"
19
- - title: "History"
20
- type: "postback"
19
+ - type: "postback"
20
+ title: "History"
21
21
  payload: "HISTORY_PAYLOAD"
22
- - title: "Contact Info"
23
- type: "postback"
22
+ - type: "postback"
23
+ title: "Contact Info"
24
24
  payload: "CONTACT_INFO_PAYLOAD"
25
25
  - type: "web_url"
26
26
  title: "Get some help"
@@ -9,17 +9,17 @@ fr:
9
9
  persistent_menu:
10
10
  composer_input_disabled: false
11
11
  call_to_actions:
12
- - title: "Mon compte"
13
- type: "nested"
12
+ - type: "nested"
13
+ title: "Mon compte"
14
14
  call_to_actions:
15
- - title: "C'est quoi un chatbot ?"
16
- type: "postback"
15
+ - type: "postback"
16
+ title: "C'est quoi un chatbot ?"
17
17
  payload: "WHAT_IS_A_CHATBOT"
18
- - title: "Historique"
19
- type: "postback"
18
+ - type: "postback"
19
+ title: "Historique"
20
20
  payload: "HISTORY_PAYLOAD"
21
- - title: "Contact Info"
22
- type: "postback"
21
+ - type: "postback"
22
+ title: "Contact Info"
23
23
  payload: "CONTACT_INFO_PAYLOAD"
24
24
  - type: "web_url"
25
25
  title: "Obtenir de l'aide"
data/spec/rails_helper.rb CHANGED
@@ -62,4 +62,7 @@ RSpec.configure do |config|
62
62
  c.pages = []
63
63
  end
64
64
  end
65
+ config.before :each do
66
+ Typhoeus::Expectation.clear
67
+ end
65
68
  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: 3.0.3
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Navid EMAD
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-28 00:00:00.000000000 Z
11
+ date: 2017-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: typhoeus
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  description: Bobot is a Ruby wrapped framework to build easily a Facebook Messenger
48
62
  Bot.
49
63
  email:
@@ -157,7 +171,6 @@ files:
157
171
  - spec/dummy/tmp/generator/config/initializers/bobot.rb
158
172
  - spec/dummy/tmp/generator/config/locales/bobot.en.yml
159
173
  - spec/dummy/tmp/generator/config/locales/bobot.fr.yml
160
- - spec/dummy/tmp/generator/config/routes.rb
161
174
  - spec/examples.txt
162
175
  - spec/helpers/graph_api_helpers.rb
163
176
  - spec/jobs/bobot/commander_job_spec.rb
@@ -251,7 +264,6 @@ test_files:
251
264
  - spec/dummy/tmp/generator/config/initializers/bobot.rb
252
265
  - spec/dummy/tmp/generator/config/locales/bobot.en.yml
253
266
  - spec/dummy/tmp/generator/config/locales/bobot.fr.yml
254
- - spec/dummy/tmp/generator/config/routes.rb
255
267
  - spec/examples.txt
256
268
  - spec/helpers/graph_api_helpers.rb
257
269
  - spec/jobs/bobot/commander_job_spec.rb
File without changes