hipbot-plugins 1.0.1 → 1.0.2

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: c30652ba6332517579abf6342c768f2d3116c7a9
4
- data.tar.gz: 744466fd9846b70c90550b2ad869037df65561d8
3
+ metadata.gz: 7413e3e88a6f97c43b264b0fa154dd172483f4a0
4
+ data.tar.gz: 724a3bfcaf01d8569ca719ac9aa01368cd62012a
5
5
  SHA512:
6
- metadata.gz: 087d7e421dd75cd96d95cf3e6fc721b4c2a3ee780846b25cfc4af7e9415cbd7926dcdb87f0917c88692e03e2e345f28d9e382829356ad4c167a11473242b8dce
7
- data.tar.gz: cc05e2b8f6fc29a90a816712a24701177f0f26cfcadb3da67c544d529eadf61905b05c4f18855e9923e7227040ef2b17cfa786da1c51ac04f04e01a968ffc750
6
+ metadata.gz: ef6004a04df220d9079fc4bb37dad49ba69bf1f4a98c09058d530748cb51b6ad5c6637e809286424cc3eb80ee0d9fa3cf8e337d524b9a9d193e9f4288ea9c3cd
7
+ data.tar.gz: 835a112d937fdd52ccf5ae58a38665d81d6e7f0cac6eba61e87d7d357c03b1e06fa4e70032b16566fa9fda93e668b9fde17c1124d878917fbb3b54c9573155cf
@@ -1,11 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
6
5
  - 2.1.0
7
6
  - jruby-19mode
8
- - rbx-19mode
7
+ - rbx-2.1.1
9
8
  - ruby-head
10
9
  matrix:
11
10
  allow_failures:
data/Gemfile CHANGED
@@ -3,3 +3,9 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in hipbot-plugins.gemspec
4
4
  gemspec
5
5
  gem 'hipbot', github: 'pewniak747/hipbot', branch: 'master'
6
+
7
+ platforms :rbx do
8
+ gem 'racc'
9
+ gem 'rubysl', '~> 2.0'
10
+ gem 'psych'
11
+ end
@@ -8,6 +8,7 @@ require "hipbot-plugins/github"
8
8
  require "hipbot-plugins/google"
9
9
  require "hipbot-plugins/wolfram_alpha"
10
10
  require "hipbot-plugins/meme_generator"
11
+ require "hipbot-plugins/rapportive"
11
12
 
12
13
  module Hipbot
13
14
  module Plugins
@@ -20,8 +20,10 @@ module Hipbot
20
20
  end
21
21
 
22
22
  desc 'slaps given user eg. `slap @admin`'
23
- on /slap (.+)/ do |name|
24
- reply("/me slaps #{name} around a bit with a large trout.")
23
+ on /slap (.+)/ do
24
+ message.mentions.each do |mention|
25
+ reply("/me slaps #{mention} around a bit with a large trout.")
26
+ end
25
27
  end
26
28
 
27
29
  desc 'randomly chooses by default 1 person from online users eg. `choose 3`'
@@ -0,0 +1,89 @@
1
+ require 'open-uri'
2
+
3
+ module Hipbot
4
+ module Plugins
5
+ class Rapportive
6
+ include Hipbot::Plugin
7
+
8
+ desc 'do something'
9
+ on /^raport (\S*) (\S*) from (.*)/ do |firstname, lastname, domain|
10
+ raport = Rapportive.new(firstname, lastname, domain)
11
+ reply(raport.to_s)
12
+ end
13
+
14
+ class Rapportive
15
+ attr_accessor :firstname, :lastname, :domain
16
+
17
+ def initialize(firstname, lastname, domain)
18
+ self.firstname = firstname
19
+ self.lastname = lastname
20
+ self.domain = domain
21
+ end
22
+
23
+ def to_s
24
+ return "Sorry, I could not find email address" if profile.nil?
25
+ "Found it! Email #{profile['contact']['email']} is valid."
26
+ end
27
+
28
+ private
29
+
30
+ def session_token
31
+ begin
32
+ @token ||= open(session_token_url).read
33
+ JSON.parse(@token).fetch(:session_token) { "" }
34
+ rescue OpenURI::HTTPError
35
+ ""
36
+ end
37
+ end
38
+
39
+ def session_token_url
40
+ "https://rapportive.com/login_status?user_email=#{random_email}"
41
+ end
42
+
43
+ def profile
44
+ emails.each do |email|
45
+ begin
46
+ body = open(profiles_url(email), "X-Session-Token" => session_token).read
47
+ contact = JSON.parse(body)
48
+ return contact if found?(contact)
49
+ rescue OpenURI::HTTPError
50
+ nil # returns nil for check in to_s method - requests limit reached
51
+ end
52
+ end
53
+ nil
54
+ end
55
+
56
+ def profiles_url(email)
57
+ "https://profiles.rapportive.com/contacts/email/#{email}"
58
+ end
59
+
60
+ def emails
61
+ [
62
+ "#{firstname}.#{lastname}",
63
+ "#{firstname}#{lastname}",
64
+ "#{firstname_letter}#{lastname}",
65
+ "#{firstname_letter}.#{lastname}",
66
+ "#{firstname}",
67
+ "#{lastname}",
68
+ "#{firstname}-#{lastname}",
69
+ "#{firstname}_#{lastname}"
70
+ ].map do |email|
71
+ email + '@' + domain
72
+ end
73
+ end
74
+
75
+ def firstname_letter
76
+ self.firstname[0]
77
+ end
78
+
79
+ def random_email
80
+ SecureRandom.hex + '@gmail.com'
81
+ end
82
+
83
+ def found?(contact)
84
+ contact['contact']['first_name'] != "" && contact['contact']['last_name'] != ""
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -1,5 +1,5 @@
1
1
  module Hipbot
2
2
  module Plugins
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hipbot-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Kopiński
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-03 00:00:00.000000000 Z
12
+ date: 2014-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hipbot
@@ -125,6 +125,7 @@ files:
125
125
  - lib/hipbot-plugins/help.rb
126
126
  - lib/hipbot-plugins/human.rb
127
127
  - lib/hipbot-plugins/meme_generator.rb
128
+ - lib/hipbot-plugins/rapportive.rb
128
129
  - lib/hipbot-plugins/urban_dictionary.rb
129
130
  - lib/hipbot-plugins/version.rb
130
131
  - lib/hipbot-plugins/wolfram_alpha.rb