warehaus 0.0.2 → 0.1.0
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 +4 -4
- data/lib/warehaus.rb +33 -17
- data/lib/warehaus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03b7c03389b5a48a63749e1b03c37ae91c0b55ac
|
|
4
|
+
data.tar.gz: 504d5ab4dbe34758ee1281641ddfc8e4dbd9321e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 260414d62bb981dae17add734d03bbc63932302640c015970842cc783f92e02a6b27aea936143c83cfd76c8ed538c288a8ebaaacd3598156e50b892b9730b824
|
|
7
|
+
data.tar.gz: a1a7dbe846e25b334a515c9140b13f592d23d6c82ac9f5504ce15d7ddd609de70cff0a854d60afcda4ceeef2b541d71d1d33596d18711756dce4d25d1017edb7
|
data/lib/warehaus.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
require "warehaus/version"
|
|
2
2
|
require "httparty"
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
3
5
|
require "json"
|
|
4
6
|
require "zip"
|
|
5
7
|
require "fileutils"
|
|
@@ -10,8 +12,8 @@ module Warehaus
|
|
|
10
12
|
class Getter
|
|
11
13
|
include HTTParty
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
BASE_URI = '3dwarehouse.sketchup.com'
|
|
16
|
+
base_uri BASE_URI
|
|
15
17
|
ENTITY_PATH = '/3dw/GetEntity'
|
|
16
18
|
KMZ_PATH = '/warehouse/getpubliccontent'
|
|
17
19
|
|
|
@@ -32,7 +34,7 @@ module Warehaus
|
|
|
32
34
|
|
|
33
35
|
def fetch_entity
|
|
34
36
|
log("📠 Fetching JSON representation of model")
|
|
35
|
-
@response
|
|
37
|
+
@response ||= JSON.parse(self.class.get(ENTITY_PATH, @options), :symbolize_names => true)
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def get_kmz_id
|
|
@@ -61,22 +63,38 @@ module Warehaus
|
|
|
61
63
|
}
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
def download_kmz
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
def download_kmz(tries=3, redirect=false)
|
|
67
|
+
return raise_error 'HTTP Redirect too deep' if tries == 0
|
|
68
|
+
|
|
69
|
+
log("📥 Downloading KMZ file") unless redirect
|
|
68
70
|
|
|
69
|
-
def write_kmz
|
|
70
71
|
FileUtils::mkdir_p "#{@model_path}/.tmp"
|
|
71
|
-
|
|
72
|
+
url = redirect ? URI.parse( redirect ) : URI.parse("http://" + BASE_URI + "#{KMZ_PATH}?contentId=#{@kmz_options[:query][:contentId]}&fn=#{@kmz_options[:query][:fn]}")
|
|
73
|
+
|
|
72
74
|
begin
|
|
73
|
-
|
|
74
|
-
f.write @kmz
|
|
75
|
-
end
|
|
76
|
-
FileUtils::mv "#{@model_path}/.tmp/#{@name}.kmz", "#{@model_path}/.tmp/#{@name}.zip"
|
|
75
|
+
resp = Net::HTTP.get_response(url)
|
|
77
76
|
rescue Exception => e
|
|
78
77
|
return raise_error e.message
|
|
79
78
|
end
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
case resp
|
|
82
|
+
when Net::HTTPSuccess then
|
|
83
|
+
|
|
84
|
+
File.open("#{@model_path}/.tmp/#{@name}.kmz", "wb") do |file|
|
|
85
|
+
|
|
86
|
+
file.write(resp.body)
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
FileUtils.mv "#{@model_path}/.tmp/#{@name}.kmz", "#{@model_path}/.tmp/#{@name}.zip"
|
|
91
|
+
|
|
92
|
+
when Net::HTTPRedirection then
|
|
93
|
+
download_kmz( tries-1, resp['location'])
|
|
94
|
+
else raise_error("Response neither successful nor redirecting")
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
80
98
|
end
|
|
81
99
|
|
|
82
100
|
def unzip_kmz
|
|
@@ -105,7 +123,7 @@ module Warehaus
|
|
|
105
123
|
|
|
106
124
|
def cleanup
|
|
107
125
|
log("🛀 Cleaning up")
|
|
108
|
-
FileUtils.rm_rf("#{@model_path}
|
|
126
|
+
FileUtils.rm_rf("#{@model_path}")
|
|
109
127
|
end
|
|
110
128
|
|
|
111
129
|
def unbox
|
|
@@ -113,9 +131,7 @@ module Warehaus
|
|
|
113
131
|
fetch_entity
|
|
114
132
|
get_kmz_id
|
|
115
133
|
download_kmz
|
|
116
|
-
|
|
117
|
-
unzip_kmz
|
|
118
|
-
cleanup
|
|
134
|
+
unzip_km
|
|
119
135
|
"#{@path}/#{@name}/"
|
|
120
136
|
end
|
|
121
137
|
|
data/lib/warehaus/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: warehaus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Erik Sälgström Peterson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|