portal_scraper 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: 33892f3c3d5127d2a1330f14ef249281e9de97b4
4
+ data.tar.gz: 8063f1e877d9f6da2f18784b12f12b70cde6993f
5
+ SHA512:
6
+ metadata.gz: 397013f41893a3f0cb9d461e736cc23248e8ba20b1bdabf0894d2f6ed262c3d741802c0d1f671ae183556ec7e55625cad5674aa5888a3d0936b971f478a8663d
7
+ data.tar.gz: a677e1c67c6dd0f4e23a9bcffecadbc8e0b4a9fbf563379ee0900ea6028f9c878ecfa02901d17cc2c0155d405c3600409be99f58a60e163bad4432f57a79b156
@@ -0,0 +1,56 @@
1
+ require 'mechanize'
2
+
3
+ module PortalScraper
4
+ module Accounts
5
+ class Client
6
+ attr_accessor :app_id, :secret
7
+
8
+ def initialize(app_id = nil, secret = nil)
9
+ @app_id = app_id || config.app_id
10
+ @secret = secret || config.secret
11
+ end
12
+
13
+ def login
14
+ app.get(url_for(config.login_url)) do |login_page|
15
+ login_page.form_with(name: /login/i) do |creds|
16
+ creds.username = app_id
17
+ creds.password = secret
18
+ end.submit
19
+ end
20
+ app.get(url_for(config.token_url))
21
+ end
22
+
23
+ def get_accounts_balance
24
+ login
25
+ accounts_data = { accounts: [] }
26
+ results = app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
27
+ results.links_with(href: /appTiersDetail.do/).each do |link|
28
+ account = link.click
29
+ accounts_data[:accounts] << {
30
+ client_ref: find_table_value(account, 'Identifiant tiers'),
31
+ balance: account.search('table#contrat th.n').text.gsub(/[[:space:]]+/, '').to_f
32
+ }
33
+ end
34
+ accounts_data
35
+ end
36
+
37
+ private
38
+
39
+ def app
40
+ @app ||= Mechanize.new
41
+ end
42
+
43
+ def url_for(path)
44
+ [config.root_url, path].join
45
+ end
46
+
47
+ def find_table_value(node, column_name)
48
+ node.search('td.CA_LABEL').find { |column| column.text.strip == column_name }.parent.search('td.CA_LIB').text.strip
49
+ end
50
+
51
+ def config
52
+ PortalScraper.config
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,12 @@
1
+ module PortalScraper
2
+ class Version
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
+ PRE = nil
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, TINY, PRE].compact.join('.')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require 'portal_scraper/accounts/client'
2
+
3
+ module PortalScraper
4
+ Config = Struct.new(:root_url, :app_id, :secret, :login_url, :token_url)
5
+
6
+ def self.configure
7
+ raise ArgumentError.new('No block given') unless block_given?
8
+ yield config
9
+ end
10
+
11
+ private
12
+
13
+ def self.config
14
+ @config ||= Config.new
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'portal_scraper/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.name = 'portal_scraper'
10
+ spec.version = PortalScraper::Version
11
+ spec.authors = ['Armand Mégrot']
12
+ spec.email = ['armand.megrot@gmail.com']
13
+ spec.summary = 'Ruby portal scraper'
14
+ spec.description = 'Scrapping client for extranet portals.'
15
+ spec.license = 'Apache-2.0'
16
+ spec.homepage = 'https://github.com/cashbee-team/portal_scraper'
17
+
18
+ spec.files = Dir.glob('lib/**/*') + ['portal-scraper.gemspec']
19
+ spec.executables = []
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.required_ruby_version = '>= 2.5.3'
24
+
25
+ spec.add_dependency 'mechanize', '~> 2.7'
26
+
27
+ spec.add_development_dependency 'rspec', '~> 3.2'
28
+ spec.add_development_dependency 'bundler', "~> 1.16"
29
+ spec.add_development_dependency 'rake', "~> 10.0"
30
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: portal_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Armand Mégrot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Scrapping client for extranet portals.
70
+ email:
71
+ - armand.megrot@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/portal_scraper.rb
77
+ - lib/portal_scraper/accounts/client.rb
78
+ - lib/portal_scraper/version.rb
79
+ - portal-scraper.gemspec
80
+ homepage: https://github.com/cashbee-team/portal_scraper
81
+ licenses:
82
+ - Apache-2.0
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.5.3
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.5.2.3
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Ruby portal scraper
104
+ test_files: []