makeprintable 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56cf908e95969b49d1ce9c54c36ac0658f58dfc9
4
+ data.tar.gz: 9b760a6f4eae6cb0c943c0f3469cef345e1b41f3
5
+ SHA512:
6
+ metadata.gz: 3624f2c0a68f3af8c3a06b0b45e9c0686fc6f2c9993e80021f14d5629dc5e1995f44609c732ef5051e87565ff482f960aeddab8d898a696a24b69636098ada3b
7
+ data.tar.gz: 1027890696b27f331d1314449e5907b495f85498e37033f1106d296f34752da88e0736b250d32cef1e7b8f3150eb24abdd5034d13e2c20511bbb3c8395f7ca5e
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rest-client'
3
+ gemspec
@@ -0,0 +1 @@
1
+ # makeprintable
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -0,0 +1,23 @@
1
+ require 'makeprintable/version'
2
+ require 'rubygems'
3
+ require 'rest-client'
4
+ require 'json'
5
+
6
+ require File.expand_path('../misc/hash.rb', __FILE__)
7
+ require File.expand_path('../makeprintable/client.rb', __FILE__)
8
+
9
+ module MakePrintable
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= Configuration.new
16
+ yield(configuration)
17
+ end
18
+
19
+
20
+ class Configuration
21
+ attr_accessor :api_key, :api_secret
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../client/endpoints.rb', __FILE__)
2
+ require File.expand_path('../client/jobs.rb', __FILE__)
3
+
4
+ module MakePrintable
5
+ class Client
6
+ attr_accessor :api_key, :api_secret
7
+
8
+ def initialize
9
+ @api_key, @api_secret = [MakePrintable.configuration.api_key, MakePrintable.configuration.api_secret]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module MakePrintable
2
+ class Client
3
+ def base_uri(path='/')
4
+ "http://api.makeprintable.com#{path}?api_key=#{api_key}&api_secret=#{api_secret}"
5
+ end
6
+
7
+ def configure_payload(path, opts={})
8
+ base_uri(path) + opts.to_params
9
+ end
10
+
11
+ def get_request(uri)
12
+ JSON.parse RestClient.get(uri)
13
+ end
14
+
15
+ def post_request(path, opts)
16
+ JSON.parse RestClient.post(base_uri(path), opts)
17
+ end
18
+
19
+ def delete_request(uri)
20
+ JSON.parse RestClient.delete(uri)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ module MakePrintable
2
+ class Client
3
+ # Upload a model to fix it later
4
+ def upload(opts={})
5
+ opts.assert_valid_keys(:file)
6
+ post_request '/items', opts
7
+ end
8
+
9
+ # Return a list of previously uploaded items
10
+ def items
11
+ get_request configure_payload("/items")
12
+ end
13
+
14
+ # Return specific item information
15
+ def find_item(id)
16
+ get_request configure_payload("/items/#{id}")
17
+ end
18
+
19
+ # Delete a specific item from server.
20
+ def delete_item(id)
21
+ delete_request configure_payload("/item/#{id}")
22
+ end
23
+
24
+ # Repairs an uploaded item
25
+ def repair(opts={})
26
+ opts.assert_valid_keys(:item_id, :callback_url, :name, :wall_thickness, :print_quality, :pre_optimize, :post_optimize)
27
+ post_request '/fixes', opts
28
+ end
29
+
30
+ # Returns repair information for a specific repair request, including status, progress and download links.
31
+ def find_repaired(id)
32
+ get_request configure_payload("/fixes/#{id}")
33
+ end
34
+
35
+ # Return a list of repaired items
36
+ def repaired
37
+ get_request configure_payload('/fixes')
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module MakePrintable
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../object', __FILE__)
2
+
3
+ class Hash
4
+ def assert_valid_keys(*valid_keys)
5
+ valid_keys.flatten!
6
+ each_key {|k| raise(ArgumentError, "Unknown key #{k}") unless valid_keys.include?(k)}
7
+ end
8
+
9
+ def to_params
10
+ '&'+collect{|k, v| v.to_query(k)}.sort * '&'
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ class Object
2
+ def to_param
3
+ to_s
4
+ end
5
+
6
+ def to_query(key)
7
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
8
+ "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(to_param.to_s)}"
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MakePrintable::Client do
4
+ describe '#initialize' do
5
+
6
+ it 'should inherit configuration block and set it to client object' do
7
+ client = MakePrintable::Client.new
8
+ expect(client.api_key).to eq '123apikey'
9
+ expect(client.api_secret).to eq '123apisecret'
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe MakePrintable::Client do
4
+ describe '#base_uri' do
5
+ it 'should be created from set configuration' do
6
+ client = MakePrintable::Client.new
7
+ expect(client.base_uri).to eq "http://api.makeprintable.com/?api_key=123apikey&api_secret=123apisecret"
8
+ end
9
+ end
10
+
11
+ describe '#configure payload' do
12
+ it 'should add an extra variable to the base_uri' do
13
+ client = MakePrintable::Client.new
14
+ expect(client.configure_payload('/', variable: true)).to eq "http://api.makeprintable.com/?api_key=123apikey&api_secret=123apisecret&variable=true"
15
+ end
16
+
17
+ it 'should have no problems chaining variables' do
18
+ client = MakePrintable::Client.new
19
+ expect(client.configure_payload('/', variable1: true, variable2: false)).to eq "http://api.makeprintable.com/?api_key=123apikey&api_secret=123apisecret&variable1=true&variable2=false"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe MakePrintable do
4
+ describe '#configuration' do
5
+ it 'should adopt configuration set in the initializer' do
6
+ expect(MakePrintable.configuration.api_key).to eq '123apikey'
7
+ expect(MakePrintable.configuration.api_secret).to eq '123apisecret'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require 'makeprintable'
2
+
3
+ MakePrintable.configure do |config|
4
+ config.api_key = '123apikey'
5
+ config.api_secret = '123apisecret'
6
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: makeprintable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dennis de Vulder
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - dennisdevulder@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - lib/makeprintable.rb
66
+ - lib/makeprintable/client.rb
67
+ - lib/makeprintable/client/endpoints.rb
68
+ - lib/makeprintable/client/jobs.rb
69
+ - lib/makeprintable/version.rb
70
+ - lib/misc/hash.rb
71
+ - lib/misc/object.rb
72
+ - spec/client_spec.rb
73
+ - spec/endpoints_spec.rb
74
+ - spec/makeprintable_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: http://rubygems.org/gems/makeprintable
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Ruby wrapper for detecting flaws in 3D designs and repairing them for 3D
100
+ printing. Using the makeprintable API.
101
+ test_files:
102
+ - spec/client_spec.rb
103
+ - spec/endpoints_spec.rb
104
+ - spec/makeprintable_spec.rb
105
+ - spec/spec_helper.rb