hylafax 0.1.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bafeedd8e5c2a0e7ce1b8b15a40435d7fd12e25d
4
- data.tar.gz: 531c59bfbf6b91817103b2f697335af172436c01
2
+ SHA256:
3
+ metadata.gz: fa7d134cb036f06376a5d87efab2b5eee5e737ba4b41c22efff4cc92784430f7
4
+ data.tar.gz: 43ee998f84f20b5e81ecf07174ef65407c8337500a0ef7428d6b482014f80e39
5
5
  SHA512:
6
- metadata.gz: e536b9f0a9da95a221f6553653b5daf8a87a36fa7744202efa38276d5f5c8307b3f1ccaa0db511329465a9bd35ff3bebd81caefe74ed38aca02f32b634f3354d
7
- data.tar.gz: fec8805a6b4e2f3fa47e827c281a114b80b4f638f3dfb4b86871e37dfd62b73bc5a6ac64e5adb0e6e7c96295f79a8466da4e7c6b70ee300736474c21796281f8
6
+ metadata.gz: 86cddd5561ed193cf4bb324ed28893e6c4676a50f6a234ba7af4d86bf0fb53b5d09293efc0f296e12dbfc82015e00614dc21f575fdefabb55a0d193b12cf7ecd
7
+ data.tar.gz: 3b2a60a934dba704dc9b749f7bc9ffdb59b242284deb253b4e236cec94b6a0b27727a2078cbdd2c9dae6d1a396956c5af6f6546e0377a0e5c02499751728bf6f
data/Dockerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM ruby:2.0
2
+ RUN mkdir -p /opt/hylafax
3
+ WORKDIR /opt/hylafax
4
+ COPY . .
5
+ RUN bundle install --binstubs
6
+ CMD ["bash"]
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Björn Albers
3
+ Copyright (c) 2021 Björn Albers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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,19 +32,31 @@ 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
33
38
 
34
- # This will send the fax and return the job id.
39
+ ```
40
+
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
 
38
50
  ## Development
39
51
 
40
- After checking out the repo, run `bin/setup` to install dependencies.
41
- Then, run `rake spec` to run the tests.
42
- You can also run `bin/console` for an interactive prompt that will allow you to
43
- experiment.
52
+ You need to have Docker installed.
53
+ After checking out the repo, run the tests with:
54
+
55
+ $ docker-compose run --rm lib bin/rspec
56
+
57
+ For an interactive prompt run:
44
58
 
59
+ $ docker-compose run --rm lib bin/console
45
60
 
46
61
  ## Contributing
47
62
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
2
+ #require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ #RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ #task :default => :spec
@@ -0,0 +1,8 @@
1
+ version: '3'
2
+
3
+ services:
4
+ lib:
5
+ build: .
6
+ tty: true
7
+ volumes:
8
+ - .:/opt/hylafax
data/hylafax.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.15'
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  end
data/lib/hylafax.rb CHANGED
@@ -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,30 @@
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
+
17
+ @ftp.passive = true if opts[:passive]
18
+ end
19
+
20
+ private
21
+
22
+ def connect
23
+ ftp.connect(host, port)
24
+ end
25
+
26
+ def login
27
+ ftp.login(user, password)
28
+ end
29
+ end
30
+ 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,23 +1,22 @@
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'
4
+ DEFAULT_PAGEWIDTH = 209
5
+ DEFAULT_PAGELENGTH = 296
6
+ DEFAULT_PAGECHOP = 'NONE'
7
+ DEFAULT_CHOPTHRESHOLD = 0
8
+ DOCUMENT_PREFIX = 'doc.'
8
9
 
9
- attr_reader :ftp, :host, :port, :user, :password, :dialstring, :document,
10
- :tmp_dir, :job_id
10
+ attr_reader :dialstring, :document, :tmp_dir, :job_id, :pagewidth,
11
+ :pagelength
11
12
 
12
13
  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 }
14
+ super
15
+ @tmp_dir = opts.fetch(:tmp_dir) { DEFAULT_TMP_DIR }
19
16
  @dialstring = opts.fetch(:dialstring)
20
17
  @document = opts.fetch(:document)
18
+ @pagewidth = opts.fetch(:pagewidth) { DEFAULT_PAGEWIDTH }
19
+ @pagelength = opts.fetch(:pagelength) { DEFAULT_PAGELENGTH }
21
20
  @job_id = nil
22
21
  end
23
22
 
@@ -28,6 +27,10 @@ module HylaFAX
28
27
  create_new_job
29
28
  set_lasttime
30
29
  set_dialstring
30
+ set_pagewidth
31
+ set_pagelength
32
+ set_pagechop
33
+ set_chopthreshold
31
34
  set_document
32
35
  submit_job
33
36
  job_id
@@ -35,14 +38,6 @@ module HylaFAX
35
38
 
36
39
  private
37
40
 
38
- def connect
39
- ftp.connect(host, port)
40
- end
41
-
42
- def login
43
- ftp.login(user, password)
44
- end
45
-
46
41
  def upload_document
47
42
  ftp.put(document, remote_document) unless document_uploaded?
48
43
  end
@@ -52,7 +47,8 @@ module HylaFAX
52
47
  end
53
48
 
54
49
  def document_filename
55
- @document_filename ||= Digest::MD5.file(document).hexdigest
50
+ @document_filename ||= DOCUMENT_PREFIX +
51
+ Digest::MD5.file(document).hexdigest
56
52
  end
57
53
 
58
54
  def document_uploaded?
@@ -72,6 +68,22 @@ module HylaFAX
72
68
  ftp.sendcmd("JPARM DIALSTRING \"#{dialstring}\"")
73
69
  end
74
70
 
71
+ def set_pagewidth
72
+ ftp.sendcmd(%Q{JPARM PAGEWIDTH #{pagewidth}})
73
+ end
74
+
75
+ def set_pagelength
76
+ ftp.sendcmd(%Q{JPARM PAGELENGTH #{pagelength}})
77
+ end
78
+
79
+ def set_pagechop
80
+ ftp.sendcmd(%Q{JPARM PAGECHOP "#{DEFAULT_PAGECHOP}"})
81
+ end
82
+
83
+ def set_chopthreshold
84
+ ftp.sendcmd(%Q{JPARM CHOPTHRESHOLD #{DEFAULT_CHOPTHRESHOLD}})
85
+ end
86
+
75
87
  def set_document
76
88
  ftp.sendcmd("JPARM DOCUMENT \"#{remote_document}\"")
77
89
  end
@@ -1,3 +1,3 @@
1
1
  module HylaFAX
2
- VERSION = '0.1.0'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
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.4.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: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '1.11'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '1.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  description: The Ruby HylaFAX Client
@@ -59,18 +59,22 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .rspec
64
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
65
  - CODE_OF_CONDUCT.md
66
+ - Dockerfile
66
67
  - Gemfile
67
68
  - LICENSE.txt
68
69
  - README.md
69
70
  - Rakefile
70
71
  - bin/console
71
72
  - bin/setup
73
+ - docker-compose.yml
72
74
  - hylafax.gemspec
73
75
  - lib/hylafax.rb
76
+ - lib/hylafax/command.rb
77
+ - lib/hylafax/fax_stat.rb
74
78
  - lib/hylafax/send_fax.rb
75
79
  - lib/hylafax/version.rb
76
80
  homepage: https://github.com/bjoernalbers/hylafax
@@ -83,18 +87,17 @@ require_paths:
83
87
  - lib
84
88
  required_ruby_version: !ruby/object:Gem::Requirement
85
89
  requirements:
86
- - - '>='
90
+ - - ">="
87
91
  - !ruby/object:Gem::Version
88
92
  version: '0'
89
93
  required_rubygems_version: !ruby/object:Gem::Requirement
90
94
  requirements:
91
- - - '>='
95
+ - - ">="
92
96
  - !ruby/object:Gem::Version
93
97
  version: '0'
94
98
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.6.10
99
+ rubygems_version: 3.0.3
97
100
  signing_key:
98
101
  specification_version: 4
99
- summary: hylafax-0.1.0
102
+ summary: hylafax-0.4.0
100
103
  test_files: []