hubs3d 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -5
- data/lib/hubs3d/api.rb +8 -1
- data/lib/hubs3d/error.rb +4 -0
- data/lib/hubs3d/model.rb +12 -5
- data/lib/hubs3d/tip.rb +7 -4
- data/lib/hubs3d/version.rb +1 -1
- data/spec/cart_spec.rb +3 -3
- data/spec/model_spec.rb +22 -5
- data/spec/tip_spec.rb +17 -6
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d27cf81d7ea6eee957d3ca46f23b933fc4baa75b
|
4
|
+
data.tar.gz: c6222907a6282f605c18765d657d97ab9928b890
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c129f18035969ffece8b11dfbd36eb1a9fdb1d1a51877caf31fba0c4807c067d2b4eb9f827318fda32b88d927fffd178d23b571f3bec7230013e0c29a44d311
|
7
|
+
data.tar.gz: b8fc61b1e714a5ca590e3f6e3fba3ba07b003800dbaa6c1748b968f25d60575999759c5cadbbf67a6c27abb0b4f8ce45b685d9cfa0add2c3b95b04a9c1f6ca31
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
Ruby gem to access
|
2
|
-
|
1
|
+
Ruby gem to access 3D Hubs' API
|
2
|
+
===============================
|
3
3
|
|
4
|
-
|
4
|
+
Configuration
|
5
5
|
-------------
|
6
6
|
|
7
7
|
```rb
|
@@ -9,18 +9,39 @@ Hubs3D.configure do |c|
|
|
9
9
|
c.oauth_key = "YOUR_API_KEY_HERE"
|
10
10
|
c.oauth_secret = "YOUR_API_SECRET_HERE"
|
11
11
|
end
|
12
|
+
```
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
|
17
|
+
### Upload a model and get its id back
|
12
18
|
|
13
|
-
|
19
|
+
```rb
|
14
20
|
model = Hubs3D::Model.new(path: "/path/to/example.stl",
|
15
21
|
name: "example.stl")
|
16
22
|
model.id # => 42
|
23
|
+
```
|
24
|
+
|
25
|
+
### Create a cart and get its url to redirect to
|
17
26
|
|
18
|
-
|
27
|
+
```rb
|
19
28
|
cart = Hubs3D::Cart.new
|
20
29
|
cart << model
|
21
30
|
cart.url # => "https://www.3dhubs.com/…"
|
22
31
|
```
|
23
32
|
|
33
|
+
### A cart can also take a third_party_id and a designer_tip
|
34
|
+
|
35
|
+
```rb
|
36
|
+
cart = Hubs3D::Cart.new(
|
37
|
+
designer_tip: Hubs3D::Tip.new(amount_cents: 42_00,
|
38
|
+
currency: "EUR",
|
39
|
+
uuid: "5-42-42",
|
40
|
+
mandatory: true),
|
41
|
+
third_party_id: 42
|
42
|
+
)
|
43
|
+
```
|
44
|
+
|
24
45
|
Install
|
25
46
|
-------
|
26
47
|
|
data/lib/hubs3d/api.rb
CHANGED
@@ -6,6 +6,7 @@ require "oauth"
|
|
6
6
|
# Net::HTTP.http_logger_options = {:verbose => true}
|
7
7
|
|
8
8
|
require "hubs3d/configuration"
|
9
|
+
require "hubs3d/error"
|
9
10
|
|
10
11
|
module Hubs3D
|
11
12
|
module API
|
@@ -18,7 +19,13 @@ module Hubs3D
|
|
18
19
|
response = token.post(Hubs3D.configuration.api_path + path,
|
19
20
|
params,
|
20
21
|
"Accept" => "application/json")
|
21
|
-
JSON.parse(response.body)
|
22
|
+
body = JSON.parse(response.body)
|
23
|
+
|
24
|
+
if response.code == "200"
|
25
|
+
body
|
26
|
+
else
|
27
|
+
fail Error, "API #{response.code}: #{body.join(" ")}"
|
28
|
+
end
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
data/lib/hubs3d/error.rb
ADDED
data/lib/hubs3d/model.rb
CHANGED
@@ -16,20 +16,27 @@ module Hubs3D
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def id
|
19
|
-
@id ||=
|
19
|
+
@id ||= begin
|
20
|
+
result = post
|
21
|
+
fail "Expected #{result.inspect} to have modelId" if !result["modelId"]
|
22
|
+
result["modelId"].to_i
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
|
23
27
|
private
|
24
28
|
|
25
|
-
def
|
29
|
+
def base_64_file
|
26
30
|
Base64.encode64 open(@path, 'r') { |f| f.read }
|
27
31
|
end
|
28
32
|
|
29
33
|
def post
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
params = {
|
35
|
+
file: base_64_file,
|
36
|
+
fileName: name,
|
37
|
+
}
|
38
|
+
params[:attachments] = attachments if attachments
|
39
|
+
API.post("/model", params)
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
data/lib/hubs3d/tip.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
module Hubs3D
|
2
2
|
class Tip
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :amount_cents, :currency, :uuid, :mandatory
|
4
4
|
|
5
|
-
def initialize(
|
5
|
+
def initialize(amount_cents: nil,
|
6
6
|
currency: nil,
|
7
7
|
uuid: nil,
|
8
8
|
mandatory: nil)
|
9
|
-
@
|
9
|
+
@amount_cents = amount_cents
|
10
10
|
@currency = currency
|
11
11
|
@uuid = uuid
|
12
12
|
@mandatory = mandatory
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_h
|
16
|
-
{ amount:
|
16
|
+
{ amount: amount_cents,
|
17
|
+
currency: currency,
|
18
|
+
uuid: uuid,
|
19
|
+
mandatory: mandatory }
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
data/lib/hubs3d/version.rb
CHANGED
data/spec/cart_spec.rb
CHANGED
@@ -3,9 +3,9 @@ require "hubs3d/cart"
|
|
3
3
|
require "hubs3d/tip"
|
4
4
|
|
5
5
|
describe Hubs3D::Cart do
|
6
|
-
let(:designer_tip) { Hubs3D::Tip.new(
|
6
|
+
let(:designer_tip) { Hubs3D::Tip.new(amount_cents: 42_00,
|
7
7
|
currency: "EUR",
|
8
|
-
uuid: 5,
|
8
|
+
uuid: "5-42-42",
|
9
9
|
mandatory: true) }
|
10
10
|
let(:cart) { described_class.new(designer_tip: designer_tip,
|
11
11
|
third_party_id: "foo0") }
|
@@ -57,7 +57,7 @@ describe Hubs3D::Cart do
|
|
57
57
|
designer_tip: {
|
58
58
|
amount: 42_00,
|
59
59
|
currency: "EUR",
|
60
|
-
uuid: 5,
|
60
|
+
uuid: "5-42-42",
|
61
61
|
mandatory: true
|
62
62
|
},
|
63
63
|
third_party_id: "foo0",
|
data/spec/model_spec.rb
CHANGED
@@ -2,20 +2,37 @@ require "spec_helper"
|
|
2
2
|
require "hubs3d/model"
|
3
3
|
|
4
4
|
describe Hubs3D::Model do
|
5
|
-
let(:model) {
|
5
|
+
let(:model) {
|
6
|
+
described_class.new(name: "foo.stl", path: "spec/fixtures/example.stl")
|
7
|
+
}
|
6
8
|
|
7
9
|
describe "#name" do
|
8
10
|
it "returns the name" do
|
9
|
-
expect(model.name).to eq("
|
11
|
+
expect(model.name).to eq("foo.stl")
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
15
|
describe "#path" do
|
14
16
|
it "returns the path" do
|
15
|
-
expect(model.path).to eq("example.stl")
|
17
|
+
expect(model.path).to eq("spec/fixtures/example.stl")
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
describe "#id" do
|
22
|
+
it "sends a request" do
|
23
|
+
stub_request(:post, "https://www.3dhubs.com/api/v1/model")
|
24
|
+
.with(body: {"file"=>"Rk9vTwo=\n", "fileName"=>"foo.stl"},
|
25
|
+
headers: {'Accept' => 'application/json'})
|
26
|
+
.to_return(status: 200, body: '{"modelId":"42"}')
|
27
|
+
|
28
|
+
expect(model.id).to eq(42)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#attachments" do
|
33
|
+
it "returns the attachments" do
|
34
|
+
model = described_class.new(attachments: { foo: 42 })
|
35
|
+
expect(model.attachments).to eq({ foo: 42 })
|
36
|
+
end
|
37
|
+
end
|
21
38
|
end
|
data/spec/tip_spec.rb
CHANGED
@@ -2,14 +2,14 @@ require "spec_helper"
|
|
2
2
|
require "hubs3d/model"
|
3
3
|
|
4
4
|
describe Hubs3D::Tip do
|
5
|
-
let(:model) { described_class.new(
|
5
|
+
let(:model) { described_class.new(amount_cents: 42_00,
|
6
6
|
currency: "EUR",
|
7
|
-
uuid: "51",
|
7
|
+
uuid: "51-42-43",
|
8
8
|
mandatory: false) }
|
9
9
|
|
10
|
-
describe "#
|
11
|
-
it "returns the
|
12
|
-
expect(model.
|
10
|
+
describe "#amount_cents" do
|
11
|
+
it "returns the amount_cents" do
|
12
|
+
expect(model.amount_cents).to eq(42_00)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -21,7 +21,7 @@ describe Hubs3D::Tip do
|
|
21
21
|
|
22
22
|
describe "#uuid" do
|
23
23
|
it "returns the uuid" do
|
24
|
-
expect(model.uuid).to eq("51")
|
24
|
+
expect(model.uuid).to eq("51-42-43")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -30,4 +30,15 @@ describe Hubs3D::Tip do
|
|
30
30
|
expect(model.mandatory).to eq(false)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe "#to_h" do
|
35
|
+
it "returns a serialized tip" do
|
36
|
+
expect(model.to_h).to eq(
|
37
|
+
amount: 42_00,
|
38
|
+
currency: "EUR",
|
39
|
+
uuid: "51-42-43",
|
40
|
+
mandatory: false
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
33
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubs3d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sunny Ripert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description: Upload 3D Models and create carts on
|
83
|
+
description: Upload 3D Models and create carts on 3D Hubs
|
84
84
|
email:
|
85
85
|
- sunny@sunfox.org
|
86
86
|
executables: []
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/hubs3d/api.rb
|
95
95
|
- lib/hubs3d/cart.rb
|
96
96
|
- lib/hubs3d/configuration.rb
|
97
|
+
- lib/hubs3d/error.rb
|
97
98
|
- lib/hubs3d/model.rb
|
98
99
|
- lib/hubs3d/tip.rb
|
99
100
|
- lib/hubs3d/version.rb
|
@@ -126,7 +127,7 @@ rubyforge_project:
|
|
126
127
|
rubygems_version: 2.4.5
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
|
-
summary: Access the
|
130
|
+
summary: Access the 3D Hubs API
|
130
131
|
test_files:
|
131
132
|
- spec/api_spec.rb
|
132
133
|
- spec/cart_spec.rb
|