efax 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7 # (current default)
3
+ - ree
4
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "test-unit", "~> 2.3.2", :require => false
6
+ gem "mocha", "~> 0.9.12", :require => false
7
+ gem "rake"
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ efax (1.3.3)
5
+ builder (~> 3.0.0)
6
+ hpricot (~> 0.8.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ builder (3.0.0)
12
+ hpricot (0.8.4)
13
+ mocha (0.9.12)
14
+ rake (0.9.2)
15
+ test-unit (2.3.2)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ efax!
22
+ mocha (~> 0.9.12)
23
+ rake
24
+ test-unit (~> 2.3.2)
@@ -0,0 +1,76 @@
1
+ # efax [![Build Status](https://secure.travis-ci.org/szimek/efax.png)](http://travis-ci.org/szimek/efax)
2
+
3
+ Ruby library for accessing [eFax Developer service](http://www.efaxdeveloper.com).
4
+
5
+ You can find eFax Developer API guides at [efaxdeveloper.com](https://secure.efaxdeveloper.com/techDocs/eFaxDeveloper_Universal_Implementation_Kit_v1.0.zip) or on [Scribd](www.scribd.com/doc/5382394/eFax-Developer-Universal-User-Guide-Outbound).
6
+
7
+ ## Usage
8
+
9
+ ### Outbound Faxes
10
+
11
+ First you need to provide your account id and credentials:
12
+
13
+ ```ruby
14
+ EFax::Request.account_id = <your account id>
15
+ EFax::Request.user = <your login>
16
+ EFax::Request.password = <your password>
17
+ ```
18
+ Sending an HTML page using eFax service is pretty simple:
19
+
20
+ ```ruby
21
+ response = EFax::OutboundRequest.post(recipient_name, company_name, fax_number, subject, content)
22
+ ```
23
+
24
+ See `EFax::RequestStatus` class for details on status codes.
25
+
26
+
27
+ Having ID of your request, you can get its current status:
28
+
29
+ ```ruby
30
+ response = OutboundRequestStatus.post(doc_id)
31
+ ```
32
+
33
+ The status response has the following attributes:
34
+
35
+ ```ruby
36
+ response.status_code
37
+ response.message # "user friendly" status message
38
+ ```
39
+
40
+ See `EFax::QueryStatus` class for details on status codes.
41
+
42
+ ### Inbound Faxes
43
+
44
+ Inbound faxes work by exposing a URL that EFax can post to when it receives a fax on your account. An example end-point in rails might look like this:
45
+
46
+ ```ruby
47
+ class InboundFaxesController < AdminController
48
+ def create
49
+ efax = EFax::InboundPostRequest.receive_by_params(params)
50
+ Fax.create(:file => efax.file, :name => efax.name) # etc
51
+ render :text => efax.post_successful_message # This is important to let EFax know you successfully processed the incoming request.
52
+ end
53
+ end
54
+ ```
55
+
56
+ ## Test helpers
57
+
58
+ You can generate a `EFax::InboundPostRequest` based on optional explicit fields by using a helper method `efax_inbound_post`:
59
+
60
+ In your tests:
61
+
62
+ ```ruby
63
+ require "efax/helpers/inbound_helpers"
64
+
65
+ describe InboundFax do
66
+ include EFax::Helpers::InboundHelpers
67
+
68
+ it "should create a fax from efax data" do
69
+ person = Person.make
70
+ person.save
71
+ efax = efax_inbound_post(:barcode => person.barcode_number)
72
+ fax = InboundFax.create_from_efax!(efax)
73
+ fax.person.should == person
74
+ end
75
+ end
76
+ ```
data/Rakefile CHANGED
@@ -1,43 +1,10 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
- require 'rake/clean'
4
- require 'rake/gempackagetask'
5
- require 'rake/rdoctask'
2
+ require 'bundler/setup'
6
3
  require 'rake/testtask'
7
4
 
8
- begin
9
- require 'jeweler'
10
- Jeweler::Tasks.new do |gem|
11
- gem.name = "efax"
12
- gem.summary = 'Ruby library for accessing the eFax Developer service'
13
- gem.authors = ["Szymon Nowak", "Pawel Kozlowski", "Dr Nic Williams"]
14
- gem.email = "szimek@gmail.com"
15
- gem.homepage = "http://github.com/szimek/efax"
16
- gem.rubyforge_project = "efax"
17
-
18
- gem.add_dependency('hpricot', '>= 0.8.1')
19
- gem.add_development_dependency('test-unit', '~> 2')
20
- gem.add_development_dependency('mocha', '>= 0.9')
21
- end
22
-
23
- Jeweler::RubyforgeTasks.new do |rubyforge|
24
- rubyforge.doc_task = "rdoc"
25
- end
26
-
27
- Jeweler::GemcutterTasks.new
28
- rescue LoadError
29
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
30
- end
31
-
32
- Rake::RDocTask.new do |rdoc|
33
- files =['README.rdoc', 'lib/**/*.rb']
34
- rdoc.rdoc_files.add(files)
35
- rdoc.main = "README.rdoc" # page to start on
36
- rdoc.title = 'eFax: Ruby library for accessing the eFax Developer service'
37
- rdoc.rdoc_dir = 'rdoc' # rdoc output folder
38
- rdoc.options << '--line-numbers'
39
- end
40
-
41
5
  Rake::TestTask.new do |t|
42
6
  t.test_files = FileList['test/**/*.rb']
43
7
  end
8
+
9
+ desc "Default: run all tests"
10
+ task :default => [:test]
@@ -1,62 +1,14 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
1
  Gem::Specification.new do |s|
7
- s.name = %q{efax}
8
- s.version = "1.3.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
2
+ s.name = "efax"
3
+ s.version = "1.4.0"
11
4
  s.authors = ["Szymon Nowak", "Pawel Kozlowski", "Dr Nic Williams"]
12
- s.date = %q{2010-03-17}
13
- s.email = %q{szimek@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README.rdoc"
16
- ]
17
- s.files = [
18
- ".gitignore",
19
- "README.rdoc",
20
- "Rakefile",
21
- "VERSION",
22
- "efax.gemspec",
23
- "lib/efax.rb",
24
- "lib/efax/helpers/inbound_helpers.rb",
25
- "lib/efax/inbound.rb",
26
- "lib/efax/outbound.rb",
27
- "test/efax_inbound_test.rb",
28
- "test/efax_outbound_test.rb",
29
- "test/test_helper.rb"
30
- ]
31
- s.homepage = %q{http://github.com/szimek/efax}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
- s.require_paths = ["lib"]
34
- s.rubyforge_project = %q{efax}
35
- s.rubygems_version = %q{1.3.6}
36
- s.summary = %q{Ruby library for accessing the eFax Developer service}
37
- s.test_files = [
38
- "test/efax_inbound_test.rb",
39
- "test/efax_outbound_test.rb",
40
- "test/test_helper.rb"
41
- ]
42
-
43
- if s.respond_to? :specification_version then
44
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
- s.specification_version = 3
46
-
47
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
- s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
49
- s.add_development_dependency(%q<test-unit>, ["~> 2"])
50
- s.add_development_dependency(%q<mocha>, [">= 0.9"])
51
- else
52
- s.add_dependency(%q<hpricot>, [">= 0.8.1"])
53
- s.add_dependency(%q<test-unit>, ["~> 2"])
54
- s.add_dependency(%q<mocha>, [">= 0.9"])
55
- end
56
- else
57
- s.add_dependency(%q<hpricot>, [">= 0.8.1"])
58
- s.add_dependency(%q<test-unit>, ["~> 2"])
59
- s.add_dependency(%q<mocha>, [">= 0.9"])
60
- end
5
+ s.email = "szimek@gmail.com"
6
+ s.files = `git ls-files`.split("\n")
7
+ s.test_files = `git ls-files -- test/*`.split("\n")
8
+ s.homepage = "http://github.com/szimek/efax"
9
+ s.require_path = "lib"
10
+ s.rubygems_version = "1.3.6"
11
+ s.summary = "Ruby library for accessing the eFax Developer service"
12
+ s.add_runtime_dependency "builder", "~> 3.0.0"
13
+ s.add_runtime_dependency "hpricot", "~> 0.8.1"
61
14
  end
62
-
@@ -1,13 +1,13 @@
1
1
  require 'hpricot'
2
2
  require 'base64'
3
3
  require 'tempfile'
4
- require 'time'
4
+ require 'date'
5
5
 
6
6
  module EFax
7
7
  class InboundPostStatus
8
8
  SUCCESS = 1
9
9
  end
10
-
10
+
11
11
  class InboundPostRequest
12
12
  attr_reader :encoded_file_contents,
13
13
  :file_type,
@@ -22,9 +22,9 @@ module EFax
22
22
  :date_received,
23
23
  :request_date,
24
24
  :barcodes
25
-
25
+
26
26
  alias_method :sender_fax_number, :ani
27
-
27
+
28
28
  def initialize(xml)
29
29
  doc = Hpricot(xml)
30
30
  @encoded_file_contents = doc.at(:filecontents).inner_text
@@ -37,34 +37,52 @@ module EFax
37
37
  @mcfid = doc.at(:mcfid).inner_text.to_i
38
38
  @page_count = doc.at(:pagecount).inner_text.to_i
39
39
  @request_type = doc.at(:requesttype).inner_text
40
- @date_received = Time.parse("#{doc.at(:datereceived).inner_text} -08:00")
41
- @request_date = Time.parse("#{doc.at(:requestdate).inner_text} -08:00")
40
+ @date_received = datetime_to_time(DateTime.strptime("#{doc.at(:datereceived).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z"))
41
+ @request_date = datetime_to_time(DateTime.strptime("#{doc.at(:requestdate).inner_text} -08:00", "%m/%d/%Y %H:%M:%S %z"))
42
42
  @barcodes = doc.search("//barcode/key").map { |key| key.inner_html }
43
43
  end
44
-
44
+
45
45
  def file_contents
46
46
  @file_contents ||= Base64.decode64(encoded_file_contents)
47
47
  end
48
-
48
+
49
49
  def file
50
50
  @file ||= begin
51
- file = Tempfile.new(fax_name)
51
+ if defined?(Encoding)
52
+ file = Tempfile.new(fax_name, {:encoding => 'ascii-8bit'})
53
+ else
54
+ file = Tempfile.new(fax_name)
55
+ end
52
56
  file << file_contents
53
57
  file.rewind
54
58
  file
55
59
  end
56
60
  end
61
+
57
62
  def post_successful_message
58
63
  "Post Successful"
59
64
  end
60
-
65
+
61
66
  def self.receive_by_params(params)
62
67
  receive_by_xml(params[:xml] || params["xml"])
63
68
  end
64
-
69
+
65
70
  def self.receive_by_xml(xml)
66
71
  new(xml)
67
72
  end
73
+
74
+
75
+ private
76
+
77
+ def datetime_to_time(datetime)
78
+ if datetime.respond_to?(:to_time)
79
+ datetime.to_time
80
+ else
81
+ d = datetime.new_offset(0)
82
+ d.instance_eval do
83
+ Time.utc(year, mon, mday, hour, min, sec + sec_fraction)
84
+ end.getlocal
85
+ end
86
+ end
68
87
  end
69
88
  end
70
-
@@ -30,6 +30,7 @@ module EFaxInboundTest
30
30
  assert_not_nil response.file_contents
31
31
  assert_not_nil response.file
32
32
  assert_respond_to response.file, :read
33
+
33
34
  assert_equal response.file_contents, response.file.read
34
35
 
35
36
  # According to docs these will always be "Pacific Time Zone" (sometimes -8, sometimes -7 -- using -8)
@@ -39,4 +40,3 @@ module EFaxInboundTest
39
40
 
40
41
  end
41
42
  end
42
-
metadata CHANGED
@@ -1,76 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: efax
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 3
8
- - 3
9
- version: 1.3.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Szymon Nowak
13
9
  - Pawel Kozlowski
14
10
  - Dr Nic Williams
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2010-03-17 00:00:00 +01:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
23
- name: hpricot
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
- - 8
32
- - 1
33
- version: 0.8.1
14
+ date: 2011-08-20 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: builder
18
+ requirement: &2153358560 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.0
34
24
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: test-unit
38
25
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- requirements:
26
+ version_requirements: *2153358560
27
+ - !ruby/object:Gem::Dependency
28
+ name: hpricot
29
+ requirement: &2153357980 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
41
32
  - - ~>
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 2
45
- version: "2"
46
- type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: mocha
33
+ - !ruby/object:Gem::Version
34
+ version: 0.8.1
35
+ type: :runtime
50
36
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- - 9
58
- version: "0.9"
59
- type: :development
60
- version_requirements: *id003
37
+ version_requirements: *2153357980
61
38
  description:
62
39
  email: szimek@gmail.com
63
40
  executables: []
64
-
65
41
  extensions: []
66
-
67
- extra_rdoc_files:
68
- - README.rdoc
69
- files:
42
+ extra_rdoc_files: []
43
+ files:
70
44
  - .gitignore
71
- - README.rdoc
45
+ - .travis.yml
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - README.md
72
49
  - Rakefile
73
- - VERSION
74
50
  - efax.gemspec
75
51
  - lib/efax.rb
76
52
  - lib/efax/helpers/inbound_helpers.rb
@@ -79,37 +55,31 @@ files:
79
55
  - test/efax_inbound_test.rb
80
56
  - test/efax_outbound_test.rb
81
57
  - test/test_helper.rb
82
- has_rdoc: true
83
58
  homepage: http://github.com/szimek/efax
84
59
  licenses: []
85
-
86
60
  post_install_message:
87
- rdoc_options:
88
- - --charset=UTF-8
89
- require_paths:
61
+ rdoc_options: []
62
+ require_paths:
90
63
  - lib
91
- required_ruby_version: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
- version: "0"
98
- required_rubygems_version: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
- version: "0"
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
105
76
  requirements: []
106
-
107
- rubyforge_project: efax
108
- rubygems_version: 1.3.6
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.8
109
79
  signing_key:
110
80
  specification_version: 3
111
81
  summary: Ruby library for accessing the eFax Developer service
112
- test_files:
82
+ test_files:
113
83
  - test/efax_inbound_test.rb
114
84
  - test/efax_outbound_test.rb
115
85
  - test/test_helper.rb
@@ -1,70 +0,0 @@
1
- = efax
2
-
3
- Ruby library for accessing the eFax Developer service (http://www.efaxdeveloper.com).
4
-
5
- Strange class names and their attribute names come from "eFax Developer Universal User Guide for Outbound Processing" document.
6
- You can get it on eFax Developer pages or on Scribd (http://www.scribd.com/doc/5382394/eFax-Developer-Universal-User-Guide-Outbound).
7
-
8
- == Usage
9
-
10
- === Outbound Faxes
11
-
12
- First you need to provide your account id and credentials:
13
- EFax::Request.account_id = <your account id>
14
- EFax::Request.user = <your login>
15
- EFax::Request.password = <your password>
16
-
17
-
18
- Sending an HTML page using eFax service is pretty simple:
19
- response = EFax::OutboundRequest.post(recipient_name, company_name, fax_number, subject, content)
20
-
21
- The response object has the following attributes:
22
- response.status_code
23
- response.doc_id # unique identifier of your request
24
- response.error_level
25
- response.error_message
26
-
27
- See EFax::RequestStatus class for details on status codes.
28
-
29
-
30
- Having ID of your request, you can get its current status:
31
- response = OutboundRequestStatus.post(doc_id)
32
-
33
- The status response has the following attributes:
34
- response.status_code
35
- response.message # "user friendly" status message
36
-
37
- See EFax::QueryStatus class for details on status codes.
38
-
39
- === Inbound Faxes
40
-
41
- Inbound faxes work by exposing a URL that EFax can post to when it receives a fax on your account. An example end-point in rails might look like this:
42
-
43
- class InboundFaxesController < AdminController
44
- def create
45
- efax = EFax::InboundPostRequest.receive_by_params(params)
46
- Fax.create(:file => efax.file, :name => efax.name) # etc
47
- render :text => efax.post_successful_message # This is important to let EFax know you successfully processed the incoming request.
48
- end
49
- end
50
-
51
- == Test Helpers
52
-
53
- You can generate a EFax::InboundPostRequest based on optional explicit fields by using a helper method +efax_inbound_post+:
54
-
55
- In your tests:
56
-
57
- require "efax/helpers/inbound_helpers"
58
-
59
- describe InboundFax do
60
- include EFax::Helpers::InboundHelpers
61
-
62
- it "should create a fax from efax data" do
63
- person = Person.make
64
- person.save
65
- efax = efax_inbound_post(:barcode => person.barcode_number)
66
- fax = InboundFax.create_from_efax!(efax)
67
- fax.person.should == person
68
- end
69
- end
70
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.3.3