carve 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/carve.gemspec +27 -0
- data/lib/carve/document.rb +21 -0
- data/lib/carve/version.rb +3 -0
- data/lib/carve.rb +74 -0
- data/spec/carve/document_spec.rb +119 -0
- data/spec/carve/version_spec.rb +5 -0
- data/spec/carve_spec.rb +41 -0
- data/spec/spec_helper.rb +20 -0
- metadata +159 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 scottmotte
|
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,48 @@
|
|
1
|
+
# Carve.io Ruby Bindings
|
2
|
+
|
3
|
+
This gem is a wrapper for [Carve.io](http://carve.io)'s API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carve'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carve
|
18
|
+
|
19
|
+
Then in your application initialize the gem:
|
20
|
+
|
21
|
+
$ Carve.secret_api_key = "your_secret_api_key"
|
22
|
+
|
23
|
+
Alternatively, you can simply set the environment variables CARVE_SECRET_API_KEY on your machine. The rubygem will read it automatically so that you can skip the initialization.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Create Document
|
28
|
+
|
29
|
+
$ Carve::Document.create(:url => "https://www.signature.io/pdfs/sign-below.pdf")
|
30
|
+
|
31
|
+
Replace the url with a url of the PDF or Microsoft Word file you choose.
|
32
|
+
|
33
|
+
### Retrieve Document
|
34
|
+
|
35
|
+
$ Carve::Document.retrieve("id_of_document")
|
36
|
+
|
37
|
+
### Retrieve Document Pages
|
38
|
+
|
39
|
+
$ Carve::Document.pages("id_of_document")
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. export CARVE_SECRET_API_KEY="your_test_secret_api_key"
|
46
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
7. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/carve.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carve/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "carve"
|
8
|
+
gem.version = Carve::VERSION
|
9
|
+
gem.authors = ["scottmotte"]
|
10
|
+
gem.email = ["scott@scottmotte.com"]
|
11
|
+
gem.description = %q{Ruby bindings for the Carve.io API.}
|
12
|
+
gem.summary = %q{Convert documents or webpages to PDF and PNGs}
|
13
|
+
gem.homepage = "http://carve.io/api"
|
14
|
+
|
15
|
+
gem.add_dependency "faraday"
|
16
|
+
gem.add_dependency "faraday_middleware"
|
17
|
+
gem.add_dependency "recursive-open-struct"
|
18
|
+
|
19
|
+
gem.add_development_dependency "pry"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
|
23
|
+
gem.files = `git ls-files`.split($/)
|
24
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
25
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
26
|
+
gem.require_paths = ["lib"]
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Carve
|
2
|
+
class Document
|
3
|
+
#
|
4
|
+
# Api calls
|
5
|
+
#
|
6
|
+
def self.create(attrs={})
|
7
|
+
response = Carve.request.post "documents.json", attrs
|
8
|
+
RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.retrieve(id=nil)
|
12
|
+
response = Carve.request.get "documents/#{id}.json"
|
13
|
+
RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.pages(id=nil)
|
17
|
+
response = Carve.request.get "documents/#{id}/pages.json"
|
18
|
+
RecursiveOpenStruct.new(response.body, :recurse_over_arrays => true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/carve.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require "recursive-open-struct"
|
4
|
+
require "carve/version"
|
5
|
+
require "carve/document"
|
6
|
+
|
7
|
+
module Carve
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def request=(request)
|
11
|
+
@request = request
|
12
|
+
end
|
13
|
+
|
14
|
+
def request
|
15
|
+
@request || setup_request!
|
16
|
+
end
|
17
|
+
|
18
|
+
def secret_api_key=(secret_api_key)
|
19
|
+
@secret_api_key = secret_api_key
|
20
|
+
setup_request!
|
21
|
+
|
22
|
+
@secret_api_key
|
23
|
+
end
|
24
|
+
|
25
|
+
def secret_api_key
|
26
|
+
return @secret_api_key if @secret_api_key
|
27
|
+
ENV['CARVE_SECRET_API_KEY'] || "missing_secret_api_key"
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_version=(api_version)
|
31
|
+
@api_version = api_version
|
32
|
+
setup_request!
|
33
|
+
|
34
|
+
@api_version
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_version
|
38
|
+
return @api_version if @api_version
|
39
|
+
0
|
40
|
+
end
|
41
|
+
|
42
|
+
def _root_url=(_root_url)
|
43
|
+
@_root_url = _root_url
|
44
|
+
end
|
45
|
+
|
46
|
+
def _root_url
|
47
|
+
return @_root_url if @_root_url
|
48
|
+
"https://carve.herokuapp.com"
|
49
|
+
end
|
50
|
+
|
51
|
+
def api_endpoint
|
52
|
+
[_root_url, "/api/v", api_version].join
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def setup_request!
|
58
|
+
options = {
|
59
|
+
headers: {'Accept' => "application/json"},
|
60
|
+
ssl: {:verify => false},
|
61
|
+
url: Carve.api_endpoint
|
62
|
+
}
|
63
|
+
|
64
|
+
Carve.request = ::Faraday::Connection.new(options) do |builder|
|
65
|
+
builder.use ::Faraday::Request::UrlEncoded
|
66
|
+
builder.use ::FaradayMiddleware::ParseJson
|
67
|
+
builder.adapter ::Faraday.default_adapter
|
68
|
+
end
|
69
|
+
|
70
|
+
Carve.request.basic_auth(Carve.secret_api_key, '')
|
71
|
+
|
72
|
+
Carve.request
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Carve::Document do
|
4
|
+
let(:subject) { Carve::Document }
|
5
|
+
let(:url) { "https://www.signature.io/pdfs/sign-below.pdf" }
|
6
|
+
|
7
|
+
context "incorrect secret api key" do
|
8
|
+
before do
|
9
|
+
Carve.secret_api_key = "incorrect_secret_api_key"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "attempt .create" do
|
13
|
+
before do
|
14
|
+
@response = subject.create({:url => url})
|
15
|
+
end
|
16
|
+
|
17
|
+
it do
|
18
|
+
@response.success.should be_false
|
19
|
+
@response.error.message.should_not be_empty
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "attempt .retrieve" do
|
24
|
+
before do
|
25
|
+
@response = subject.retrieve("1234")
|
26
|
+
end
|
27
|
+
|
28
|
+
it do
|
29
|
+
@response.success.should be_false
|
30
|
+
@response.error.message.should_not be_empty
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "correct secret api key" do
|
36
|
+
before do
|
37
|
+
Carve.secret_api_key = ENV['CARVE_SECRET_API_KEY']
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".create" do
|
41
|
+
before do
|
42
|
+
@response = subject.create(attrs)
|
43
|
+
end
|
44
|
+
|
45
|
+
context "default" do
|
46
|
+
let(:attrs) { {:url => url} }
|
47
|
+
|
48
|
+
it do
|
49
|
+
@response.success.should be_true
|
50
|
+
@response.document.id.should_not be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "blank url" do
|
55
|
+
let(:attrs) { {:url => nil} }
|
56
|
+
|
57
|
+
it do
|
58
|
+
@response.success.should be_false
|
59
|
+
@response.error.message.should_not be_empty
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "invalid url" do
|
64
|
+
let(:attrs) { {:url => "noexisturl"} }
|
65
|
+
|
66
|
+
it do
|
67
|
+
@response.success.should be_false
|
68
|
+
@response.error.message.should_not be_empty
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".retrieve" do
|
74
|
+
before do
|
75
|
+
response = subject.create({:url => url})
|
76
|
+
@id = response.document.id
|
77
|
+
end
|
78
|
+
|
79
|
+
context "default" do
|
80
|
+
before do
|
81
|
+
@response = subject.retrieve(@id)
|
82
|
+
end
|
83
|
+
|
84
|
+
it do
|
85
|
+
@response.success.should be_true
|
86
|
+
@response.document.id.should eq @id
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "incorrect id" do
|
91
|
+
before do
|
92
|
+
@response = subject.retrieve("1234")
|
93
|
+
end
|
94
|
+
|
95
|
+
it do
|
96
|
+
@response.success.should be_false
|
97
|
+
@response.error.message.should_not be_empty
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe ".pages" do
|
103
|
+
before do
|
104
|
+
response = subject.create({:url => url})
|
105
|
+
@id = response.document.id
|
106
|
+
puts "sleep for 30"
|
107
|
+
sleep 30
|
108
|
+
@response = subject.pages(@id)
|
109
|
+
end
|
110
|
+
|
111
|
+
context "default" do
|
112
|
+
it do
|
113
|
+
@response.success.should be_true
|
114
|
+
@response.pages.count.should >= 1
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/spec/carve_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Carve do
|
4
|
+
subject { Carve }
|
5
|
+
|
6
|
+
describe "defaults" do
|
7
|
+
before do
|
8
|
+
subject.secret_api_key = nil
|
9
|
+
subject.api_version = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it { subject.api_endpoint.should eq "https://carve.herokuapp.com/api/v0" }
|
13
|
+
it { subject.api_version.should eq 0 }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "setting values" do
|
17
|
+
let(:secret_api_key) { "sk_1234" }
|
18
|
+
let(:api_version) { 1 }
|
19
|
+
|
20
|
+
before do
|
21
|
+
subject.secret_api_key = secret_api_key
|
22
|
+
subject.api_version = api_version
|
23
|
+
end
|
24
|
+
|
25
|
+
it { subject.api_version.should eq api_version }
|
26
|
+
it { subject.secret_api_key.should eq secret_api_key }
|
27
|
+
it { subject.api_endpoint.should eq "https://carve.herokuapp.com/api/v1" }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "setting _root_url" do
|
31
|
+
let(:api_version) { 0 }
|
32
|
+
|
33
|
+
before do
|
34
|
+
subject.api_version = api_version
|
35
|
+
subject._root_url = "http://localhost:3000"
|
36
|
+
end
|
37
|
+
|
38
|
+
it { subject._root_url = "http://localhost:3000" }
|
39
|
+
it { subject.api_endpoint.should eq "http://localhost:3000/api/v0" }
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'pry'
|
4
|
+
require 'carve'
|
5
|
+
|
6
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.before(:suite) do
|
10
|
+
# FakeWeb.allow_net_connect = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# config.after(:suite) do
|
14
|
+
# FakeWeb.allow_net_connect = true
|
15
|
+
# end
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_secret_and_public_api_keys!
|
19
|
+
Carve.secret_api_key = ENV['CARVE_SECRET_API_KEY']
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carve
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- scottmotte
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
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: faraday_middleware
|
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: recursive-open-struct
|
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: pry
|
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: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Ruby bindings for the Carve.io API.
|
111
|
+
email:
|
112
|
+
- scott@scottmotte.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- .rspec
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- carve.gemspec
|
124
|
+
- lib/carve.rb
|
125
|
+
- lib/carve/document.rb
|
126
|
+
- lib/carve/version.rb
|
127
|
+
- spec/carve/document_spec.rb
|
128
|
+
- spec/carve/version_spec.rb
|
129
|
+
- spec/carve_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: http://carve.io/api
|
132
|
+
licenses: []
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.8.23
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Convert documents or webpages to PDF and PNGs
|
155
|
+
test_files:
|
156
|
+
- spec/carve/document_spec.rb
|
157
|
+
- spec/carve/version_spec.rb
|
158
|
+
- spec/carve_spec.rb
|
159
|
+
- spec/spec_helper.rb
|