mailerlite-ruby 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/.github/workflows/main.yml +17 -0
- data/.github/workflows/publish_gem.yml +21 -0
- data/.gitignore +60 -0
- data/.rspec +1 -0
- data/.rubocop.yml +36 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +801 -0
- data/Rakefile +8 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/fixtures/automations/fetch.yml +61 -0
- data/fixtures/automations/get.yml +68 -0
- data/fixtures/automations/get_subscriber_activity.yml +71 -0
- data/fixtures/batch/request.yml +59 -0
- data/fixtures/campaigns/activity.yml +64 -0
- data/fixtures/campaigns/create.yml +65 -0
- data/fixtures/campaigns/delete.yml +53 -0
- data/fixtures/campaigns/fetch.yml +64 -0
- data/fixtures/campaigns/get.yml +68 -0
- data/fixtures/campaigns/languages.yml +60 -0
- data/fixtures/campaigns/schedule.yml +160 -0
- data/fixtures/campaigns/update.yml +159 -0
- data/fixtures/fields/create.yml +57 -0
- data/fixtures/fields/delete.yml +53 -0
- data/fixtures/fields/get.yml +60 -0
- data/fixtures/fields/update.yml +57 -0
- data/fixtures/forms/delete.yml +53 -0
- data/fixtures/forms/fetch.yml +60 -0
- data/fixtures/forms/fetch_subscribers.yml +59 -0
- data/fixtures/forms/list.yml +62 -0
- data/fixtures/forms/update.yml +60 -0
- data/fixtures/groups/assign_subscriber.yml +58 -0
- data/fixtures/groups/create.yml +58 -0
- data/fixtures/groups/delete.yml +53 -0
- data/fixtures/groups/get.yml +63 -0
- data/fixtures/groups/get_subscribers.yml +62 -0
- data/fixtures/groups/unassign_subscriber.yml +53 -0
- data/fixtures/groups/update.yml +58 -0
- data/fixtures/segments/delete.yml +53 -0
- data/fixtures/segments/get_subscribers.yml +61 -0
- data/fixtures/segments/list.yml +60 -0
- data/fixtures/segments/update.yml +58 -0
- data/fixtures/subscribers/create.yml +57 -0
- data/fixtures/subscribers/delete.yml +51 -0
- data/fixtures/subscribers/fetch.yml +68 -0
- data/fixtures/subscribers/fetch_count.yml +55 -0
- data/fixtures/subscribers/get.yml +62 -0
- data/fixtures/timezones/list.yml +575 -0
- data/fixtures/webhooks/create.yml +58 -0
- data/fixtures/webhooks/delete.yml +53 -0
- data/fixtures/webhooks/get.yml +58 -0
- data/fixtures/webhooks/list.yml +61 -0
- data/fixtures/webhooks/update.yml +58 -0
- data/lib/mailerlite/automations/automations.rb +62 -0
- data/lib/mailerlite/batch/batch.rb +24 -0
- data/lib/mailerlite/campaigns/campaigns.rb +216 -0
- data/lib/mailerlite/client.rb +35 -0
- data/lib/mailerlite/fields/fields.rb +61 -0
- data/lib/mailerlite/forms/forms.rb +73 -0
- data/lib/mailerlite/groups/groups.rb +90 -0
- data/lib/mailerlite/segments/segments.rb +62 -0
- data/lib/mailerlite/subscribers/subscribers.rb +116 -0
- data/lib/mailerlite/timezones/timezones.rb +22 -0
- data/lib/mailerlite/version.rb +5 -0
- data/lib/mailerlite/webhooks/webhooks.rb +67 -0
- data/lib/mailerlite-ruby.rb +3 -0
- data/lib/mailerlite.rb +13 -0
- data/mailerlite-ruby.gemspec +42 -0
- data/renovate.json +5 -0
- data/spec/automations_rspec.rb +63 -0
- data/spec/batches_rspec.rb +41 -0
- data/spec/campaigns_rspec.rb +155 -0
- data/spec/fields_rspec.rb +70 -0
- data/spec/forms_rspec.rb +81 -0
- data/spec/groups_rspec.rb +97 -0
- data/spec/segments_rspec.rb +70 -0
- data/spec/spec_helper.rb +101 -0
- data/spec/subscribers_rspec.rb +84 -0
- data/spec/timezones_rspec.rb +36 -0
- data/spec/webhooks_rspec.rb +86 -0
- metadata +303 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the Fields from MailerLite API.
|
5
|
+
class Fields
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Fields` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of Fields that match the specified filter criteria.
|
16
|
+
#
|
17
|
+
# @param filter [:keyword, :type] Returns partial matches for fields
|
18
|
+
# @param limit [Integer] the maximum number of Fields to return
|
19
|
+
# @param page [Integer] the page number of the results to return
|
20
|
+
# @return [HTTP::Response] the response from the API
|
21
|
+
def get(limit: nil, page: nil, filter: {}, sort: nil)
|
22
|
+
params = {}
|
23
|
+
params['filter[keyword]'] = filter[:keyword] if filter.key?(:keyword)
|
24
|
+
params['filter[type]'] = filter[:type] if filter.key?(:type)
|
25
|
+
params['sort'] = sort if sort
|
26
|
+
params['limit'] = limit if limit
|
27
|
+
params['page'] = page if page
|
28
|
+
uri = URI("#{API_URL}/fields")
|
29
|
+
uri.query = URI.encode_www_form(params.compact)
|
30
|
+
client.http.get(uri)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Update the specified Field
|
34
|
+
#
|
35
|
+
# @param name [String] the name of the field to create
|
36
|
+
# @param type [String] the type, can be text, number or date
|
37
|
+
# @return [HTTP::Response] the response from the API
|
38
|
+
def create(type:, name:)
|
39
|
+
params = { 'name' => name, 'type' => type }
|
40
|
+
client.http.post("#{API_URL}/fields", json: params.compact)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Update the specified Field
|
44
|
+
#
|
45
|
+
# @param field_id [Integer] the field_id to update
|
46
|
+
# @param name [String] the name to update
|
47
|
+
# @return [HTTP::Response] the response from the API
|
48
|
+
def update(field_id:, name:)
|
49
|
+
params = { 'name' => name }
|
50
|
+
client.http.put("#{API_URL}/fields/#{field_id}", json: params.compact)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Deletes the specified Field.
|
54
|
+
#
|
55
|
+
# @param field_id [String] the ID of the Field to delete
|
56
|
+
# @return [HTTP::Response] the response from the API
|
57
|
+
def delete(field_id)
|
58
|
+
client.http.delete("#{API_URL}/fields/#{field_id}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the Forms from MailerLite API.
|
5
|
+
class Forms
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Forms` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of Forms that match the specified filter criteria.
|
16
|
+
#
|
17
|
+
# @param filter [#name] the name of the Forms to include in the results
|
18
|
+
# @param limit [Integer] the maximum number of Forms to return
|
19
|
+
# @param page [Integer] the page number of the results to return
|
20
|
+
# @return [HTTP::Response] the response from the API
|
21
|
+
def list(type:, filter: {}, limit: nil, sort: nil, page: nil)
|
22
|
+
params = {}
|
23
|
+
params['filter[name]'] = filter[:name] if filter.key?(:name)
|
24
|
+
params['limit'] = limit if limit
|
25
|
+
params['sort'] = sort if sort
|
26
|
+
params['page'] = page if page
|
27
|
+
uri = URI("#{API_URL}/forms/#{type}")
|
28
|
+
uri.query = URI.encode_www_form(params.compact)
|
29
|
+
client.http.get(uri)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the details of the specified Forms
|
33
|
+
#
|
34
|
+
# @param form_id [String] the ID of the forms to fetch
|
35
|
+
# @return [HTTP::Response] the response from the API
|
36
|
+
def fetch(form_id)
|
37
|
+
client.http.get("#{API_URL}/forms/#{form_id}")
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the subscribers who signed up to a specific form
|
41
|
+
#
|
42
|
+
# @param form_id [String] the ID of the forms to fetch
|
43
|
+
# @return [HTTP::Response] the response from the API
|
44
|
+
def fetch_subscribers(form_id)
|
45
|
+
client.http.get("#{API_URL}/forms/#{form_id}/subscribers")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Update the specified Forms
|
49
|
+
#
|
50
|
+
# @param form_id [String] the ID of the forms to fetch
|
51
|
+
# @param name [String] the name to update
|
52
|
+
# @return [HTTP::Response] the response from the API
|
53
|
+
def update(form_id:, name:)
|
54
|
+
params = { 'name' => name }
|
55
|
+
client.http.put("#{API_URL}/forms/#{form_id}", json: params.compact)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the total number of Forms in the MailerLite account.
|
59
|
+
#
|
60
|
+
# @return [HTTP::Response] the response from the API
|
61
|
+
def fetch_count
|
62
|
+
client.http.get("#{API_URL}/forms/?limit=0")
|
63
|
+
end
|
64
|
+
|
65
|
+
# Deletes the specified forms.
|
66
|
+
#
|
67
|
+
# @param form_id [String] the ID of the forms to delete
|
68
|
+
# @return [HTTP::Response] the response from the API
|
69
|
+
def delete(form_id)
|
70
|
+
client.http.delete("#{API_URL}/forms/#{form_id}")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the Groups from MailerLite API.
|
5
|
+
class Groups
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Groups` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of Groups that match the specified filter criteria.
|
16
|
+
#
|
17
|
+
# @param filter[:name] the name of the Groups to include in the results
|
18
|
+
# @param limit [Integer] the maximum number of Groups to return
|
19
|
+
# @param page [Integer] the page number of the results to return
|
20
|
+
# @return [HTTP::Response] the response from the API
|
21
|
+
def get(filter: {}, limit: nil, sort: nil, page: nil)
|
22
|
+
params = {}
|
23
|
+
params['filter[name]'] = filter[:name] if filter.key?(:name)
|
24
|
+
params['limit'] = limit if limit
|
25
|
+
params['sort'] = sort if sort
|
26
|
+
params['page'] = page if page
|
27
|
+
uri = URI("#{API_URL}/groups")
|
28
|
+
uri.query = URI.encode_www_form(params.compact)
|
29
|
+
client.http.get(uri)
|
30
|
+
end
|
31
|
+
|
32
|
+
# create a Group
|
33
|
+
#
|
34
|
+
# @param name [String] the name to update
|
35
|
+
# @return [HTTP::Response] the response from the API
|
36
|
+
def create(name:)
|
37
|
+
params = { 'name' => name }
|
38
|
+
client.http.post("#{API_URL}/groups", json: params.compact)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Update the specified Group
|
42
|
+
#
|
43
|
+
# @param group_id [String] the ID of the Groups to update
|
44
|
+
# @param name [String] the name to update
|
45
|
+
# @return [HTTP::Response] the response from the API
|
46
|
+
def update(group_id:, name:)
|
47
|
+
params = { 'name' => name }
|
48
|
+
client.http.put("#{API_URL}/groups/#{group_id}", json: params.compact)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Get Subscribers assigned to the specified group.
|
52
|
+
# @param group_id [Integer] The id of existing group belonging to the account
|
53
|
+
# @param filter[:status] [String] Must be one of the possible statuses: active, unsubscribed, unconfirmed, bounced or junk. Defaults to active.
|
54
|
+
# @param limit [Integer] the maximum number of subscribers to return
|
55
|
+
# @param page [Integer] the page number of the results to return
|
56
|
+
# @return [HTTP::Response] the response from the API
|
57
|
+
def get_subscribers(group_id:, filter: {}, limit: nil, page: nil, sort: nil)
|
58
|
+
params = {}
|
59
|
+
params['filter[status]'] = filter[:status] if filter.key?(:status)
|
60
|
+
params['limit'] = limit if limit
|
61
|
+
params['sort'] = sort if sort
|
62
|
+
params['page'] = page if page
|
63
|
+
client.http.get("#{API_URL}/groups/#{group_id}/subscribers", json: params.compact)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Assign Subscriber to the specified group.
|
67
|
+
# @param group_id [Integer] The id of existing group belonging to the account
|
68
|
+
# @param subscriber [Integer] The id of existing subscriber belonging to the account
|
69
|
+
# @return [HTTP::Response] the response from the API
|
70
|
+
def assign_subscriber(group_id:, subscriber:)
|
71
|
+
client.http.post("#{API_URL}/subscribers/#{subscriber}/groups/#{group_id}")
|
72
|
+
end
|
73
|
+
|
74
|
+
# Unassign Subscriber to the specified group.
|
75
|
+
# @param group_id [Integer] The id of existing group belonging to the account
|
76
|
+
# @param subscriber [Integer] The id of existing subscriber belonging to the account
|
77
|
+
# @return [HTTP::Response] the response from the API
|
78
|
+
def unassign_subscriber(group_id:, subscriber:)
|
79
|
+
client.http.delete("#{API_URL}/subscribers/#{subscriber}/groups/#{group_id}")
|
80
|
+
end
|
81
|
+
|
82
|
+
# Deletes the specified Groups.
|
83
|
+
#
|
84
|
+
# @param group_id [String] the ID of the Groups to delete
|
85
|
+
# @return [HTTP::Response] the response from the API
|
86
|
+
def delete(group_id)
|
87
|
+
client.http.delete("#{API_URL}/groups/#{group_id}")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the Segments from MailerLite API.
|
5
|
+
class Segments
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Segments` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of Segments that match the specified filter criteria.
|
16
|
+
#
|
17
|
+
# @param limit [Integer] the maximum number of Segments to return
|
18
|
+
# @param page [Integer] the page number of the results to return
|
19
|
+
# @return [HTTP::Response] the response from the API
|
20
|
+
def list(limit: nil, page: nil)
|
21
|
+
params = {}
|
22
|
+
params['limit'] = limit if limit
|
23
|
+
params['page'] = page if page
|
24
|
+
|
25
|
+
client.http.get("#{API_URL}/segments", json: params.compact)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Update the specified Segment
|
29
|
+
#
|
30
|
+
# @param segment_id [String] the ID of the Segments to update
|
31
|
+
# @param name [String] the name to update
|
32
|
+
# @return [HTTP::Response] the response from the API
|
33
|
+
def update(segment_id:, name:)
|
34
|
+
params = { 'name' => name }
|
35
|
+
client.http.put("#{API_URL}/segments/#{segment_id}", json: params.compact)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get Subscribers assigned to the specified Segment.
|
39
|
+
# @param segment_id [Integer] The id of existing Segment belonging to the account
|
40
|
+
# @param filter[status] [String] Must be one of the possible statuses: active, unsubscribed, unconfirmed, bounced or junk. Defaults to active.
|
41
|
+
# @param limit [Integer] the maximum number of subscribers to return
|
42
|
+
# @param after [Integer] The last subscriber id, available in meta.last
|
43
|
+
# @return [HTTP::Response] the response from the API
|
44
|
+
def get_subscribers(segment_id:, filter: {}, limit: nil, after: nil)
|
45
|
+
params = {}
|
46
|
+
params['filter[status]'] = filter[:status] if filter.key?(:status)
|
47
|
+
params['limit'] = limit if limit
|
48
|
+
params['after'] = after if after
|
49
|
+
uri = URI("#{API_URL}/segments/#{segment_id}/subscribers")
|
50
|
+
uri.query = URI.encode_www_form(params.compact)
|
51
|
+
client.http.get(uri)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Deletes the specified Segments.
|
55
|
+
#
|
56
|
+
# @param segment_id [String] the ID of the Segments to delete
|
57
|
+
# @return [HTTP::Response] the response from the API
|
58
|
+
def delete(segment_id)
|
59
|
+
client.http.delete("#{API_URL}/segments/#{segment_id}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the subscribers from MailerLite API.
|
5
|
+
class Subscribers
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Subscribers` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of subscribers that match the specified filter criteria.
|
16
|
+
#
|
17
|
+
# @param filter[:status] [Array] the status of the subscribers to include in the results
|
18
|
+
# @param limit [Integer] the maximum number of subscribers to return
|
19
|
+
# @param page [Integer] the page number of the results to return
|
20
|
+
# @return [HTTP::Response] the response from the API
|
21
|
+
def fetch(filter:, limit: nil, page: nil)
|
22
|
+
params = { 'filter[status]' => filter[:status] }
|
23
|
+
|
24
|
+
params['limit'] = limit if limit
|
25
|
+
params['page'] = page if page
|
26
|
+
uri = URI("#{API_URL}/subscribers")
|
27
|
+
uri.query = URI.encode_www_form(params.compact)
|
28
|
+
client.http.get(uri)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates a new subscriber with the specified details.
|
32
|
+
#
|
33
|
+
# @param email [String] the email address of the new subscriber
|
34
|
+
# @param fields [Hash] a hash of custom fields and their values for the subscriber
|
35
|
+
# @param groups [Array] an array of group IDs to add the subscriber to
|
36
|
+
# @param status [String] the status of the new subscriber
|
37
|
+
# @param subscribed_at [DateTime] the date and time when the subscriber was added
|
38
|
+
# @param ip_address [String] the IP address of the subscriber
|
39
|
+
# @param opted_in_at [DateTime] the date and time when the subscriber confirmed their subscription
|
40
|
+
# @param optin_ip [String] the IP address of the subscriber when they confirmed their subscription
|
41
|
+
# @param unsubscribed_at [DateTime] the date and time when the subscriber was unsubscribed
|
42
|
+
# @return [HTTP::Response] the response from the API
|
43
|
+
def create(email:, fields: nil, groups: nil, status: nil, subscribed_at: nil, ip_address: nil, opted_in_at: nil, optin_ip: nil, unsubscribed_at: nil)
|
44
|
+
params = { 'email' => email }
|
45
|
+
|
46
|
+
params['fields'] = fields if fields
|
47
|
+
params['groups'] = groups if groups
|
48
|
+
params['status'] = status if status
|
49
|
+
params['subscribed_at'] = subscribed_at if subscribed_at
|
50
|
+
params['ip_address'] = ip_address if ip_address
|
51
|
+
params['opted_in_at'] = opted_in_at if opted_in_at
|
52
|
+
params['optin_ip'] = optin_ip if optin_ip
|
53
|
+
params['unsubscribed_at'] = unsubscribed_at if unsubscribed_at
|
54
|
+
|
55
|
+
client.http.post("#{API_URL}/subscribers", json: params.compact)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Creates a new subscriber with the specified details.
|
59
|
+
#
|
60
|
+
# @param email [String] the email address of the new subscriber
|
61
|
+
# @param fields [Hash] a hash of custom fields and their values for the subscriber
|
62
|
+
# @param groups [Array] an array of group IDs to add the subscriber to
|
63
|
+
# @param status [String] the status of the new subscriber
|
64
|
+
# @param subscribed_at [DateTime] the date and time when the subscriber was added
|
65
|
+
# @param ip_address [String] the IP address of the subscriber
|
66
|
+
# @param opted_in_at [DateTime] the date and time when the subscriber confirmed their subscription
|
67
|
+
# @param optin_ip [String] the IP address of the subscriber when they confirmed their subscription
|
68
|
+
# @param unsubscribed_at [DateTime] the date and time when the subscriber was unsubscribed
|
69
|
+
# @return [HTTP::Response] the response from the API
|
70
|
+
def update(email:, fields: nil, groups: nil, status: nil, subscribed_at: nil, ip_address: nil, opted_in_at: nil, optin_ip: nil, unsubscribed_at: nil)
|
71
|
+
params = { 'email' => email }
|
72
|
+
|
73
|
+
params['fields'] = fields if fields
|
74
|
+
params['groups'] = groups if groups
|
75
|
+
params['status'] = status if status
|
76
|
+
params['subscribed_at'] = subscribed_at if subscribed_at
|
77
|
+
params['ip_address'] = ip_address if ip_address
|
78
|
+
params['opted_in_at'] = opted_in_at if opted_in_at
|
79
|
+
params['optin_ip'] = optin_ip if optin_ip
|
80
|
+
params['unsubscribed_at'] = unsubscribed_at if unsubscribed_at
|
81
|
+
|
82
|
+
client.http.post("#{API_URL}/subscribers", json: params.compact)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the details of the specified subscribers
|
86
|
+
#
|
87
|
+
# @param subscriber_id [String] the ID of the subscriber to get
|
88
|
+
# @return [HTTP::Response] the response from the API
|
89
|
+
def get(subscriber_id)
|
90
|
+
client.http.get("#{API_URL}/subscribers/#{subscriber_id}")
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the details of the specified subscribers
|
94
|
+
#
|
95
|
+
# @param import_id [String] the ID of the import to fetch report
|
96
|
+
# @return [HTTP::Response] the response from the API
|
97
|
+
def get_single_import(import_id)
|
98
|
+
client.http.get("#{API_URL}/subscribers/import/#{import_id}")
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns the total number of subscribers in the MailerLite account.
|
102
|
+
#
|
103
|
+
# @return [HTTP::Response] the response from the API
|
104
|
+
def fetch_count
|
105
|
+
client.http.get("#{API_URL}/subscribers/?limit=0")
|
106
|
+
end
|
107
|
+
|
108
|
+
# Deletes the specified subscriber.
|
109
|
+
#
|
110
|
+
# @param subscriber_id [String] the ID of the subscriber to delete
|
111
|
+
# @return [HTTP::Response] the response from the API
|
112
|
+
def delete(subscriber_id)
|
113
|
+
client.http.delete("#{API_URL}/subscribers/#{subscriber_id}")
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the Timezones from MailerLite API.
|
5
|
+
class Timezones
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Timezones` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of Timezones
|
16
|
+
#
|
17
|
+
# @return [HTTP::Response] the response from the API
|
18
|
+
def list
|
19
|
+
client.http.get("#{API_URL}/timezones")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MailerLite
|
4
|
+
# This is a class for manipulating the Webhooks from MailerLite API.
|
5
|
+
class Webhooks
|
6
|
+
attr_reader :client
|
7
|
+
|
8
|
+
# Inits the `Webhooks` class with the specified `client`.
|
9
|
+
#
|
10
|
+
# @param client [MailerLite::Client] the `Client` instance to use
|
11
|
+
def initialize(client: MailerLite::Client.new)
|
12
|
+
@client = client
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of Webhooks
|
16
|
+
#
|
17
|
+
# @return [HTTP::Response] the response from the API
|
18
|
+
def list
|
19
|
+
client.http.get("#{API_URL}/webhooks")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the details of the specified webhooks
|
23
|
+
#
|
24
|
+
# @param webhook_id [String] the ID of the webhooks to fetch
|
25
|
+
# @return [HTTP::Response] the response from the API
|
26
|
+
def get(webhook_id)
|
27
|
+
client.http.get("#{API_URL}/webhooks/#{webhook_id}")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create a Webhook
|
31
|
+
#
|
32
|
+
# @param name [String] the name of the Webhook to create
|
33
|
+
# @param events [Array] the events, must one from the list of supported events
|
34
|
+
# @param url [String] the events, can be text, number or date
|
35
|
+
# @return [HTTP::Response] the response from the API
|
36
|
+
def create(events:, url:, name: nil)
|
37
|
+
params = { 'events' => events, 'url' => url }
|
38
|
+
params['name'] = name if name
|
39
|
+
client.http.post("#{API_URL}/webhooks", json: params.compact)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Update the specified Webhook
|
43
|
+
#
|
44
|
+
# @param webhook_id [String] the ID of the Webhook to update
|
45
|
+
# @param name [String] the name to update
|
46
|
+
# @param events [Array] the events to update
|
47
|
+
# @param url [String] the url to update
|
48
|
+
# @param enabled [Boolean] the enabled to update
|
49
|
+
# @return [HTTP::Response] the response from the API
|
50
|
+
def update(webhook_id:, events: nil, name: nil, url: nil, enabled: nil)
|
51
|
+
params = {}
|
52
|
+
params['events'] = events if events
|
53
|
+
params['name'] = name if name
|
54
|
+
params['url'] = url if url
|
55
|
+
params['enabled'] = enabled if enabled
|
56
|
+
client.http.put("#{API_URL}/webhooks/#{webhook_id}", json: params.compact)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Deletes the specified Webhook.
|
60
|
+
#
|
61
|
+
# @param webhook_id [String] the ID of the Webhook to delete
|
62
|
+
# @return [HTTP::Response] the response from the API
|
63
|
+
def delete(webhook_id)
|
64
|
+
client.http.delete("#{API_URL}/webhooks/#{webhook_id}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/mailerlite.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'mailerlite/client'
|
4
|
+
require_relative 'mailerlite/subscribers/subscribers'
|
5
|
+
require_relative 'mailerlite/campaigns/campaigns'
|
6
|
+
require_relative 'mailerlite/forms/forms'
|
7
|
+
require_relative 'mailerlite/groups/groups'
|
8
|
+
require_relative 'mailerlite/segments/segments'
|
9
|
+
require_relative 'mailerlite/fields/fields'
|
10
|
+
require_relative 'mailerlite/automations/automations'
|
11
|
+
require_relative 'mailerlite/webhooks/webhooks'
|
12
|
+
require_relative 'mailerlite/batch/batch'
|
13
|
+
require_relative 'mailerlite/timezones/timezones'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'mailerlite/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'mailerlite-ruby'
|
9
|
+
spec.version = MailerLite::VERSION
|
10
|
+
spec.authors = ['Nikola Milojević', 'Ahsan Gondal']
|
11
|
+
spec.email = ['info@mailerlite.com']
|
12
|
+
|
13
|
+
spec.summary = "MailerLite's official Ruby SDK"
|
14
|
+
spec.description = "MailerLite's official Ruby SDK. Interacts with all endpoints at MailerLite API."
|
15
|
+
spec.homepage = 'https://www.MailerLite.com'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = '>= 2.5.0'
|
18
|
+
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = 'https://github.com/mailerlite/mailerlite-ruby'
|
23
|
+
spec.metadata['changelog_uri'] = 'https://github.com/mailerlite/mailerlite-ruby/blob/main/CHANGELOG.md'
|
24
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0")
|
27
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 2.4.7'
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 1.7'
|
33
|
+
spec.add_dependency 'dotenv', '~> 2.7'
|
34
|
+
spec.add_dependency 'http', '~> 5.0'
|
35
|
+
spec.add_dependency 'json', '~> 2.5'
|
36
|
+
spec.add_dependency 'uri', '~> 0.12.0'
|
37
|
+
spec.add_development_dependency 'rspec'
|
38
|
+
spec.add_development_dependency 'simplecov'
|
39
|
+
spec.add_development_dependency 'vcr'
|
40
|
+
spec.add_development_dependency 'webmock'
|
41
|
+
spec.add_development_dependency 'yard'
|
42
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Import the RSpec and VCR gems
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'vcr'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# require "webmock/rspec"
|
9
|
+
# Import the `Automations` class
|
10
|
+
|
11
|
+
# Configure VCR to save and replay HTTP requests
|
12
|
+
VCR.configure do |config|
|
13
|
+
config.cassette_library_dir = './fixtures'
|
14
|
+
config.hook_into :webmock
|
15
|
+
config.filter_sensitive_data('<AUTH>') do |interaction|
|
16
|
+
interaction.request.headers['Authorization'][0]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Set up the test for the `Automations` class
|
21
|
+
RSpec.describe MailerLite::Automations do
|
22
|
+
let(:client) { MailerLite::Client.new }
|
23
|
+
let(:automations) { described_class.new(client: client) }
|
24
|
+
|
25
|
+
describe '#get' do
|
26
|
+
# Use VCR to record and replay the HTTP request
|
27
|
+
it 'gets all automation' do
|
28
|
+
VCR.use_cassette('automations/get') do
|
29
|
+
response = automations.get
|
30
|
+
body = JSON.parse(response.body)
|
31
|
+
expect(response.status).to eq 200
|
32
|
+
expect(body['data']).to be_an Array
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#fetch' do
|
38
|
+
# Use VCR to record and replay the HTTP request
|
39
|
+
it 'fetchs all automation' do
|
40
|
+
VCR.use_cassette('automations/fetch') do
|
41
|
+
response = automations.fetch(75_040_845_299_975_641)
|
42
|
+
body = JSON.parse(response.body)
|
43
|
+
expect(response.status).to eq 200
|
44
|
+
expect(Integer(body['data']['id'])).to be_an Integer
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#get_subscriber_activity' do
|
50
|
+
# Use VCR to record and replay the HTTP request
|
51
|
+
it 'get_subscriber_activitys all automation' do
|
52
|
+
VCR.use_cassette('automations/get_subscriber_activity') do
|
53
|
+
response = automations.get_subscriber_activity(
|
54
|
+
automation_id: '75040845299975641',
|
55
|
+
filter: { status: 'completed' }
|
56
|
+
)
|
57
|
+
# body = JSON.parse(response.body)
|
58
|
+
expect(response.status).to eq 200
|
59
|
+
# expect(Integer(body['data']['id'])).to be_an Integer
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Import the RSpec and VCR gems
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'vcr'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# require "webmock/rspec"
|
9
|
+
# Import the `Batch` class
|
10
|
+
|
11
|
+
# Configure VCR to save and replay HTTP requests
|
12
|
+
VCR.configure do |config|
|
13
|
+
config.cassette_library_dir = './fixtures'
|
14
|
+
config.hook_into :webmock
|
15
|
+
config.filter_sensitive_data('<AUTH>') do |interaction|
|
16
|
+
interaction.request.headers['Authorization'][0]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Set up the test for the `Batch` class
|
21
|
+
RSpec.describe MailerLite::Batch do
|
22
|
+
let(:client) { MailerLite::Client.new }
|
23
|
+
let(:batch) { described_class.new(client: client) }
|
24
|
+
|
25
|
+
describe '#request' do
|
26
|
+
# Use VCR to record and replay the HTTP request
|
27
|
+
it 'executes a batch request' do
|
28
|
+
VCR.use_cassette('batch/request') do
|
29
|
+
response = batch.request(
|
30
|
+
requests: [
|
31
|
+
{ method: 'GET', path: 'api/subscribers/list' },
|
32
|
+
{ method: 'GET', path: 'api/campaigns/list' }
|
33
|
+
]
|
34
|
+
)
|
35
|
+
body = JSON.parse(response.body)
|
36
|
+
expect(response.status).to eq 200
|
37
|
+
expect(body['responses']).to be_an Array
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|