lita-chilean-bip 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd1046dde727035c3d52c48ee9d286c7dc56c9bb
4
+ data.tar.gz: 53c0e721e9d6598e8200c663507db63e5f8aadba
5
+ SHA512:
6
+ metadata.gz: d3b5b3b7a703f03295603c95809d205d54832eab35d1c00bfcc649a5cb13385cbb0965a470df028bc5e9a729da31b9b0c0b1afd8182bb13c71390292610f8180
7
+ data.tar.gz: 4a8dd33034fc48d148944626dc9d33a5be6f46436a97d23208920b5e899925f9263d108af28279f494e517eae22edcd9013a35fb72a39c614fc1bc5d26369e8a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ .idea/*
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Milo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # lita-chilean-bip
2
+
3
+ TODO: Add a description of the plugin.
4
+
5
+ ## Installation
6
+
7
+ Add lita-chilean-bip to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-chilean-bip"
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ TODO: Describe any configuration attributes the plugin exposes.
16
+
17
+ ## Usage
18
+
19
+ TODO: Describe the plugin's features and how to use them.
20
+
21
+ ## License
22
+
23
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/chilean_bip"
@@ -0,0 +1,90 @@
1
+ module Lita
2
+ module Handlers
3
+ class Gitlab < Handler
4
+
5
+ def self.default_config(config)
6
+ config.default_room = '#general'
7
+ end
8
+
9
+ http.post '/lita/gitlab', :receive
10
+
11
+ def receive(request, response)
12
+ json_body = request.params['payload'] || extract_json_from_request(request)
13
+ data = symbolize parse_payload(json_body)
14
+ message = format_message(data)
15
+ targets = request.params['targets'] || '#general'
16
+ rooms = []
17
+ targets.split(',').each do |param_target|
18
+ rooms << param_target
19
+ end
20
+ rooms.each do |room|
21
+ target = Source.new(room: room)
22
+ robot.send_message(target, message)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def extract_json_from_request(request)
29
+ request.body.rewind
30
+ request.body.read
31
+ end
32
+
33
+ def format_message(data)
34
+ data.key?(:event_name) ? system_message(data) : web_message(data)
35
+ end
36
+
37
+ def system_message(data)
38
+ build_message "system.#{data[:event_name]}", data
39
+ rescue
40
+ Lita.logger.warn "Error formatting message: #{data.inspect}"
41
+ end
42
+
43
+ def web_message(data)
44
+ if data.key? :object_kind
45
+ if data[:object_attributes].key? :target_branch
46
+ # Merge request
47
+ data[:object_attributes][:link] = "#{data[:object_attributes][:target_branch]}/#{data[:object_attributes][:iid]}"
48
+ build_message "web.#{data[:object_kind]}.#{data[:object_attributes][:state]}", data[:object_attributes]
49
+ else
50
+ # Issue
51
+ build_message "web.#{data[:object_kind]}.#{data[:object_attributes][:state]}", data[:object_attributes]
52
+ end
53
+ else
54
+ # Push has no object kind
55
+ branch = data[:ref].split('/').drop(2).join('/')
56
+ data[:link] = data[:repository][:name]
57
+ if data[:before] =~ /^0+$/
58
+ build_message 'web.push.new_branch', data
59
+ else
60
+ build_message 'web.push.add_to_branch', data
61
+ end
62
+ end
63
+ rescue
64
+ Lita.logger.warn "Error formatting message: #{data.inspect}"
65
+ end
66
+
67
+ # General methods
68
+
69
+ def build_message(key, data)
70
+ t(key) % data
71
+ end
72
+
73
+ def parse_payload(payload)
74
+ MultiJson.load(payload)
75
+ rescue MultiJson::LoadError => e
76
+ Lita.logger.error("Could not parse JSON payload from Github: #{e.message}")
77
+ return
78
+ end
79
+
80
+ def symbolize(obj)
81
+ return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo} if obj.is_a? Hash
82
+ return obj.inject([]){|memo,v | memo << symbolize(v); memo} if obj.is_a? Array
83
+ return obj
84
+ end
85
+
86
+ end
87
+
88
+ Lita.register_handler(Gitlab)
89
+ end
90
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'lita-chilean-bip'
3
+ spec.version = '1.0.0'
4
+ spec.authors = ['Emilio Figueroa']
5
+ spec.email = ['emiliofigueroatorres@gmail.com']
6
+ spec.description = %q{A Lita handler for checking the BIP card balance}
7
+ spec.summary = %q{A Lita handler for checking the BIP card balance}
8
+ spec.homepage = 'https://github.com/milo-ft/lita-chilean-bip'
9
+ spec.license = 'MIT'
10
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_runtime_dependency 'lita', '>= 3.0'
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.3'
20
+ spec.add_development_dependency 'nokogiri', '~> 1.6.1'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
23
+ spec.add_development_dependency 'shoulda', '>= 3.5.0'
24
+ spec.add_development_dependency 'simplecov'
25
+ spec.add_development_dependency 'coveralls'
26
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,7 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ chilean_bip:
5
+ invalid_number: "Mmmh.. It seems like you gave me an invalid number"
6
+ service_down: "Ouch! I can't get your balance for now"
7
+ actual_balance: "Your Balance: %{balance} (to date %{date})"
@@ -0,0 +1,102 @@
1
+
2
+ <!-- ynkblmn -->
3
+ <!DOCTYPE html>
4
+ <html lang='es-cl'>
5
+ <head>
6
+ <title>saldoBip</title>
7
+ <meta charset='UTF-8'>
8
+ <meta name='description' content='Conoce el saldo de tu tarjeta Bip del Transantiago'>
9
+ <meta name='keywords' content='saldo, tarjeta, bip, transantiago, tne, pase escolar, santiago, transporte, consultar, tarjetabip.cl'>
10
+ <meta name='robots' content='index,follow'>
11
+ <meta name="googlebot" content="index,follow">
12
+ <meta name="revisit-after" content="1 days">
13
+ <link rel="shortcut icon" href="imagenes/logo.png" type="image/ico">
14
+ <link rel='stylesheet' media='screen' href='css/style.css'>
15
+ <!--[if IE]>
16
+ <script src='http://html5shiv.googlecode.com/svn/trunk/html5.js'></script>
17
+ <![endif]-->
18
+
19
+ </head>
20
+ <body>
21
+ <div id="fb-root"></div>
22
+ <script>
23
+ (function(d, s, id) {
24
+ var js, fjs = d.getElementsByTagName(s)[0];
25
+ if (d.getElementById(id)) return;
26
+ js = d.createElement(s); js.id = id;
27
+ js.src = "//connect.facebook.net/es_ES/all.js#xfbml=1";
28
+ fjs.parentNode.insertBefore(js, fjs);
29
+ }(document, 'script', 'facebook-jssdk'));
30
+ </script>
31
+ <header id=redes>
32
+ <div id=a1024>
33
+ <nav id=redes-nav>
34
+ <!--<a href=#>Something in SCL</a>-->
35
+ </nav>
36
+ <div id=redes-seguidores>
37
+ <div class=fb><div class="fb-like" data-href="http://facebook.com/pages/Saldo-BIP/209933739045036" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div></div>
38
+ <div class=tw><a href="https://twitter.com/saldo_bip" class="twitter-follow-button" data-show-count="true" data-lang="es" data-show-screen-name="false">Seguir a @saldo_bip</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script></div>
39
+ <div class=gplus>
40
+ <div class="g-follow" data-annotation="bubble" data-height="20" data-href="//plus.google.com/110401169434924559329" data-rel="publisher"></div><script type="text/javascript">window.___gcfg = {lang: 'es-419'};(function() {var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;po.src = 'https://apis.google.com/js/plusone.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);})();</script>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </header>
45
+
46
+ <div id=sitio>
47
+ <header id=cabeza>
48
+ <h1><a href=http://saldobip.com/>saldoBip</a></h1>
49
+ <h2>El saldo de tu Tarjeta Bip del Transantiago</h2>
50
+ </header>
51
+ <aside>
52
+ <div id="amigos-centro">
53
+ <script type="text/javascript"><!--
54
+ google_ad_client = "pub-1578973468341035";
55
+ google_ad_slot = "3363741911";
56
+ google_ad_width = 728;
57
+ google_ad_height = 90;
58
+ //-->
59
+ </script>
60
+ <script type="text/javascript"
61
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
62
+ </script>
63
+ </div>
64
+ </aside>
65
+ <div id=contenidos-centrales>
66
+ <section>
67
+ <form id=formulario method=post action=http://saldobip.com/>
68
+ <h1>Ingresa tus datos:</h1>
69
+ <input name=NumTarjeta type='search' placeholder='Tu número de tarjeta Bip o pase' MaxLength="10" value='15214173'required>
70
+ <button name=pedirSaldo>Ver mi saldo</button>
71
+ <div style="margin:30px auto 10px auto;border-top:1px solid #e1e1e1;padding:10px;text-align:center;">
72
+ <a href="http://saldobip.com/concurso.php"><h1>Ya hay ganador de recarga de $5.000</h1></a>
73
+ </div>
74
+ </form>
75
+ <aside id=resultados>
76
+ <div id=datos>
77
+ <p>Saldo: <strong>$10.460.</strong></p>
78
+ <p>Fecha: <strong>01/01/2014 12:00.</strong></p>
79
+ <p>Tarjeta: <strong>12345678.</strong></p>
80
+ </div> <div id=adevertencia>Fíjate que la fecha del saldo coincida con tu último uso de la tarjeta, en ocasiones el saldo está desactualizado porque los buses se demoran en traspasar la información al servidor.</div> </aside>
81
+ </section>
82
+ </div>
83
+
84
+ </div>
85
+ <footer>
86
+ &copy; saldoBip 2011-2013 - versión [3] - <a href=http://facebook.com/pages/Saldo-BIP/209933739045036 target='_blank'>Facebook</a> <a href=https://twitter.com/saldo_bip target='_blank'>Twitter</a> <a href=http://plus.google.com/110401169434924559329 target='_blank'>Google Plus</a> - Tambien puedes usar sitio <a href=http://saldobip.com/2.0/ target='_blank'><strong>2.0</strong></a> o <a href=http://saldobip.com/1.0/ target='_blank'>1.0</a>.
87
+ </footer>
88
+
89
+ <script type="text/javascript">
90
+ var pkBaseURL = (("https:" == document.location.protocol) ? "https://centinela.yanko.cl/" : "http://centinela.yanko.cl/");
91
+ document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
92
+ </script><script type="text/javascript">
93
+ try {
94
+ var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
95
+ piwikTracker.trackPageView();
96
+ piwikTracker.enableLinkTracking();
97
+ } catch( err ) {}
98
+ </script><noscript><p><img src="http://centinela.yanko.cl/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
99
+ </body>
100
+ </html>
101
+
102
+ <!-- ynkblmn -->
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::ChileanBip, lita_handler: true do
4
+
5
+ end
@@ -0,0 +1,10 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-chilean-bip"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-chilean-bip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Emilio Figueroa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0.beta2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0.beta2
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.5.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.5.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A Lita handler for checking the BIP card balance
126
+ email:
127
+ - emiliofigueroatorres@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .travis.yml
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - lib/lita-chilean-bip.rb
139
+ - lib/lita/handlers/chilean_bip.rb
140
+ - lita-chilean-bip.gemspec
141
+ - locales/en.yml
142
+ - spec/fixtures/response.html
143
+ - spec/lita/handlers/chilean_bip_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage: https://github.com/milo-ft/lita-chilean-bip
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ lita_plugin_type: handler
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.2.2
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: A Lita handler for checking the BIP card balance
170
+ test_files:
171
+ - spec/fixtures/response.html
172
+ - spec/lita/handlers/chilean_bip_spec.rb
173
+ - spec/spec_helper.rb