faxomat-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a65176c45a7d314b7f4ccfe43e25369981c589e
4
+ data.tar.gz: 121ab7a4355492cd200a493ff75c82213de744cb
5
+ SHA512:
6
+ metadata.gz: 5655b57ebdb48e1d41b98594df48d90e72b497b4db0ceeda68eda14704947fa7982446d1aa5cae7094a376a3635f055f23e700344b6b974c473a24fe49713ffa
7
+ data.tar.gz: d8212319b143290fb8211e19eef6d7c84ef3387a846966830796b7cbeb87072166efab97e4f534daefdedf56beff5b3e4824e4cbf8a94284169ab07b6b9283e7
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faxomat-client.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Björn Albers
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,15 @@
1
+ # Faxomat-Client
2
+
3
+ Client for Faxomat HTTP-API.
4
+
5
+ ## Installation
6
+
7
+ $ gem install faxomat-client
8
+
9
+ ## Usage
10
+
11
+ $ faxomat --phone 0123456789 --title 'Chunky Bacon' chunky.pdf
12
+
13
+ ## Copyright
14
+
15
+ Copyright 2015 Björn Albers
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'faxomat/client'
5
+
6
+ include Faxomat::Client
7
+
8
+ opts = CLI.new.parse(ARGV)
9
+ path = opts.args.first
10
+ raise "File is missing!" unless path
11
+ Fax.new(phone: opts[:phone], title: opts[:title], path: path).deliver
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'faxomat/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'faxomat-client'
8
+ spec.version = Faxomat::Client::VERSION
9
+ spec.authors = ['Björn Albers']
10
+ spec.email = ['bjoernalbers@gmail.com']
11
+ spec.summary = "#{spec.name}-#{spec.version}"
12
+ spec.description = 'Client for Faxomat HTTP API'
13
+ spec.homepage = 'https://github.com/bjoernalbers/faxomat-client'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'slop', '~> 4.0'
22
+ spec.add_dependency 'rest-client', '~> 1.7'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,5 @@
1
+ require 'slop'
2
+ require 'rest-client'
3
+ require 'faxomat/client/version'
4
+ require 'faxomat/client/fax'
5
+ require 'faxomat/client/cli'
@@ -0,0 +1,12 @@
1
+ module Faxomat
2
+ module Client
3
+ class CLI
4
+ def parse(argv)
5
+ Slop.parse(argv) do |o|
6
+ o.string '-p', '--phone', 'phone number of recipient'
7
+ o.string '-t', '--title', 'title of fax'
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,39 @@
1
+ module Faxomat
2
+ module Client
3
+ class Fax
4
+ attr_reader :phone, :title, :path
5
+
6
+ def initialize(opts={})
7
+ @phone = opts[:phone]
8
+ @title = opts[:title]
9
+ @path = opts[:path]
10
+ end
11
+
12
+ def deliver
13
+ RestClient.post url, params
14
+ ensure
15
+ file.close unless file.closed?
16
+ end
17
+
18
+ private
19
+
20
+ def url
21
+ 'http://faxomat/faxes'
22
+ end
23
+
24
+ def params
25
+ {
26
+ fax: {
27
+ phone: phone,
28
+ title: title,
29
+ document: file
30
+ }
31
+ }
32
+ end
33
+
34
+ def file
35
+ @file ||= File.new(path, 'rb')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Faxomat
2
+ module Client
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ describe Faxomat::Client::CLI do
2
+ let(:cli) { Faxomat::Client::CLI.new }
3
+ let(:argv) { %w(--phone 0123456789 --title chunky chunky.pdf) }
4
+
5
+ describe '#parse' do
6
+ it 'assigns phone' do
7
+ opts = cli.parse(argv)
8
+ expect(opts[:phone]).to eq '0123456789'
9
+ end
10
+
11
+ it 'assigns title' do
12
+ opts = cli.parse(argv)
13
+ expect(opts[:title]).to eq 'chunky'
14
+ end
15
+
16
+ it 'assigns args' do
17
+ opts = cli.parse(argv)
18
+ expect(opts.args).to eq ['chunky.pdf']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ describe Faxomat::Client::Fax do
2
+ let(:fax) { Faxomat::Client::Fax.new(phone: '0123456789', title: 'chunky bacon', path: 'chunky.pdf') }
3
+
4
+ describe '#deliver' do
5
+ it 'faxes via HTTP' do
6
+ file = double('file')
7
+ allow(file).to receive(:close)
8
+ allow(fax).to receive(:file).and_return(file)
9
+ url = 'http://faxomat/faxes'
10
+ params = { phone: '0123456789',
11
+ title: 'chunky bacon',
12
+ document: file }
13
+ allow(RestClient).to receive(:post)
14
+ fax.deliver
15
+ expect(RestClient).to have_received(:post).with(url, params)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,91 @@
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
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
90
+
91
+ require 'faxomat/client'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faxomat-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Björn Albers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Client for Faxomat HTTP API
84
+ email:
85
+ - bjoernalbers@gmail.com
86
+ executables:
87
+ - faxomat
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/faxomat
98
+ - faxomat-client.gemspec
99
+ - lib/faxomat/client.rb
100
+ - lib/faxomat/client/cli.rb
101
+ - lib/faxomat/client/fax.rb
102
+ - lib/faxomat/client/version.rb
103
+ - spec/faxomat/client/cli_spec.rb
104
+ - spec/faxomat/client/fax_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/bjoernalbers/faxomat-client
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.14
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: faxomat-client-0.1.0
130
+ test_files:
131
+ - spec/faxomat/client/cli_spec.rb
132
+ - spec/faxomat/client/fax_spec.rb
133
+ - spec/spec_helper.rb