Class: AskAwesomely::Typeform

Inherits:
Object
  • Object
show all
Defined in:
lib/ask_awesomely/typeform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(structure) ⇒ Typeform

Returns a new instance of Typeform.



5
6
7
8
# File 'lib/ask_awesomely/typeform.rb', line 5

def initialize(structure)
  @structure = structure
  @fields = []
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



3
4
5
# File 'lib/ask_awesomely/typeform.rb', line 3

def fields
  @fields
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/ask_awesomely/typeform.rb', line 3

def id
  @id
end

Returns the value of attribute links.



3
4
5
# File 'lib/ask_awesomely/typeform.rb', line 3

def links
  @links
end

#structureObject (readonly)

Returns the value of attribute structure.



3
4
5
# File 'lib/ask_awesomely/typeform.rb', line 3

def structure
  @structure
end

Instance Method Details

#embed_as(type, options = {}) ⇒ Object



26
27
28
# File 'lib/ask_awesomely/typeform.rb', line 26

def embed_as(type, options = {})
  Embeddable.new(type).render(self, options)
end

#private_urlObject



20
21
22
23
24
# File 'lib/ask_awesomely/typeform.rb', line 20

def private_url
  @private_url ||= links.find do |link|
    link['rel'] == 'self'
  end.fetch('href')
end

#public_urlObject



14
15
16
17
18
# File 'lib/ask_awesomely/typeform.rb', line 14

def public_url
  @public_url ||= links.find do |link|
    link['rel'] == 'form_render'
  end.fetch('href')
end

#titleObject



10
11
12
# File 'lib/ask_awesomely/typeform.rb', line 10

def title
  @structure.class._state.title
end

#to_jsonObject



36
37
38
# File 'lib/ask_awesomely/typeform.rb', line 36

def to_json
  @structure.to_json
end

#update_with_api_response(response) ⇒ Object



30
31
32
33
34
# File 'lib/ask_awesomely/typeform.rb', line 30

def update_with_api_response(response)
  @links = response['_links']
  @id = response['id']
  @fields = response['fields']
end