Class: Vinery::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/vinery/record.rb

Overview

Public: A Vine post. Contains attributes and helper methods for working with a specific post.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Record

Public: Initializes a new Record instance.

data - A Hash that contains the posting’s attributes. Typically this is

a record from a parsed JSON response.

Returns the new Vine instance.



13
14
15
16
17
18
19
20
21
22
# File 'lib/vinery/record.rb', line 13

def initialize(data)
  @description = data["description"]
  @id = data["postId"]
  @raw = data
  @share_url = data["shareUrl"]
  @thumbnail_url = data["thumbnailUrl"]
  @user_id = data["userId"]
  @venue = data["venue_name"]
  @video_url = data["videoUrl"]
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/vinery/record.rb', line 5

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/vinery/record.rb', line 5

def id
  @id
end

#rawObject (readonly)

Returns the value of attribute raw.



5
6
7
# File 'lib/vinery/record.rb', line 5

def raw
  @raw
end

#share_urlObject (readonly)

Returns the value of attribute share_url.



5
6
7
# File 'lib/vinery/record.rb', line 5

def share_url
  @share_url
end

#thumbnail_urlObject (readonly)

Returns the value of attribute thumbnail_url.



5
6
7
# File 'lib/vinery/record.rb', line 5

def thumbnail_url
  @thumbnail_url
end

#user_idObject (readonly)

Returns the value of attribute user_id.



5
6
7
# File 'lib/vinery/record.rb', line 5

def user_id
  @user_id
end

#venueObject (readonly)

Returns the value of attribute venue.



5
6
7
# File 'lib/vinery/record.rb', line 5

def venue
  @venue
end

#video_urlObject (readonly)

Returns the value of attribute video_url.



5
6
7
# File 'lib/vinery/record.rb', line 5

def video_url
  @video_url
end

Instance Method Details

#embed_tag(type = :simple, html_attrs = {}) ⇒ Object

Public: Produces a HTML iframe embed tag.

type - A Symbol that specifies the type of embed layout to display.

Possible types are :simple and :postcard (default: :simple).
If the type is not allowed, it will revert to :simple.

html_attrs - A Hash of HTML attributes for the iframe tag (default: {}).

Any keys with an underscore ("_") will be replaced with a 
hyphen ("-").

Examples

record.embed_tag
# => '<iframe src=".../embed/simple"></iframe>'

record.embed_tag(:postcard)
# => '<iframe src=".../embed/postcard"></iframe>'

record.embed_tag(:simple, {
  width: 600,
  height: 600,
  id: "vine-video",
  class: "class1 class2",
  data_foo: "bar"
})
# => '<iframe src="..." width="600" height="600" id="vine-video"
     class="class1 class2" data-foo="bar"></iframe>'


75
76
77
78
79
80
81
82
83
84
# File 'lib/vinery/record.rb', line 75

def embed_tag(type = :simple, html_attrs = {})
  allowed_types = [:simple, :postcard]
  type = :simple unless allowed_types.include?(type)
  attrs = ""
  html_attrs = attrs.each do |attr, val|
    attrs << " #{attr.to_s.replace('_', '-')}=\"#{val}\""
  end

  "<iframe src=\"#{@share_url}/embed/#{type}\"#{attrs}></iframe>"
end

#inspectObject

Public: Produces a human-readable representation of the Record.

Returns the String representation of the Record.



45
46
47
# File 'lib/vinery/record.rb', line 45

def inspect
  "<#{self.class} @id=\"#{@id}\" @video_url=\"#{@video_url}\" @description=\"#{@description}\">"
end

#to_hObject

Public: Converts the Record into a Hash.

Returns the String representation of the Record.



27
28
29
30
31
32
33
# File 'lib/vinery/record.rb', line 27

def to_h
  h = {}
  instance_variables.map { |iv| iv.to_s.gsub(/^@/, "") }.each do |attribute|
    h[attribute] = send(attribute)
  end
  h
end

#to_json(*a) ⇒ Object

Public: Converts the Record into JSON.

Returns the String raw JSON data of the record.



38
39
40
# File 'lib/vinery/record.rb', line 38

def to_json(*a)
  to_h.to_json(*a)
end