lita-chilean-bip 1.1.0 → 1.1.1

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: 190ff3e223f889a9963bc190ace1a1f658e23fd8
4
- data.tar.gz: 081c324ca3c43d485141f570238c21c15bc3ff0c
3
+ metadata.gz: 8e0690da95f2df9abedbe29876bfc3638ad5cbe9
4
+ data.tar.gz: d57e3bde5c0bb0bd6b52b3fac506669b64be2eeb
5
5
  SHA512:
6
- metadata.gz: 673a460c18b2a11ef904fab2d9f508460f12c3a258c119f7b53beedb110375c4013946ff6cbeb49df260bffbcaf88894f310ee0679325766556994508f53f451
7
- data.tar.gz: e81fe14a20c9639e8a5209078ab88a2f6e23e941c650da81de069c977412aea184800064840d157d9699f2d3600f530764eb2459766472ba62d92d68692eef9b
6
+ metadata.gz: 558d4f42951e226aa6e1448709e1f276b42523e8329e7ae709e54ba6466a8e246be6870469caf2723dc540093ccd6d8beec3cc03e7dbee4528ca949ebad316aa
7
+ data.tar.gz: 9a6a4a12ae1f1beaffbe741fa5d9edeab315bd967a37f2d37368d1430b59fc40b209040c8d52ac2de70116115be6a31caa49e368195ba2d0b13b64ecf4e4d747
data/README.md CHANGED
@@ -1,22 +1,37 @@
1
1
  # lita-chilean-bip
2
2
 
3
- TODO: Add a description of the plugin.
3
+ [![Build Status](https://travis-ci.org/milo-ft/lita-chilean-bip.png)](https://travis-ci.org/milo-ft/lita-chilean-bip)
4
+ [![Code Climate](https://codeclimate.com/github/milo-ft/lita-chilean-bip.png)](https://codeclimate.com/github/milo-ft/lita-chilean-bip)
5
+ [![Coverage Status](https://coveralls.io/repos/milo-ft/lita-chilean-bip/badge.png)](https://coveralls.io/r/milo-ft/lita-chilean-bip)
6
+
7
+ **lita-chilean-bip** is a [Lita](https://github.com/jimmycuadra/lita) handler for checking the BIP card balance.
4
8
 
5
9
  ## Installation
6
10
 
7
- Add lita-chilean-bip to your Lita instance's Gemfile:
11
+ Add **lita-chilean-bip** to your Lita instance's Gemfile:
8
12
 
9
13
  ``` ruby
10
14
  gem "lita-chilean-bip"
11
15
  ```
12
16
 
13
- ## Configuration
17
+ ## Usage
14
18
 
15
- TODO: Describe any configuration attributes the plugin exposes.
19
+ To check your balance:
20
+ ```
21
+ @bot bip <number>
22
+ ```
16
23
 
17
- ## Usage
24
+ Also you can store your number for future requests:
25
+
26
+ ```
27
+ @bot my bip is <number>
28
+ ```
29
+ then...
30
+ ```
31
+ @bot bip
32
+ ```
18
33
 
19
- TODO: Describe the plugin's features and how to use them.
34
+ Requests are case-insensitive
20
35
 
21
36
  ## License
22
37
 
@@ -5,6 +5,15 @@ module Lita
5
5
  class ChileanBip < Handler
6
6
 
7
7
  REDIS_KEY = 'lita-chilean-bip'
8
+ QUERY_URL = 'http://saldobip.com'
9
+ PARSE_SELECTOR = '#resultados #datos strong'
10
+ POST_HEADERS = {
11
+ 'Content-Type' => 'application/x-www-form-urlencoded',
12
+ 'Host' => 'saldobip.com',
13
+ 'Origin' => 'http://saldobip.com',
14
+ 'Referer' => 'http://saldobip.com/',
15
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36'
16
+ }
8
17
 
9
18
  route %r{^bip\s*(\d+)}i, :bip_balance, help: { 'bip ...' => 'gets the balance for BIP card ...' }
10
19
  route %r{^my bip is (\d+)}i, :store_bip, help: { 'my bip is ...' => "stores the user's BIP card ..." }
@@ -37,7 +46,7 @@ module Lita
37
46
  end
38
47
 
39
48
  def key_from_user(user)
40
- user.to_s.downcase.strip
49
+ user.id
41
50
  end
42
51
 
43
52
  def balance_for_card_number(card_number, response)
@@ -52,28 +61,19 @@ module Lita
52
61
  end
53
62
 
54
63
  def post_query_for_card(card_number)
55
- headers = {
56
- 'Content-Type' => 'application/x-www-form-urlencoded',
57
- 'Host' => 'saldobip.com',
58
- 'Origin' => 'http://saldobip.com',
59
- 'Referer' => 'http://saldobip.com/',
60
- 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36'
61
- }
62
-
63
- conn = Faraday.new(:url => 'http://saldobip.com') do |faraday|
64
+ conn = Faraday.new(:url => QUERY_URL) do |faraday|
64
65
  faraday.request :url_encoded # form-encode POST params
65
66
  faraday.response :logger # log requests to STDOUT
66
67
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
67
68
  end
68
-
69
- response = conn.post '/', { NumTarjeta: card_number, pedirSaldo: '' }, headers
69
+ response = conn.post '/', { NumTarjeta: card_number, pedirSaldo: '' }, POST_HEADERS
70
70
  response.body
71
71
  end
72
72
 
73
73
  def parse_data_from_html(response)
74
74
  tag_data = []
75
75
  doc = Nokogiri::HTML(response)
76
- doc.css('#resultados #datos strong').each do |tag|
76
+ doc.css(PARSE_SELECTOR).each do |tag|
77
77
  tag_data << tag.content
78
78
  end
79
79
  data = tag_data.empty? ? {} : { balance: tag_data[0], date: tag_data[1] }
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-chilean-bip'
3
- spec.version = '1.1.0'
3
+ spec.version = '1.1.1'
4
4
  spec.authors = ['Emilio Figueroa']
5
5
  spec.email = ['emiliofigueroatorres@gmail.com']
6
6
  spec.description = %q{A Lita handler for checking the BIP card balance}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-chilean-bip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emilio Figueroa