Class: Pagifyio

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

Defined Under Namespace

Modules: Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, secret) ⇒ Pagifyio

Returns a new instance of Pagifyio.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/pagifyio.rb', line 4

def initialize(id, secret)
    @app_id = id
    @app_secret = secret
    @options = {
        :host_name => "alpha.pagify.io",
        :port => "80",
        :method => "",
        :path => "",
        :accept_type => ""
    }
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



2
3
4
# File 'lib/pagifyio.rb', line 2

def app_id
  @app_id
end

#app_secretObject

Returns the value of attribute app_secret.



2
3
4
# File 'lib/pagifyio.rb', line 2

def app_secret
  @app_secret
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/pagifyio.rb', line 2

def options
  @options
end

Instance Method Details

#create_template(name) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pagifyio.rb', line 40

def create_template(name)
    throw 'Please supply name' if (name == '' || name == nil)
    request_data = {
        :template_name => name
    }
    @options[:path] = "/api/templates"
    @options[:accept_type] = "application/json"
    @options[:method] = "post"
    res = Client.request(@options, request_data, @app_id, @app_secret)
    JSON.parse(res.body)
end

#delete_template(template_id) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/pagifyio.rb', line 61

def delete_template(template_id)
    @options[:path] = "/api/templates/#{template_id}"
    @options[:accept_type] = "application/json"
    @options[:method] = "delete"
    res = Client.request(@options, {}, @app_id, @app_secret)
    JSON.parse(res.body)
end

#edit_template(template_id) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/pagifyio.rb', line 52

def edit_template(template_id)
    throw 'Please supply template_id' if (template_id == '' || template_id == nil)
    @options[:path] = "/api/templates/#{template_id}/edit"
    @options[:accept_type] = "application/json"
    @options[:method] = "get"
    res = Client.request(@options, {}, @app_id, @app_secret)
    JSON.parse(res.body)
end

#generate_pdf(template_id, data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pagifyio.rb', line 16

def generate_pdf(template_id, data)
    throw 'Please supply template_id' if (template_id == '' || template_id == nil)
    request_data = {
        :data => data
    }
    @options[:path] = "/api/templates/#{template_id}/generate_pdf"
    @options[:accept_type] = "application/pdf"
    @options[:method] = "post"
    res = Client.request(@options, request_data, @app_id, @app_secret)
    begin
        JSON.parse(res.body)
    rescue
        res.body
    end
end

#list_templatesObject



32
33
34
35
36
37
38
# File 'lib/pagifyio.rb', line 32

def list_templates
    @options[:path] = "/api/templates"
    @options[:accept_type] = "application/json"
    @options[:method] = "get"
    res = Client.request(@options, {}, @app_id, @app_secret)
    JSON.parse(res.body)
end