autoexpreso 1.0.2 → 2.0.0

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
- SHA1:
3
- metadata.gz: 01f6d8da2466fc73fe50f7afa664348eb4d9dbf0
4
- data.tar.gz: 0bcf1883d33c9d26664a9c794075387047388567
2
+ SHA256:
3
+ metadata.gz: 55498b4536218b4166e414cff6d06db0c6bdb8740c3f64c97b1dae4ad0c55386
4
+ data.tar.gz: 0e5db18bc018df5caf8d518e2891ca382ceaa0e651541251dc707090621197bf
5
5
  SHA512:
6
- metadata.gz: 0c38655881d0b332f58ecd7d1605e460d8c1dff38c9fde0292cbac48e4dd4aab8697f2db535436c01757826fc6148be48b55698ad1d02fc2b25f36c6c1ce2144
7
- data.tar.gz: 755218ce25bd091e92131a0283d5eed0d5a742929eb50f90ea6a797e3e5411cf534090b4d6f2702e83b25760fdcd3bb915482b0361d9694a950620e87cce8899
6
+ metadata.gz: df25eaea388b51735ab1471bd3f877ea5dff9dac96da166cab9f40f07913dbaf0a2ee30017f3a3dc396bfac888ea7244aebdb84d1d241250099c688d350fecd0
7
+ data.tar.gz: 7d98592cd5e477a3003fcfa41b30b731c059220235757e35d635c5756381da0b1ad08e4be2969a5b9f97382e27f51f0cef017d335f73edc8104dc1b715f60ef6
@@ -1 +1 @@
1
- ruby-2.4.1
1
+ ruby-2.7.1
@@ -1,5 +1,14 @@
1
1
  # AutoExpreso Changelog
2
2
 
3
+ ### 2.0.0
4
+ Released July 5, 2020 ([2.0.0](https://github.com/jonahoffline/autoexpreso-cli/tree/v2.0.0)).
5
+
6
+ * Replace Old AutoExpreso (scraped) API with newly REST endpoints.
7
+ * Replace `mechanize` dependency for `faraday` and `typhoeus`.
8
+ * Replace `awesome_print` dependency to `awesome_print`.
9
+ * Add Typhoeus caching.
10
+ * Update gemspec to require Ruby version >= 2.4
11
+
3
12
  ### 1.0.2
4
13
  Released August 5, 2017 ([1.0.2](https://github.com/jonahoffline/autoexpreso-cli/tree/v1.0.2)).
5
14
 
data/README.md CHANGED
@@ -1,9 +1,6 @@
1
1
  ## Autoexpreso
2
- [![Build Status](http://img.shields.io/travis/jonahoffline/autoexpreso-cli.svg?style=flat-square)](https://travis-ci.org/jonahoffline/autoexpreso-cli)
3
2
  [![Gem Version](http://img.shields.io/gem/v/autoexpreso.svg?style=flat-square)](http://badge.fury.io/rb/autoexpreso)
4
- [![Dependency Status](http://img.shields.io/gemnasium/jonahoffline/autoexpreso-cli.svg?style=flat-square)](https://gemnasium.com/jonahoffline/autoexpreso-cli)
5
- [![Code Climate](http://img.shields.io/codeclimate/github/jonahoffline/autoexpreso-cli.svg?style=flat-square)](https://codeclimate.com/github/jonahoffline/autoexpreso-cli)
6
- [![security](https://hakiri.io/github/jonahoffline/autoexpreso-cli/master.svg)](https://hakiri.io/github/jonahoffline/autoexpreso-cli/master)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/9cde80c2131b5ca913f2/maintainability)](https://codeclimate.com/github/jonahoffline/autoexpreso-cli/maintainability)
7
4
 
8
5
  A Ruby Gem and Command-Line App for getting your account status from autoexpreso.com
9
6
 
@@ -41,30 +38,37 @@ In your terminal:
41
38
  **************************************************
42
39
  Enter your account details
43
40
 
44
- Username: tavin_pumarejo
41
+ Email: tavin_pumarejo
45
42
  Password: **************
46
43
  Account Details:
47
- {
48
- "account_name_id": "TAVIN PUMAREJO",
49
- "account_balance_id": "$ 17.80",
50
- "account_status_id": "Activo",
51
- "account_last_payment_id": "$ 20.00",
52
- "account_last_payment_date_id": "20/11/2014 05:29:10 p.m.",
44
+ ```
45
+
46
+ ```json
47
+
48
+ {
49
+ "currentBalance": 13.5500,
50
+ "firstName": "Tavin",
51
+ "lastName": "Pumarejo",
52
+ "email": "tavin@pumarejo.com",
53
53
  "transactions": [
54
- {
55
- "date": "20/11/2014 10:21:44 p.m.",
56
- "location": "Toa Baja - 5",
57
- "amount": "$ 1.10",
58
- "tag_number": "1337"
59
- },
60
- {
61
- "date": "20/11/2014 05:43:17 p.m.",
62
- "location": "Buchanan - 21",
63
- "amount": "$ 1.10",
64
- "tag_number": "1337"
65
- }
66
- ]
67
- }
54
+ {
55
+ "transactionDate": "4/27/2020 9:27:34 PM",
56
+ "plaza": "Buchanan Eb Ort - 8",
57
+ "amount": 0.7000,
58
+ "tagNumber": 1337,
59
+ "location": "Buchanan Eb Ort - 3",
60
+ "isReplenish": false,
61
+ "vehicle": {
62
+ "brand": "Suzuki",
63
+ "model": "Forsa Tres Potes 800",
64
+ "year": 1985,
65
+ "plate": "TP123",
66
+ "axles": 0,
67
+ "tagNumber": 0
68
+ }
69
+ }
70
+ ]
71
+ }
68
72
  ```
69
73
 
70
74
  ### Command-Line Options
@@ -6,10 +6,10 @@ require 'autoexpreso/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'autoexpreso'
8
8
  spec.version = AutoExpreso::VERSION
9
- spec.authors = ['Axel Rivera','Jonah Ruiz']
10
- spec.email = ['axel@riveralabs.com','jonah@pixelhipsters.com']
11
- spec.description = %q{Scrape autoexpreso.com for your account status}
12
- spec.summary = %q{Scrape autoexpreso.com for your account status and last transactions.}
9
+ spec.authors = ['Jonah Ruiz']
10
+ spec.email = ['jonah@pixelhipsters.com']
11
+ spec.description = %q{Non-official autoexpreso.com Ruby library and CLI application.}
12
+ spec.summary = %q{Non-official autoexpreso.com Ruby library and CLI for the service}
13
13
  spec.homepage = 'https://www.github.com/jonahoffline/autoexpreso-cli'
14
14
  spec.license = 'MIT'
15
15
 
@@ -17,13 +17,14 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
- spec.required_ruby_version = '>= 2.2.2'
20
+ spec.required_ruby_version = '>= 2.4'
21
21
 
22
- spec.add_dependency 'awesome_print', '~> 1.8'
23
- spec.add_dependency 'highline', '~> 1.7.8'
24
- spec.add_dependency 'mechanize', '~> 2.7.5'
22
+ spec.add_dependency 'amazing_print', '~> 1.2.1'
23
+ spec.add_dependency 'highline', '~> 2.0.3'
24
+ spec.add_dependency 'faraday', '~> 1.0.1'
25
+ spec.add_dependency 'typhoeus', '~> 1.4.0'
25
26
 
26
27
  spec.add_development_dependency 'bundler'
27
28
  spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'rspec', '~> 3.6'
29
+ spec.add_development_dependency 'rspec', '~> 3.9'
29
30
  end
@@ -18,7 +18,7 @@ $ rackup config.ru
18
18
 
19
19
  Posting to `/account_details`
20
20
 
21
- `curl -X POST -H "Content-Type: application/json" -d '{"username":"tavi_pumarejo","password":"tututuah-tuah"}' http://autoexpreso-api.herokuapp.com/account_details`
21
+ `curl -X POST -H "Content-Type: application/json" -d '{"email":"tavi_pumarejo","password":"tututuah-tuah"}' http://autoexpreso-api.herokuapp.com/account_details`
22
22
 
23
23
 
24
24
  ## Deploying to Heroku
@@ -14,7 +14,7 @@ module AutoExpreso
14
14
  data = JSON.parse(request.body.read)
15
15
 
16
16
  ae = AutoExpreso::Client.new
17
- ae.login(data['username'], data['password'])
17
+ ae.login(data['email'], data['password'])
18
18
 
19
19
  json ae.account_details
20
20
  end
@@ -1,7 +1,10 @@
1
1
  require 'autoexpreso/version'
2
2
  require 'autoexpreso/data_utils'
3
- require 'mechanize'
4
- require 'awesome_print'
3
+ require 'autoexpreso/cache'
4
+ require 'faraday'
5
+ require 'typhoeus'
6
+ require 'typhoeus/adapters/faraday'
7
+ require 'amazing_print'
5
8
  require 'ostruct'
6
9
  require 'json'
7
10
 
@@ -9,71 +12,75 @@ module AutoExpreso
9
12
  class Client
10
13
  include AutoExpreso::DataUtils
11
14
 
12
- AE_LOGIN = 'https://www.autoexpreso.com/Login.aspx'
13
- AE_ACCOUNT = 'https://www.autoexpreso.com/dynamic/'
15
+ BASE_URL = 'https://tp-api.autoexpreso.com'
16
+ USER_AGENT = "AutoExpreso-Rubygem/#{AutoExpreso::VERSION}"
14
17
 
15
- attr_reader :client, :account, :transactions, :account_page
18
+ ENDPOINTS = {
19
+ login: '/api/Auth/Login',
20
+ account_summary: '/api/Account/GetAccountSummary'
21
+ }
22
+
23
+ attr_reader :account
24
+ attr_accessor :jwt_header
16
25
 
17
26
  def initialize(*args)
18
- @client = Mechanize.new
19
- @account = Hash.new
20
- @transactions = []
27
+ @account = Hash.new
21
28
  end
22
29
 
23
- def login(username, password)
24
- authenticate(username, password)
25
- process_request
30
+ def login(email, password)
31
+ authenticate(email, password)
32
+ account_summary
26
33
  end
27
34
 
28
- def authenticate(username, password)
29
- @client.get(AE_LOGIN) do |page|
30
- page.form_with(id: form_data.login_form_id) do |form|
31
- form[form_data.login_form_username_name] = username
32
- form[form_data.login_form_password_name] = password
33
- end.click_button
35
+ def account_details(json: false)
36
+ if json
37
+ puts JSON.pretty_generate(account)
38
+ else
39
+ ap account
34
40
  end
35
41
  end
36
42
 
37
- def process_request
38
- process_transactions
39
- save_account
40
- table_strip
41
- end
42
-
43
- def process_transactions
44
- @account_page = @client.get(AE_ACCOUNT)
45
- end
43
+ protected
46
44
 
47
- def save_account
48
- attributes.map do |attribute|
49
- @account[attribute] = text_strip(form_data.send(attribute))
45
+ def authorization_header
46
+ "Bearer #{jwt_header}"
50
47
  end
51
- end
52
48
 
53
- def text_strip(field_name)
54
- @account_page.search(field_name).text.strip
55
- end
49
+ def default_connection(debug = false)
50
+ Faraday.new(url: BASE_URL) do |conn|
51
+ conn.adapter :typhoeus
52
+ conn.headers[:user_agent] = USER_AGENT
53
+ conn.headers[:content_type] = 'application/json'
54
+ conn.headers['Authorization'] = authorization_header if @jwt_header
55
+ conn.response :logger if debug
56
+ end
57
+ end
56
58
 
57
- def table_data
58
- @account_page.search("#{form_data.account_transaction_table_id} tbody tr")
59
- end
59
+ def authenticate(email, password)
60
+ payload = { email: email, password: password }
60
61
 
61
- def table_strip
62
- table_data.each do |tr|
63
- tds = tr.search('td')
64
- next unless tds.count == 4
62
+ response = default_connection.post do |req|
63
+ req.url(ENDPOINTS[:login])
64
+ req.body = JSON.generate(payload)
65
+ end
65
66
 
66
- save_transactions(tds, @transactions)
67
+ if response.success?
68
+ @response_body = JSON.parse(response.body, object_class: OpenStruct)
69
+ @jwt_header = @response_body.accessToken
70
+ end
67
71
  end
68
- @account[:transactions] = @transactions
69
- end
70
72
 
71
- def account_details(json: false)
72
- if json
73
- puts JSON.pretty_generate(account)
74
- else
75
- ap account
73
+ def account_summary
74
+ response = default_connection.get do |req|
75
+ req.url(ENDPOINTS[:account_summary])
76
+ end
77
+
78
+ if response.success?
79
+ @response_body = JSON.parse(response.body)
80
+ @account = @response_body
81
+ end
76
82
  end
77
- end
78
83
  end
79
84
  end
85
+
86
+ Typhoeus::Config.cache = AutoExpreso::Cache.new
@@ -0,0 +1,15 @@
1
+ module AutoExpreso
2
+ class Cache
3
+ def initialize
4
+ @memory = Hash.new
5
+ end
6
+
7
+ def get(request)
8
+ @memory[request]
9
+ end
10
+
11
+ def set(request, response)
12
+ @memory[request] = response
13
+ end
14
+ end
15
+ end
@@ -59,11 +59,11 @@ MSG
59
59
  def login
60
60
  header
61
61
 
62
- username = ask('Username: ')
62
+ email = ask('Email: ')
63
63
  password = ask('Password: ') { |q| q.echo = '*' }
64
64
 
65
65
  ae = AutoExpreso::Client.new
66
- ae.login(username, password)
66
+ ae.login(email, password)
67
67
  puts "Account Details:"
68
68
 
69
69
  @json ? ae.account_details(json: true) : ae.account_details
@@ -1,3 +1,3 @@
1
1
  module AutoExpreso
2
- VERSION = '1.0.2'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,58 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoexpreso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Axel Rivera
8
7
  - Jonah Ruiz
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2017-08-06 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: awesome_print
14
+ name: amazing_print
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: '1.8'
19
+ version: 1.2.1
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: '1.8'
26
+ version: 1.2.1
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: highline
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - "~>"
33
32
  - !ruby/object:Gem::Version
34
- version: 1.7.8
33
+ version: 2.0.3
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - "~>"
40
39
  - !ruby/object:Gem::Version
41
- version: 1.7.8
40
+ version: 2.0.3
42
41
  - !ruby/object:Gem::Dependency
43
- name: mechanize
42
+ name: faraday
44
43
  requirement: !ruby/object:Gem::Requirement
45
44
  requirements:
46
45
  - - "~>"
47
46
  - !ruby/object:Gem::Version
48
- version: 2.7.5
47
+ version: 1.0.1
49
48
  type: :runtime
50
49
  prerelease: false
51
50
  version_requirements: !ruby/object:Gem::Requirement
52
51
  requirements:
53
52
  - - "~>"
54
53
  - !ruby/object:Gem::Version
55
- version: 2.7.5
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: typhoeus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.0
56
69
  - !ruby/object:Gem::Dependency
57
70
  name: bundler
58
71
  requirement: !ruby/object:Gem::Requirement
@@ -87,17 +100,16 @@ dependencies:
87
100
  requirements:
88
101
  - - "~>"
89
102
  - !ruby/object:Gem::Version
90
- version: '3.6'
103
+ version: '3.9'
91
104
  type: :development
92
105
  prerelease: false
93
106
  version_requirements: !ruby/object:Gem::Requirement
94
107
  requirements:
95
108
  - - "~>"
96
109
  - !ruby/object:Gem::Version
97
- version: '3.6'
98
- description: Scrape autoexpreso.com for your account status
110
+ version: '3.9'
111
+ description: Non-official autoexpreso.com Ruby library and CLI application.
99
112
  email:
100
- - axel@riveralabs.com
101
113
  - jonah@pixelhipsters.com
102
114
  executables:
103
115
  - autoexpreso
@@ -108,7 +120,6 @@ files:
108
120
  - ".rspec"
109
121
  - ".ruby-gemset"
110
122
  - ".ruby-version"
111
- - ".travis.yml"
112
123
  - Changelog.md
113
124
  - Gemfile
114
125
  - LICENSE
@@ -124,18 +135,16 @@ files:
124
135
  - examples/api/autoexpreso_api.rb
125
136
  - examples/api/config.ru
126
137
  - lib/autoexpreso.rb
138
+ - lib/autoexpreso/cache.rb
127
139
  - lib/autoexpreso/cli.rb
128
140
  - lib/autoexpreso/data_utils.rb
129
141
  - lib/autoexpreso/version.rb
130
- - spec/autoexpreso_spec.rb
131
- - spec/data_utils_spec.rb
132
142
  - spec/spec_helper.rb
133
- - wercker.yml
134
143
  homepage: https://www.github.com/jonahoffline/autoexpreso-cli
135
144
  licenses:
136
145
  - MIT
137
146
  metadata: {}
138
- post_install_message:
147
+ post_install_message:
139
148
  rdoc_options: []
140
149
  require_paths:
141
150
  - lib
@@ -143,19 +152,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
152
  requirements:
144
153
  - - ">="
145
154
  - !ruby/object:Gem::Version
146
- version: 2.2.2
155
+ version: '2.4'
147
156
  required_rubygems_version: !ruby/object:Gem::Requirement
148
157
  requirements:
149
158
  - - ">="
150
159
  - !ruby/object:Gem::Version
151
160
  version: '0'
152
161
  requirements: []
153
- rubyforge_project:
154
- rubygems_version: 2.6.12
155
- signing_key:
162
+ rubygems_version: 3.1.4
163
+ signing_key:
156
164
  specification_version: 4
157
- summary: Scrape autoexpreso.com for your account status and last transactions.
165
+ summary: Non-official autoexpreso.com Ruby library and CLI for the service
158
166
  test_files:
159
- - spec/autoexpreso_spec.rb
160
- - spec/data_utils_spec.rb
161
167
  - spec/spec_helper.rb
@@ -1,8 +0,0 @@
1
- ---
2
- language: ruby
3
- rvm:
4
- - 2.4.1
5
- - 2.3.3
6
- - 2.2.6
7
- - 2.2.2
8
- script: bundle exec rake test
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AutoExpreso::Client do
4
- let(:auto) { AutoExpreso::Client.new }
5
-
6
- describe '#client' do
7
- it 'returns a new Mechanize instance' do
8
- expect(auto.client).to be_kind_of(Mechanize)
9
- end
10
- end
11
-
12
- describe '#account' do
13
- it 'returns a Hash' do
14
- expect(auto.account).to be_a(Hash)
15
- end
16
- end
17
-
18
- describe '#transactions' do
19
- it 'returns an array' do
20
- expect(auto.transactions).to be_a(Array)
21
- end
22
- end
23
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AutoExpreso::DataUtils do
4
- let(:data_utils) { AutoExpreso::DataUtils }
5
-
6
- describe '#attributes' do
7
- it 'returns an array of symbols' do
8
- expect(data_utils.attributes)
9
- .to match_array [:account_name_id, :account_balance_id, :account_status_id,:account_last_payment_id, :account_last_payment_date_id]
10
- end
11
- end
12
-
13
- describe '#form_data' do
14
- it 'returns an OpenStruct instance' do
15
- expect(data_utils.form_data).to be_a(OpenStruct)
16
- end
17
-
18
- it 'contains methods' do
19
- expect(data_utils.attributes)
20
- .to match_array [:account_name_id, :account_balance_id, :account_status_id, :account_last_payment_id, :account_last_payment_date_id]
21
- end
22
-
23
- it 'returns html attributes correctly' do
24
- expect(data_utils.form_data.login_form_id).to eq('aspnetForm')
25
- expect(data_utils.form_data.login_form_username_name).to eq('ctl00$ContentPlaceHolder1$Login1$uxUserNameField')
26
- expect(data_utils.form_data.login_form_password_name).to eq('ctl00$ContentPlaceHolder1$Login1$uxPasswordField')
27
- expect(data_utils.form_data.account_name_id).to eq('#ctl00_Content_uxLogonAccountName')
28
- expect(data_utils.form_data.account_balance_id).to eq('#ctl00_Content_uxLogonBalanceAmount')
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- box: wercker/rvm
2
- build:
3
- steps:
4
- - rvm-use:
5
- version: 2.1.4
6
- - bundle-install
7
- - script:
8
- name: echo ruby information
9
- code: |
10
- echo "ruby version $(ruby --version) running"
11
- echo "from location $(which ruby)"
12
- echo -p "gem list: $(gem list)"
13
- - script:
14
- name: rspec
15
- code: rake spec