slash3d 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f293a2b373781f1bab3fbb20331a0cead2fb13de
4
+ data.tar.gz: 561d431cebe0cbfd8e6d652a7670378f90dd94e2
5
+ SHA512:
6
+ metadata.gz: 2b1f797a59959d09aa7412146c8c81419d7da22f19ca151bca9a03e430b9153182ae34df0c87229b69fd58eb6fae878cde4c7034951c8e215fa90245ce5863b8
7
+ data.tar.gz: 7c5162c6bb6f06b4e6e9aae9506c819880cb751c6e63d57f3cb1f633d5ee49a360fcbfb85e1057917a9a3bb19041eacbef798228e35169518fbd1e66569999c5
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in slash3d.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sunny Ripert
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,107 @@
1
+ Ruby gem to access [3D Slash](https://www.3dslash.net/)'s API
2
+ =============================================================
3
+
4
+ Here be dragons
5
+ ---------------
6
+
7
+ This gem has not yet been tested in production. But it works. Probably.
8
+
9
+
10
+ Installation
11
+ ------------
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```rb
16
+ gem "slash3d"
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```sh
22
+ $ bundle
23
+ ```
24
+
25
+
26
+ Configuration
27
+ -------------
28
+
29
+ ```rb
30
+ Slash3D.configure do |c|
31
+ c.partner_code = "foobar"
32
+ c.api_key = "d4he4fae262352e4…"
33
+ end
34
+ ```
35
+
36
+ You should get the partner code and API key by asking 3D Slash.
37
+
38
+
39
+ Usage
40
+ -----
41
+
42
+ ### Get an Iframe url
43
+
44
+ ```rb
45
+ iframe = Slash3D::Iframe.new(
46
+ source: <url of stl or 3d slash id>,
47
+ redirect_url: <your url>,
48
+ )
49
+
50
+ iframe.url #=> "https://www.3dslash.net/slash.php?…"
51
+ iframe.content_id #=> "4c5fd2b2aa423d430f22ba940f4e28f7060fc39b2e44…"
52
+ ```
53
+
54
+ You can then use it in your page:
55
+
56
+ ```html
57
+ <iframe frameborder="0" src="<%= iframe.url %>"></iframe>
58
+ ```
59
+
60
+ ### Handle the POST
61
+
62
+ Once the user has clicked "export", a `POST` request will be sent to the
63
+ `redirect_url` you have given.
64
+
65
+ To get URLs from these parameters, pass them to a `Response`:
66
+
67
+ ```rb
68
+ response = Slash3D::Response.new(params)
69
+ ```
70
+
71
+ You can get temporary URLs:
72
+
73
+ ```rb
74
+ response.stl_url # => "https://www.3dslash.net/…"
75
+ response.thumbnail_url # => "https://www.3dslash.net/…"
76
+ response.slash3d_url # => "https://www.3dslash.net/…"
77
+ ```
78
+
79
+ And the full URL to the creation:
80
+
81
+ ```rb
82
+ response.permanent_url # => "https://www.3dslash.net/…"
83
+ ```
84
+
85
+ For thumbnails you can specify size (defaults to 192x192):
86
+
87
+ ```rb
88
+ response.thumbnail_url(width: 42, height: 42) # => "https://www.3dslash.net/…"
89
+ ```
90
+
91
+ You can store this model's uid to use it as a `source` the next time
92
+ you make an `Iframe`.
93
+
94
+ ```rb
95
+ response.uid # => "d430f22ba940f4e28f7060…"
96
+ ```
97
+
98
+
99
+ Contributing
100
+ ------------
101
+
102
+ 1. Fork it ( https://github.com/sunny/slash3d/fork )
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Launch specs (`bundle exec rspec`)
105
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
106
+ 5. Push to the branch (`git push origin my-new-feature`)
107
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,16 @@
1
+ module Slash3D
2
+ # Global configuration options
3
+ class Configuration
4
+ attr_accessor :api_key
5
+ attr_accessor :partner_code
6
+ end
7
+
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield(configuration)
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ require "active_support/core_ext/object/to_query"
2
+ require "securerandom"
3
+
4
+ module Slash3D
5
+ # Represent an Iframe to build a model with 3D Slash
6
+ class Iframe
7
+ def initialize(content_id: nil,
8
+ source: nil,
9
+ redirect_url: nil)
10
+ @content_id = content_id
11
+ @source = source
12
+ @redirect_url = redirect_url
13
+ end
14
+
15
+ def content_id
16
+ @content_id ||= SecureRandom.hex(32)
17
+ end
18
+
19
+ def url
20
+ parameters = {
21
+ partner: Slash3D.configuration.partner_code,
22
+ content: content_id,
23
+ src: source,
24
+ redirect: redirect_url,
25
+ sign: signature,
26
+ }
27
+
28
+ "https://www.3dslash.net/slash.php?" + parameters.to_query
29
+ end
30
+
31
+ private
32
+
33
+ def signature
34
+ signature_values = [
35
+ Slash3D.configuration.api_key,
36
+ Slash3D.configuration.partner_code,
37
+ content_id,
38
+ source,
39
+ redirect_url,
40
+ ]
41
+
42
+ Digest::SHA256.hexdigest(signature_values.join("|"))
43
+ end
44
+
45
+ attr_reader :source, :redirect_url
46
+ end
47
+ end
@@ -0,0 +1,66 @@
1
+ require "active_support/core_ext/object/to_query"
2
+ require "securerandom"
3
+ require "net/http"
4
+
5
+ module Slash3D
6
+ # Parse a 3D Slash POST response and extract URLs to the new model
7
+ class Response
8
+ attr_reader :content
9
+
10
+ def initialize(params)
11
+ @api = params[:api]
12
+ @content = params[:content]
13
+ @uid = params[:dslashUID]
14
+ @nonce = params[:nonce]
15
+ end
16
+
17
+ def stl_url
18
+ action_url("stl")
19
+ end
20
+
21
+ def thumbnail_url(width: nil, height: nil)
22
+ action_url("thumbnail", width: width, height: height)
23
+ end
24
+
25
+ def slash3d_url
26
+ action_url("3dslash")
27
+ end
28
+
29
+ def permanent_url
30
+ url = URI.parse(action_url("url"))
31
+ Net::HTTP.get_response(url).body
32
+ end
33
+
34
+
35
+ private
36
+
37
+ attr_reader :api, :nonce, :uid
38
+
39
+ def action_url(action, width: nil, height: nil)
40
+ params = {
41
+ action: action,
42
+ :alias => uid,
43
+ nonce: nonce,
44
+ partner: Slash3D.configuration.partner_code,
45
+ sign: signature(action),
46
+ }
47
+
48
+ params[:width] = width if width
49
+ params[:height] = height if height
50
+
51
+ "#{api}?#{params.to_query}"
52
+ end
53
+
54
+ def signature(action)
55
+ signature_values = [
56
+ Slash3D.configuration.api_key,
57
+ Slash3D.configuration.partner_code,
58
+ nonce,
59
+ uid,
60
+ action,
61
+ ]
62
+
63
+ Digest::SHA256.hexdigest(signature_values.join("|"))
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Slash3D
2
+ VERSION = "0.0.1"
3
+ end
data/lib/slash3d.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "slash3d/configuration"
2
+ require "slash3d/iframe"
3
+ require "slash3d/version"
4
+ require "slash3d/response"
data/slash3d.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "slash3d/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slash3d"
8
+ spec.version = Slash3D::VERSION
9
+ spec.authors = ["Sunny Ripert"]
10
+ spec.email = ["sunny@sunfox.org"]
11
+ spec.summary = "Access 3D Slash's API"
12
+ # spec.description = "TODO: Write a longer description. Optional."
13
+ spec.homepage = ""
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{^(spec)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+ # spec.add_dependency "securerandom"
23
+
24
+ # Tasks for gem development
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake"
27
+
28
+ # Specs
29
+ spec.add_development_dependency "rspec"
30
+
31
+ # Block HTTP connections in specs
32
+ spec.add_development_dependency "webmock"
33
+ end
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+ require "slash3d/iframe"
3
+
4
+ module Slash3D
5
+ describe Iframe do
6
+ let(:iframe) { described_class.new(options) }
7
+ let(:options) { { source: "http://source-url",
8
+ redirect_url: "http://redirect-url" } }
9
+
10
+ describe "#url" do
11
+ before do
12
+ allow(iframe).to receive(:content_id) { "c97ff01cdf0fca07a33dce9" }
13
+ end
14
+
15
+ it "returns a full url to 3dslash" do
16
+ url = "https://www.3dslash.net/slash.php" \
17
+ "?content=c97ff01cdf0fca07a33dce9" \
18
+ "&partner=test_partner_code" \
19
+ "&redirect=http%3A%2F%2Fredirect-url" \
20
+ "&sign=4c5fd2b2aa423d430f22ba940f4e28f7060fc39b2e44a70e656f74b94a38859c" \
21
+ "&src=http%3A%2F%2Fsource-url"
22
+
23
+ expect(iframe.url).to eq(url)
24
+ end
25
+ end
26
+
27
+ describe "#content_id" do
28
+ it "generates a random hex" do
29
+ expect(iframe.content_id).to match(/^[0-9a-f]{10,256}$/)
30
+ end
31
+
32
+ it "is memoized" do
33
+ expect(iframe.content_id).to eq(iframe.content_id)
34
+ end
35
+
36
+ context "when given in the options" do
37
+ let(:options) { { content_id: "f00" } }
38
+
39
+ it "returns the same value" do
40
+ expect(iframe.content_id).to eq("f00")
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+ require "slash3d/response"
3
+
4
+ module Slash3D
5
+ describe Response do
6
+ let(:response) { described_class.new(params) }
7
+ let(:params) { { content: "f004221",
8
+ dslashUID: "b484221",
9
+ api: "https://api.3dslash.net/",
10
+ nonce: "e4f57b89" } }
11
+
12
+ describe "#stl_url" do
13
+ it "returns a full url to 3dslash" do
14
+ url = "https://api.3dslash.net/" \
15
+ "?action=stl" \
16
+ "&alias=b484221" \
17
+ "&nonce=e4f57b89" \
18
+ "&partner=test_partner_code" \
19
+ "&sign=d9c3924d0fb3e428034b6918f3d4d9f206e034baf7c25dbc602344ed60bd0d6d"
20
+
21
+ expect(response.stl_url).to eq(url)
22
+ end
23
+ end
24
+
25
+ describe "#thumbnail_url" do
26
+ it "returns a full url to 3dslash" do
27
+ url = "https://api.3dslash.net/" \
28
+ "?action=thumbnail" \
29
+ "&alias=b484221" \
30
+ "&nonce=e4f57b89" \
31
+ "&partner=test_partner_code" \
32
+ "&sign=26ce6e91823e9cfe08ca520031dd417c2a928c61e62b2153a978787bfe813c62"
33
+
34
+ expect(response.thumbnail_url).to eq(url)
35
+ end
36
+
37
+ it "adds the given width and height to the url" do
38
+ url = "https://api.3dslash.net/" \
39
+ "?action=thumbnail" \
40
+ "&alias=b484221" \
41
+ "&height=456" \
42
+ "&nonce=e4f57b89" \
43
+ "&partner=test_partner_code" \
44
+ "&sign=26ce6e91823e9cfe08ca520031dd417c2a928c61e62b2153a978787bfe813c62" \
45
+ "&width=123"
46
+
47
+ expect(response.thumbnail_url(width: 123, height: 456)).to eq(url)
48
+ end
49
+ end
50
+
51
+ describe "#slash3d_url" do
52
+ it "returns a full url to 3dslash" do
53
+ url = "https://api.3dslash.net/" \
54
+ "?action=3dslash" \
55
+ "&alias=b484221" \
56
+ "&nonce=e4f57b89" \
57
+ "&partner=test_partner_code" \
58
+ "&sign=06de2763db0fbef294770827d9f5ddb613bc9c717a28381a44992ea36a515f29"
59
+
60
+ expect(response.slash3d_url).to eq(url)
61
+ end
62
+ end
63
+
64
+ describe "#permanent_url" do
65
+ it "returns the permanent url to a 3dslash creation" do
66
+ url = "https://api.3dslash.net/" \
67
+ "?action=url" \
68
+ "&alias=b484221" \
69
+ "&nonce=e4f57b89" \
70
+ "&partner=test_partner_code" \
71
+ "&sign=f3b529b43c4591de2f33049f7cd572f3faa024f43c0e75aef357b87daa5db2ca"
72
+
73
+ stub_request(:get, url)
74
+ .to_return(body: "https://foo.com")
75
+
76
+ expect(response.permanent_url).to eq("https://foo.com")
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,8 @@
1
+ require "webmock/rspec"
2
+
3
+ require "slash3d/configuration"
4
+
5
+ Slash3D.configure do |c|
6
+ c.partner_code = "test_partner_code"
7
+ c.api_key = "test_api_key"
8
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slash3d
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-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
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
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - sunny@sunfox.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/slash3d.rb
96
+ - lib/slash3d/configuration.rb
97
+ - lib/slash3d/iframe.rb
98
+ - lib/slash3d/response.rb
99
+ - lib/slash3d/version.rb
100
+ - slash3d.gemspec
101
+ - spec/iframe_spec.rb
102
+ - spec/response_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Access 3D Slash's API
128
+ test_files:
129
+ - spec/iframe_spec.rb
130
+ - spec/response_spec.rb
131
+ - spec/spec_helper.rb