base-api-io 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +76 -23
- data/lib/base/client.rb +10 -0
- data/lib/base/endpoints/mailing_lists.rb +83 -0
- data/lib/base/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e74548e5c837271421a840efb03a5f1628fd966d983c4c625b5e9f9cfb46030
|
4
|
+
data.tar.gz: 29fb96e090096e92481bf4f5dd469cb78209b1bb0e2c10c781a30e747abfb491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ebd5db36d69905b2865580e7af8789e62c94a81044421d80fc9eabcaeb6edd661f5ce56238bd4ac37c9d071c9c0d081820a7843adc75e8e73aad34279b04e9
|
7
|
+
data.tar.gz: a0a1580044bbb747f038840f3976b75477c312add6df34d2228e13a8ef98981c50e9ddfe98e6cfb796caf5e2b7fbb68790133a5cc579bc9b97e9db393b408876
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Just run this command: `gem install base-api-io`
|
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
client =
|
39
|
-
Base::Client.new(access_token:
|
39
|
+
Base::Client.new(access_token: 'your_access_token')
|
40
40
|
```
|
41
41
|
|
42
42
|
### Sending email
|
@@ -47,11 +47,11 @@ Using the `emails` endpoint on the client you can send emails:
|
|
47
47
|
# Sending an email
|
48
48
|
email =
|
49
49
|
client.emails.send(
|
50
|
-
from:
|
51
|
-
to:
|
52
|
-
subject:
|
53
|
-
html:
|
54
|
-
text:
|
50
|
+
from: 'from@example.com',
|
51
|
+
to: 'to@example.com',
|
52
|
+
subject: 'Test Email',
|
53
|
+
html: '<b>Html message</b>',
|
54
|
+
text: 'Text message')
|
55
55
|
```
|
56
56
|
|
57
57
|
### Users
|
@@ -67,17 +67,29 @@ users.metadata # The metadata object containing the total count
|
|
67
67
|
# Create a user with email / password
|
68
68
|
user =
|
69
69
|
client.users.create(
|
70
|
-
email:
|
71
|
-
confirmation:
|
72
|
-
password:
|
70
|
+
email: 'test@user.com',
|
71
|
+
confirmation: '12345',
|
72
|
+
password: '12345',
|
73
|
+
custom_data: {
|
74
|
+
age: 32
|
75
|
+
})
|
73
76
|
|
74
77
|
# Get a users details by the id
|
75
78
|
user =
|
76
|
-
client.users.get(
|
79
|
+
client.users.get('user_id')
|
80
|
+
|
81
|
+
# Update a users email or custom_data
|
82
|
+
user =
|
83
|
+
client.users.update(
|
84
|
+
id: 'user_id',
|
85
|
+
email: 'test@user.com',
|
86
|
+
custom_data: {
|
87
|
+
age: 32
|
88
|
+
})
|
77
89
|
|
78
90
|
# Delete a user by id
|
79
91
|
user =
|
80
|
-
client.users.delete(
|
92
|
+
client.users.delete('user_id')
|
81
93
|
```
|
82
94
|
|
83
95
|
### Sessions
|
@@ -88,8 +100,8 @@ Using the `sessions` endpoint on the client you can authenticate a user.
|
|
88
100
|
# Create a user with email / password
|
89
101
|
user =
|
90
102
|
client.sessions.authenticate(
|
91
|
-
email:
|
92
|
-
password:
|
103
|
+
email: 'test@user.com',
|
104
|
+
password: '12345')
|
93
105
|
```
|
94
106
|
|
95
107
|
### Forgot Password Flow
|
@@ -99,14 +111,14 @@ Using the `passwords` endpoint on the client you can perform a forgot password f
|
|
99
111
|
```ruby
|
100
112
|
# Create an forgot password token for the user with the given email address.
|
101
113
|
token =
|
102
|
-
client.passwords.forgot_password(email:
|
114
|
+
client.passwords.forgot_password(email: 'test@user.com')
|
103
115
|
|
104
116
|
# Using that token set a new password.
|
105
117
|
user =
|
106
118
|
client.passwords.set_password(
|
107
119
|
forgot_password_token: token.forgot_password_token,
|
108
|
-
confirmation:
|
109
|
-
password:
|
120
|
+
confirmation: '123456',
|
121
|
+
password: '123456')
|
110
122
|
```
|
111
123
|
|
112
124
|
### Files
|
@@ -129,19 +141,19 @@ file =
|
|
129
141
|
|
130
142
|
# Get a file by id
|
131
143
|
file =
|
132
|
-
client.files.get(
|
144
|
+
client.files.get('file_id')
|
133
145
|
|
134
146
|
# Delete a file by id
|
135
147
|
file =
|
136
|
-
client.files.delete(
|
148
|
+
client.files.delete('file_id')
|
137
149
|
|
138
150
|
# Get a download URL to the file by id
|
139
151
|
url =
|
140
|
-
client.files.download_url(
|
152
|
+
client.files.download_url('file_id')
|
141
153
|
|
142
154
|
# Download the file by id into an IO
|
143
155
|
io =
|
144
|
-
client.files.download(
|
156
|
+
client.files.download('file_id')
|
145
157
|
```
|
146
158
|
|
147
159
|
### Images
|
@@ -164,21 +176,62 @@ image =
|
|
164
176
|
|
165
177
|
# Get a image by id
|
166
178
|
image =
|
167
|
-
client.images.get(
|
179
|
+
client.images.get('image_id')
|
168
180
|
|
169
181
|
# Delete a image by id
|
170
182
|
image =
|
171
|
-
client.images.delete(
|
183
|
+
client.images.delete('image_id')
|
172
184
|
|
173
185
|
# Get a link to a prcessed version (crop & resize) of the image by id
|
174
186
|
url =
|
175
187
|
client.images.image_url(i.id,
|
176
188
|
crop: Base::Crop.new(width: 100, height: 100, top: 0, left: 0),
|
177
189
|
resize: Base::Resize.new(width: 100, height: 100),
|
178
|
-
format:
|
190
|
+
format: 'jpg',
|
179
191
|
quality: 10)
|
180
192
|
```
|
181
193
|
|
194
|
+
### Mailing Lists
|
195
|
+
|
196
|
+
A project can have many mailing lists which can be managed from the interface.
|
197
|
+
|
198
|
+
The `mailingLists` endpoint allows you to programatically subscribe / unsubscribe
|
199
|
+
emails to a mailing list and send emails to all subscribes using a single call.
|
200
|
+
|
201
|
+
```ruby
|
202
|
+
# List mailing lists
|
203
|
+
lists = client.mailing_lists.list(page: 1, per_page: 10)
|
204
|
+
lists.items # The array of mailing lists
|
205
|
+
lists.metadata # The metadata object containing the total count
|
206
|
+
|
207
|
+
# Get a mailing list by id
|
208
|
+
list =
|
209
|
+
client.mailing_lists.get('list_id')
|
210
|
+
|
211
|
+
# Subscribe an email to a mailing list.
|
212
|
+
list =
|
213
|
+
client.mailing_lists.subscribe(id: 'mailing_list_id', email: 'test@user.com')
|
214
|
+
|
215
|
+
# Unsubscribe an email from a mailing list.
|
216
|
+
list =
|
217
|
+
client.mailing_lists.unsubscribe(id: 'mailing_list_id', email: 'test@user.com')
|
218
|
+
|
219
|
+
# Get a public unsubscribe url for the given mailing list and email which
|
220
|
+
# when click unsubscribes a user from the mailing list and redirects to the
|
221
|
+
# unsubscribe_redirect_url of the list.
|
222
|
+
url =
|
223
|
+
client.mailing_lists.unsubscribe_url(id: 'mailing_list_id', email: 'test@user.com')
|
224
|
+
|
225
|
+
# Send the same email to all of the subscribers
|
226
|
+
results =
|
227
|
+
client.mailing_lists.send(
|
228
|
+
from: 'from@example.com',
|
229
|
+
id: 'mailing_list_id',
|
230
|
+
subject: 'subject',
|
231
|
+
html: 'HTML',
|
232
|
+
text: 'Text')
|
233
|
+
```
|
234
|
+
|
182
235
|
## Development
|
183
236
|
|
184
237
|
This library uses [Faraday](https://lostisland.github.io/faraday/), you can run the
|
data/lib/base/client.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative 'models/crop'
|
|
4
4
|
require_relative 'models/resize'
|
5
5
|
|
6
6
|
require_relative 'endpoint'
|
7
|
+
require_relative 'endpoints/mailing_lists'
|
7
8
|
require_relative 'endpoints/passwords'
|
8
9
|
require_relative 'endpoints/sessions'
|
9
10
|
require_relative 'endpoints/images'
|
@@ -14,6 +15,9 @@ require_relative 'endpoints/files'
|
|
14
15
|
module Base
|
15
16
|
# A client containing all the endpoints.
|
16
17
|
class Client
|
18
|
+
# Endpoint for the mailing lists
|
19
|
+
attr_reader :mailing_lists
|
20
|
+
|
17
21
|
# Endpoint for the forgot password flow.
|
18
22
|
attr_reader :passwords
|
19
23
|
|
@@ -69,6 +73,12 @@ module Base
|
|
69
73
|
access_token: access_token,
|
70
74
|
url: url
|
71
75
|
)
|
76
|
+
|
77
|
+
@mailing_lists =
|
78
|
+
Endpoints::MailingLists.new(
|
79
|
+
access_token: access_token,
|
80
|
+
url: url
|
81
|
+
)
|
72
82
|
end
|
73
83
|
end
|
74
84
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Base
|
4
|
+
module Endpoints
|
5
|
+
# This endpoint contains methods for managing mailing lists.
|
6
|
+
class MailingLists < Endpoint
|
7
|
+
# Initializes this endpoint.
|
8
|
+
def initialize(access_token:, url:)
|
9
|
+
@path = 'mailing_lists'
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
# Lists the mailing lists of a project
|
14
|
+
def list(page: 1, per_page: 10)
|
15
|
+
request do
|
16
|
+
response =
|
17
|
+
connection.get('', per_page: per_page, page: page)
|
18
|
+
|
19
|
+
parse(response.body)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sends an email with the given parameters.
|
24
|
+
#
|
25
|
+
# If there is no sending domain set up all emails will use the
|
26
|
+
# `proxy@base-api.io` sender and ignore the given one, also in this case
|
27
|
+
# there is a rate limit which is 30 emails in an hour.
|
28
|
+
#
|
29
|
+
# If there is a sending domain, the sender must match that domain
|
30
|
+
# otherwise it will return an error.
|
31
|
+
def send(id:, subject:, from:, html:, text:)
|
32
|
+
request do
|
33
|
+
response =
|
34
|
+
connection.post("#{id}/send",
|
35
|
+
'from' => from,
|
36
|
+
'subject' => subject,
|
37
|
+
'html' => html,
|
38
|
+
'text' => text)
|
39
|
+
|
40
|
+
parse(response.body)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Subscribes an email to the mailing list with the given id.
|
45
|
+
def subscribe(id:, email:)
|
46
|
+
request do
|
47
|
+
response =
|
48
|
+
connection.post("#{id}/subscribe", 'email' => email)
|
49
|
+
|
50
|
+
parse(response.body)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Unsubscribes an email from the mailing list with the given id.
|
55
|
+
def unsubscribe(id:, email:)
|
56
|
+
request do
|
57
|
+
response =
|
58
|
+
connection.post("#{id}/unsubscribe", 'email' => email)
|
59
|
+
|
60
|
+
parse(response.body)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the unsubscribe url for the given email of list the given id.
|
65
|
+
def unsubscribe_url(id:, email:)
|
66
|
+
token =
|
67
|
+
Base64.encode64("#{id}:#{email}")
|
68
|
+
|
69
|
+
"#{connection.url_prefix}unsubscribe?token=#{token}"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the metadata of the mailing list with the given ID.
|
73
|
+
def get(id)
|
74
|
+
request do
|
75
|
+
response =
|
76
|
+
connection.get id
|
77
|
+
|
78
|
+
parse(response.body)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/base/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base-api-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gusztáv Szikszai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/base/endpoints/emails.rb
|
120
120
|
- lib/base/endpoints/files.rb
|
121
121
|
- lib/base/endpoints/images.rb
|
122
|
+
- lib/base/endpoints/mailing_lists.rb
|
122
123
|
- lib/base/endpoints/passwords.rb
|
123
124
|
- lib/base/endpoints/sessions.rb
|
124
125
|
- lib/base/endpoints/users.rb
|