portal_scraper 1.0.0 → 1.1.0

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
- SHA1:
3
- metadata.gz: 33892f3c3d5127d2a1330f14ef249281e9de97b4
4
- data.tar.gz: 8063f1e877d9f6da2f18784b12f12b70cde6993f
2
+ SHA256:
3
+ metadata.gz: c17340a2ba668c837521fc740a1b2f6f845e79f689121e351c0a46d3929de5ab
4
+ data.tar.gz: a9e36eea49ee51e7d0128f9cc706839983ef9dcafd8e584823527725c660e1ab
5
5
  SHA512:
6
- metadata.gz: 397013f41893a3f0cb9d461e736cc23248e8ba20b1bdabf0894d2f6ed262c3d741802c0d1f671ae183556ec7e55625cad5674aa5888a3d0936b971f478a8663d
7
- data.tar.gz: a677e1c67c6dd0f4e23a9bcffecadbc8e0b4a9fbf563379ee0900ea6028f9c878ecfa02901d17cc2c0155d405c3600409be99f58a60e163bad4432f57a79b156
6
+ metadata.gz: b188d4e98c4e8cf0cedc6e474cdaae9cb7de80f40e96776f94fbb2aff476bd2bb0a4b44aae497b29481104e80d139137adf76e19133a45c1c76a370c39075970
7
+ data.tar.gz: b711ef1ff9de12d9c51460e7df2e8b71717bf11154bc31d84fb960a17f587606b1ffde83080caa94cd172eac3065a9acde01f5e0c951877c5aa477b85b29f0c6
@@ -1,4 +1,6 @@
1
1
  require 'portal_scraper/accounts/client'
2
+ require 'portal_scraper/bad_root_url'
3
+ require 'portal_scraper/bad_login_url'
2
4
 
3
5
  module PortalScraper
4
6
  Config = Struct.new(:root_url, :app_id, :secret, :login_url, :token_url)
@@ -3,27 +3,38 @@ require 'mechanize'
3
3
  module PortalScraper
4
4
  module Accounts
5
5
  class Client
6
- attr_accessor :app_id, :secret
6
+ attr_accessor :_app_id, :_secret
7
7
 
8
8
  def initialize(app_id = nil, secret = nil)
9
- @app_id = app_id || config.app_id
10
- @secret = secret || config.secret
9
+ _app_id = app_id || config.app_id
10
+ _secret = secret || config.secret
11
+ raise BadRootUrl unless config.root_url =~ URI::regexp
12
+ end
13
+
14
+ def try_form_fields(form, fields, value)
15
+ fields.each do |field|
16
+ if form.respond_to?("#{field}=")
17
+ form.send("#{}=", value)
18
+ break
19
+ end
20
+ end
11
21
  end
12
22
 
13
23
  def login
24
+ raise BadLoginUrl if config.login_url.nil?
14
25
  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
26
+ form = login_page.form_with(name: /login/i) || login_page.forms[0]
27
+ try_form_fields(form, %i(username login), _app_id)
28
+ try_form_fields(form, %i(password secret), _secret)
29
+ form.submit
19
30
  end
20
- app.get(url_for(config.token_url))
31
+ app.get(url_for(config.token_url)) unless config.token_url.nil?
21
32
  end
22
33
 
23
34
  def get_accounts_balance
24
35
  login
25
36
  accounts_data = { accounts: [] }
26
- results = app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
37
+ results = app.post(url_for('/appRecherche.do'), { nom: '', prenom: '', chercher: 'Chercher' })
27
38
  results.links_with(href: /appTiersDetail.do/).each do |link|
28
39
  account = link.click
29
40
  accounts_data[:accounts] << {
@@ -0,0 +1,6 @@
1
+ require 'portal_scraper/portal_scraper_error'
2
+
3
+ module PortalScraper
4
+ class BadLoginUrl < Error
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'portal_scraper/portal_scraper_error'
2
+
3
+ module PortalScraper
4
+ class BadRootUrl < Error
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module PortalScraper
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -1,12 +1,11 @@
1
1
  module PortalScraper
2
2
  class Version
3
3
  MAJOR = 1
4
- MINOR = 0
5
- TINY = 0
6
- PRE = nil
4
+ MINOR = 1
5
+ PATCH = 0
7
6
 
8
7
  def self.to_s
9
- [MAJOR, MINOR, TINY, PRE].compact.join('.')
8
+ [MAJOR, MINOR, PATCH].compact.join('.')
10
9
  end
11
10
  end
12
11
  end
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'mechanize', '~> 2.7'
26
26
 
27
27
  spec.add_development_dependency 'rspec', '~> 3.2'
28
- spec.add_development_dependency 'bundler', "~> 1.16"
29
- spec.add_development_dependency 'rake', "~> 10.0"
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'vcr'
31
+ spec.add_development_dependency 'webmock'
30
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portal_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armand Mégrot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: Scrapping client for extranet portals.
70
98
  email:
71
99
  - armand.megrot@gmail.com
@@ -75,6 +103,9 @@ extra_rdoc_files: []
75
103
  files:
76
104
  - lib/portal_scraper.rb
77
105
  - lib/portal_scraper/accounts/client.rb
106
+ - lib/portal_scraper/bad_login_url.rb
107
+ - lib/portal_scraper/bad_root_url.rb
108
+ - lib/portal_scraper/portal_scraper_error.rb
78
109
  - lib/portal_scraper/version.rb
79
110
  - portal-scraper.gemspec
80
111
  homepage: https://github.com/cashbee-team/portal_scraper
@@ -97,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
128
  version: '0'
98
129
  requirements: []
99
130
  rubyforge_project:
100
- rubygems_version: 2.5.2.3
131
+ rubygems_version: 2.7.8
101
132
  signing_key:
102
133
  specification_version: 4
103
134
  summary: Ruby portal scraper