voys_api 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,12 +13,18 @@ class VoysApi::Client
13
13
  end
14
14
 
15
15
  def login
16
- @logged_in = true
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
@@ -0,0 +1,5 @@
1
+ module VoysApi
2
+
3
+ class AuthenticationError < StandardError; end
4
+
5
+ end
@@ -1,3 +1,3 @@
1
1
  module VoysApi
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/voys_api.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative "voys_api/version"
2
2
  require_relative "voys_api/client"
3
+ require_relative "voys_api/exceptions"
3
4
 
4
5
  module VoysApi
5
6
  end
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
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