hylafax 0.1.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: bafeedd8e5c2a0e7ce1b8b15a40435d7fd12e25d
4
- data.tar.gz: 531c59bfbf6b91817103b2f697335af172436c01
3
+ metadata.gz: 48ac10855d7064eaadb8ccbf8f5981c626275bb6
4
+ data.tar.gz: 5b01e8cde7fe8b3881803372aeb4ba97bb4265c0
5
5
  SHA512:
6
- metadata.gz: e536b9f0a9da95a221f6553653b5daf8a87a36fa7744202efa38276d5f5c8307b3f1ccaa0db511329465a9bd35ff3bebd81caefe74ed38aca02f32b634f3354d
7
- data.tar.gz: fec8805a6b4e2f3fa47e827c281a114b80b4f638f3dfb4b86871e37dfd62b73bc5a6ac64e5adb0e6e7c96295f79a8466da4e7c6b70ee300736474c21796281f8
6
+ metadata.gz: ea62247c292a0d0667a17d247acd9f885bb17dd59217638b27f47dce1013430c2623e56dc3d85fb239773979844065fb12b3047a520c32115ee8647372f6985f
7
+ data.tar.gz: e5f2bf5d99fe1738c11c6803f3e7494cb7e7e96c9a166d14b989da0713685d3b6341ffe744fd517eee017ddec492829071f6c2c848bdc09c515ed8ff816776a6
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # The Ruby HylaFAX Client
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hylafax.svg)](https://badge.fury.io/rb/hylafax)
4
+ [![Build Status](https://travis-ci.org/bjoernalbers/hylafax.svg?branch=master)](https://travis-ci.org/bjoernalbers/hylafax)
5
+
3
6
  Send faxes with a
4
7
  [HylaFAX](http://www.hylafax.org/)
5
8
  server via Ruby.
@@ -29,9 +32,18 @@ Sending a fax:
29
32
  ```ruby
30
33
  require 'hylafax'
31
34
 
35
+ # Send fax and return the job id.
32
36
  HylaFAX.sendfax(host: '10.2.2.1', dialstring: '0123456', document: 'foo.pdf')
37
+ # => 29
38
+
39
+ ```
33
40
 
34
- # This will send the fax and return the job id.
41
+ Checking fax statuses:
42
+
43
+ ```ruby
44
+ # Query status by job id for completed faxes.
45
+ HylaFAX.faxstat(host: '10.2.2.1')
46
+ # => {29=>:done, 28=>:done, 27=>:failed}
35
47
  ```
36
48
 
37
49
 
@@ -2,10 +2,16 @@ require 'net/ftp'
2
2
  require 'digest/md5'
3
3
 
4
4
  require 'hylafax/version'
5
+ require 'hylafax/command'
5
6
  require 'hylafax/send_fax'
7
+ require 'hylafax/fax_stat'
6
8
 
7
9
  module HylaFAX
8
10
  def self.sendfax(*opts)
9
11
  SendFax.new(*opts).run
10
12
  end
13
+
14
+ def self.faxstat(*opts)
15
+ FaxStat.new(*opts).run
16
+ end
11
17
  end
@@ -0,0 +1,28 @@
1
+ module HylaFAX
2
+ class Command
3
+ DEFAULT_HOST = '127.0.0.1'
4
+ DEFAULT_PORT = 4559
5
+ DEFAULT_USER = 'anonymous'
6
+ DEFAULT_PASSWORD = 'anonymous'
7
+
8
+ attr_reader :ftp, :host, :port, :user, :password
9
+
10
+ def initialize(opts = {})
11
+ @ftp = opts.fetch(:ftp) { Net::FTP.new }
12
+ @host = opts.fetch(:host) { DEFAULT_HOST }
13
+ @port = opts.fetch(:port) { DEFAULT_PORT }
14
+ @user = opts.fetch(:user) { DEFAULT_USER }
15
+ @password = opts.fetch(:password) { DEFAULT_PASSWORD }
16
+ end
17
+
18
+ private
19
+
20
+ def connect
21
+ ftp.connect(host, port)
22
+ end
23
+
24
+ def login
25
+ ftp.login(user, password)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ module HylaFAX
2
+ class FaxStat < Command
3
+ DEFAULT_QUEUE = 'doneq'
4
+ JOB_FORMAT = '%j %a'
5
+ STATES = {
6
+ '?' => :undefined,
7
+ 'T' => :suspended,
8
+ 'P' => :pending,
9
+ 'S' => :sleeping,
10
+ 'B' => :blocked,
11
+ 'W' => :waiting,
12
+ 'R' => :running,
13
+ 'D' => :done,
14
+ 'F' => :failed,
15
+ }
16
+
17
+ attr_reader :queue
18
+
19
+ def initialize(opts = {})
20
+ super
21
+ @queue = opts.fetch(:queue) { DEFAULT_QUEUE }
22
+ end
23
+
24
+ def run
25
+ connect
26
+ login
27
+ set_jobformat
28
+ list
29
+ end
30
+
31
+ private
32
+
33
+ def set_jobformat
34
+ ftp.sendcmd(%Q{JOBFMT "#{JOB_FORMAT}"})
35
+ end
36
+
37
+ def list
38
+ ftp.list(queue).inject({ }) do |jobs, line|
39
+ job_id, status = line.split(' ')
40
+ jobs[job_id.to_i] = STATES[status]
41
+ jobs
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,21 +1,12 @@
1
1
  module HylaFAX
2
- class SendFax
3
- DEFAULT_HOST = '127.0.0.1'
4
- DEFAULT_PORT = 4559
5
- DEFAULT_USER = 'anonymous'
6
- DEFAULT_PASSWORD = 'anonymous'
7
- DEFAULT_TMP_DIR = 'tmp'
2
+ class SendFax < Command
3
+ DEFAULT_TMP_DIR = 'tmp'
8
4
 
9
- attr_reader :ftp, :host, :port, :user, :password, :dialstring, :document,
10
- :tmp_dir, :job_id
5
+ attr_reader :dialstring, :document, :tmp_dir, :job_id
11
6
 
12
7
  def initialize(opts = {})
13
- @ftp = opts.fetch(:ftp) { Net::FTP.new }
14
- @host = opts.fetch(:host) { DEFAULT_HOST }
15
- @port = opts.fetch(:port) { DEFAULT_PORT }
16
- @user = opts.fetch(:user) { DEFAULT_USER }
17
- @password = opts.fetch(:password) { DEFAULT_PASSWORD }
18
- @tmp_dir = opts.fetch(:tmp_dir) { DEFAULT_TMP_DIR }
8
+ super
9
+ @tmp_dir = opts.fetch(:tmp_dir) { DEFAULT_TMP_DIR }
19
10
  @dialstring = opts.fetch(:dialstring)
20
11
  @document = opts.fetch(:document)
21
12
  @job_id = nil
@@ -35,14 +26,6 @@ module HylaFAX
35
26
 
36
27
  private
37
28
 
38
- def connect
39
- ftp.connect(host, port)
40
- end
41
-
42
- def login
43
- ftp.login(user, password)
44
- end
45
-
46
29
  def upload_document
47
30
  ftp.put(document, remote_document) unless document_uploaded?
48
31
  end
@@ -1,3 +1,3 @@
1
1
  module HylaFAX
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hylafax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Björn Albers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-16 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,8 @@ files:
71
71
  - bin/setup
72
72
  - hylafax.gemspec
73
73
  - lib/hylafax.rb
74
+ - lib/hylafax/command.rb
75
+ - lib/hylafax/fax_stat.rb
74
76
  - lib/hylafax/send_fax.rb
75
77
  - lib/hylafax/version.rb
76
78
  homepage: https://github.com/bjoernalbers/hylafax
@@ -96,5 +98,5 @@ rubyforge_project:
96
98
  rubygems_version: 2.6.10
97
99
  signing_key:
98
100
  specification_version: 4
99
- summary: hylafax-0.1.0
101
+ summary: hylafax-0.2.0
100
102
  test_files: []