Class: MailerLite::Fields
- Inherits:
-
Object
- Object
- MailerLite::Fields
- Defined in:
- lib/mailerlite/fields/fields.rb
Overview
This is a class for manipulating the Fields from MailerLite API.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#create(type:, name:) ⇒ HTTP::Response
Update the specified Field.
-
#delete(field_id) ⇒ HTTP::Response
Deletes the specified Field.
-
#get(limit: nil, page: nil, filter: {}, sort: nil) ⇒ HTTP::Response
Returns a list of Fields that match the specified filter criteria.
-
#initialize(client: MailerLite::Client.new) ⇒ Fields
constructor
Inits the ‘Fields` class with the specified `client`.
-
#update(field_id:, name:) ⇒ HTTP::Response
Update the specified Field.
Constructor Details
#initialize(client: MailerLite::Client.new) ⇒ Fields
Inits the ‘Fields` class with the specified `client`.
11 12 13 |
# File 'lib/mailerlite/fields/fields.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/fields/fields.rb', line 6 def client @client end |
Instance Method Details
#create(type:, name:) ⇒ HTTP::Response
Update the specified Field
38 39 40 41 |
# File 'lib/mailerlite/fields/fields.rb', line 38 def create(type:, name:) params = { 'name' => name, 'type' => type } client.http.post("#{MAILERLITE_API_URL}/fields", json: params.compact) end |
#delete(field_id) ⇒ HTTP::Response
Deletes the specified Field.
57 58 59 |
# File 'lib/mailerlite/fields/fields.rb', line 57 def delete(field_id) client.http.delete("#{MAILERLITE_API_URL}/fields/#{field_id}") end |
#get(limit: nil, page: nil, filter: {}, sort: nil) ⇒ HTTP::Response
Returns a list of Fields that match the specified filter criteria.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mailerlite/fields/fields.rb', line 21 def get(limit: nil, page: nil, filter: {}, sort: nil) params = {} params['filter[keyword]'] = filter[:keyword] if filter.key?(:keyword) params['filter[type]'] = filter[:type] if filter.key?(:type) params['sort'] = sort if sort params['limit'] = limit if limit params['page'] = page if page uri = URI("#{MAILERLITE_API_URL}/fields") uri.query = URI.encode_www_form(params.compact) client.http.get(uri) end |
#update(field_id:, name:) ⇒ HTTP::Response
Update the specified Field
48 49 50 51 |
# File 'lib/mailerlite/fields/fields.rb', line 48 def update(field_id:, name:) params = { 'name' => name } client.http.put("#{MAILERLITE_API_URL}/fields/#{field_id}", json: params.compact) end |