Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/document_cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'date'

require_relative 'document_cloud/document'
require_relative 'document_cloud/oembed'
require_relative 'document_cloud/project'
require_relative 'document_cloud/search_results'
require_relative 'document_cloud/default'
Expand Down
35 changes: 35 additions & 0 deletions lib/document_cloud/api/oembed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'cgi'

module DocumentCloud
module API
module OEmbed
include DocumentCloud::API::Utils
OEMBED_PATH = '/api/oembed.json'

# Get oEmbed json object for a given document
#
# @see https://www.documentcloud.org/help/api#oembed
# @param url [String] The url of the document to be shown in the embeded visor
# @param options [Hash] Customizable set of options
# @param options [Integer] :maxheight The viewer's height (pixels)
# @param options [Integer] :maxwidth The viewer's width (pixels)
# @param options [String] :container Specify the DOM container in which to embed the viewer, example: '#my-document-div'
# @param options [Boolean] :notes Enable the notes tab. default: true
# @param options [Boolean] :text Enable the text tab. default: true
# @param options [Boolean] :zoom Show the zoom slider. default: true
# @param options [Boolean] :search Show the search box. default: true
# @param options [Boolean] :sidebar Show the sidebar. default: true
# @param options [Boolean] :pdf Include a link to the original PDF. default: true
# @param options [Boolean] :responsive Make the viewer responsive. default: false
# @param options [Integer] :responsive_offset Specify header height (pixels)
# @param options [Integer] :default_note Open the document to a specific note. An integer representing the note ID
# @param options [Integer] :default_page Open the document to a specific page
# @returns [DocumentCloud::OEmbed] object wrapper to oEmbed's json response
def oembed(url, options={})
escaped_url = CGI.escape url
build_object DocumentCloud::oEmbed, get(OEMBED_PATH, options.merge(:url => escaped_url))
end

end
end
end
2 changes: 2 additions & 0 deletions lib/document_cloud/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require_relative 'api/update'
require_relative 'api/destroy'
require_relative 'api/entities'
require_relative 'api/oembed'
require_relative 'api/projects'
require_relative 'api/create_project'
require_relative 'api/update_project'
Expand All @@ -19,6 +20,7 @@ class Client
include DocumentCloud::API::Update
include DocumentCloud::API::Destroy
include DocumentCloud::API::Entities
include DocumentCloud::API::OEmbed
include DocumentCloud::API::Projects
include DocumentCloud::API::CreateProject
include DocumentCloud::API::UpdateProject
Expand Down
8 changes: 8 additions & 0 deletions lib/document_cloud/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def entities
@entities ||= DocumentCloud.entities(@id)
@entities
end

# Fetch oembed object for this document
#
# @param options [Hash] Options Hash with oEmbed's parameters
# @returns [DocumentCloud::OEmbed] object wrapper to oEmbed's json response
def oembed(options)
@oembed = DocumentCloud.oembed(@canonical_url, options)
end

end
end
18 changes: 18 additions & 0 deletions lib/document_cloud/oembed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module DocumentCloud
class OEmbed
attr_reader :type, :version, :provider_name, :provider_url,
:cache_age, :height, :width, :html

def initialize(attrs={})
@type = attrs[:type]
@version = attrs[:version]
@provider_name = attrs[:provider_name]
@provider_url = attrs[:provider_url]
@cache_age = attrs[:cache_age]
@height = attrs[:height]
@width = attrs[:width]
@html = attrs[:html]
end

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the empty spaces before the "end" statements and I'm good with merging this :)

end
end