ifin24-client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/ifin24 CHANGED
@@ -1,21 +1,75 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
3
2
 
4
3
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
4
 
6
5
  require 'rubygems'
7
-
8
- require 'yaml'
9
6
  require 'mechanize'
10
7
  require 'highline/import'
11
8
 
9
+ require 'optparse'
10
+ require 'ostruct'
11
+
12
12
  require 'ifin24'
13
13
 
14
- def main
15
- config = Ifin24::Configuration.instance
16
- client = Ifin24::Client.new(config[:login], config[:password])
17
- console = Ifin24::Console.new(client)
18
- console.main_menu
14
+ class App
15
+
16
+ def initialize(arguments)
17
+ @arguments = arguments
18
+
19
+ # Set defaults
20
+ @options = OpenStruct.new
21
+ @options.verbose = false
22
+ @options.quiet = false
23
+ end
24
+
25
+ def run
26
+ parse_options
27
+
28
+ config = Ifin24::Configuration.instance
29
+ login = @options.login || config[:login]
30
+ password = @options.password || config[:password]
31
+ client = Ifin24::Client.new(login, password)
32
+
33
+ if client.logged?
34
+ console = Ifin24::Console.new(client)
35
+ console.main_menu
36
+ else
37
+ puts "Bad login or password."
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def parse_options
44
+ # Specify options
45
+ opts = OptionParser.new
46
+ opts.set_summary_indent(' ')
47
+ script_name = File.basename($0)
48
+ opts.banner = "Usage: #{script_name} [OPTIONS]"
49
+ opts.define_head "Abstract description of script"
50
+
51
+ opts.separator ""
52
+ opts.separator "Mandatory arguments to long options are mandatory for short options too."
53
+ opts.separator ""
54
+
55
+ opts.on("-l", "--login", "User login") do |login|
56
+ @options.login = login
57
+ end
58
+
59
+ opts.on("-p", "--password", "User password") do |password|
60
+ @options.password = password
61
+ end
62
+
63
+ opts.on_tail("-h", "--help", "Show this help message.") do
64
+ puts opts
65
+ exit
66
+ end
67
+
68
+ opts.parse!(@arguments) rescue return false
69
+ end
70
+
19
71
  end
20
72
 
21
- main
73
+ # Create and run the application
74
+ app = App.new(ARGV)
75
+ app.run
@@ -8,4 +8,3 @@ module Ifin24
8
8
  autoload :Models, 'ifin24/models'
9
9
 
10
10
  end
11
-
@@ -67,6 +67,10 @@ class Ifin24::Client
67
67
  return entries, total_pages
68
68
  end
69
69
 
70
+ def logged?
71
+ @logged
72
+ end
73
+
70
74
  private
71
75
 
72
76
  def login(login, password)
@@ -76,7 +80,8 @@ class Ifin24::Client
76
80
  form['login'] = login
77
81
  form['password'] = password
78
82
 
79
- form.submit
83
+ page = form.submit
84
+ @logged = page.forms.first.nil?
80
85
  end
81
86
 
82
87
  def fetch_categories
@@ -1,4 +1,5 @@
1
1
  require 'singleton'
2
+ require 'yaml'
2
3
 
3
4
  class Ifin24::Configuration
4
5
  include Singleton
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ifin24-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "\xC5\x81ukasz Bandzarewicz"