laposta 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 997bf6145b9640522c55f283fbe928a36c436700d9f96bfcadaf5f7203b461f9
4
+ data.tar.gz: 7ae672f7ec4fdf6d60ecbbc0ecaf7ae7c0c70ce8c9a00b5f93e594e1e8a115b6
5
+ SHA512:
6
+ metadata.gz: 5de80f7baecdf9fde14c91b218ddf900c6b5140dfd90b91327332c790e37ab249ce52026cdec1a73a03255c62f1b136634b79d1a2beeb886eef44f37a6c7755d
7
+ data.tar.gz: 531094768dd4a8a327bb16a959f1a03e8d4176ec0b34008fdd44d332d5d53c8ef862b31e3e11de2ee74a858c476c4a891e4d6f8f08e7a1265aa72e26079b8e70
@@ -0,0 +1,38 @@
1
+ module Laposta
2
+ class Client
3
+ module Accounts
4
+ def accounts(params = {})
5
+ list("account", params)
6
+ end
7
+
8
+ # Parameters
9
+ # Name Type Description
10
+ # ------------------------------------------------------------
11
+ # account_id string (mandatory) The ID of the account
12
+ # ------------------------------------------------------------
13
+ def get_account(account_id)
14
+ get("account/#{account_id}")
15
+ end
16
+
17
+ # Allowed attributes:
18
+ # Name Type Description
19
+ # ------------------------------------------------------------
20
+ # hostname string The hostname for this account, for in the url hostname.email-provider.com
21
+ # company object (mandatory)
22
+ # company[name1] string (mandatory) The name of the organization of this account
23
+ # company[name2] string Extra line for the name of the organization of this account
24
+ # user object (mandatory)
25
+ # user[email] string (mandatory) Email address of the user associated with this account
26
+ # user[sex] string The sex of the user associated with this account (male or female)
27
+ # user[name1] string The first name of the user associated with this account
28
+ # user[name2] string The last name of the user associated with this account
29
+ # ------------------------------------------------------------
30
+ def create_account!(params = {})
31
+ cleaned = params.permit(:hostname,
32
+ { company: [:name1, :name2] },
33
+ { user: [:email, :sex, :name1, :name2] })
34
+ create("account", cleaned)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,153 @@
1
+ module Laposta
2
+ class Client
3
+ module Campaigns
4
+ def campaigns(params = {})
5
+ list("campaign", params)
6
+ end
7
+
8
+ # Parameters
9
+ # Name Type Description
10
+ # ------------------------------------------------------------
11
+ # campaign_id string (mandatory) The ID of the campaign
12
+ # ------------------------------------------------------------
13
+ def get_campaign(campaign_id)
14
+ get("campaign/#{campaign_id}")
15
+ end
16
+
17
+ # Allowed attributes:
18
+ # Name Type Description
19
+ # ------------------------------------------------------------
20
+ # type string (mandatory) Type of campaign (must be set to: regular)
21
+ # name string (mandatory) A name for this campaign for internal use
22
+ # subject string (mandatory) Subject line
23
+ # from object (mandatory)
24
+ # from[name] string (mandatory) The name of the sender
25
+ # from[email] string (mandatory) The email address of the sender (must be a sender address approved within the program)
26
+ # reply_to string Email address for receiving replies
27
+ # list_ids array (mandatory) Recipients, array of list_ids and segment_ids if needed
28
+ # stats object
29
+ # stats[ga] boolean Link Google Analytics (true or false)
30
+ # stats[mtrack] boolean Link Mtrack (true or false)
31
+ # ------------------------------------------------------------
32
+ def create_campaign!(params = {})
33
+ cleaned = params.permit(:type,
34
+ :name,
35
+ :subject,
36
+ { from: [:name, :email] },
37
+ :reply_to,
38
+ :list_ids,
39
+ { stats: [:ga, :mtrack] })
40
+ create("campaign", cleaned)
41
+ end
42
+
43
+ # Parameters
44
+ # Name Type Description
45
+ # ------------------------------------------------------------
46
+ # campaign_id string (mandatory) The ID of the campaign that has to be modified
47
+ # ------------------------------------------------------------
48
+ #
49
+ # Allowed attributes:
50
+ # Name Type Description
51
+ # ------------------------------------------------------------
52
+ # name string (mandatory) A name for this campaign for internal use
53
+ # subject string (mandatory) Subject line
54
+ # from object (mandatory)
55
+ # from[name] string (mandatory) The name of the sender
56
+ # from[email] string (mandatory) The email address of the sender (must be a sender address approved within the program)
57
+ # reply_to string Email address for receiving replies
58
+ # list_ids array (mandatory) Recipients, array of list_ids and segment_ids if needed
59
+ # stats object
60
+ # stats[ga] boolean Link Google Analytics (true or false)
61
+ # stats[mtrack] boolean Link Mtrack (true or false)
62
+ # ------------------------------------------------------------
63
+ def update_campaign!(campaign_id, params = {})
64
+ cleaned = params.permit(:name,
65
+ :subject,
66
+ { from: [:name, :email] },
67
+ :reply_to,
68
+ :list_ids,
69
+ { stats: [:ga, :mtrack] })
70
+ update("campaign/#{campaign_id}", cleaned)
71
+ end
72
+
73
+ # Parameters
74
+ # Name Type Description
75
+ # ------------------------------------------------------------
76
+ # campaign_id string (mandatory) The ID of the campaign to be deleted
77
+ # ------------------------------------------------------------
78
+ def delete_campaign!(campaign_id, params = {})
79
+ delete("campaign/#{campaign_id}")
80
+ end
81
+
82
+ # Parameters
83
+ # Name Type Description
84
+ # ------------------------------------------------------------
85
+ # campaign_id string (mandatory) The ID of the campaign
86
+ # ------------------------------------------------------------
87
+ def get_campaign_content(campaign_id)
88
+ get("campaign/#{campaign_id}/content")
89
+ end
90
+
91
+ # Parameters
92
+ # Name Type Description
93
+ # ------------------------------------------------------------
94
+ # campaign_id string (mandatory) The ID of the campaign
95
+ # ------------------------------------------------------------
96
+ #
97
+ # Allowed attributes:
98
+ # Name Type Description
99
+ # ------------------------------------------------------------
100
+ # html string The html for the campaign
101
+ # import_url string The URL from which the html must be imported
102
+ # inline_css boolean Potential inlining of css (true or false)
103
+ # ------------------------------------------------------------
104
+ def fill_campaign_content!(campaign_id, params = {})
105
+ cleaned = params.permit(:html,
106
+ :import_url,
107
+ :inline_css)
108
+ update("campaign/#{campaign_id}/content", cleaned)
109
+ end
110
+
111
+ # Parameters
112
+ # Name Type Description
113
+ # ------------------------------------------------------------
114
+ # campaign_id string (mandatory) The ID of the campaign
115
+ # ------------------------------------------------------------
116
+ def send_campaign!(campaign_id)
117
+ update("campaign/#{campaign_id}/action/send")
118
+ end
119
+
120
+ # Parameters
121
+ # Name Type Description
122
+ # ------------------------------------------------------------
123
+ # campaign_id string (mandatory) The ID of the campaign
124
+ # ------------------------------------------------------------
125
+ #
126
+ # Allowed attributes:
127
+ # Name Type Description
128
+ # ------------------------------------------------------------
129
+ # delivery_requested string(mandatory) The time and date of sending (format YYYY-MM-DD HH:MM:SS)
130
+ # ------------------------------------------------------------
131
+ def schedule_campaign!(campaign_id, params = {})
132
+ cleaned = params.permit(:delivery_requested)
133
+ update("campaign/#{campaign_id}/action/schedule", cleaned)
134
+ end
135
+
136
+ # Parameters
137
+ # Name Type Description
138
+ # ------------------------------------------------------------
139
+ # campaign_id string (mandatory) The ID of the campaign
140
+ # ------------------------------------------------------------
141
+ #
142
+ # Allowed attributes:
143
+ # Name Type Description
144
+ # ------------------------------------------------------------
145
+ # email string(mandatory) The email address to which the test should be sent.
146
+ # ------------------------------------------------------------
147
+ def test_campaign!(campaign_id, params = {})
148
+ cleaned = params.permit(:email)
149
+ update("campaign/#{campaign_id}/action/testmail", cleaned)
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,110 @@
1
+ module Laposta
2
+ class Client
3
+ module Fields
4
+ # Parameters
5
+ # Name Type Description
6
+ # ------------------------------------------------------------
7
+ # field_id string The ID of the list to which the field belongs
8
+ # ------------------------------------------------------------
9
+ #
10
+ # Allowed attributes:
11
+ # Name Type Description
12
+ # ------------------------------------------------------------
13
+ # list_id string The ID of the list to which the field belongs
14
+ # ------------------------------------------------------------
15
+ def get_field(field_id, params = {})
16
+ cleaned = params.permit(:list_id)
17
+ list("field/#{field_id}", cleaned)
18
+ end
19
+
20
+ # Allowed attributes:
21
+ # Name Type Description
22
+ # ------------------------------------------------------------
23
+ # list_id string The ID of the list to which the field belongs
24
+ # ------------------------------------------------------------
25
+ def get_fields_for_list(params = {})
26
+ cleaned = params.permit(:list_id)
27
+ list("field", cleaned)
28
+ end
29
+
30
+ # Allowed attributes:
31
+ # Name Type Description
32
+ # ------------------------------------------------------------
33
+ # list_id string The ID of the list to which the field belongs
34
+ # name string A name for this field
35
+ # defaultvalue string (optional) A potential default value
36
+ # datatype string The data type: text, numeric, date, select_single or select_multiple
37
+ # datatype_display string (optional) Only applicable for select_single: the desired display (select, radio)
38
+ # options array (optional) What selection options are available? (mandatory for the data types select_single of select_multiple).
39
+ # The options can be given as an array. In the answer the options are repeated, but there is also an extra field options_full.
40
+ # Also listed are the option IDs, which may eventually be used to change the options later.
41
+ # required boolean Is this a mandatory field?
42
+ # in_form boolean Does this field occur in the subscription form?
43
+ # in_list boolean Is this field visible in Laposta's overview?
44
+ # ------------------------------------------------------------
45
+ def create_field!(params = {})
46
+ cleaned = params.permit(:list_id,
47
+ :name,
48
+ :defaultvalue,
49
+ :datatype,
50
+ :datatype_display,
51
+ :options,
52
+ :required,
53
+ :in_form,
54
+ :in_list)
55
+ create("field", cleaned)
56
+ end
57
+
58
+
59
+ # Parameters
60
+ # Name Type Description
61
+ # ------------------------------------------------------------
62
+ # field_id string The field's ID
63
+ # ------------------------------------------------------------
64
+ #
65
+ # Allowed attributes:
66
+ # Name Type Description
67
+ # ------------------------------------------------------------
68
+ # list_id string The ID of the list to which the field belongs
69
+ # name string (optional) A name for this field
70
+ # defaultvalue string (optional) A potential default value
71
+ # datatype string (optional) The data type: text, numeric, date, select_single or select_multiple
72
+ # datatype_display string (optional) Only applicable for select_single: the desired display (select, radio)
73
+ # options array (optional) What selection options are available? (mandatory for the data types select_single of select_multiple).
74
+ # The options can be given as an array. In the answer the options are repeated, but there is also an extra field options_full.
75
+ # Also listed are the option IDs, which may eventually be used to change the options later.
76
+ # required boolean (optional) Is this a mandatory field?
77
+ # in_form boolean (optional) Does this field occur in the subscription form?
78
+ # in_list boolean (optional) Is this field visible in Laposta's overview?
79
+ # ------------------------------------------------------------
80
+ def update_field!(field_id, params = {})
81
+ cleaned = params.permit(:list_id,
82
+ :name,
83
+ :defaultvalue,
84
+ :datatype,
85
+ :datatype_display,
86
+ :options,
87
+ :required,
88
+ :in_form,
89
+ :in_list)
90
+ update("field/#{field_id}", cleaned)
91
+ end
92
+
93
+ # Parameters
94
+ # Name Type Description
95
+ # ------------------------------------------------------------
96
+ # list_id string The ID of the list to which the field belongs
97
+ # ------------------------------------------------------------
98
+ #
99
+ # Allowed attributes:
100
+ # Name Type Description
101
+ # ------------------------------------------------------------
102
+ # list_id string The ID of the list to which the field belongs
103
+ # ------------------------------------------------------------
104
+ def delete_field!(field_id, params = {})
105
+ cleaned = params.permit(:list_id)
106
+ delete("field/#{field_id}", cleaned)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,72 @@
1
+ module Laposta
2
+ class Client
3
+ module Lists
4
+ def lists(params = {})
5
+ list("list", params)
6
+ end
7
+
8
+ # Parameters
9
+ # Name Type Description
10
+ # ------------------------------------------------------------
11
+ # list_id string The list's ID
12
+ # ------------------------------------------------------------
13
+ def get_list(list_id)
14
+ get("list/#{list_id}")
15
+ end
16
+
17
+ # Allowed attributes:
18
+ # Name Type Description
19
+ # ------------------------------------------------------------
20
+ # name string A name for the list in question
21
+ # remarks string (optional) Potential remarks
22
+ # subscribe_notification_email string (optional) Email address to which a notification will be sent upon a subscription
23
+ # unsubscribe_notification_email string (optional) Email address to which a notification will be sent upon the cancelling of a subscription
24
+ # ------------------------------------------------------------
25
+ def create_list!(params = {})
26
+ cleaned = params.permit(:name,
27
+ :remark,
28
+ :subscribe_notification_email,
29
+ :unsubscribe_notification_email)
30
+ create("list", cleaned)
31
+ end
32
+
33
+ # Parameters
34
+ # Name Type Description
35
+ # -------------------------------
36
+ # list_id string The ID of the list that has to be modified
37
+ # -------------------------------
38
+ #
39
+ # Allowed attributes:
40
+ # Name Type Description
41
+ # ------------------------------------------------------------
42
+ # name string (optional) A name for the list in question
43
+ # remarks string (optional) Potential remarks
44
+ # subscribe_notification_email string (optional) Email address to which a notification will be sent upon a subscription
45
+ # unsubscribe_notification_email string (optional) Email address to which a notification will be sent upon the cancelling of a subscription
46
+ # ------------------------------------------------------------
47
+ def update_list!(list_id, params = {})
48
+ cleaned = params.permit(:name,
49
+ :remark,
50
+ :subscribe_notification_email,
51
+ :unsubscribe_notification_email)
52
+ update("list/#{list_id}", cleaned)
53
+ end
54
+
55
+ # Name Type Description
56
+ # ------------------------------------------------------------
57
+ # list_id string The ID of the list
58
+ # ------------------------------------------------------------
59
+ def delete_list!(list_id)
60
+ delete("list/#{list_id}")
61
+ end
62
+
63
+ # Name Type Description
64
+ # ------------------------------------------------------------
65
+ # list_id string The ID of the list
66
+ # ------------------------------------------------------------
67
+ def purge_list!(list_id)
68
+ delete("list/#{list_id}/members")
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,16 @@
1
+ module Laposta
2
+ class Client
3
+ module Login
4
+ # Allowed attributes:
5
+ # Name Type Description
6
+ # ------------------------------------------------------------
7
+ # login string The login
8
+ # password string The password
9
+ # ------------------------------------------------------------
10
+ def login(params = {})
11
+ cleaned = params.permit(:login, :password)
12
+ get("login", cleaned)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Laposta
2
+ class Client
3
+ module Reports
4
+ def reports(params = {})
5
+ list("report", params)
6
+ end
7
+
8
+ # Parameters
9
+ # Name Type Description
10
+ # ------------------------------------------------------------
11
+ # campaign_id string (mandatory) The ID of a campaign
12
+ # ------------------------------------------------------------
13
+ def get_report(campaign_id)
14
+ get("report/#{campaign_id}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,91 @@
1
+ module Laposta
2
+ class Client
3
+ module Subscribers
4
+ # Allowed attributes:
5
+ # Name Type Description
6
+ # ------------------------------------------------------------
7
+ # list_id string The ID of the list from which the subscribers are being requested
8
+ # state string (optional) The status of the requested subscribers: active, unsubscribed or cleaned
9
+ # ------------------------------------------------------------
10
+ def get_subscribers_for_list(params = {})
11
+ cleaned = params.permit(:list_id, :state)
12
+ list("member", cleaned)
13
+ end
14
+
15
+ # Parameters
16
+ # Name Type Description
17
+ # ------------------------------------------------------------
18
+ # member_id string The ID or the email address of the subscriber
19
+ # ------------------------------------------------------------
20
+ #
21
+ # Allowed attributes:
22
+ # Name Type Description
23
+ # ------------------------------------------------------------
24
+ # list_id string The ID of the list in which the subscriber appears
25
+ # ------------------------------------------------------------
26
+ def get_subscriber(member_id, params = {})
27
+ cleaned = params.permit(:list_id, :state)
28
+ get("member/#{member_id}", cleaned)
29
+ end
30
+
31
+ # Allowed attributes:
32
+ # Name Type Description
33
+ # ------------------------------------------------------------
34
+ # list_id string The ID of the list to which the subscriber must be added
35
+ # ip string The IP address from which the subscriber is registered
36
+ # email string The email address of the subscriber to be added
37
+ # source_url string (optional) The URL from which the subscriber is registered
38
+ # custom_fields array (optional) The values of the additionally created fields
39
+ # options array (optional) Additional instructions, with possibilities being:
40
+ # suppress_email_notification: true to prevent a notification email from being sent every time someone logs in via an API,
41
+ # suppress_email_welcome: true to prevent the welcome email from being sent when registering via the API, and
42
+ # ignore_doubleoptin: true to instantly activate subscribers on a double-optin list and ensure that no confirmation email is sent when signing up through the API.
43
+ # ------------------------------------------------------------
44
+ def create_subscriber!(params = {})
45
+ cleaned = params.permit(:list_id,
46
+ :ip,
47
+ :email,
48
+ :source_url,
49
+ :custom_fields,
50
+ :options)
51
+ create("member", cleaned)
52
+ end
53
+
54
+ # Parameters
55
+ # Name Type Description
56
+ # ------------------------------------------------------------
57
+ # member_id string The subscriber's ID
58
+ # ------------------------------------------------------------
59
+ #
60
+ # Allowed attributes:
61
+ # Name Type Description
62
+ # ------------------------------------------------------------
63
+ # list_id string The ID of the list to which the subscriber must be modified
64
+ # email string (optional) The email address of the subscriber that must be modified
65
+ # state string (optional) The new status of the subscriber: active or unsubscribed
66
+ # custom_fields array (optional) The values of the extra created fields
67
+ # ------------------------------------------------------------
68
+ def update_subscriber!(member_id, params = {})
69
+ cleaned = params.permit(:list_id,
70
+ :email,
71
+ :state,
72
+ :custom_fields)
73
+ update("member/#{member_id}", cleaned)
74
+ end
75
+
76
+ # Name Type Description
77
+ # ------------------------------------------------------------
78
+ # member_id string The subscriber's ID
79
+ # ------------------------------------------------------------
80
+ #
81
+ # Allowed attributes:
82
+ # Name Type Description
83
+ # ------------------------------------------------------------
84
+ # list_id string The ID of the list to which the subscriber must be modified
85
+ # ------------------------------------------------------------
86
+ def delete_subscriber!(member_id)
87
+ delete("member/#{member_id}")
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,86 @@
1
+ module Laposta
2
+ class Client
3
+ module Webhooks
4
+ # Parameters
5
+ # Name Type Description
6
+ # ------------------------------------------------------------
7
+ # webhook_id string The ID of the webhookto be requested
8
+ # ------------------------------------------------------------
9
+ #
10
+ # Allowed attributes:
11
+ # Name Type Description
12
+ # ------------------------------------------------------------
13
+ # list_id string The ID of the list to which the webhook belongs
14
+ # ------------------------------------------------------------
15
+ def get_webhook(webhook_id, params = {})
16
+ cleaned = params.permit(:list_id)
17
+ get("webhook/#{webhook_id}", cleaned)
18
+ end
19
+
20
+ # Allowed attributes:
21
+ # Name Type Description
22
+ # ------------------------------------------------------------
23
+ # list_id string The ID of the list to which the webhook belongs
24
+ # ------------------------------------------------------------
25
+ def get_webhooks_for_list(params = {})
26
+ cleaned = params.permit(:list_id)
27
+ list("webhook", cleaned)
28
+ end
29
+
30
+ # Allowed attributes:
31
+ # Name Type Description
32
+ # ------------------------------------------------------------
33
+ # list_id string (mandatory) The ID of the list to which the webhook belongs
34
+ # event string (mandatory) When will the webhook be requested? (subscribed, modified of deactivated)
35
+ # url string (mandatory) The URL to be accessed
36
+ # blocked boolean (mandatory) Is the accessing of the webhook (temporarily) blocked? (true or false)
37
+ # ------------------------------------------------------------
38
+ def create_webhook!(params = {})
39
+ cleaned = params.permit(:list_id,
40
+ :event,
41
+ :url,
42
+ :blocked)
43
+ create("webhook", cleaned)
44
+ end
45
+
46
+
47
+ # Parameters
48
+ # Name Type Description
49
+ # ------------------------------------------------------------
50
+ # webhook_id string The ID of the webhook to be modified
51
+ # ------------------------------------------------------------
52
+ #
53
+ # Allowed attributes:
54
+ # Name Type Description
55
+ # ------------------------------------------------------------
56
+ # list_id string (mandatory) The ID of the list to which the webhook belongs
57
+ # event string When will the webhook be requested? (subscribed, modified or deactivated)
58
+ # url string The URL to be accessed
59
+ # blocked boolean Is the accessing of the webhook (temporarily) blocked? (true or false)
60
+ # ------------------------------------------------------------
61
+ def update_webhook!(webhook_id, params = {})
62
+ cleaned = params.permit(:list_id,
63
+ :event,
64
+ :url,
65
+ :blocked)
66
+ update("webhook/#{webhook_id}", cleaned)
67
+ end
68
+
69
+ # Parameters
70
+ # Name Type Description
71
+ # ------------------------------------------------------------
72
+ # webhook_id string The ID of the webhook to be deleted
73
+ # ------------------------------------------------------------
74
+ #
75
+ # Allowed attributes:
76
+ # Name Type Description
77
+ # ------------------------------------------------------------
78
+ # list_id string (mandatory) The ID of the list to which the webhook belongs
79
+ # ------------------------------------------------------------
80
+ def delete_webhook!(webhook_id, params = {})
81
+ cleaned = params.permit(:list_id)
82
+ delete("webhook/#{webhook_id}", cleaned)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,148 @@
1
+ require 'uri'
2
+ require 'http'
3
+ require 'json'
4
+ require_relative 'client/accounts.rb'
5
+ require_relative 'client/campaigns.rb'
6
+ require_relative 'client/fields.rb'
7
+ require_relative 'client/lists.rb'
8
+ require_relative 'client/login.rb'
9
+ require_relative 'client/reports.rb'
10
+ require_relative 'client/subscribers.rb'
11
+ require_relative 'client/webhooks.rb'
12
+ require_relative 'error'
13
+ require_relative 'version'
14
+
15
+ module Laposta
16
+ class Client
17
+
18
+ include Laposta::Client::Accounts
19
+ include Laposta::Client::Campaigns
20
+ include Laposta::Client::Fields
21
+ include Laposta::Client::Lists
22
+ include Laposta::Client::Login
23
+ include Laposta::Client::Reports
24
+ include Laposta::Client::Subscribers
25
+ include Laposta::Client::Webhooks
26
+
27
+ def initialize(options={})
28
+ auth_token = options[:auth_token]
29
+ user_agent = options[:user_agent] || "Laposta Ruby Gem #{VERSION}"
30
+ @headers = HTTP.basic_auth(user: auth_token, pass: '')
31
+ .headers({
32
+ Accept: "application/json",
33
+ "User-Agent": user_agent,
34
+ "Content-Type": "application/x-www-form-urlencoded"
35
+ })
36
+ end
37
+
38
+ def list(path, params = {})
39
+ query = format_query(params)
40
+ url = "#{base_url}#{path}?#{query}"
41
+ res = @headers.get(url)
42
+ if !res.status.success?
43
+ raise Error.from_response(res)
44
+ end
45
+ JSON.parse(res.to_s)
46
+ end
47
+
48
+ def get(path)
49
+ res = @headers.get("#{base_url}#{path}")
50
+ if !res.status.success?
51
+ raise Error.from_response(res)
52
+ end
53
+ JSON.parse(res.to_s)
54
+ end
55
+
56
+ def get_plain(path)
57
+ headers_copy = @headers.dup
58
+ res = @headers.accept("text/plain").get("#{base_url}#{path}")
59
+ if !res.status.success?
60
+ raise Error.from_response(res)
61
+ end
62
+ res.to_s
63
+ end
64
+
65
+ def get_raw(path)
66
+ headers_copy = @headers.dup
67
+ res = @headers.get("#{base_url}#{path}")
68
+ if !res.status.success?
69
+ raise Error.from_response(res)
70
+ end
71
+ res
72
+ end
73
+
74
+ def create(path, body)
75
+ res = @headers.post("#{base_url}#{path}", body: format_query(flatten_hash(body)))
76
+ response = JSON.parse(res.to_s)
77
+ if !res.status.success?
78
+ raise Error.from_response(res)
79
+ end
80
+ response
81
+ end
82
+
83
+ def create_without_response(path, body)
84
+ res = @headers.post("#{base_url}#{path}", body: format_query(flatten_hash(body)))
85
+ if !res.status.success?
86
+ raise Error.from_response(res)
87
+ end
88
+ end
89
+
90
+ def update(path, body)
91
+ res = @headers.post("#{base_url}#{path}", body: format_query(flatten_hash(body)))
92
+ response = JSON.parse(res.to_s)
93
+ if !res.status.success?
94
+ raise Error.from_response(res)
95
+ end
96
+ response
97
+ end
98
+
99
+ def delete(path, body)
100
+ res = @headers.delete("#{base_url}#{path}", body: format_query(flatten_hash(body)))
101
+ response = JSON.parse(res.to_s)
102
+ if !res.status.success?
103
+ raise Error.from_response(res)
104
+ end
105
+ response
106
+ end
107
+
108
+ private
109
+ def format_query(params)
110
+ res = []
111
+ if params.is_a?(Hash)
112
+ res << params.map do |k, v|
113
+ case v
114
+ when Hash
115
+ v.map { |nk, nv| "#{k}[#{nk}]=#{URI.encode_www_form_component(nv.to_s)}" }.join("&")
116
+ when Symbol, String
117
+ "#{k}=#{URI.encode_www_form_component(v)}"
118
+ when Array then
119
+ v.map { |c| "#{k}[]=#{URI.encode_www_form_component(c.to_s)}" }.join("&")
120
+ else
121
+ "#{k}=#{URI.encode_www_form_component(v.to_s)}"
122
+ end
123
+ end
124
+ end
125
+ res.join("&")
126
+ end
127
+
128
+ def flatten_hash(params)
129
+ res = {}
130
+ if params.is_a?(Hash)
131
+ params.each do |k, v|
132
+ case v
133
+ when Hash
134
+ v.each { |nk, nv| res["#{k}[#{nk}]"] = nv }
135
+ else
136
+ res[k] = v
137
+ end
138
+ end
139
+ end
140
+ res
141
+ end
142
+
143
+ def base_url
144
+ "https://api.laposta.nl/v2/"
145
+ end
146
+
147
+ end
148
+ end
@@ -0,0 +1,41 @@
1
+ module Laposta
2
+ class Error < StandardError
3
+ def self.from_response(response)
4
+ error_class = case response.status
5
+
6
+ when 301 then LoginDoesNotExistError # This login does not exist
7
+ when 302 then InvalidPasswordError # The password entered is incorrect
8
+ when 303 then UserNotAllowedToLoginError # This user is not (or no longer) allowed to log in
9
+ when 304 then AccountNotAllowedToLoginError # This account is not (or no longer) allowed to log in
10
+ when 305 then AccountNotVerifiedError # This account has not been verified
11
+ when 400 then BadRequestError # Incomplete input
12
+ when 401 then UnauthorizedError # No valid API key was provided
13
+ when 402 then RequestFailedError # Input was in order, but request was not processed
14
+ when 404 then NotFoundError # The requested object does not exist/could not be located
15
+ when 429 then TooManyRequestsError # The maximum number of requests was reached within the given unit of time
16
+ when 500 then ServerError # Error detected on Laposta's side
17
+ else self
18
+ end
19
+ error_class.new(response)
20
+ end
21
+
22
+ def initialize(response)
23
+ @response = response
24
+ super("Response: #{response.inspect}\nBody: #{response.body}")
25
+ end
26
+ end
27
+
28
+ # Login errors
29
+ class LoginDoesNotExistError < Error; end
30
+ class InvalidPasswordError < Error; end
31
+ class UserNotAllowedToLoginError < Error; end
32
+ class AccountNotAllowedToLoginError < Error; end
33
+ class AccountNotVerifiedError < Error; end
34
+ # Generic errors
35
+ class BadRequestError < Error; end
36
+ class NotFoundError < Error; end
37
+ class RequestFailedError < Error; end
38
+ class UnauthorizedError < Error; end
39
+ class TooManyRequestsError < Error; end
40
+ class ServerError < Error; end
41
+ end
@@ -0,0 +1,15 @@
1
+ class Hash
2
+ def permit(*filters)
3
+ res = {}
4
+ filters.flatten.each do |filter|
5
+ case filter
6
+ when Symbol, String
7
+ res[filter] = self[filter] if self.keys.include?(filter)
8
+ when Hash then
9
+ key = filter.keys.first
10
+ res[key] = self[key].permit(filter[key]) if self.keys.include?(key)
11
+ end
12
+ end
13
+ res
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Laposta
2
+ VERSION = "0.0.1"
3
+ end
data/lib/laposta.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative 'laposta/utils/hash.rb'
2
+ require_relative 'laposta/client.rb'
3
+ require 'openssl'
4
+ require 'http'
5
+ require 'json'
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: laposta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Niels van der Zanden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ description: Ruby client for Laposta API
70
+ email: niels@phusion.nl
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/laposta.rb
76
+ - lib/laposta/client.rb
77
+ - lib/laposta/client/accounts.rb
78
+ - lib/laposta/client/campaigns.rb
79
+ - lib/laposta/client/fields.rb
80
+ - lib/laposta/client/lists.rb
81
+ - lib/laposta/client/login.rb
82
+ - lib/laposta/client/reports.rb
83
+ - lib/laposta/client/subscribers.rb
84
+ - lib/laposta/client/webhooks.rb
85
+ - lib/laposta/error.rb
86
+ - lib/laposta/utils/hash.rb
87
+ - lib/laposta/version.rb
88
+ homepage: https://github.com/phusion/laposta
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ruby client for Laposta API
111
+ test_files: []