Class: Pagifyio
- Inherits:
-
Object
- Object
- Pagifyio
- Defined in:
- lib/pagifyio.rb
Defined Under Namespace
Modules: Client
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
Returns the value of attribute app_secret.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #create_template(name) ⇒ Object
- #delete_template(template_id) ⇒ Object
- #edit_template(template_id) ⇒ Object
- #generate_pdf(template_id, data) ⇒ Object
-
#initialize(id, secret) ⇒ Pagifyio
constructor
A new instance of Pagifyio.
- #list_templates ⇒ Object
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_id ⇒ Object
Returns the value of attribute app_id.
2 3 4 |
# File 'lib/pagifyio.rb', line 2 def app_id @app_id end |
#app_secret ⇒ Object
Returns the value of attribute app_secret.
2 3 4 |
# File 'lib/pagifyio.rb', line 2 def app_secret @app_secret end |
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/pagifyio.rb', line 2 def @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 |