voys_api 0.0.4 → 0.1.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.
- data/lib/voys_api/client.rb +9 -1
- data/lib/voys_api/exceptions.rb +5 -0
- data/lib/voys_api/version.rb +1 -1
- data/lib/voys_api.rb +1 -0
- metadata +2 -1
data/lib/voys_api/client.rb
CHANGED
@@ -13,12 +13,18 @@ class VoysApi::Client
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def login
|
16
|
-
@logged_in
|
16
|
+
return true if @logged_in
|
17
17
|
page = agent.get('https://client.voys.nl/user/login/')
|
18
18
|
login_form = page.form
|
19
|
+
login_form.fields.detect {|field| field.name == 'this_is_the_login_form'} || raise(VoysApi::AuthenticationError, "Could not find the login form!")
|
19
20
|
login_form.field_with(:name => "username").value = @username
|
20
21
|
login_form.field_with(:name => "password").value = @password
|
21
22
|
login_result = agent.submit login_form
|
23
|
+
if (login_result.form && login_result.form.fields.detect {|field| field.name == 'this_is_the_login_form'})
|
24
|
+
# We're still on the login page!
|
25
|
+
raise(VoysApi::AuthenticationError, "Error logging in!")
|
26
|
+
end
|
27
|
+
@logged_in = true
|
22
28
|
end
|
23
29
|
|
24
30
|
# Options:
|
@@ -42,6 +48,8 @@ class VoysApi::Client
|
|
42
48
|
csv_options = {col_sep: ';', converters: [:date_time], headers: :first_row, header_converters: :symbol}.merge(options)
|
43
49
|
export = CSV.parse(raw_export, csv_options)
|
44
50
|
return export
|
51
|
+
rescue CSV::MalformedCSVError => exception
|
52
|
+
raise exception, "#{exception.message}\nCSV:\n#{raw_export}"
|
45
53
|
end
|
46
54
|
|
47
55
|
def logout
|
data/lib/voys_api/version.rb
CHANGED
data/lib/voys_api.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voys_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- Rakefile
|
74
74
|
- lib/voys_api.rb
|
75
75
|
- lib/voys_api/client.rb
|
76
|
+
- lib/voys_api/exceptions.rb
|
76
77
|
- lib/voys_api/version.rb
|
77
78
|
- voys_api.gemspec
|
78
79
|
homepage: https://github.com/joost/voys_api
|