phaxion 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ phaxion
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p374
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phaxion.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 bjh
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.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Phaxion
2
+
3
+ **pronounced like Faction**
4
+
5
+ A (hopefully) small wrapper around the [Phaxio API](https://www.phaxio.com/docs).
6
+
7
+ I made it to be flexible regarding what Phaxio API methods can be called.
8
+ You can use camel case `sexyMethodCall` or be more Ruby-esque `sexy_method_call` and the gem figures it out for you.
9
+
10
+ **NOTE:** I have borrowed gratuitously from [this phaxio gem](https://github.com/gristmill/phaxio) so all credit should probably go to that author.
11
+ The reason I wrote this was because the aforementioned gem author hardcoded the available methods you could call on the Phaxio API.
12
+ This cut out PhaxCodes and some other fun things.
13
+
14
+ **ANOTHER NOTE:** let's be honest, almost every single gemified API wrapper is a messy wrapper around HttParty. *Now that is one useful gem.*
15
+
16
+ The only real win here is managing the API keys...you can actually call all the Phaxio
17
+ API methods using this gem like so: `Phaxion.direct(:phaxio_api_method, arg1:123, arg2:'magic')`, the rest of this gem is fluff. I should have named it fluffy...dammit!
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ gem 'phaxion'
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install phaxion
32
+
33
+ ## Usage
34
+
35
+ **note:** Phaxio uses `send` as the name of a method which conflicts with Ruby so I have mapped it to `fax`. This is the only method name I have changed. I did not want to mess around with aliasing and other *meta*.
36
+
37
+ ```ruby
38
+ # initialize with your keys
39
+ Phaxion.api_keys = '7d7f87d7f8d78f7'
40
+ Phaxion.api_secret = '999dfdf33f3f'
41
+
42
+ # OR
43
+ Phaxion.configuration do |cfg|
44
+ cfg.api_key = "8udf8duf8duf"
45
+ cfg.api_secret = "34jhdf873jh"
46
+ end
47
+
48
+ # enjoy the magic
49
+ Phaxion.fax(to: '555-123-1234' string_data:"hello there fax people!")
50
+
51
+ # you are mad at me cause I was lazy and did not wrap one of the Phaxio API methods...
52
+ # just call it directly
53
+ Phaxion.direct(:send, to: '555-123-1234' string_data:"hello there fax people!")
54
+
55
+ # use camelCase OR Ruby style api names
56
+ Phaxion.test_receive == Phaxion.testReceive
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Open an irb session preloaded with this library"
4
+ task :console do
5
+ sh "irb -rubygems -I lib -r phaxion.rb"
6
+ end
@@ -0,0 +1,5 @@
1
+ #module Phaxion
2
+ #module API
3
+
4
+ #end
5
+ #end
@@ -0,0 +1,5 @@
1
+ # module Phaxion
2
+ # module Configuration
3
+ # attr_accessor :api_key, :api_secret
4
+ # end
5
+ # end
@@ -0,0 +1,21 @@
1
+ module Phaxion
2
+ module DTO
3
+ class Fax < Struct.new(
4
+ :id,
5
+ :direction,
6
+ :num_pages,
7
+ :cost,
8
+ :status,
9
+ :is_test,
10
+ :requested_at,
11
+ # not always present
12
+ :from_number,
13
+ :to_number,
14
+ :recipients,
15
+ :error_type,
16
+ :error_code,
17
+ :completed_at
18
+ )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Phaxion
2
+ module DTO
3
+ class PhoneNumber < Struct.new(:number, :city, :state, :cost, :last_billed_at, :provisioned_at)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Phaxion
2
+ module DTO
3
+ class Recipient < Struct.new(:number, :status, :completed_at)
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ #module Phaxion
2
+ #module Mapper
3
+ #end
4
+ #end
@@ -0,0 +1,39 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/string'
3
+
4
+ module Phaxion
5
+ include HTTMultiParty
6
+
7
+ @@api_url = 'https://api.phaxio.com/v1'
8
+
9
+ def self.url(api_method)
10
+ "#{@@api_url}/#{api_method.to_s}"
11
+ end
12
+
13
+ def self.renamer(method)
14
+ method.to_s.camelize(:lower)
15
+ end
16
+
17
+ def self.method_missing(method, *args, &block)
18
+ if method.to_sym == :fax
19
+ method = :send
20
+ end
21
+
22
+ method = renamer(method)
23
+ post(url(method), query: Hash[*args].merge({api_key: api_key, api_secret: api_secret}))
24
+ end
25
+
26
+ def self.direct(method, *args)
27
+ post(url(renamer(method)), query: Hash[*args].merge({api_key: api_key, api_secret: api_secret}))
28
+ end
29
+
30
+ def self.configuration
31
+ yield(self) if block_given?
32
+ end
33
+
34
+ module Configuration
35
+ attr_accessor :api_key, :api_secret
36
+ end
37
+
38
+ extend Configuration
39
+ end
@@ -0,0 +1,3 @@
1
+ module Phaxion
2
+ VERSION = "0.0.1"
3
+ end
data/lib/phaxion.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "httmultiparty"
2
+ require "phaxion/version"
3
+ require "phaxion/phaxion"
data/phaxion.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phaxion/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "phaxion"
8
+ gem.version = Phaxion::VERSION
9
+ gem.authors = ["bjh"]
10
+ gem.email = ["bjh@fake.fake"]
11
+ gem.description = %q{giving the Phaxio API a nice big hug.}
12
+ gem.summary = %q{Phaxio API wrapper}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "httmultiparty"
21
+ gem.add_runtime_dependency "active_support"
22
+ gem.add_runtime_dependency "i18n"
23
+ gem.add_development_dependency "rspec"
24
+ gem.add_development_dependency "fakeweb"
25
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ # require 'json'
3
+ require_relative '../lib/phaxion'
4
+
5
+ describe Phaxion do
6
+ before :all do
7
+ Phaxion.configuration do |cfg|
8
+ cfg.api_key = "8udf8duf8duf"
9
+ cfg.api_secret = "34jhdf873jh"
10
+ end
11
+ end
12
+
13
+ describe ".fax" do
14
+ it "calls the Phaxio :send method" do
15
+ response = Phaxion.fax(to: '555-123-1234')
16
+ expect(response["success"]).to be_true
17
+ expect(response["message"]).to eq "Fax queued for sending"
18
+ end
19
+ end
20
+
21
+ describe ".direct" do
22
+ context "you can call anything with direct" do
23
+ it "posts the method to the Phaxio API" do
24
+ response = Phaxion.direct(:send, to: '555-123-1234')
25
+ expect(response["success"]).to be_true
26
+ end
27
+
28
+ it "translates the given api method to the expected camelCase version" do
29
+ response = Phaxion.direct(:test_receive, to: '555-123-1234')
30
+ expect(response["success"]).to be_true
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "calling methods using camelCase or under_score syntax" do
36
+ it "accepts test_receive" do
37
+ expect(Phaxion.renamer(:test_receive)).to eq "testReceive"
38
+ end
39
+
40
+ it "accepts testReceive" do
41
+ expect(Phaxion.renamer(:testReceive)).to eq "testReceive"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ require 'fakeweb'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
10
+ # puts "requiring #{f}"
11
+ require f
12
+ end
13
+
14
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
+ RSpec.configure do |config|
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ # Run specs in random order to surface order dependencies. If you find an
21
+ # order dependency and want to debug it, you can fix the order by providing
22
+ # the seed, which is printed after each run.
23
+ # --seed 1234
24
+ config.order = 'random'
25
+
26
+ config.before(:each) do
27
+ # FakeWeb.clean_registry
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module Fake
3
+ @@base_url = "https://api.phaxio.com/v1"
4
+ @@base_response_dir = "#{File.dirname(__FILE__)}/responses"
5
+
6
+ def self.body(response)
7
+ File.open(File.join(@@base_response_dir, "#{response.to_s}.json")).read
8
+ end
9
+
10
+ def self.content_type
11
+ "application/json"
12
+ end
13
+
14
+ def self.register(action)
15
+ FakeWeb.register_uri(:post, "#{@@base_url}/#{action.to_s}", body:body(action), content_type:content_type)
16
+ end
17
+ end
18
+
19
+ # load all the fakeweb responses and register them by name/API call
20
+ Dir[File.dirname(__FILE__) + "/responses/*.json"].each do |file|
21
+ Fake.register(File.basename(file, ".*" ))
22
+ end
23
+
@@ -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,68 @@
1
+ {
2
+ "success":true,
3
+ "message":"Retrieved faxes successfully",
4
+ "paging":{
5
+ "max_per_page":1000,
6
+ "page":1,
7
+ "total_pages":1,
8
+ "total_results":3
9
+ },
10
+ "data":[
11
+ {
12
+ "id":123456,
13
+ "num_pages":3,
14
+ "cost":21,
15
+ "direction":"sent",
16
+ "status":"success",
17
+ "is_test":true,
18
+ "requested_at":1293910680,
19
+ "completed_at":1293911100,
20
+ "recipients":[
21
+ {
22
+ "number":"4141234567",
23
+ "status":"success",
24
+ "completed_at":1293911100
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "id":123457,
30
+ "num_pages":1,
31
+ "cost":7,
32
+ "direction":"sent",
33
+ "status":"success",
34
+ "is_test":false,
35
+ "requested_at":1293984720,
36
+ "completed_at":1293985800,
37
+ "recipients":[
38
+ {
39
+ "number":"4145554567",
40
+ "status":"success",
41
+ "completed_at":1293985800
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "id":123458,
47
+ "num_pages":1,
48
+ "cost":14,
49
+ "direction":"sent",
50
+ "status":"success",
51
+ "is_test":false,
52
+ "requested_at":1294094700,
53
+ "completed_at":1294095000,
54
+ "recipients":[
55
+ {
56
+ "number":"4145554568",
57
+ "status":"success",
58
+ "completed_at":1294095000
59
+ },
60
+ {
61
+ "number":"4145554567",
62
+ "status":"success",
63
+ "completed_at":1293985800
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "success":true,
3
+ "message":"Retrieved user phone numbers successfully",
4
+ "data":[
5
+ {
6
+ "number":"8021112222",
7
+ "city":"Burlington",
8
+ "state":"Vermont",
9
+ "cost":200,
10
+ "last_billed_at":"2012-10-11 10:51:33",
11
+ "provisioned_at":"2012-10-11 10:51:33"
12
+ },
13
+ {
14
+ "number":"8023334444",
15
+ "city":"Montpelier",
16
+ "state":"Vermont",
17
+ "cost":200,
18
+ "last_billed_at":"2012-10-11 10:51:33",
19
+ "provisioned_at":"2012-10-11 10:51:33"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "success":true,
3
+ "message":"Number provisioned successfully!",
4
+ "data":{
5
+ "number":"8021112222",
6
+ "city":"Burlington",
7
+ "state":"Vermont",
8
+ "cost":200,
9
+ "last_billed_at":"2012-10-11 10:00:44",
10
+ "provisioned_at":"2012-10-11 10:00:44"
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "success":true,
3
+ "message":"Number released successfully!",
4
+ "data":[
5
+
6
+ ]
7
+ }
@@ -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,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,4 @@
1
+ {
2
+ "success":true,
3
+ "message":"Test fax received from 234567890. Calling back now..."
4
+ }
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phaxion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - bjh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httmultiparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: active_support
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: i18n
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: fakeweb
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: giving the Phaxio API a nice big hug.
95
+ email:
96
+ - bjh@fake.fake
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - .ruby-gemset
104
+ - .ruby-version
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/phaxion.rb
110
+ - lib/phaxion/api.rb
111
+ - lib/phaxion/configuration.rb
112
+ - lib/phaxion/dto/fax.rb
113
+ - lib/phaxion/dto/phone_number.rb
114
+ - lib/phaxion/dto/recipient.rb
115
+ - lib/phaxion/mapper.rb
116
+ - lib/phaxion/phaxion.rb
117
+ - lib/phaxion/version.rb
118
+ - phaxion.gemspec
119
+ - spec/phaxion_spec.rb
120
+ - spec/spec_helper.rb
121
+ - spec/support/fakeweb_urls.rb
122
+ - spec/support/responses/accountStatus.json
123
+ - spec/support/responses/cancel.json
124
+ - spec/support/responses/faxStatus.json
125
+ - spec/support/responses/listFaxes.json
126
+ - spec/support/responses/numberList.json
127
+ - spec/support/responses/provisionNumber.json
128
+ - spec/support/responses/releaseNumber.json
129
+ - spec/support/responses/send.json
130
+ - spec/support/responses/sendFailure.json
131
+ - spec/support/responses/testReceive.json
132
+ homepage: ''
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.25
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: Phaxio API wrapper
156
+ test_files:
157
+ - spec/phaxion_spec.rb
158
+ - spec/spec_helper.rb
159
+ - spec/support/fakeweb_urls.rb
160
+ - spec/support/responses/accountStatus.json
161
+ - spec/support/responses/cancel.json
162
+ - spec/support/responses/faxStatus.json
163
+ - spec/support/responses/listFaxes.json
164
+ - spec/support/responses/numberList.json
165
+ - spec/support/responses/provisionNumber.json
166
+ - spec/support/responses/releaseNumber.json
167
+ - spec/support/responses/send.json
168
+ - spec/support/responses/sendFailure.json
169
+ - spec/support/responses/testReceive.json