hubs3d 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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +54 -0
- data/Rakefile +11 -0
- data/lib/hubs3d.rb +3 -0
- data/lib/hubs3d/api.rb +24 -0
- data/lib/hubs3d/cart.rb +33 -0
- data/lib/hubs3d/configuration.rb +24 -0
- data/lib/hubs3d/model.rb +28 -0
- data/lib/hubs3d/version.rb +3 -0
- data/spec/api_spec.rb +21 -0
- data/spec/cart_spec.rb +36 -0
- data/spec/fixtures/example.stl +1 -0
- data/spec/model_spec.rb +8 -0
- data/spec/spec_helper.rb +9 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 559f60efc7b85dae84b93b800c790cd3ff9bd646
|
4
|
+
data.tar.gz: 39a40028d8fa6c25a89bfe2fd096ff83e90ffa8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f2402f78e2d8f09361d507ac34b0e1a4a812e6fb4e814cbe076d4516f61b4116ffcf07410ba857a973f7330f7e2dcedd587e1ee9643259430e3f5a0f9a99d8b
|
7
|
+
data.tar.gz: 7cc411fe00ba12822a8a0c297c447969cdd83518fd2773c2bdffdaa824ec73ea600f6d8799d025627d6d142990dea86529484f2063b128692cd7e4fe3b228a4e
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Sunny Ripert
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
Ruby gem to access 3DHub's API
|
2
|
+
==============================
|
3
|
+
|
4
|
+
Example usage
|
5
|
+
-------------
|
6
|
+
|
7
|
+
```rb
|
8
|
+
Hubs3D.configure do |c|
|
9
|
+
c.oauth_key = "YOUR_API_KEY_HERE"
|
10
|
+
c.oauth_secret = "YOUR_API_SECRET_HERE"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Upload a model get its id
|
14
|
+
model = Hubs3D::Model.new(path: "/path/to/example.stl",
|
15
|
+
name: "example.stl")
|
16
|
+
model.id # => 42
|
17
|
+
|
18
|
+
# Create a cart and get its url
|
19
|
+
cart = Hubs3D::Cart.new
|
20
|
+
cart << model
|
21
|
+
cart.url # => "http://3dhubs.com/…"
|
22
|
+
```
|
23
|
+
|
24
|
+
Install
|
25
|
+
-------
|
26
|
+
|
27
|
+
Add the following line to your Gemfile if you are using the `bundler` gem:
|
28
|
+
|
29
|
+
```rb
|
30
|
+
gem "hubs3d"
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
Development
|
35
|
+
-----------
|
36
|
+
|
37
|
+
To launch specs:
|
38
|
+
|
39
|
+
```sh
|
40
|
+
$ rake
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
License
|
45
|
+
-------
|
46
|
+
|
47
|
+
Created by Sunny Ripert for [Cults.](https://cults3d.com),
|
48
|
+
licensed under the MIT License.
|
49
|
+
|
50
|
+
|
51
|
+
See also
|
52
|
+
--------
|
53
|
+
|
54
|
+
- https://bitbucket.org/bram_rongen/hubs3d_api_example
|
data/Rakefile
ADDED
data/lib/hubs3d.rb
ADDED
data/lib/hubs3d/api.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "json"
|
2
|
+
require "oauth"
|
3
|
+
|
4
|
+
# To help debugging:
|
5
|
+
# require 'net-http-spy'
|
6
|
+
# Net::HTTP.http_logger_options = {:verbose => true}
|
7
|
+
|
8
|
+
require "hubs3d/configuration"
|
9
|
+
|
10
|
+
module Hubs3D
|
11
|
+
module API
|
12
|
+
module_function
|
13
|
+
def post(path, params = {})
|
14
|
+
consumer = OAuth::Consumer.new(Hubs3D.configuration.oauth_key,
|
15
|
+
Hubs3D.configuration.oauth_secret,
|
16
|
+
site: Hubs3D.configuration.api_site)
|
17
|
+
token = OAuth::AccessToken.new(consumer)
|
18
|
+
response = token.post(Hubs3D.configuration.api_path + path,
|
19
|
+
params,
|
20
|
+
"Accept" => "application/json")
|
21
|
+
JSON.parse(response.body)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/hubs3d/cart.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "hubs3d/api"
|
2
|
+
|
3
|
+
module Hubs3D
|
4
|
+
class Cart
|
5
|
+
attr_reader :items
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@items = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(item)
|
12
|
+
@items << item
|
13
|
+
end
|
14
|
+
|
15
|
+
def url(options = {})
|
16
|
+
@url ||= post.fetch("url")
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def post
|
23
|
+
fail "Cart is empty" if @items.compact.empty?
|
24
|
+
|
25
|
+
hash = {}
|
26
|
+
@items.each do |item|
|
27
|
+
hash[item.id] = { modelId: item.id, quantity: 1 }
|
28
|
+
end
|
29
|
+
|
30
|
+
API.post("/cart", items: hash)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "hubs3d/api"
|
2
|
+
|
3
|
+
module Hubs3D
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :oauth_key
|
6
|
+
attr_accessor :oauth_secret
|
7
|
+
attr_accessor :api_site
|
8
|
+
attr_accessor :api_path
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@api_site = "http://test.3dhubs.com"
|
12
|
+
@api_path = "/api/v1"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure
|
21
|
+
self.configuration ||= Configuration.new
|
22
|
+
yield(configuration)
|
23
|
+
end
|
24
|
+
end
|
data/lib/hubs3d/model.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "hubs3d/api"
|
3
|
+
|
4
|
+
module Hubs3D
|
5
|
+
class Model
|
6
|
+
attr_accessor :id, :name, :path
|
7
|
+
def initialize(id: nil, name: nil, path: nil)
|
8
|
+
@id = id
|
9
|
+
@name = name
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
|
13
|
+
def id
|
14
|
+
@id ||= post["modelId"].to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def base_64
|
21
|
+
Base64.encode64 open(@path, 'r') { |f| f.read }
|
22
|
+
end
|
23
|
+
|
24
|
+
def post
|
25
|
+
API.post("/model", file: base_64, fileName: name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Hubs3D::API do
|
4
|
+
describe ".post" do
|
5
|
+
it "posts" do
|
6
|
+
stub_request(:post, "http://test.3dhubs.com/api/v1/some/path")
|
7
|
+
.with(body: { "foo" => "bar" },
|
8
|
+
headers: {
|
9
|
+
'Accept' => 'application/json',
|
10
|
+
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
11
|
+
'Authorization' => /\AOAuth/,
|
12
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
13
|
+
'User-Agent' => 'OAuth gem v0.4.7',
|
14
|
+
})
|
15
|
+
.to_return(status: 200, body: '{ "answer": 42 }')
|
16
|
+
|
17
|
+
post = Hubs3D::API.post("/some/path", foo: "bar")
|
18
|
+
post.must_equal({ "answer" => 42 })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/cart_spec.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hubs3d/cart"
|
3
|
+
|
4
|
+
describe Hubs3D::Cart do
|
5
|
+
let(:cart) { Hubs3D::Cart.new }
|
6
|
+
let(:item) { Minitest::Mock.new }
|
7
|
+
|
8
|
+
describe "#items" do
|
9
|
+
it "defaults to empty" do
|
10
|
+
cart.items.empty?.must_equal true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#<<" do
|
15
|
+
it "adds items" do
|
16
|
+
cart << item
|
17
|
+
cart << item
|
18
|
+
cart.items.size.must_equal 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#url" do
|
23
|
+
before do
|
24
|
+
cart << item
|
25
|
+
item.expect :id, 42
|
26
|
+
item.expect :id, 42
|
27
|
+
end
|
28
|
+
|
29
|
+
it "calls the API" do
|
30
|
+
returned = { "url" => "http://example" }
|
31
|
+
Hubs3D::API.stub :post, returned do
|
32
|
+
cart.url.must_equal "http://example"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
FOoO
|
data/spec/model_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubs3d
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sunny Ripert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
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: oauth
|
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: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Upload 3D Models and create carts on 3DHubs
|
70
|
+
email:
|
71
|
+
- sunny@sunfox.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- MIT-LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- lib/hubs3d.rb
|
80
|
+
- lib/hubs3d/api.rb
|
81
|
+
- lib/hubs3d/cart.rb
|
82
|
+
- lib/hubs3d/configuration.rb
|
83
|
+
- lib/hubs3d/model.rb
|
84
|
+
- lib/hubs3d/version.rb
|
85
|
+
- spec/api_spec.rb
|
86
|
+
- spec/cart_spec.rb
|
87
|
+
- spec/fixtures/example.stl
|
88
|
+
- spec/model_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: http://github.com/sunny/hubs3d
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Access the 3DHubs API
|
114
|
+
test_files:
|
115
|
+
- spec/api_spec.rb
|
116
|
+
- spec/cart_spec.rb
|
117
|
+
- spec/fixtures/example.stl
|
118
|
+
- spec/model_spec.rb
|
119
|
+
- spec/spec_helper.rb
|