glossyapp 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/glossyapp/session/assets.rb +5 -8
- data/lib/glossyapp/session/documents.rb +8 -8
- data/lib/glossyapp/session/page_elements.rb +2 -2
- data/lib/glossyapp/session/pages.rb +3 -3
- data/lib/glossyapp/session.rb +69 -9
- data/lib/glossyapp/version.rb +1 -1
- metadata +1 -2
- data/old_vanga_main.rb +0 -154
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 783887e5937c63054721cbdb020cfcec02e7d71f
|
4
|
+
data.tar.gz: 1fccc4563c990803cdfe1a2a9773654731bf81a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 023f8bc3ab091ae40291a3346262b9cfb0ef887a62f4744b74cf76faf6a93aaa28e828f01ef72177bf1c6b73d0e5eb4beab8eef3b85c633959cd8432c767e77d
|
7
|
+
data.tar.gz: 6d9afc2477c2dce5908add0a2a735f8c2ac1062e569c5ad49e40626b7497d7234eb536d2381d6cef26f9711beb78cdfe419707cfbcef31a2b8721c4058780937
|
@@ -3,10 +3,7 @@ module GlossyApp
|
|
3
3
|
class Session
|
4
4
|
|
5
5
|
def create_file_asset(file_path, asset_folder_id)
|
6
|
-
|
7
|
-
setup_session
|
8
|
-
|
9
|
-
response = @glossy_api.post_multipart("/asset_folders/#{asset_folder_id}/asset_files", {}, { 'asset_file[asset_file]' => file_path })
|
6
|
+
response = glossy_post_multipart("/asset_folders/#{asset_folder_id}/asset_files", {}, { 'asset_file[asset_file]' => file_path })
|
10
7
|
|
11
8
|
if [200, 201].include?(response.status)
|
12
9
|
asset_file = JSON.parse(response.body)
|
@@ -19,7 +16,7 @@ module GlossyApp
|
|
19
16
|
end
|
20
17
|
|
21
18
|
def delete_file_asset(asset_folder_id, asset_file_id)
|
22
|
-
response =
|
19
|
+
response = glossy_delete("/asset_folders/#{asset_folder_id}/asset_files/#{asset_file_id}")
|
23
20
|
if [200, 201].include?(response.status)
|
24
21
|
return true
|
25
22
|
else
|
@@ -35,7 +32,7 @@ module GlossyApp
|
|
35
32
|
}
|
36
33
|
}
|
37
34
|
|
38
|
-
response =
|
35
|
+
response = glossy_post('/asset_folders', data.to_json, {"Content-Type" => "application/json"})
|
39
36
|
if [200, 201].include?(response.status)
|
40
37
|
asset_folder = JSON.parse(response.body)
|
41
38
|
return asset_folder['asset_folder']['id']
|
@@ -45,7 +42,7 @@ module GlossyApp
|
|
45
42
|
end
|
46
43
|
|
47
44
|
def delete_assets_folder(assets_folder_id)
|
48
|
-
response =
|
45
|
+
response = glossy_delete("/asset_folders/#{assets_folder_id}")
|
49
46
|
if [200, 201].include?(response.status)
|
50
47
|
return true
|
51
48
|
else
|
@@ -54,7 +51,7 @@ module GlossyApp
|
|
54
51
|
end
|
55
52
|
|
56
53
|
def asset_folder_with_name_exists?(asset_folder_name, parent_folder_id='root')
|
57
|
-
response =
|
54
|
+
response = glossy_get "/asset_folders/#{parent_folder_id}"
|
58
55
|
if [200].include?(response.status)
|
59
56
|
root = JSON.parse(response.body)
|
60
57
|
root['asset_folder']['children'].each do |folder|
|
@@ -3,7 +3,7 @@ module GlossyApp
|
|
3
3
|
class Session
|
4
4
|
|
5
5
|
def get_document_with_external_id(external_id)
|
6
|
-
response =
|
6
|
+
response = glossy_get "/documents"
|
7
7
|
if [200].include?(response.status)
|
8
8
|
json = JSON.parse(response.body)
|
9
9
|
|
@@ -27,7 +27,7 @@ module GlossyApp
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def get_document(document_id)
|
30
|
-
response =
|
30
|
+
response = glossy_get "/documents/#{document_id}"
|
31
31
|
if [200].include?(response.status)
|
32
32
|
return JSON.parse(response.body)
|
33
33
|
else
|
@@ -47,7 +47,7 @@ module GlossyApp
|
|
47
47
|
}
|
48
48
|
}
|
49
49
|
|
50
|
-
response =
|
50
|
+
response = glossy_post("/documents", post_data.to_json, {"Content-Type" => "application/json"})
|
51
51
|
if [200, 201].include?(response.status)
|
52
52
|
document = JSON.parse(response.body)
|
53
53
|
|
@@ -60,7 +60,7 @@ module GlossyApp
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def delete_document(document_id)
|
63
|
-
response =
|
63
|
+
response = glossy_delete("/documents/#{document_id}")
|
64
64
|
if [200, 201].include?(response.status)
|
65
65
|
return true
|
66
66
|
else
|
@@ -69,7 +69,7 @@ module GlossyApp
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def document_exists?(document_id)
|
72
|
-
response =
|
72
|
+
response = glossy_get "/documents/#{document_id}"
|
73
73
|
if [200].include?(response.status)
|
74
74
|
doc = JSON.parse(response.body)
|
75
75
|
return document_id.to_s == doc['id'].to_s
|
@@ -79,7 +79,7 @@ module GlossyApp
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def publish_document(document_id)
|
82
|
-
response =
|
82
|
+
response = glossy_post("/documents/#{document_id}/publish", {})
|
83
83
|
if [200, 201].include?(response.status)
|
84
84
|
return true
|
85
85
|
else
|
@@ -88,7 +88,7 @@ module GlossyApp
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def unpublish_document(document_id)
|
91
|
-
response =
|
91
|
+
response = glossy_post("/documents/#{document_id}/unpublish", {})
|
92
92
|
if [200, 201].include?(response.status)
|
93
93
|
return true
|
94
94
|
else
|
@@ -97,7 +97,7 @@ module GlossyApp
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def import_asset_file_into_document(document_id, asset_file_id)
|
100
|
-
response =
|
100
|
+
response = glossy_post("/documents/#{document_id}/import", {:asset_file_id => asset_file_id}.to_json, {"Content-Type" => "application/json"})
|
101
101
|
if [200, 201].include?(response.status)
|
102
102
|
return true
|
103
103
|
else
|
@@ -15,7 +15,7 @@ module GlossyApp
|
|
15
15
|
}.merge(data)
|
16
16
|
}
|
17
17
|
|
18
|
-
response =
|
18
|
+
response = glossy_post("/documents/#{document_id}/pages/#{page_id}/page_elements", data.to_json, {"Content-Type" => "application/json"})
|
19
19
|
if [200, 201].include?(response.status)
|
20
20
|
json = JSON.parse(response.body)
|
21
21
|
return json['page_element']['id']
|
@@ -25,7 +25,7 @@ module GlossyApp
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def delete_page_element(document_id, page_id, page_element_id)
|
28
|
-
response =
|
28
|
+
response = glossy_delete "/documents/#{document_id}/pages/#{page_id}/page_elements/#{page_element_id}"
|
29
29
|
if [200].include?(response.status)
|
30
30
|
return true
|
31
31
|
else
|
@@ -9,7 +9,7 @@ module GlossyApp
|
|
9
9
|
}
|
10
10
|
}
|
11
11
|
|
12
|
-
response =
|
12
|
+
response = glossy_put("/documents/#{document_id}/pages/#{page_id}", post_data.to_json, {"Content-Type" => "application/json"})
|
13
13
|
if [200, 201].include?(response.status)
|
14
14
|
return true
|
15
15
|
|
@@ -20,7 +20,7 @@ module GlossyApp
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def get_pages(document_id)
|
23
|
-
response =
|
23
|
+
response = glossy_get "/documents/#{document_id}/pages"
|
24
24
|
if [200].include?(response.status)
|
25
25
|
return JSON.parse(response.body)
|
26
26
|
else
|
@@ -29,7 +29,7 @@ module GlossyApp
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def page_id_for_page_position(document_id, position)
|
32
|
-
response =
|
32
|
+
response = glossy_get "/documents/#{document_id}/pages?positions=#{position}"
|
33
33
|
if [200].include?(response.status)
|
34
34
|
json = JSON.parse(response.body)
|
35
35
|
if json['pages'].is_a?(Array) and json['pages'].size > 0
|
data/lib/glossyapp/session.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'patron'
|
2
2
|
require 'json'
|
3
|
+
require 'net/http'
|
3
4
|
|
4
5
|
require "glossyapp/session/documents"
|
5
6
|
require "glossyapp/session/publications"
|
@@ -23,11 +24,16 @@ module GlossyApp
|
|
23
24
|
@proxy = proxy
|
24
25
|
@timeout = timeout
|
25
26
|
|
26
|
-
|
27
|
+
@user_agent = "glossyapp-api-ruby/#{GlossyApp::VERSION}"
|
28
|
+
|
29
|
+
# Handle Proxy
|
30
|
+
if @proxy
|
31
|
+
raise "Setting a proxy is no longer supported"
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
def ping
|
30
|
-
response =
|
36
|
+
response = glossy_get "/ping"
|
31
37
|
if [200].include?(response.status)
|
32
38
|
return true
|
33
39
|
else
|
@@ -35,14 +41,27 @@ module GlossyApp
|
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
|
-
# FIXME: remove before publishing
|
39
|
-
def self.local_dev
|
40
|
-
GlossyApp::Session.new("1rbsyZyuqyYeUxzsAkpJ", "http://localhost:3000/api/v1")#, 'http://localhost:8888')
|
41
|
-
end
|
42
44
|
|
43
45
|
protected
|
44
46
|
|
45
|
-
def
|
47
|
+
def glossy_get(path, headers = {})
|
48
|
+
request = Net::HTTP::Get.new(build_uri(path))
|
49
|
+
return make_request(request, headers)
|
50
|
+
end
|
51
|
+
|
52
|
+
def glossy_put(path, data, headers = {})
|
53
|
+
request = Net::HTTP::Put.new(build_uri(path))
|
54
|
+
request.body = data
|
55
|
+
return make_request(request, headers)
|
56
|
+
end
|
57
|
+
|
58
|
+
def glossy_post(path, data, headers = {})
|
59
|
+
request = Net::HTTP::Post.new(build_uri(path))
|
60
|
+
request.body = data
|
61
|
+
return make_request(request, headers)
|
62
|
+
end
|
63
|
+
|
64
|
+
def glossy_post_multipart(path, data, file, headers = {})
|
46
65
|
@glossy_api = Patron::Session.new
|
47
66
|
@glossy_api.timeout = @timeout
|
48
67
|
|
@@ -54,12 +73,53 @@ module GlossyApp
|
|
54
73
|
|
55
74
|
@glossy_api.proxy = @proxy
|
56
75
|
|
57
|
-
@glossy_api.headers['User-Agent'] =
|
76
|
+
@glossy_api.headers['User-Agent'] = @user_agent
|
58
77
|
@glossy_api.headers['Accept'] = 'application/json'
|
59
78
|
|
60
|
-
|
79
|
+
response = @glossy_api.post_multipart(path, data, file, headers)
|
80
|
+
|
81
|
+
return GlossyResponse.new(response.status, response.body)
|
82
|
+
end
|
83
|
+
|
84
|
+
def glossy_delete(path, headers = {})
|
85
|
+
request = Net::HTTP::Delete.new(build_uri(path))
|
86
|
+
return make_request(request, headers)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
def build_uri(path)
|
94
|
+
return URI("#{@base_url}#{path}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def make_request(request, headers)
|
98
|
+
request['Accept'] = 'application/json'
|
99
|
+
request['User-Agent'] = @user_agent
|
100
|
+
|
101
|
+
headers.each_pair { |key, value| request[key] = value }
|
102
|
+
|
103
|
+
request.basic_auth @api_key, ''
|
104
|
+
|
105
|
+
response = Net::HTTP.start(request.uri.hostname, request.uri.port, :use_ssl => request.uri.scheme == 'https', :read_timeout => @timeout) do |http|
|
106
|
+
http.request(request)
|
107
|
+
end
|
108
|
+
|
109
|
+
return GlossyResponse.new(response.code.to_i, response.body)
|
61
110
|
end
|
62
111
|
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
class GlossyResponse
|
116
|
+
attr_accessor :status
|
117
|
+
attr_accessor :body
|
118
|
+
|
119
|
+
def initialize(status, body)
|
120
|
+
@status = status
|
121
|
+
@body = body
|
122
|
+
end
|
63
123
|
end
|
64
124
|
|
65
125
|
end
|
data/lib/glossyapp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glossyapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Schmid
|
@@ -105,7 +105,6 @@ files:
|
|
105
105
|
- lib/glossyapp/session/publications.rb
|
106
106
|
- lib/glossyapp/util.rb
|
107
107
|
- lib/glossyapp/version.rb
|
108
|
-
- old_vanga_main.rb
|
109
108
|
homepage: http://www.glossyapp.com
|
110
109
|
licenses:
|
111
110
|
- MIT
|
data/old_vanga_main.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
|
2
|
-
def create_article(article, gallery = nil, asset_file_id = nil)
|
3
|
-
post_data = {
|
4
|
-
'article' => {
|
5
|
-
'title' => article[:title],
|
6
|
-
'subtitle' => article[:subtitle],
|
7
|
-
'abstract' => article[:pretext],
|
8
|
-
'content' => article[:textbody]
|
9
|
-
}
|
10
|
-
}
|
11
|
-
|
12
|
-
if gallery
|
13
|
-
post_data['article']['image_gallery_id'] = gallery[:glossyapp_id]
|
14
|
-
end
|
15
|
-
|
16
|
-
if asset_file_id
|
17
|
-
post_data['article']['header_image_asset_file_id'] = asset_file_id
|
18
|
-
end
|
19
|
-
|
20
|
-
response = @glossy_api.post("/documents/#{@options[:document_id]}/articles", post_data.to_json, {"Content-Type" => "application/json"})
|
21
|
-
if [200, 201].include?(response.status)
|
22
|
-
article = JSON.parse(response.body)
|
23
|
-
|
24
|
-
article_id = article['id']
|
25
|
-
return article_id
|
26
|
-
|
27
|
-
else
|
28
|
-
raise "Couldn't create article: #{response.inspect}\n#{response.body}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def toc_section_id_for_section_with_title(title)
|
34
|
-
response = @glossy_api.get "/documents/#{@options[:document_id]}/toc_sections?title=#{CGI.escape(title)}"
|
35
|
-
if [200].include?(response.status)
|
36
|
-
json = JSON.parse(response.body)
|
37
|
-
if json['toc_sections'].is_a?(Array) and json['toc_sections'].size > 0
|
38
|
-
return json['toc_sections'].first['id']
|
39
|
-
else
|
40
|
-
return nil
|
41
|
-
end
|
42
|
-
else
|
43
|
-
return nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def create_toc_section(title, description)
|
48
|
-
post_data = {
|
49
|
-
'toc_section' => {
|
50
|
-
'title' => title,
|
51
|
-
'description' => description
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
response = @glossy_api.post("/documents/#{@options[:document_id]}/toc_sections", post_data.to_json, {"Content-Type" => "application/json"})
|
56
|
-
if [200, 201].include?(response.status)
|
57
|
-
json = JSON.parse(response.body)
|
58
|
-
return json['id']
|
59
|
-
else
|
60
|
-
raise "Invalid response: #{response.inspect}\n#{response.body}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def create_toc_entry(section_id, title, page_index)
|
65
|
-
post_data = {
|
66
|
-
'toc_entry' => {
|
67
|
-
'title' => title,
|
68
|
-
'page_index' => page_index
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
response = @glossy_api.post("/documents/#{@options[:document_id]}/toc_sections/#{section_id}/toc_entries", post_data.to_json, {"Content-Type" => "application/json"})
|
73
|
-
if [200, 201].include?(response.status)
|
74
|
-
json = JSON.parse(response.body)
|
75
|
-
return json['id']
|
76
|
-
else
|
77
|
-
raise "Invalid response: #{response.inspect}\n#{response.body}"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
def old_vanga_main
|
86
|
-
|
87
|
-
# Check if document exists on GlossyApp
|
88
|
-
if check_if_document_exists
|
89
|
-
@logger.info "Document #{@options[:document_id]} does exist"
|
90
|
-
else
|
91
|
-
raise "Document #{@options[:document_id]} does NOT exist"
|
92
|
-
end
|
93
|
-
|
94
|
-
|
95
|
-
# create assets_folder_for_this_import
|
96
|
-
asset_folder_id = create_assets_folder("Import of: #{Time.now}")
|
97
|
-
|
98
|
-
# create articles and ToC
|
99
|
-
articles.each do |article|
|
100
|
-
# create header image for article
|
101
|
-
asset_file_id = nil
|
102
|
-
if article[:url_headerimage_large]
|
103
|
-
begin
|
104
|
-
Tempfile.open('article_header_image') do |f|
|
105
|
-
download_file(article[:url_headerimage_large], f.path)
|
106
|
-
|
107
|
-
asset_file_id = create_file_asset(f.path, asset_folder_id)
|
108
|
-
end
|
109
|
-
rescue Exception => e
|
110
|
-
asset_file_id = nil
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# create gallery for article
|
115
|
-
gallery = gallery_from_article(article)
|
116
|
-
gallery[:glossyapp_id] = create_gallery(gallery) if gallery
|
117
|
-
|
118
|
-
# create article
|
119
|
-
article_id = create_article(article, gallery, asset_file_id)
|
120
|
-
|
121
|
-
# create ToC entry
|
122
|
-
unless article[:title].nil? or article[:title].size <= 0
|
123
|
-
section_id = toc_section_id_for_section_with_title(article[:title])
|
124
|
-
unless section_id
|
125
|
-
if article[:title] && article[:subtitle]
|
126
|
-
section_id = create_toc_section(article[:title], article[:subtitle])
|
127
|
-
create_toc_entry(section_id, article[:title], article[:pageStart].to_i - 1)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# create ToC section entries & article_links
|
133
|
-
article[:pageStart].to_i.upto(article[:pageEnd].to_i) do |page_position|
|
134
|
-
|
135
|
-
# create article_link
|
136
|
-
page_id = page_id_for_page_position(page_position)
|
137
|
-
if page_id
|
138
|
-
create_page_element(page_id,
|
139
|
-
0,
|
140
|
-
0,
|
141
|
-
0,
|
142
|
-
0,
|
143
|
-
'article_link',
|
144
|
-
{'article_id' => article_id },
|
145
|
-
article[:title])
|
146
|
-
else
|
147
|
-
@logger.error "Did not find page for article..."
|
148
|
-
end
|
149
|
-
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
|