Class: TypePadTemplate::Template

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/type_pad_template/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blog, name, filename, edit_url) ⇒ Template

Returns a new instance of Template.



9
10
11
12
13
14
# File 'lib/type_pad_template/template.rb', line 9

def initialize(blog, name, filename, edit_url)
  @blog = blog
  @name = name
  @filename = filename
  @edit_path = URI.parse(edit_url).path
end

Instance Attribute Details

#blogObject (readonly)

Returns the value of attribute blog.



7
8
9
# File 'lib/type_pad_template/template.rb', line 7

def blog
  @blog
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/type_pad_template/template.rb', line 7

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/type_pad_template/template.rb', line 7

def name
  @name
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/type_pad_template/template.rb', line 7

def text
  @text
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/type_pad_template/template.rb', line 7

def url
  @url
end

Instance Method Details

#enqueue_get(&block) ⇒ Object



16
17
18
19
20
21
# File 'lib/type_pad_template/template.rb', line 16

def enqueue_get(&block)
  request(@edit_path).enqueue do |response|
    @text = get_text_from_response(response)
    block.call(text)
  end
end

#enqueue_post(text, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/type_pad_template/template.rb', line 29

def enqueue_post(text, &block)
  request(@edit_path).enqueue do |response|
    form = get_form_for_body(response).tap do |f|
      f[:text] = text
    end
    request_for_form(form).enqueue do |response|
      @text = text
      block.call(response)
    end
  end
end

#getObject



23
24
25
26
27
# File 'lib/type_pad_template/template.rb', line 23

def get
  request(@edit_path) do |response|
    @text = get_text_from_response(response)
  end
end

#post(text) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/type_pad_template/template.rb', line 41

def post(text)
  request(@edit_path) do |response|
    form = get_form_for_body(response).tap do |f|
      f[:text] = text
    end

    response = request_for_form(form).dispatch.response
    @text = text

    response
  end
end