phaxio 0.1.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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "fakeweb", "~> 1.3.0"
4
+ gem "httparty", "~> 0.9.0"
5
+ gem "rake", "~> 0.9.2.2"
6
+
7
+ # Specify your gem's dependencies in phaxio.gemspec
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Gristmill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Phaxio
2
+
3
+ A Ruby gem for interacting with the [Phaxio API]( https://www.phaxio.com/docs ).
4
+
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'phaxio'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install phaxio
20
+
21
+ ## Usage
22
+
23
+ Configure a client with an api_key and api_secret:
24
+
25
+ @client = Phaxio.client.config do |config|
26
+ config.api_key = 10987654321
27
+ config.api_secret = 12345678910
28
+ end
29
+
30
+ Send a fax:
31
+
32
+ @client.send_fax(to: "0123456789", filename: "test.pdf")
33
+
34
+ ### Currently Supported API Calls
35
+
36
+ * send_fax
37
+ * test_receive
38
+ * get_fax_status
39
+ * cancel_fax
40
+ * get_account_status
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/test*.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ desc "Run tests"
13
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ require "httparty"
2
+
3
+ require "phaxio/version"
4
+ require "phaxio/client"
@@ -0,0 +1,145 @@
1
+ module Phaxio
2
+ module Config
3
+ attr_accessor :api_key, :api_secret
4
+ end
5
+
6
+ class Client
7
+ include HTTParty
8
+ base_uri 'https://api.phaxio.com/v1'
9
+
10
+ # Public: Initialize a new Client.
11
+ #
12
+ # Returns nothing.
13
+ def initialize
14
+ extend(Config)
15
+ end
16
+
17
+ # Public: Configure a Client.
18
+ #
19
+ # Returns the Client.
20
+ def config
21
+ if block_given?
22
+ yield(self)
23
+ end
24
+
25
+ self
26
+ end
27
+
28
+ # Public: Send a fax.
29
+ #
30
+ # options - The Hash options used to refine the selection (default: {}):
31
+ # :to - The Phone Number (i.e. [country
32
+ # code][number] or just a 10 digit
33
+ # number in the US or Canada). Put
34
+ # square brackets after parameter
35
+ # name to send to multiple
36
+ # recipients (e.g. to[]) (required).
37
+ # :filename - The Binary Stream name of the file
38
+ # you want to fax. This is optional
39
+ # if you specify string_data. Must
40
+ # have file name in the filename
41
+ # field of the body-part header. Put
42
+ # square brackets after parameter
43
+ # name to send multiple files (e.g.
44
+ # filename[]) (required).
45
+ # :string_data - A String of html, plain text, or a
46
+ # URL. If additional files are
47
+ # specified as well, this data will
48
+ # be included first in the fax
49
+ # (optional).
50
+ # :string_data_type - An enum of the type of the string
51
+ # data that can be 'html', 'url', or
52
+ # 'text'. If not specified, default
53
+ # is 'text'. See string data
54
+ # rendering for more info (optional).
55
+ # :batch - The bool for running in batching
56
+ # mode. If present and true, fax will
57
+ # be sent in batching mode. Requires
58
+ # batch_delay to be specified
59
+ # (optional).
60
+ # :batch_delay - The int the of amount of time, in
61
+ # seconds, before the batch is fired.
62
+ # Must be specified if batch=true.
63
+ # Maximum delay is 3600 (1 hour)
64
+ # (optional).
65
+ # :batch_collision_avoidance - The bool for collision avoidance
66
+ # with batches. If true when
67
+ # batch=true, fax will be blocked
68
+ # until the receiving machine is no
69
+ # longer busy (optional).
70
+ # :callback_url - The String url for the callback.
71
+ # Overrides the globally set one
72
+ # (optional).
73
+ # :cancel_timeout - An int of the number of minutes
74
+ # after which the fax will be
75
+ # canceled if it hasn't yet
76
+ # completed. Must be between 1 and 60
77
+ # (optional).
78
+ #
79
+ # Returns a HTTParty::Response object containing a success bool,
80
+ # a String message, and an in faxID.
81
+ def send_fax(options)
82
+ options.merge!({api_key: api_key, api_secret: api_secret})
83
+ self.class.post("/send", options)
84
+ end
85
+
86
+ # Public: Test receiving a fax.
87
+ #
88
+ # options - The Hash options used to refine the selection (default: {}):
89
+ # from_number - The Phone Number of the simulated sender
90
+ # (optional).
91
+ # to_number - The Phone Number receiving the fax (optional).
92
+ # filename - A String containing the name of the PDF that has
93
+ # a PhaxCode and is the file you want to simulate
94
+ # sending (required).
95
+ #
96
+ # Returns a HTTParty::Response object containing a success bool
97
+ # and a String message.
98
+ def test_receive(options)
99
+ options.merge!({api_key: api_key, api_secret: api_secret})
100
+ self.class.post("/testReceive", options)
101
+ end
102
+
103
+ # Public: Get the status of a specific fax.
104
+ #
105
+ # options - The Hash options used to refine the selection (default: {}):
106
+ # id - The int id of the fax you want to get the status of
107
+ # (required).
108
+ #
109
+ # Returns a HTTParty::Response object containing a success bool,
110
+ # a String message, and the data of the fax.
111
+ def get_fax_status(options)
112
+ if options[:id].nil?
113
+ raise StandardError, "You must include a fax id."
114
+ end
115
+
116
+ options.merge!({api_key: api_key, api_secret: api_secret})
117
+ self.class.post("/faxStatus", options)
118
+ end
119
+
120
+ # Public: Cancel a specific fax.
121
+ #
122
+ # options - The Hash options used to refine the selection (defaults: {}):
123
+ # id - The int id of the fax you want to cancel (required).
124
+ #
125
+ # Returns a HTTParty::Response object containing a success bool
126
+ # and a String message.
127
+ def cancel_fax(options)
128
+ options.merge!({api_key: api_key, api_secret: api_secret})
129
+ self.class.post("/faxCancel", options)
130
+ end
131
+
132
+ # Public: Get the status of Client's account.
133
+ #
134
+ # Returns a HTTParty::Response object with success, message, and data
135
+ # (containing faxes_sent_this_month, faxes_sent_today, and balance).
136
+ def get_account_status
137
+ self.class.post("/accountStatus", { api_key: api_key, api_secret:api_secret })
138
+ end
139
+ end
140
+
141
+ def self.client
142
+ @client ||= Client.new
143
+ end
144
+
145
+ end
@@ -0,0 +1,3 @@
1
+ module Phaxio
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/phaxio/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sean Behan", "Brett Chalupa"]
6
+ gem.email = ["inbox@seanbehan.com", "brettchalupa@gmail.com"]
7
+ gem.description = %q{A Ruby Gem for interacting with Phaxio's JSON API}
8
+ gem.summary = %q{A Ruby Gem for interacting with Phaxio's JSON API}
9
+ gem.homepage = "http://gristmill.io"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "phaxio"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Phaxio::VERSION
17
+
18
+ gem.add_runtime_dependency "httparty", "~> 0.9.0"
19
+ gem.add_development_dependency "fakeweb", "~> 1.3.0"
20
+ gem.add_development_dependency "rake", "~> 0.9.2.2"
21
+ end
@@ -0,0 +1,9 @@
1
+ {
2
+ "success":true,
3
+ "message":"Account status retrieved successfully",
4
+ "data":{
5
+ "faxes_sent_this_month":120,
6
+ "faxes_sent_today":10,
7
+ "balance":3000
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "success":true,
3
+ "message":"Account status retrieved successfully",
4
+ "data":{
5
+ "faxes_sent_this_month":120,
6
+ "faxes_sent_today":10,
7
+ "balance":3000
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "success":true,
3
+ "message":"Fax canceled successfully."
4
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "success":true,
3
+ "message":"Retrieved fax successfully",
4
+ "data":{
5
+ "id":123456,
6
+ "num_pages":3,
7
+ "cost":21,
8
+ "direction":"sent",
9
+ "status":"success",
10
+ "is_test":true,
11
+ "requested_at":1293910680,
12
+ "completed_at":1293911100,
13
+ "recipients":[
14
+ {
15
+ "number":"4141234567",
16
+ "status":"success",
17
+ "completed_at":1293911100
18
+ }
19
+ ]
20
+ }
21
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "success":false,
3
+ "message":"Fax not queued for sending",
4
+ "faxId":1234,
5
+ "data":{
6
+ "faxId":1234
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "success":true,
3
+ "message":"Fax queued for sending",
4
+ "faxId":1234,
5
+ "data":{
6
+ "faxId":1234
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "success":true,
3
+ "message":"Test fax received from 234567890. Calling back now..."
4
+ }
@@ -0,0 +1,28 @@
1
+ $:<<(".")
2
+ require "test/unit"
3
+ require "fakeweb"
4
+ require "lib/phaxio"
5
+
6
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/send",
7
+ :body => File.open("test/support/responses/send_success.json").read,
8
+ :content_type => "application/json")
9
+
10
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/testReceive",
11
+ :body => File.open("test/support/responses/test_receive.json").read,
12
+ :content_type => "application/json")
13
+
14
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/testReceive",
15
+ :body => File.open("test/support/responses/test_receive.json").read,
16
+ :content_type => "application/json")
17
+
18
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxStatus",
19
+ :body => File.open("test/support/responses/fax_status_success.json").read,
20
+ :content_type => "application/json")
21
+
22
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/faxCancel",
23
+ :body => File.open("test/support/responses/cancel_success.json").read,
24
+ :content_type => "application/json")
25
+
26
+ FakeWeb.register_uri(:post, "https://api.phaxio.com/v1/accountStatus",
27
+ :body => File.open("test/support/responses/account_status.json").read,
28
+ :content_type => "application/json")
@@ -0,0 +1,51 @@
1
+ require_relative "test_helper"
2
+
3
+ class TestPhaxio < Test::Unit::TestCase
4
+ def setup
5
+ @client = Phaxio.client.config do |config|
6
+ config.api_key = 10987654321
7
+ config.api_secret = 12345678910
8
+ end
9
+ end
10
+
11
+ def test_config
12
+ assert_equal 10987654321, @client.api_key
13
+ assert_equal 12345678910, @client.api_secret
14
+ end
15
+
16
+ def test_initialize
17
+ assert_instance_of Phaxio::Client, @client
18
+ end
19
+
20
+ def test_send_fax
21
+ @response = @client.send_fax(to: "0123456789", filename: "test.pdf")
22
+ assert_equal true, @response["success"]
23
+ assert_equal "Fax queued for sending", @response["message"]
24
+ assert_equal 1234, @response["faxId"]
25
+ end
26
+
27
+ def test_test_receive
28
+ @response = @client.test_receive(filename: "test_file.pdf")
29
+ assert_equal true, @response["success"]
30
+ assert_equal "Test fax received from 234567890. Calling back now...", @response["message"]
31
+ end
32
+
33
+ def test_get_fax_status
34
+ @response = @client.get_fax_status(id: "123456")
35
+ assert_equal true, @response["success"]
36
+ assert_equal "Retrieved fax successfully", @response["message"]
37
+ end
38
+
39
+ def test_cancel_fax
40
+ @response = @client.cancel_fax(id: "123456")
41
+ assert_equal true, @response["success"]
42
+ assert_equal "Fax canceled successfully.", @response["message"]
43
+ end
44
+
45
+ def test_get_account_status
46
+ @response = @client.get_account_status
47
+ assert_equal true, @response["success"]
48
+ assert_equal "Account status retrieved successfully", @response["message"]
49
+ assert_equal 120, @response["data"]["faxes_sent_this_month"]
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phaxio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Behan
9
+ - Brett Chalupa
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-10-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.9.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: fakeweb
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.3.0
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.3.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.9.2.2
63
+ description: A Ruby Gem for interacting with Phaxio's JSON API
64
+ email:
65
+ - inbox@seanbehan.com
66
+ - brettchalupa@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE
74
+ - README.md
75
+ - Rakefile
76
+ - lib/phaxio.rb
77
+ - lib/phaxio/client.rb
78
+ - lib/phaxio/version.rb
79
+ - phaxio.gemspec
80
+ - test/support/account_status.json
81
+ - test/support/responses/account_status.json
82
+ - test/support/responses/cancel_success.json
83
+ - test/support/responses/fax_status_success.json
84
+ - test/support/responses/send_failure.json
85
+ - test/support/responses/send_success.json
86
+ - test/support/responses/test_receive.json
87
+ - test/test_helper.rb
88
+ - test/test_phaxio.rb
89
+ homepage: http://gristmill.io
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.24
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: A Ruby Gem for interacting with Phaxio's JSON API
113
+ test_files:
114
+ - test/support/account_status.json
115
+ - test/support/responses/account_status.json
116
+ - test/support/responses/cancel_success.json
117
+ - test/support/responses/fax_status_success.json
118
+ - test/support/responses/send_failure.json
119
+ - test/support/responses/send_success.json
120
+ - test/support/responses/test_receive.json
121
+ - test/test_helper.rb
122
+ - test/test_phaxio.rb