bot 0.0.23 → 0.0.26

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7967225a37443fee41b93f193463dfdf05c1b565
4
- data.tar.gz: 18e97306e18829909941cdd6b5769d51c4104bc0
3
+ metadata.gz: f8a7f2d7d490fb9cbe15964fada2a76ae89d6413
4
+ data.tar.gz: 378726e279dcec7929bbd070af2ad36a7114e4a7
5
5
  SHA512:
6
- metadata.gz: 536f9426be975038b276580bc567ea8f262f83a439fa2203226756497862a1e25d974af3351409d91de4470733ef98c0c1462322ad7a95824359005257d3a111
7
- data.tar.gz: f41538f75df8b8e36621aeb46a0824dc974f98c5187535e9cd09e1b87178ef5b5d57b98113bef93fc8ec4dd6e99ba8cdddb11d640f4c92e259aeea31a2db8c3c
6
+ metadata.gz: 62de4860542e8b99017b65b9269b05614627ede2d310ef5293d6faf5b48c4774055cd079bd6081bc6e3b9cb345b7b40aefd8aee9979a80f14435cad58f28830e
7
+ data.tar.gz: 86d29f627b43ac29904a3a0934d0d31e6c25f808e483ce7f1b01caeb5ae790c5bf61c60b1691dade119a9275a0e815619136afe78f437aced86ed1ba0c833c9f
@@ -2,7 +2,7 @@ class Bot::BotController < ActionController::Base
2
2
  def notify
3
3
  @responses = bot_handler.handle(messages).compact
4
4
 
5
- adapter.send_messages(@responses) if @responses.present?
5
+ adapter.send_messages(@responses, params[:bot_username]) if @responses.present?
6
6
 
7
7
  render json: []
8
8
  end
@@ -1,13 +1,15 @@
1
1
  module Bot
2
2
  module Adapter
3
3
  class Base
4
- attr_reader :config
4
+ def initialize(config={}, &block)
5
+ @config = lambda { |u| config.merge(block ? block.call(u) : {}) }
6
+ end
5
7
 
6
- def initialize(config={})
7
- @config = config
8
+ def config(username=nil)
9
+ @config.call(username)
8
10
  end
9
11
 
10
- def send_messages(messages)
12
+ def send_messages(messages, from)
11
13
  raise NotImplementedError
12
14
  end
13
15
  end
@@ -4,18 +4,19 @@ module Bot
4
4
  module Adapter
5
5
  class Kik < Base
6
6
 
7
- AUTH_URL = "https://auth.kik.com/verification/v1/check"
8
- MESSAGING_URL = "https://engine.apikik.com/api/v1/message"
7
+ AUTH_URL = "https://auth.kik.com/verification/v1/check".freeze
8
+ MESSAGING_URL = "https://engine.apikik.com/api/v1/message".freeze
9
+ PROFILE_URL = 'https://api.kik.com/v1/user'.freeze
9
10
 
10
- def send_messages(messages)
11
+ def send_messages(messages, from)
11
12
  Rails.logger.error "\n\n\nSending:\n"
12
13
  Rails.logger.error messages.to_json
13
14
  Rails.logger.error "\n\n\n"
14
15
 
15
16
  RestClient::Request.execute({
16
17
  method: :post,
17
- user: config[:bot_user],
18
- password: config[:bot_token],
18
+ user: config(from)[:bot_user],
19
+ password: config(from)[:bot_token],
19
20
  url: MESSAGING_URL,
20
21
  payload: { messages: messages }.to_json,
21
22
  headers: { content_type: :json }
@@ -26,6 +27,25 @@ module Bot
26
27
  Rails.logger.error "\n\n\n"
27
28
  raise e
28
29
  end
30
+
31
+ def get_profile_image(username, as_user)
32
+ profile = get_profile(username, as_user)
33
+ profile['profilePicUrl'] || ''
34
+ end
35
+
36
+ protected
37
+
38
+ def get_profile(username, from)
39
+ response = RestClient::Request.execute(
40
+ method: :get,
41
+ url: "#{PROFILE_URL}/#{username}",
42
+ user: config(from)[:bot_user],
43
+ password: config(from)[:bot_token],
44
+ headers: { content_type: :json }
45
+ )
46
+
47
+ JSON.parse(response)
48
+ end
29
49
  end
30
50
  end
31
51
  end
@@ -3,7 +3,7 @@ module Bot
3
3
  class Test < Base
4
4
  @@sent_messages = []
5
5
 
6
- def send_messages(messages)
6
+ def send_messages(messages, from)
7
7
  @@sent_messages += Array.wrap(messages)
8
8
  end
9
9
 
data/lib/bot/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bot
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.26"
3
3
  end
@@ -4,13 +4,16 @@ namespace :bot do
4
4
  namespace :kik do
5
5
 
6
6
  desc "Update a bot config"
7
- task :configure => :environment do
7
+ task :configure do
8
8
  uri = URI.parse("https://api.kik.com/v1/config")
9
9
 
10
+ bot_user = ENV['KIK_BOT_USER']
11
+ bot_token = ENV['KIK_TOKEN']
12
+
10
13
  request = Net::HTTP::Post.new(uri.request_uri, initheader = { "Content-Type" => "application/json" })
11
- request.basic_auth Bot.configuration.adapter.config[:bot_user], Bot.configuration.adapter.config[:bot_token]
14
+ request.basic_auth bot_user, bot_token
12
15
  request.body = {
13
- webhook: "#{ENV['CALLBACK_URL']}",
16
+ webhook: "#{ENV['CALLBACK_URL']}?bot_username=#{bot_user}",
14
17
  features: {
15
18
  manuallySendReadReceipts: false,
16
19
  receiveReadReceipts: false,
@@ -2648,3 +2648,175 @@ Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2648
2648
  BotTest: test_truth
2649
2649
  -------------------
2650
2650
   (0.1ms) rollback transaction
2651
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
2652
+  (5.1ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
2653
+  (0.1ms) select sqlite_version(*)
2654
+  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2655
+  (0.2ms) SELECT version FROM "schema_migrations"
2656
+  (1.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
2657
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2658
+  (0.3ms) begin transaction
2659
+ -------------------
2660
+ BotTest: test_truth
2661
+ -------------------
2662
+  (0.1ms) rollback transaction
2663
+  (0.1ms) begin transaction
2664
+ ---------------------------
2665
+ NavigationTest: test_notify
2666
+ ---------------------------
2667
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:07:44 -0400
2668
+ Processing by Bot::BotController#notify as HTML
2669
+ Parameters: {"bot"=>ApplicationHandler}
2670
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
2671
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:07:44 -0400
2672
+ Processing by Bot::BotController#notify as HTML
2673
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2674
+ Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
2675
+  (0.1ms) rollback transaction
2676
+  (0.1ms) begin transaction
2677
+ -----------------------------------------
2678
+ NavigationTest: test_notify_special_types
2679
+ -----------------------------------------
2680
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:07:44 -0400
2681
+ Processing by Bot::BotController#notify as HTML
2682
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2683
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2684
+  (0.1ms) rollback transaction
2685
+  (0.1ms) begin transaction
2686
+ ---------------------------------------
2687
+ NavigationTest: test_notify_multi_types
2688
+ ---------------------------------------
2689
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:07:44 -0400
2690
+ Processing by Bot::BotController#notify as HTML
2691
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2692
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2693
+  (0.1ms) rollback transaction
2694
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2695
+  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
2696
+  (0.1ms) select sqlite_version(*)
2697
+  (1.4ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2698
+  (0.2ms) SELECT version FROM "schema_migrations"
2699
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
2700
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2701
+  (0.2ms) begin transaction
2702
+ ---------------------------
2703
+ NavigationTest: test_notify
2704
+ ---------------------------
2705
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:08:02 -0400
2706
+ Processing by Bot::BotController#notify as HTML
2707
+ Parameters: {"bot"=>ApplicationHandler}
2708
+ Completed 200 OK in 1ms (Views: 0.3ms | ActiveRecord: 0.0ms)
2709
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:08:02 -0400
2710
+ Processing by Bot::BotController#notify as HTML
2711
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2712
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2713
+  (0.1ms) rollback transaction
2714
+  (0.0ms) begin transaction
2715
+ ---------------------------------------
2716
+ NavigationTest: test_notify_multi_types
2717
+ ---------------------------------------
2718
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:08:02 -0400
2719
+ Processing by Bot::BotController#notify as HTML
2720
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2721
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2722
+  (0.1ms) rollback transaction
2723
+  (0.1ms) begin transaction
2724
+ -----------------------------------------
2725
+ NavigationTest: test_notify_special_types
2726
+ -----------------------------------------
2727
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-13 15:08:02 -0400
2728
+ Processing by Bot::BotController#notify as HTML
2729
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2730
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2731
+  (0.1ms) rollback transaction
2732
+  (0.1ms) begin transaction
2733
+ -------------------
2734
+ BotTest: test_truth
2735
+ -------------------
2736
+  (0.0ms) rollback transaction
2737
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
2738
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
2739
+  (0.1ms) select sqlite_version(*)
2740
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2741
+  (0.1ms) SELECT version FROM "schema_migrations"
2742
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
2743
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2744
+  (0.1ms) begin transaction
2745
+ ---------------------------------------
2746
+ NavigationTest: test_notify_multi_types
2747
+ ---------------------------------------
2748
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-17 11:38:44 -0400
2749
+ Processing by Bot::BotController#notify as HTML
2750
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2751
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
2752
+  (0.1ms) rollback transaction
2753
+  (0.1ms) begin transaction
2754
+ ---------------------------
2755
+ NavigationTest: test_notify
2756
+ ---------------------------
2757
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-17 11:38:44 -0400
2758
+ Processing by Bot::BotController#notify as HTML
2759
+ Parameters: {"bot"=>ApplicationHandler}
2760
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2761
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-17 11:38:44 -0400
2762
+ Processing by Bot::BotController#notify as HTML
2763
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2764
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2765
+  (0.1ms) rollback transaction
2766
+  (0.1ms) begin transaction
2767
+ -----------------------------------------
2768
+ NavigationTest: test_notify_special_types
2769
+ -----------------------------------------
2770
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-17 11:38:44 -0400
2771
+ Processing by Bot::BotController#notify as HTML
2772
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2773
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2774
+  (0.1ms) rollback transaction
2775
+  (0.1ms) begin transaction
2776
+ -------------------
2777
+ BotTest: test_truth
2778
+ -------------------
2779
+  (0.0ms) rollback transaction
2780
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2781
+  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
2782
+  (0.1ms) select sqlite_version(*)
2783
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
2784
+  (0.1ms) SELECT version FROM "schema_migrations"
2785
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
2786
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2787
+  (0.1ms) begin transaction
2788
+ -------------------
2789
+ BotTest: test_truth
2790
+ -------------------
2791
+  (0.1ms) rollback transaction
2792
+  (0.0ms) begin transaction
2793
+ -----------------------------------------
2794
+ NavigationTest: test_notify_special_types
2795
+ -----------------------------------------
2796
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-18 16:40:23 -0400
2797
+ Processing by Bot::BotController#notify as HTML
2798
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2799
+ Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
2800
+  (0.1ms) rollback transaction
2801
+  (0.1ms) begin transaction
2802
+ ---------------------------
2803
+ NavigationTest: test_notify
2804
+ ---------------------------
2805
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-18 16:40:23 -0400
2806
+ Processing by Bot::BotController#notify as HTML
2807
+ Parameters: {"bot"=>ApplicationHandler}
2808
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2809
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-18 16:40:23 -0400
2810
+ Processing by Bot::BotController#notify as HTML
2811
+ Parameters: {"messages"=>[{"body"=>"Hello", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"text", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2812
+ Completed 200 OK in 0ms (Views: 0.0ms | ActiveRecord: 0.0ms)
2813
+  (0.0ms) rollback transaction
2814
+  (0.1ms) begin transaction
2815
+ ---------------------------------------
2816
+ NavigationTest: test_notify_multi_types
2817
+ ---------------------------------------
2818
+ Started POST "/bot/notify" for 127.0.0.1 at 2016-04-18 16:40:23 -0400
2819
+ Processing by Bot::BotController#notify as HTML
2820
+ Parameters: {"messages"=>[{"body"=>"multi", "readReceiptRequested"=>"true", "from"=>"bnmrrs", "timestamp"=>"1452785908454", "type"=>"scan-data", "id"=>"2af0d873-d157-4627-b863-8be11b0dfd86"}], "bot"=>ApplicationHandler}
2821
+ Completed 200 OK in 0ms (Views: 0.1ms | ActiveRecord: 0.0ms)
2822
+  (0.1ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Morris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails