mailerlite 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b653e7ee2b97df02b06cbbdb24b36acb55386856
4
- data.tar.gz: 05adea07f99865e8d61cf1d8e2d42214c1ec7c56
3
+ metadata.gz: a739963fd127ae8c42af6a2ceacfded67e42eb96
4
+ data.tar.gz: 21d605553139028079007949fc7515877aa5c218
5
5
  SHA512:
6
- metadata.gz: a88a88a51c5e22f50c287572f834a7bdc18cad89bce48e9d226185273ede75aad4ca8b8dd8a78548b722a5794ac4351ff74250e2383f4cfb0907998db9904294
7
- data.tar.gz: 53e2597cc7f762d86b61754483e1f736bcaf4631a0677d76a7804dbc2fad27a1cb4e61f7579e0ad55e9bc69de85449bee73bcc0becd3e8b0fada9dc1ae16a011
6
+ metadata.gz: e3ee319eda69a4cb89625a105c09baa29a2291efb40ec1c55235c2336c177ece212ad376793722b56490eb3b792f10a596624d7861b8d35ecb28e414f4faa03d
7
+ data.tar.gz: 2d189d579c72281e66a45065f5b7ed3f785a36b9ab64d397e2dadf08d8b1d2e99c0bee41d4e0f3f2db742b680333524838ac1ec5191c8abeccb480febb75f8e7
data/.rubocop.yml CHANGED
@@ -20,11 +20,15 @@ Style/MultilineMethodCallIndentation:
20
20
 
21
21
  Style/CaseIndentation:
22
22
  Enabled: true
23
- IndentWhenRelativeTo: end
23
+ EnforcedStyle: end
24
24
 
25
25
  Lint/EndAlignment:
26
26
  Enabled: true
27
- AlignWith: variable
27
+ EnforcedStyleAlignWith: variable
28
28
 
29
29
  Style/FrozenStringLiteralComment:
30
30
  Enabled: false
31
+
32
+ Metrics/BlockLength:
33
+ ExcludedMethods:
34
+ - 'describe'
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
4
  gem 'guard-rspec', '~> 4.7'
5
- gem 'rubocop', '~> 0.46'
5
+ gem 'rubocop', '~> 0.48'
6
6
  end
7
7
 
8
8
  group :development, :test do
@@ -14,7 +14,7 @@ group :test do
14
14
  gem 'coveralls', '~> 0.8', require: false
15
15
  gem 'rake' # For Travis CI
16
16
  gem 'rspec', '~> 3.5'
17
- gem 'simplecov', '~> 0.12', require: false
17
+ gem 'simplecov', '~> 0.14', require: false
18
18
  gem 'webmock', '~> 2.3'
19
19
  end
20
20
 
data/README.md CHANGED
@@ -18,6 +18,10 @@ gem 'mailerlite'
18
18
 
19
19
  ## Usage
20
20
 
21
+ Before making any request, you should authenticate first. Use the response object to
22
+ make requests afterward.
23
+ See [create a campaign][create_a_campaign] example.
24
+
21
25
  ### Authentication
22
26
 
23
27
  When you sign up for an account, you are given an **API key**. You authenticate to
@@ -36,6 +40,8 @@ MailerLite.configure do |config|
36
40
  end
37
41
  ```
38
42
 
43
+ See more documentation in [examples][examples] directory.
44
+
39
45
  ## Supported Ruby Versions
40
46
 
41
47
  This library aims to support and is [tested against][travis] the following Ruby
@@ -57,5 +63,7 @@ Copyright (c) 2017 Justas Palumickas. See [LICENSE][license] for details.
57
63
  [codeclimate]: https://codeclimate.com/github/jpalumickas/mailerlite-ruby
58
64
 
59
65
  [license]: https://raw.githubusercontent.com/jpalumickas/mailerlite-ruby/master/LICENSE
66
+ [create_a_campaign]: https://raw.githubusercontent.com/jpalumickas/mailerlite-ruby/master/examples/create_campaign.md
67
+ [examples]: https://github.com/jpalumickas/mailerlite-ruby/tree/master/examples
60
68
 
61
69
  [mailerlite]: https://www.mailerlite.com
@@ -0,0 +1,13 @@
1
+ # MailerLite Examples
2
+
3
+ ## Documentation
4
+
5
+ * [Authentication](authentication.md)
6
+ * [Campaigns](campaigns.md)
7
+ * [Fields](fields.md)
8
+ * [Groups](groups.md)
9
+ * [Subscribers](subscribers.md)
10
+
11
+ ## How To
12
+
13
+ * [How to create a campaign](create_campaign.md)
@@ -0,0 +1,31 @@
1
+ # Campaigns
2
+
3
+ ## Create campaign where you will use your custom HTML template
4
+
5
+ ```ruby
6
+ client.create_campaign
7
+ ```
8
+
9
+ ## Upload your HTML template to created campaign
10
+
11
+ ```ruby
12
+ client.update_campaign_content(id, options)
13
+ ```
14
+
15
+ ## Send, schedule or cancel campaign
16
+
17
+ ```ruby
18
+ client.campaign_action(id, action)
19
+ ```
20
+
21
+ ## Returns all campaigns you have in your account by :status which is required. Also basic summary for each campaign including the ID
22
+
23
+ ```ruby
24
+ client.campaign_by_status(status)
25
+ ```
26
+
27
+ ## Remove a campaign
28
+
29
+ ```ruby
30
+ client.delete_campaign(id)
31
+ ```
@@ -0,0 +1,44 @@
1
+ #Create Campaign Example
2
+
3
+ ##1. Authentication
4
+ See [Developer API](https://app.mailerlite.com/integrations/api/) and find **API Key** there.
5
+ ```ruby
6
+ client = MailerLite::Client.new(api_key: 'my-secret-api-key')
7
+ ```
8
+
9
+ ##2. Create a group
10
+ create a group indicating the receivers.
11
+ ```ruby
12
+ group = client.create_group('example_group')
13
+ ```
14
+ ##3. Add user to the created group
15
+ ```ruby
16
+ client.create_group_subscriber(group.id, { email: 'an@example.com',
17
+ fields: {name: 'An Example'}})
18
+ ```
19
+ ##4. Create a campaign with created group
20
+ ```ruby
21
+ campaign = client.create_campaign(
22
+ type: 'regular',
23
+ subject: 'Newsletter',
24
+ from: 'john_smith@example.com',
25
+ from_name: 'John Smith',
26
+ groups: [ group.id ],
27
+ language: 'en'
28
+ )
29
+ ```
30
+ ##5. Put content in the campaign
31
+ ```ruby
32
+ html = "<div>Welcome,<br /><a href=\"{$unsubscribe}\">Unsubscribe</a></div>"
33
+ plain_text = 'Welcome, {$unsubscribe} {$url}'
34
+ client.update_campaign_content(campaign.id, html: html, plain: plain_text )
35
+ ```
36
+ `${url}` must be exist in plain text.
37
+ `${unsubscribe}` must be exist in both plain text and html. See the [API documentation](http://developers.mailerlite.com/reference#put-custom-content-to-campaign).
38
+
39
+ ##6. Send the campaign
40
+ ```ruby
41
+ client.campaign_action(campaign.id, 'send')
42
+ ```
43
+ hint: According to current API, you may not resend a campaign.
44
+ note: Currently, setting campaigns language parameter to "fa" for "Farsi" language causes an Internal Server Error on "send campaign" requests, use "pr" instead.
@@ -0,0 +1,25 @@
1
+ # Fields
2
+
3
+ ## Get subscriber fields of account
4
+
5
+ ```ruby
6
+ client.fields
7
+ ```
8
+
9
+ ## Create new custom field in account
10
+
11
+ ```ruby
12
+ options = { title: 'Title', type: 'TEXT' }
13
+ client.create_field(options)
14
+ ```
15
+
16
+ ## Update custom field in account
17
+
18
+ ```ruby
19
+ client.update_field(id, { title: 'New title' })
20
+ ```
21
+
22
+ ##Remove custom field from account
23
+ ```ruby
24
+ client.delete_field(id)
25
+ ```
@@ -0,0 +1,60 @@
1
+ # Groups Examples
2
+
3
+ ## Get list of groups
4
+
5
+ ```ruby
6
+ client.groups
7
+ ```
8
+
9
+ ## Get single group by ID
10
+
11
+ ```ruby
12
+ client.group(group_id)
13
+ ```
14
+
15
+ ## Create new group
16
+
17
+ ```ruby
18
+ client.create_group(name)
19
+ ```
20
+
21
+ ## Remove a group
22
+ ```ruby
23
+ client.delete_group(group_id)
24
+ ```
25
+
26
+ ## Get all subscribers in a specified group
27
+
28
+ ```ruby
29
+ client.group_subscribers(group_id)
30
+ ```
31
+
32
+ ## Add new single subscriber to specified group
33
+
34
+ ```ruby
35
+ subscriber = { email: 'subsriber@example.com' }
36
+ client.create_group_subscriber(1, subscriber)
37
+ ```
38
+
39
+ ## Add many new subscribers to specified group at once
40
+
41
+ ```ruby
42
+ subscribers = [
43
+ { email: 'subscriber1@example.com' },
44
+ { email: 'subscriber2@example.com' }
45
+ ]
46
+
47
+ client.import_group_subscribers(1, subscribers, resubscribe: true)
48
+ ```
49
+
50
+ ## Remove single subscriber from specified group
51
+
52
+ ```ruby
53
+ client.delete_group_subscriber(group_id, 'demo@mailerlite.com')
54
+ ```
55
+
56
+ or
57
+
58
+ ```ruby
59
+ client.delete_group_subscriber(group_id, subscriber_id)
60
+ ```
@@ -0,0 +1,66 @@
1
+ # Subscribers
2
+
3
+ ## Get single subscriber
4
+
5
+ ```ruby
6
+ client.subscriber(subscriber_id)
7
+ ```
8
+
9
+ or with email
10
+
11
+ ```ruby
12
+ client.subscriber('user@example.com')
13
+ ```
14
+
15
+ ## Update single subscriber
16
+
17
+ ```ruby
18
+ client.update_subscriber(subscriber_id options)
19
+ ```
20
+
21
+ or with email
22
+
23
+ ```ruby
24
+ client.update_subscriber('user@example.com', options)
25
+ ```
26
+
27
+ `options` can be:
28
+
29
+ - `fields` [Array]: Associated array where key is the same as field key.
30
+ - `type` [String]: Available values: `unsubscribed`, `active`
31
+ - `resend_autoresponders` [Boolean]: Defines if it is needed to resend autoresponders
32
+
33
+ ## Search for subscribers
34
+
35
+ ```ruby
36
+ options = {
37
+ query: 'example',
38
+ limit: 1,
39
+ minimized: true
40
+ }
41
+
42
+ client.search_subscribers(query, options)
43
+ ```
44
+
45
+ ## Get groups subscriber belongs to
46
+
47
+ ```ruby
48
+ client.subscriber_groups(subscriber_id)
49
+ ```
50
+
51
+ or with email
52
+
53
+ ```ruby
54
+ client.subscriber_groups('user@example.com')
55
+ ```
56
+
57
+ ## Get activites (clicks, opens, etc.) of selected subscriber
58
+ ```ruby
59
+ client.subscriber_activities(subscriber_id)
60
+ ```
61
+
62
+ or with email
63
+
64
+ ```ruby
65
+ client.subscriber_activities('user@example.com')
66
+ ```
@@ -49,6 +49,28 @@ module MailerLite
49
49
  def campaign_action(id, action)
50
50
  connection.post("campaigns/#{id}/actions/#{action}")
51
51
  end
52
+
53
+ # Returns all campaigns you have in your account by :status which is
54
+ # required. Also basic summary for each campaign including the ID.
55
+ #
56
+ # @see http://developers.mailerlite.com/reference#campaigns-by-type
57
+ #
58
+ # @param status [String] possible values: 'sent', 'outbox', 'draft'
59
+ # no value means 'sent'
60
+ #
61
+ # @return Response from API.
62
+ def campaigns_by_status(status)
63
+ connection.get("campaigns/#{status}")
64
+ end
65
+
66
+ # Remove a campaign.
67
+ #
68
+ # @param id [Integer] id of campaign
69
+ #
70
+ # @return [Boolean] Response from API.
71
+ def delete_campaign(id)
72
+ connection.delete("campaigns/#{id}")
73
+ end
52
74
  end
53
75
  end
54
76
  end
@@ -11,11 +11,25 @@ module MailerLite
11
11
  connection.get('groups')
12
12
  end
13
13
 
14
+ # Get single group by ID
15
+ #
16
+ # @see http://developers.mailerlite.com/reference#single-group
17
+ #
18
+ # @param id [Integer] Id of group
19
+ #
20
+ # @return [Hash] Response from API.
14
21
  def group(id)
15
22
  result = connection.get("groups/#{id}")
16
23
  result.is_a?(Array) ? result[0] : result
17
24
  end
18
25
 
26
+ # Create new group
27
+ #
28
+ # @see http://developers.mailerlite.com/reference#create-group
29
+ #
30
+ # @param name [String] Name of your group
31
+ #
32
+ # @return [Hash] Response from API.
19
33
  def create_group(name)
20
34
  connection.post('groups', name: name)
21
35
  end
@@ -24,26 +38,67 @@ module MailerLite
24
38
  connection.put("groups/#{id}", options)
25
39
  end
26
40
 
41
+ # Remove group
42
+ #
43
+ # @see http://developers.mailerlite.com/reference#delete-group
44
+ #
45
+ # @param [Integer] Id of group
46
+ #
47
+ # @return [Boolean] Response from API.
27
48
  def delete_group(id)
28
49
  connection.delete("groups/#{id}")
29
50
  end
30
51
 
52
+ # Get all subscribers in a specified group
53
+ #
54
+ # @see http://developers.mailerlite.com/reference#subscribers-in-a-group
55
+ #
56
+ # @param group_id [Integer] Id of group
57
+ # @param options [Hash] Request options
58
+ #
59
+ # @return [Array] Subscribers
31
60
  def group_subscribers(group_id, options = {})
32
61
  connection.get("groups/#{group_id}/subscribers", options)
33
62
  end
34
63
 
64
+ # Add new single subscriber to specified group
65
+ #
66
+ # @see http://developers.mailerlite.com/reference#add-single-subscriber
67
+ #
68
+ # @param group_id [Integer] Id of group
69
+ # @param options [Hash] Request options
70
+ #
71
+ # @return [Hash] Response from API
35
72
  def create_group_subscriber(group_id, options = {})
36
73
  connection.post("groups/#{group_id}/subscribers", options)
37
74
  end
38
75
 
76
+ # Add many new subscribers to specified group at once
77
+ #
78
+ # @see http://developers.mailerlite.com/reference#add-many-subscribers
79
+ #
80
+ # @param group_id [Integer] Id of group
81
+ # @param subscribers [Array] Array of hash each indicates a subscriber
82
+ # @param options [Hash] Request options
83
+ #
84
+ # @return [Hash] Response from API.
39
85
  def import_group_subscribers(group_id, subscribers, options = {})
40
86
  options[:subscribers] = subscribers
41
87
  connection.post("groups/#{group_id}/subscribers/import", options)
42
88
  end
43
89
 
90
+ # Remove single subscriber from specified group
91
+ #
92
+ # @see http://developers.mailerlite.com/reference#remove-subscriber
93
+ #
94
+ # @param group_id [Integer|String] Id of group
95
+ # @param subscriber_id_or_email [Array] Id or email of subscriber
96
+ #
97
+ # @return [Hash] Response from API.
44
98
  def delete_group_subscriber(group_id, subscriber_id_or_email)
99
+ escaped_subscriber_id_or_email = CGI.escape(subscriber_id_or_email)
45
100
  connection.delete(
46
- "groups/#{group_id}/subscribers/#{subscriber_id_or_email}"
101
+ "groups/#{group_id}/subscribers/#{escaped_subscriber_id_or_email}"
47
102
  )
48
103
  end
49
104
  end
@@ -2,6 +2,7 @@ require 'faraday'
2
2
  require 'faraday_middleware'
3
3
  require 'json'
4
4
 
5
+ require 'mailerlite/mash'
5
6
  require 'mailerlite/middleware/raise_error'
6
7
  require 'mailerlite/middleware/underscore_keys'
7
8
  require 'mailerlite/middleware/fix_unparsed_json'
@@ -63,7 +64,7 @@ module MailerLite
63
64
  builder.request :json
64
65
 
65
66
  builder.use FaradayMiddleware::FollowRedirects
66
- builder.use FaradayMiddleware::Mashify
67
+ builder.use FaradayMiddleware::Mashify, mash_class: MailerLite::Mash
67
68
  builder.use MailerLite::Middleware::UnderscoreKeys
68
69
  builder.use FaradayMiddleware::ParseJson
69
70
  builder.use MailerLite::Middleware::FixUnparsedJson
@@ -0,0 +1,7 @@
1
+ require 'hashie/mash'
2
+
3
+ module MailerLite
4
+ class Mash < Hashie::Mash
5
+ disable_warnings
6
+ end
7
+ end
@@ -1,4 +1,4 @@
1
1
  module MailerLite
2
2
  # @return [String] Version number.
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
data/mailerlite.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'mailerlite/version'
@@ -25,7 +26,7 @@ Gem::Specification.new do |spec|
25
26
 
26
27
  spec.add_dependency 'faraday', '~> 0.10'
27
28
  spec.add_dependency 'faraday_middleware', '~> 0.10'
28
- spec.add_dependency 'hashie', '~> 3.4'
29
+ spec.add_dependency 'hashie', '~> 3.5.5'
29
30
 
30
31
  spec.add_development_dependency 'bundler', '~> 1.11'
31
32
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailerlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justas Palumickas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2017-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.4'
47
+ version: 3.5.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.4'
54
+ version: 3.5.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -99,7 +99,13 @@ files:
99
99
  - Rakefile
100
100
  - bin/console
101
101
  - bin/setup
102
+ - examples/README.md
102
103
  - examples/authentication.md
104
+ - examples/campaigns.md
105
+ - examples/create_campaign.md
106
+ - examples/fields.md
107
+ - examples/groups.md
108
+ - examples/subscribers.md
103
109
  - lib/mailerlite.rb
104
110
  - lib/mailerlite/client.rb
105
111
  - lib/mailerlite/clients/campaigns.rb
@@ -110,6 +116,7 @@ files:
110
116
  - lib/mailerlite/connection.rb
111
117
  - lib/mailerlite/core_ext/string.rb
112
118
  - lib/mailerlite/error.rb
119
+ - lib/mailerlite/mash.rb
113
120
  - lib/mailerlite/middleware/fix_unparsed_json.rb
114
121
  - lib/mailerlite/middleware/raise_error.rb
115
122
  - lib/mailerlite/middleware/underscore_keys.rb
@@ -135,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
142
  version: '0'
136
143
  requirements: []
137
144
  rubyforge_project:
138
- rubygems_version: 2.6.8
145
+ rubygems_version: 2.6.11
139
146
  signing_key:
140
147
  specification_version: 4
141
148
  summary: Ruby wrapper for MailerLite API v2