Class: MailerLite::Forms
- Inherits:
-
Object
- Object
- MailerLite::Forms
- Defined in:
- lib/mailerlite/forms/forms.rb
Overview
This is a class for manipulating the Forms from MailerLite API.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#delete(form_id) ⇒ HTTP::Response
Deletes the specified forms.
-
#fetch(form_id) ⇒ HTTP::Response
Returns the details of the specified Forms.
-
#fetch_count ⇒ HTTP::Response
Returns the total number of Forms in the MailerLite account.
-
#fetch_subscribers(form_id) ⇒ HTTP::Response
Returns the subscribers who signed up to a specific form.
-
#initialize(client: MailerLite::Client.new) ⇒ Forms
constructor
Inits the ‘Forms` class with the specified `client`.
-
#list(type:, filter: {}, limit: nil, sort: nil, page: nil) ⇒ HTTP::Response
Returns a list of Forms that match the specified filter criteria.
-
#update(form_id:, name:) ⇒ HTTP::Response
Update the specified Forms.
Constructor Details
#initialize(client: MailerLite::Client.new) ⇒ Forms
Inits the ‘Forms` class with the specified `client`.
11 12 13 |
# File 'lib/mailerlite/forms/forms.rb', line 11 def initialize(client: MailerLite::Client.new) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mailerlite/forms/forms.rb', line 6 def client @client end |
Instance Method Details
#delete(form_id) ⇒ HTTP::Response
Deletes the specified forms.
69 70 71 |
# File 'lib/mailerlite/forms/forms.rb', line 69 def delete(form_id) client.http.delete("#{MAILERLITE_API_URL}/forms/#{form_id}") end |
#fetch(form_id) ⇒ HTTP::Response
Returns the details of the specified Forms
36 37 38 |
# File 'lib/mailerlite/forms/forms.rb', line 36 def fetch(form_id) client.http.get("#{MAILERLITE_API_URL}/forms/#{form_id}") end |
#fetch_count ⇒ HTTP::Response
Returns the total number of Forms in the MailerLite account.
61 62 63 |
# File 'lib/mailerlite/forms/forms.rb', line 61 def fetch_count client.http.get("#{MAILERLITE_API_URL}/forms/?limit=0") end |
#fetch_subscribers(form_id) ⇒ HTTP::Response
Returns the subscribers who signed up to a specific form
44 45 46 |
# File 'lib/mailerlite/forms/forms.rb', line 44 def fetch_subscribers(form_id) client.http.get("#{MAILERLITE_API_URL}/forms/#{form_id}/subscribers") end |
#list(type:, filter: {}, limit: nil, sort: nil, page: nil) ⇒ HTTP::Response
Returns a list of Forms that match the specified filter criteria.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mailerlite/forms/forms.rb', line 21 def list(type:, filter: {}, limit: nil, sort: nil, page: nil) params = {} params['filter[name]'] = filter[:name] if filter.key?(:name) params['limit'] = limit if limit params['sort'] = sort if sort params['page'] = page if page uri = URI("#{MAILERLITE_API_URL}/forms/#{type}") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end |
#update(form_id:, name:) ⇒ HTTP::Response
Update the specified Forms
53 54 55 56 |
# File 'lib/mailerlite/forms/forms.rb', line 53 def update(form_id:, name:) params = { 'name' => name } client.http.put("#{MAILERLITE_API_URL}/forms/#{form_id}", json: params.compact) end |