Class: GlossyApp::Session
- Inherits:
-
Object
- Object
- GlossyApp::Session
- Defined in:
- lib/glossyapp/session.rb,
lib/glossyapp/session/pages.rb,
lib/glossyapp/session/assets.rb,
lib/glossyapp/session/documents.rb,
lib/glossyapp/session/publications.rb,
lib/glossyapp/session/page_elements.rb
Overview
You find the rest of the methods in glossyapp/session/*
Instance Method Summary collapse
- #asset_folder_with_name_exists?(asset_folder_name, parent_folder_id = 'root') ⇒ Boolean
- #bla ⇒ Object
- #create_assets_folder(name, parent_id = 'root') ⇒ Object
- #create_document(publication_id, title, language = "en", external_id = nil, tag_list = [], published_at = nil) ⇒ Object
- #create_file_asset(file_path, asset_folder_id) ⇒ Object
- #create_page_element(document_id, page_id, x, y, width, height, type, data, title = nil) ⇒ Object
- #delete_assets_folder(assets_folder_id) ⇒ Object
- #delete_document(document_id) ⇒ Object
- #delete_file_asset(asset_folder_id, asset_file_id) ⇒ Object
- #delete_page_element(document_id, page_id, page_element_id) ⇒ Object
- #document_exists?(document_id) ⇒ Boolean
- #get_document(document_id) ⇒ Object
- #get_document_with_external_id(external_id) ⇒ Object
- #get_pages(document_id) ⇒ Object
- #import_asset_file_into_document(document_id, asset_file_id) ⇒ Object
-
#initialize(api_key, base_url = 'http://api.glossyapp.com/v1', proxy = nil, timeout = 30) ⇒ Session
constructor
A new instance of Session.
- #page_id_for_page_position(document_id, position) ⇒ Object
- #ping ⇒ Object
- #publish_document(document_id) ⇒ Object
- #set_external_id_for_page(document_id, page_id, external_id) ⇒ Object
- #unpublish_document(document_id) ⇒ Object
Constructor Details
#initialize(api_key, base_url = 'http://api.glossyapp.com/v1', proxy = nil, timeout = 30) ⇒ Session
Returns a new instance of Session.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/glossyapp/session.rb', line 20 def initialize(api_key, base_url = 'http://api.glossyapp.com/v1', proxy = nil, timeout = 30) @api_key = api_key @base_url = base_url @proxy = proxy @timeout = timeout @user_agent = "glossyapp-api-ruby/#{GlossyApp::VERSION}" # Handle Proxy if @proxy raise "Setting a proxy is no longer supported" end end |
Instance Method Details
#asset_folder_with_name_exists?(asset_folder_name, parent_folder_id = 'root') ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/glossyapp/session/assets.rb', line 53 def asset_folder_with_name_exists?(asset_folder_name, parent_folder_id='root') response = glossy_get "/asset_folders/#{parent_folder_id}" if [200].include?(response.status) root = JSON.parse(response.body) root['asset_folder']['children'].each do |folder| return folder['id'] if folder['name'] == asset_folder_name.to_s end return false else return false end end |
#bla ⇒ Object
5 6 7 |
# File 'lib/glossyapp/session/publications.rb', line 5 def bla puts "bla" end |
#create_assets_folder(name, parent_id = 'root') ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/glossyapp/session/assets.rb', line 27 def create_assets_folder(name, parent_id = 'root') data = { 'asset_folder' => { 'parent_id' => parent_id, 'name' => name } } response = glossy_post('/asset_folders', data.to_json, {"Content-Type" => "application/json"}) if [200, 201].include?(response.status) asset_folder = JSON.parse(response.body) return asset_folder['asset_folder']['id'] else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#create_document(publication_id, title, language = "en", external_id = nil, tag_list = [], published_at = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/glossyapp/session/documents.rb', line 38 def create_document(publication_id, title, language = "en", external_id = nil, tag_list = [], published_at = nil) post_data = { 'document' => { 'publication_id' => publication_id, 'title' => title, 'external_id' => external_id, 'language' => language, 'tag_list' => tag_list, 'published_at' => published_at } } response = glossy_post("/documents", post_data.to_json, {"Content-Type" => "application/json"}) if [200, 201].include?(response.status) document = JSON.parse(response.body) document_id = document['document']['id'] return document_id else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#create_file_asset(file_path, asset_folder_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/glossyapp/session/assets.rb', line 5 def create_file_asset(file_path, asset_folder_id) response = glossy_post_multipart("/asset_folders/#{asset_folder_id}/asset_files", {}, { 'asset_file[asset_file]' => file_path }) if [200, 201].include?(response.status) asset_file = JSON.parse(response.body) return asset_file['asset_file']['id'] else raise "Invalid response: #{response.inspect}\n#{response.body}" end return nil end |
#create_page_element(document_id, page_id, x, y, width, height, type, data, title = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/glossyapp/session/page_elements.rb', line 5 def create_page_element(document_id, page_id, x, y, width, height, type, data, title = nil) data = { 'page_element' => { 'page_id' => page_id, 'type' => type, 'title' => title, 'x' => x, 'y' => y, 'width' => width, 'height' => height }.merge(data) } response = glossy_post("/documents/#{document_id}/pages/#{page_id}/page_elements", data.to_json, {"Content-Type" => "application/json"}) if [200, 201].include?(response.status) json = JSON.parse(response.body) return json['page_element']['id'] else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#delete_assets_folder(assets_folder_id) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/glossyapp/session/assets.rb', line 44 def delete_assets_folder(assets_folder_id) response = glossy_delete("/asset_folders/#{assets_folder_id}") if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#delete_document(document_id) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/glossyapp/session/documents.rb', line 62 def delete_document(document_id) response = glossy_delete("/documents/#{document_id}") if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#delete_file_asset(asset_folder_id, asset_file_id) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/glossyapp/session/assets.rb', line 18 def delete_file_asset(asset_folder_id, asset_file_id) response = glossy_delete("/asset_folders/#{asset_folder_id}/asset_files/#{asset_file_id}") if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#delete_page_element(document_id, page_id, page_element_id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/glossyapp/session/page_elements.rb', line 27 def delete_page_element(document_id, page_id, page_element_id) response = glossy_delete "/documents/#{document_id}/pages/#{page_id}/page_elements/#{page_element_id}" if [200].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#document_exists?(document_id) ⇒ Boolean
71 72 73 74 75 76 77 78 79 |
# File 'lib/glossyapp/session/documents.rb', line 71 def document_exists?(document_id) response = glossy_get "/documents/#{document_id}" if [200].include?(response.status) doc = JSON.parse(response.body) return document_id.to_s == doc['id'].to_s else return false end end |
#get_document(document_id) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/glossyapp/session/documents.rb', line 29 def get_document(document_id) response = glossy_get "/documents/#{document_id}" if [200].include?(response.status) return JSON.parse(response.body) else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#get_document_with_external_id(external_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/glossyapp/session/documents.rb', line 5 def get_document_with_external_id(external_id) response = glossy_get "/documents" if [200].include?(response.status) json = JSON.parse(response.body) document_id = nil json['documents'].each do |document| if document['external_id'].to_s == external_id.to_s document_id = document['id'] break end end if document_id return get_document(document_id) else return nil end else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#get_pages(document_id) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/glossyapp/session/pages.rb', line 22 def get_pages(document_id) response = glossy_get "/documents/#{document_id}/pages" if [200].include?(response.status) return JSON.parse(response.body) else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#import_asset_file_into_document(document_id, asset_file_id) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/glossyapp/session/documents.rb', line 99 def import_asset_file_into_document(document_id, asset_file_id) response = glossy_post("/documents/#{document_id}/import", {:asset_file_id => asset_file_id}.to_json, {"Content-Type" => "application/json"}) if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#page_id_for_page_position(document_id, position) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/glossyapp/session/pages.rb', line 31 def page_id_for_page_position(document_id, position) response = glossy_get "/documents/#{document_id}/pages?positions=#{position}" if [200].include?(response.status) json = JSON.parse(response.body) if json['pages'].is_a?(Array) and json['pages'].size > 0 return json['pages'].first['id'] else return nil end else return nil end end |
#ping ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/glossyapp/session.rb', line 35 def ping response = glossy_get "/ping" if [200].include?(response.status) return true else return false end end |
#publish_document(document_id) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/glossyapp/session/documents.rb', line 81 def publish_document(document_id) response = glossy_post("/documents/#{document_id}/publish", {}.to_json) if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#set_external_id_for_page(document_id, page_id, external_id) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/glossyapp/session/pages.rb', line 5 def set_external_id_for_page(document_id, page_id, external_id) post_data = { 'page' => { 'external_id' => external_id } } response = glossy_put("/documents/#{document_id}/pages/#{page_id}", post_data.to_json, {"Content-Type" => "application/json"}) if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |
#unpublish_document(document_id) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/glossyapp/session/documents.rb', line 90 def unpublish_document(document_id) response = glossy_post("/documents/#{document_id}/unpublish", {}.to_json) if [200, 201].include?(response.status) return true else raise "Invalid response: #{response.inspect}\n#{response.body}" end end |