smtp_lw 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rubocop.yml +241 -0
- data/CONTRIBUTING.md +43 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +23 -24
- data/Rakefile +2 -4
- data/lib/smtp_lw.rb +4 -5
- data/lib/smtp_lw/client.rb +15 -29
- data/lib/smtp_lw/client/messages.rb +23 -4
- data/lib/smtp_lw/configurable.rb +0 -2
- data/lib/smtp_lw/default.rb +3 -3
- data/lib/smtp_lw/version.rb +1 -1
- data/smtp_lw.gemspec +15 -14
- data/test/fixtures/test_0001_find_messages_with_required_filters.yml +40 -0
- data/test/fixtures/test_0002_will_send_a_message.yml +42 -0
- data/test/fixtures/test_0003_returns_a_message.yml +57 -0
- data/test/lib/smtp_lw/client/messages_test.rb +19 -7
- data/test/lib/smtp_lw/client_test.rb +2 -4
- data/test/lib/smtp_lw/configurable_test.rb +2 -4
- data/test/lib/smtp_lw/default_test.rb +2 -4
- data/test/lib/smtp_lw/version_test.rb +1 -3
- data/test/test_helper.rb +12 -9
- metadata +27 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebe8f2235d7522ac67b6d0eaf36439d2bdbb122e
|
4
|
+
data.tar.gz: 55dc00ab47d2d8d00b7bd7da9a3cdcf39628e479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 415759598fd81071c907cc1b2933254d59cee35c729fb8efe80aa0904b9f56c10afab3e87bfd4331bb7934941eec0edd40bc046b1233bf1a1f23b33c29524db8
|
7
|
+
data.tar.gz: 1e82ad623bae16332f5ecd619ba28715b676b6fb91cbd1d235940a7f4662261dbc38a45eeb096753f5bd1e53adf6f93f4fb4ba688547307d0b2788351ad02862
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- '**/vendor/**'
|
4
|
+
- '**/db/**/*'
|
5
|
+
- '**/script/**'
|
6
|
+
|
7
|
+
DisplayCopNames: true
|
8
|
+
|
9
|
+
Style/AccessModifierIndentation:
|
10
|
+
EnforcedStyle: indent
|
11
|
+
IndentationWidth: ~
|
12
|
+
|
13
|
+
Style/Alias:
|
14
|
+
EnforcedStyle: prefer_alias
|
15
|
+
|
16
|
+
Style/AlignHash:
|
17
|
+
EnforcedHashRocketStyle: key
|
18
|
+
EnforcedColonStyle: key
|
19
|
+
EnforcedLastArgumentHashStyle: always_inspect
|
20
|
+
|
21
|
+
Style/AlignParameters:
|
22
|
+
EnforcedStyle: with_first_parameter
|
23
|
+
|
24
|
+
Style/BarePercentLiterals:
|
25
|
+
EnforcedStyle: bare_percent
|
26
|
+
SupportedStyles:
|
27
|
+
- percent_q
|
28
|
+
- bare_percent
|
29
|
+
|
30
|
+
Style/BlockDelimiters:
|
31
|
+
EnforcedStyle: line_count_based
|
32
|
+
|
33
|
+
Style/BracesAroundHashParameters:
|
34
|
+
EnforcedStyle: no_braces
|
35
|
+
|
36
|
+
Style/ClassAndModuleChildren:
|
37
|
+
EnforcedStyle: nested
|
38
|
+
|
39
|
+
Style/Documentation:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/DotPosition:
|
43
|
+
EnforcedStyle: leading
|
44
|
+
|
45
|
+
Style/EmptyElse:
|
46
|
+
EnforcedStyle: both
|
47
|
+
|
48
|
+
Style/EmptyLineBetweenDefs:
|
49
|
+
AllowAdjacentOneLineDefs: false
|
50
|
+
|
51
|
+
Style/EmptyLinesAroundBlockBody:
|
52
|
+
EnforcedStyle: no_empty_lines
|
53
|
+
|
54
|
+
Style/EmptyLinesAroundClassBody:
|
55
|
+
EnforcedStyle: no_empty_lines
|
56
|
+
|
57
|
+
Style/EmptyLinesAroundModuleBody:
|
58
|
+
EnforcedStyle: no_empty_lines
|
59
|
+
|
60
|
+
Style/FirstParameterIndentation:
|
61
|
+
EnforcedStyle: special_for_inner_method_call_in_parentheses
|
62
|
+
IndentationWidth: ~
|
63
|
+
|
64
|
+
Style/FrozenStringLiteralComment:
|
65
|
+
EnforcedStyle: when_needed
|
66
|
+
|
67
|
+
Style/GlobalVars:
|
68
|
+
AllowedVariables: []
|
69
|
+
|
70
|
+
Style/HashSyntax:
|
71
|
+
EnforcedStyle: ruby19
|
72
|
+
UseHashRocketsWithSymbolValues: false
|
73
|
+
|
74
|
+
Style/IfUnlessModifier:
|
75
|
+
MaxLineLength: 80
|
76
|
+
|
77
|
+
Style/IndentationConsistency:
|
78
|
+
EnforcedStyle: normal
|
79
|
+
|
80
|
+
Style/IndentationWidth:
|
81
|
+
Width: 2
|
82
|
+
|
83
|
+
Style/IndentArray:
|
84
|
+
EnforcedStyle: special_inside_parentheses
|
85
|
+
|
86
|
+
Style/IndentHash:
|
87
|
+
EnforcedStyle: special_inside_parentheses
|
88
|
+
|
89
|
+
Style/NonNilCheck:
|
90
|
+
IncludeSemanticChanges: false
|
91
|
+
|
92
|
+
Style/MethodDefParentheses:
|
93
|
+
EnforcedStyle: require_parentheses
|
94
|
+
|
95
|
+
Style/MethodName:
|
96
|
+
EnforcedStyle: snake_case
|
97
|
+
|
98
|
+
Style/MultilineMethodCallIndentation:
|
99
|
+
EnforcedStyle: aligned
|
100
|
+
|
101
|
+
Style/MultilineOperationIndentation:
|
102
|
+
EnforcedStyle: aligned
|
103
|
+
|
104
|
+
Style/NumericLiterals:
|
105
|
+
MinDigits: 5
|
106
|
+
|
107
|
+
Style/ParenthesesAroundCondition:
|
108
|
+
AllowSafeAssignment: true
|
109
|
+
|
110
|
+
Style/PercentLiteralDelimiters:
|
111
|
+
PreferredDelimiters:
|
112
|
+
'%': ()
|
113
|
+
'%i': ()
|
114
|
+
'%q': ()
|
115
|
+
'%Q': ()
|
116
|
+
'%r': '{}'
|
117
|
+
'%s': ()
|
118
|
+
'%w': ()
|
119
|
+
'%W': ()
|
120
|
+
'%x': ()
|
121
|
+
|
122
|
+
Style/PercentQLiterals:
|
123
|
+
EnforcedStyle: lower_case_q
|
124
|
+
|
125
|
+
Style/PredicateName:
|
126
|
+
NamePrefix:
|
127
|
+
- is_
|
128
|
+
- has_
|
129
|
+
- have_
|
130
|
+
NamePrefixBlacklist:
|
131
|
+
- is_
|
132
|
+
- has_
|
133
|
+
- have_
|
134
|
+
NameWhitelist:
|
135
|
+
- is_a?
|
136
|
+
|
137
|
+
Style/SignalException:
|
138
|
+
EnforcedStyle: only_fail
|
139
|
+
|
140
|
+
Style/SingleLineMethods:
|
141
|
+
AllowIfMethodIsEmpty: true
|
142
|
+
|
143
|
+
Style/SpaceBeforeFirstArg:
|
144
|
+
AllowForAlignment: true
|
145
|
+
|
146
|
+
Style/StringLiterals:
|
147
|
+
EnforcedStyle: single_quotes
|
148
|
+
ConsistentQuotesInMultiline: false
|
149
|
+
|
150
|
+
Style/StringLiteralsInInterpolation:
|
151
|
+
EnforcedStyle: single_quotes
|
152
|
+
|
153
|
+
Style/SpaceAroundBlockParameters:
|
154
|
+
EnforcedStyleInsidePipes: no_space
|
155
|
+
|
156
|
+
Style/SpaceAroundEqualsInParameterDefault:
|
157
|
+
EnforcedStyle: space
|
158
|
+
|
159
|
+
Style/SpaceAroundOperators:
|
160
|
+
AllowForAlignment: true
|
161
|
+
|
162
|
+
Style/SpaceBeforeBlockBraces:
|
163
|
+
EnforcedStyle: space
|
164
|
+
|
165
|
+
Style/SpaceInsideBlockBraces:
|
166
|
+
EnforcedStyle: space
|
167
|
+
EnforcedStyleForEmptyBraces: no_space
|
168
|
+
SpaceBeforeBlockParameters: true
|
169
|
+
|
170
|
+
Style/SpaceInsideHashLiteralBraces:
|
171
|
+
EnforcedStyle: space
|
172
|
+
EnforcedStyleForEmptyBraces: no_space
|
173
|
+
|
174
|
+
Style/SpaceInsideStringInterpolation:
|
175
|
+
EnforcedStyle: no_space
|
176
|
+
|
177
|
+
Style/SymbolArray:
|
178
|
+
EnforcedStyle: percent
|
179
|
+
|
180
|
+
Style/TrailingBlankLines:
|
181
|
+
EnforcedStyle: final_newline
|
182
|
+
|
183
|
+
Style/TrailingCommaInArguments:
|
184
|
+
EnforcedStyleForMultiline: no_comma
|
185
|
+
|
186
|
+
Style/TrailingCommaInLiteral:
|
187
|
+
EnforcedStyleForMultiline: no_comma
|
188
|
+
|
189
|
+
Style/VariableName:
|
190
|
+
EnforcedStyle: snake_case
|
191
|
+
|
192
|
+
##################### Metrics ##################################
|
193
|
+
|
194
|
+
Metrics/BlockNesting:
|
195
|
+
Max: 3
|
196
|
+
|
197
|
+
Metrics/ClassLength:
|
198
|
+
CountComments: false
|
199
|
+
Max: 100
|
200
|
+
|
201
|
+
Metrics/ModuleLength:
|
202
|
+
CountComments: false
|
203
|
+
Max: 100
|
204
|
+
|
205
|
+
Metrics/LineLength:
|
206
|
+
Max: 100
|
207
|
+
AllowHeredoc: true
|
208
|
+
AllowURI: true
|
209
|
+
|
210
|
+
Metrics/MethodLength:
|
211
|
+
CountComments: false
|
212
|
+
Max: 10
|
213
|
+
|
214
|
+
Metrics/ParameterLists:
|
215
|
+
Max: 5
|
216
|
+
CountKeywordArgs: true
|
217
|
+
|
218
|
+
##################### Lint ##################################
|
219
|
+
|
220
|
+
Lint/AssignmentInCondition:
|
221
|
+
AllowSafeAssignment: true
|
222
|
+
|
223
|
+
Lint/EndAlignment:
|
224
|
+
AlignWith: keyword
|
225
|
+
AutoCorrect: false
|
226
|
+
|
227
|
+
Lint/DefEndAlignment:
|
228
|
+
AlignWith: start_of_line
|
229
|
+
AutoCorrect: false
|
230
|
+
|
231
|
+
Lint/UnusedBlockArgument:
|
232
|
+
IgnoreEmptyBlocks: true
|
233
|
+
|
234
|
+
Lint/UnusedMethodArgument:
|
235
|
+
AllowUnusedKeywordArguments: false
|
236
|
+
IgnoreEmptyMethods: true
|
237
|
+
|
238
|
+
##################### Performance ############################
|
239
|
+
|
240
|
+
Performance/RedundantMerge:
|
241
|
+
MaxKeyValuePairs: 2
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Contributing to SmtpLw
|
2
|
+
|
3
|
+
Here are some ways *you* can contribute:
|
4
|
+
|
5
|
+
* by using alpha, beta, and prerelease versions
|
6
|
+
* by reporting bugs
|
7
|
+
* by suggesting new features
|
8
|
+
* by writing or editing documentation
|
9
|
+
* by writing specifications
|
10
|
+
* by writing code ( **no patch is too small** : fix typos, add comments, clean up inconsistent whitespace )
|
11
|
+
* by refactoring code
|
12
|
+
* by closing [issues][]
|
13
|
+
* by reviewing patches
|
14
|
+
|
15
|
+
[issues]: https://github.com/locaweb/smtp_lw/issues
|
16
|
+
|
17
|
+
## Submitting an Issue
|
18
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
19
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
20
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
21
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
22
|
+
the bug, including your gem version, Ruby version, and operating system.
|
23
|
+
Ideally, a bug report should include a pull request with failing specs.
|
24
|
+
|
25
|
+
[gist]: https://gist.github.com/
|
26
|
+
|
27
|
+
## Submitting a Pull Request
|
28
|
+
1. [Fork][fork] the [official repository][repo].
|
29
|
+
2. [Create a topic branch.][branch]
|
30
|
+
3. Implement your feature or bug fix.
|
31
|
+
4. Add, commit, and push your changes.
|
32
|
+
5. [Submit a pull request.][pr]
|
33
|
+
|
34
|
+
## Notes
|
35
|
+
* Please add tests and run Rubocop to check for offenses if you changed code. Contributions without tests or with Rubocop offenses won't be accepted.
|
36
|
+
* Please don't update the Gem version.
|
37
|
+
|
38
|
+
[repo]: https://github.com/locaweb/smtp_lw/tree/master
|
39
|
+
[fork]: https://help.github.com/articles/fork-a-repo/
|
40
|
+
[branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
|
41
|
+
[pr]: https://help.github.com/articles/using-pull-requests/
|
42
|
+
|
43
|
+
Inspired by https://github.com/thoughtbot/factory_girl/blob/master/CONTRIBUTING.md
|
data/{LICENSE.txt → LICENSE}
RENAMED
data/README.md
CHANGED
@@ -4,19 +4,15 @@ This is the ruby client for SMTP Locaweb product.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
```shell
|
8
|
+
gem install smtp_lw
|
9
|
+
```
|
10
|
+
or add this line to Gemfile:
|
8
11
|
|
9
12
|
```ruby
|
10
13
|
gem 'smtp_lw'
|
11
14
|
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install smtp_lw
|
15
|
+
and run `bundle install` from your shell.
|
20
16
|
|
21
17
|
## Usage
|
22
18
|
|
@@ -24,7 +20,6 @@ Or install it yourself as:
|
|
24
20
|
```ruby
|
25
21
|
client = SmtpLw::Client.new(api_token: 'your api token from the panel')
|
26
22
|
```
|
27
|
-
|
28
23
|
or
|
29
24
|
|
30
25
|
```ruby
|
@@ -33,40 +28,44 @@ SmtpLw.configure do |c|
|
|
33
28
|
c.per_page = 50
|
34
29
|
end
|
35
30
|
|
36
|
-
#
|
31
|
+
# instantiate the client
|
37
32
|
client = SmtpLw::Client.new
|
38
33
|
```
|
39
34
|
|
40
|
-
|
35
|
+
You can also authenticate setting an environment variable
|
41
36
|
|
42
|
-
```
|
37
|
+
```shell
|
43
38
|
SMTP_LW_API_TOKEN='your api token'
|
44
39
|
```
|
45
|
-
and then
|
40
|
+
and then use the client
|
46
41
|
```ruby
|
47
42
|
client = SmtpLw::Client.new
|
48
43
|
```
|
49
44
|
|
50
|
-
###
|
45
|
+
### Retrieving messages for a given period
|
51
46
|
|
52
47
|
```ruby
|
53
48
|
client.list_messages('all', '2015-07-01', '2015-07-30')
|
54
49
|
```
|
55
|
-
|
50
|
+
|
51
|
+
You can pass options as specified in the [API documentation](http://developer.locaweb.com.br/documentacoes/smtp/):
|
56
52
|
```ruby
|
57
|
-
client.list_messages('all', '2015-07-01', '2015-07-30' {page: 1, per: 50})
|
53
|
+
client.list_messages('all', '2015-07-01', '2015-07-30', {page: 1, per: 50})
|
58
54
|
```
|
59
55
|
|
60
|
-
###
|
56
|
+
### Sending a message
|
57
|
+
|
61
58
|
```ruby
|
62
|
-
client.send_message(
|
59
|
+
client.send_message('meeting tomorrow at 11', 'this is the body of my msg', 'me@domain.com',
|
63
60
|
'you@domain.com')
|
64
61
|
```
|
65
62
|
|
66
63
|
## Contributing
|
67
64
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
Please see [CONTRIBUTING.md](https://github.com/locaweb/smtp_lw/blob/master/CONTRIBUTING.md).
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
smtp_lw is Copyright © 2015-2016 Locaweb. It is free
|
70
|
+
software, and may be redistributed under the terms specified in the
|
71
|
+
[LICENSE](/LICENSE) file.
|
data/Rakefile
CHANGED
data/lib/smtp_lw.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module SmtpLw
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
2
|
+
require 'smtp_lw/version'
|
3
|
+
require 'smtp_lw/default'
|
4
|
+
require 'smtp_lw/configurable'
|
5
|
+
require 'smtp_lw/client'
|
6
6
|
require 'dotenv'
|
7
7
|
|
8
8
|
class << self
|
9
9
|
Dotenv.load
|
10
10
|
include SmtpLw::Configurable
|
11
11
|
end
|
12
|
-
|
13
12
|
end
|
data/lib/smtp_lw/client.rb
CHANGED
@@ -7,9 +7,11 @@ module SmtpLw
|
|
7
7
|
attr_accessor :api_token, :api_endpoint, :per_page, :timeout
|
8
8
|
include SmtpLw::Client::Messages
|
9
9
|
|
10
|
-
def initialize(options={})
|
10
|
+
def initialize(options = {})
|
11
11
|
SmtpLw::Configurable.keys.each do |key|
|
12
|
-
instance_variable_set(
|
12
|
+
instance_variable_set(
|
13
|
+
:"@#{key}", options[key] || SmtpLw.instance_variable_get(:"@#{key}")
|
14
|
+
)
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
@@ -18,9 +20,8 @@ module SmtpLw
|
|
18
20
|
# @param uri [String] The path, relative to {#api_endpoint}
|
19
21
|
# @param options [Hash] Query and header params for request
|
20
22
|
# @return [Faraday::Response]
|
21
|
-
def get(uri, options={})
|
22
|
-
|
23
|
-
response = connection.get uri, options
|
23
|
+
def get(uri, options = {})
|
24
|
+
connection.get(uri, options)
|
24
25
|
end
|
25
26
|
|
26
27
|
# Make a HTTP POST request
|
@@ -28,8 +29,8 @@ module SmtpLw
|
|
28
29
|
# @param uri [String] The path, relative to {#api_endpoint}
|
29
30
|
# @param options [Hash] Body and header params for request
|
30
31
|
# @return [Faraday::Response]
|
31
|
-
def post(uri, options={})
|
32
|
-
|
32
|
+
def post(uri, options = {})
|
33
|
+
connection.post(uri, options)
|
33
34
|
end
|
34
35
|
|
35
36
|
# Make a HTTP PUT request
|
@@ -37,44 +38,29 @@ module SmtpLw
|
|
37
38
|
# @param uri [String] The path, relative to {#api_endpoint}
|
38
39
|
# @param options [Hash] Body and header params for request
|
39
40
|
# @return [Faraday::Response]
|
40
|
-
def put(uri, options={})
|
41
|
-
|
41
|
+
def put(uri, options = {})
|
42
|
+
connection.put(uri, options)
|
42
43
|
end
|
43
44
|
|
44
45
|
def next_page(raw)
|
45
|
-
next_uri = raw[
|
46
|
+
next_uri = raw['links']['next']
|
46
47
|
return nil unless next_uri
|
47
|
-
response = connection.get
|
48
|
-
|
48
|
+
response = connection.get(next_uri)
|
49
|
+
response.body
|
49
50
|
end
|
50
51
|
|
51
52
|
private
|
52
53
|
|
53
|
-
def paginate(options)
|
54
|
-
page = options[:page] || 1
|
55
|
-
per = options[:per] || (@per_page || SmtpLw.per_page)
|
56
|
-
options.merge(page: page, per: per)
|
57
|
-
end
|
58
|
-
|
59
54
|
def connection
|
60
|
-
conn = Faraday.new(url: (@api_endpoint || SmtpLw.api_endpoint), ssl: {verify: false}) do |c|
|
55
|
+
conn = Faraday.new(url: (@api_endpoint || SmtpLw.api_endpoint), ssl: { verify: false }) do |c|
|
61
56
|
c.request :json
|
62
57
|
c.response :json
|
63
58
|
c.adapter Faraday.default_adapter
|
64
|
-
|
65
59
|
end
|
60
|
+
|
66
61
|
conn.headers['User-Agent'] = "SMTP LW Ruby API Client v#{VERSION}"
|
67
62
|
conn.headers['x-auth-token'] = @api_token || SmtpLw.api_token
|
68
63
|
conn
|
69
64
|
end
|
70
|
-
|
71
|
-
def per_page
|
72
|
-
@per_page || SmtpLw.per_page
|
73
|
-
end
|
74
|
-
|
75
|
-
def api_endpoint
|
76
|
-
@api_endpoint || SmtpLw.api_endpoint
|
77
|
-
end
|
78
|
-
|
79
65
|
end
|
80
66
|
end
|
@@ -1,16 +1,35 @@
|
|
1
1
|
module SmtpLw
|
2
2
|
class Client
|
3
3
|
module Messages
|
4
|
+
def list_messages(status, start_date, end_date, options = {})
|
5
|
+
options = paginate(options)
|
6
|
+
res = get(
|
7
|
+
'messages/',
|
8
|
+
options.merge(status: status, start_date: start_date, end_date: end_date)
|
9
|
+
)
|
10
|
+
res.body
|
11
|
+
end
|
4
12
|
|
5
|
-
def
|
6
|
-
res = get
|
13
|
+
def get_message(id)
|
14
|
+
res = get("messages/#{id}")
|
7
15
|
res.body
|
8
16
|
end
|
9
17
|
|
10
|
-
def send_message(subject, body, from, to, options={})
|
11
|
-
res = post
|
18
|
+
def send_message(subject, body, from, to, options = {})
|
19
|
+
res = post(
|
20
|
+
'messages',
|
21
|
+
options.merge(subject: subject, body: body, from: from, to: to)
|
22
|
+
)
|
12
23
|
res.body
|
13
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def paginate(options)
|
29
|
+
page = options[:page] || 1
|
30
|
+
per = options[:per] || (@per_page || SmtpLw.per_page)
|
31
|
+
options.merge(page: page, per: per)
|
32
|
+
end
|
14
33
|
end
|
15
34
|
end
|
16
35
|
end
|
data/lib/smtp_lw/configurable.rb
CHANGED
data/lib/smtp_lw/default.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module SmtpLw
|
2
2
|
module Default
|
3
|
-
API_BASE =
|
4
|
-
API_VERSION =
|
3
|
+
API_BASE = 'https://api.smtplw.com.br'.freeze
|
4
|
+
API_VERSION = '/v1/'.freeze
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def api_endpoint
|
@@ -21,7 +21,7 @@ module SmtpLw
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def options
|
24
|
-
Hash[SmtpLw::Configurable.keys.map{|key| [key, send(key)]}]
|
24
|
+
Hash[SmtpLw::Configurable.keys.map { |key| [key, send(key)] }]
|
25
25
|
end
|
26
26
|
|
27
27
|
# used for pagination when available on get
|
data/lib/smtp_lw/version.rb
CHANGED
data/smtp_lw.gemspec
CHANGED
@@ -4,28 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'smtp_lw/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'smtp_lw'
|
8
8
|
spec.version = SmtpLw::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary = %
|
12
|
-
spec.description = %
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Locaweb']
|
10
|
+
spec.email = ['desenvolvedores@locaweb.com.br']
|
11
|
+
spec.summary = %(This is the ruby client for SMTP Locaweb product.)
|
12
|
+
spec.description = %(This is the ruby client for SMTP Locaweb product.)
|
13
|
+
spec.homepage = 'https://github.com/locaweb/smtp_lw'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'faraday'
|
22
22
|
spec.add_dependency 'faraday_middleware'
|
23
23
|
spec.add_dependency 'dotenv'
|
24
24
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'byebug'
|
28
|
+
spec.add_development_dependency 'vcr'
|
29
|
+
spec.add_development_dependency 'webmock'
|
30
|
+
spec.add_development_dependency 'minitest-reporters'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
31
32
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.smtplw.com.br/v1/messages/?end_date=2015-01-07&page=1&per=10&start_date=2015-01-07&status=all
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SMTP LW Ruby API Client v0.0.4
|
12
|
+
X-Auth-Token:
|
13
|
+
- "<STMP_LW_API_TOKEN>"
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: Accepted
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Transfer-Encoding:
|
26
|
+
- chunked
|
27
|
+
Status:
|
28
|
+
- 200 OK
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: '{
|
32
|
+
"data": {
|
33
|
+
"messages": [
|
34
|
+
["message 1", "message 2"]
|
35
|
+
]
|
36
|
+
}
|
37
|
+
}'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Tue, 12 Jan 2016 14:47:37 GMT
|
40
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.smtplw.com.br/v1/messages
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"subject":"hello","body":"this is just a message","from":"bruno.batalha@locaweb.com.br","to":"rachad.honein@gmail.com"}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SMTP LW Ruby API Client v0.0.4
|
12
|
+
X-Auth-Token:
|
13
|
+
- "<STMP_LW_API_TOKEN>"
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: Accepted
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Status:
|
30
|
+
- 200 OK
|
31
|
+
body:
|
32
|
+
encoding: UTF-8
|
33
|
+
string: '{
|
34
|
+
"data": {
|
35
|
+
"attributes": {
|
36
|
+
"status": "Enfileirado"
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Tue, 12 Jan 2016 14:47:37 GMT
|
42
|
+
recorded_with: VCR 3.0.1
|
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.smtplw.com.br/v1/messages/123
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SMTP LW Ruby API Client v0.0.4
|
12
|
+
X-Auth-Token:
|
13
|
+
- "<STMP_LW_API_TOKEN>"
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 201
|
23
|
+
message: Created
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Status:
|
30
|
+
- 201 OK
|
31
|
+
body:
|
32
|
+
encoding: UTF-8
|
33
|
+
string: '{
|
34
|
+
"links": {
|
35
|
+
"self": "https://api.smtplw.com.br/v1/messages/123"
|
36
|
+
},
|
37
|
+
"data": {
|
38
|
+
"attributes": {
|
39
|
+
"from": "info@locaweb.com.br",
|
40
|
+
"to": "some.email@locaweb.com.br",
|
41
|
+
"cc": null,
|
42
|
+
"bcc": null,
|
43
|
+
"subject": "qualquer titulo",
|
44
|
+
"body": "qualquer corpo",
|
45
|
+
"headers": {
|
46
|
+
"Content-Type": "text/plain",
|
47
|
+
"x-source": "api",
|
48
|
+
"x-api-message-id": 123
|
49
|
+
},
|
50
|
+
"status": "Enviado",
|
51
|
+
"response": null
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}'
|
55
|
+
http_version:
|
56
|
+
recorded_at: Tue, 12 Jan 2016 14:47:37 GMT
|
57
|
+
recorded_with: VCR 3.0.1
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative '../../../test_helper'
|
2
2
|
|
3
3
|
describe SmtpLw::Client::Messages do
|
4
|
-
|
5
4
|
subject { SmtpLw::Client.new }
|
6
5
|
|
7
6
|
before do
|
@@ -12,14 +11,27 @@ describe SmtpLw::Client::Messages do
|
|
12
11
|
VCR.eject_cassette
|
13
12
|
end
|
14
13
|
|
15
|
-
it
|
16
|
-
raw
|
17
|
-
assert_equal raw[
|
14
|
+
it 'find messages with required filters' do
|
15
|
+
raw = subject.list_messages('all', '2015-01-07', '2015-01-07', per: 10)
|
16
|
+
assert_equal raw['data']['messages'].count > 0, true
|
18
17
|
end
|
19
18
|
|
20
|
-
it
|
21
|
-
raw
|
19
|
+
it 'will send a message' do
|
20
|
+
raw = subject.send_message(
|
21
|
+
'hello',
|
22
|
+
'this is just a message',
|
23
|
+
'bruno.batalha@locaweb.com.br',
|
24
|
+
'rachad.honein@gmail.com'
|
25
|
+
)
|
22
26
|
assert_equal raw['data']['attributes']['status'], 'Enfileirado'
|
23
27
|
end
|
24
|
-
end
|
25
28
|
|
29
|
+
it 'returns a message' do
|
30
|
+
raw = subject.get_message('123')
|
31
|
+
assert_equal raw['data']['attributes']['status'], 'Enviado'
|
32
|
+
assert_equal raw['data']['attributes']['from'], 'info@locaweb.com.br'
|
33
|
+
assert_equal raw['data']['attributes']['to'], 'some.email@locaweb.com.br'
|
34
|
+
assert_equal raw['data']['attributes']['headers'].count, 3
|
35
|
+
assert_equal raw['data']['attributes']['headers']['x-api-message-id'], 123
|
36
|
+
end
|
37
|
+
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
describe SmtpLw::Client do
|
4
|
-
|
5
4
|
subject { SmtpLw::Client }
|
6
5
|
|
7
|
-
it
|
6
|
+
it 'must return authentication options of client' do
|
8
7
|
client = subject.new(api_token: 'my_api_key')
|
9
|
-
assert_equal client.api_token,
|
8
|
+
assert_equal client.api_token, 'my_api_key'
|
10
9
|
end
|
11
|
-
|
12
10
|
end
|
@@ -1,20 +1,18 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
describe SmtpLw do
|
4
|
-
|
5
|
-
it "must give the correct api token" do
|
4
|
+
it 'must give the correct api token' do
|
6
5
|
SmtpLw.configure do |c|
|
7
6
|
c.api_token = 'secret_token'
|
8
7
|
end
|
9
8
|
assert_equal SmtpLw.api_token, 'secret_token'
|
10
9
|
end
|
11
10
|
|
12
|
-
it
|
11
|
+
it 'has to reset the default keys if needed' do
|
13
12
|
SmtpLw.configure do |c|
|
14
13
|
c.api_token = 'secret_token'
|
15
14
|
end
|
16
15
|
SmtpLw.reset!
|
17
16
|
assert_equal SmtpLw.api_token, ENV['SMTP_LW_API_TOKEN']
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
3
|
describe SmtpLw do
|
4
|
-
|
5
|
-
|
6
|
-
assert_equal SmtpLw::Default.api_endpoint, "https://api.smtplw.com.br/v1/"
|
4
|
+
it 'must give the correct api endpoint' do
|
5
|
+
assert_equal SmtpLw::Default.api_endpoint, 'https://api.smtplw.com.br/v1/'
|
7
6
|
end
|
8
|
-
|
9
7
|
end
|
data/test/test_helper.rb
CHANGED
@@ -6,27 +6,28 @@ require 'vcr'
|
|
6
6
|
require 'dotenv'
|
7
7
|
require File.expand_path('../../lib/smtp_lw.rb', __FILE__)
|
8
8
|
|
9
|
-
|
10
9
|
Dotenv.load
|
11
10
|
|
12
11
|
VCR.configure do |c|
|
13
|
-
|
12
|
+
ENV['SMTP_LW_API_TOKEN'] = 'my-api-test-token'
|
13
|
+
|
14
|
+
c.cassette_library_dir = 'test/fixtures'
|
14
15
|
c.hook_into :webmock
|
15
|
-
c.filter_sensitive_data(
|
16
|
+
c.filter_sensitive_data('<STMP_LW_API_TOKEN>') do
|
16
17
|
test_api_token
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
def test_api_token
|
21
|
-
ENV.fetch
|
22
|
+
ENV.fetch('SMTP_LW_API_TOKEN', 'my-api-test-token')
|
22
23
|
end
|
23
24
|
|
24
25
|
module Minitest
|
25
26
|
module Reporters
|
26
27
|
class CustomReporter < DefaultReporter
|
27
|
-
GRAY = '0;36'
|
28
|
-
GREEN = '1;32'
|
29
|
-
RED = '1;31'
|
28
|
+
GRAY = '0;36'.freeze
|
29
|
+
GREEN = '1;32'.freeze
|
30
|
+
RED = '1;31'.freeze
|
30
31
|
|
31
32
|
def initialize(options = {})
|
32
33
|
super
|
@@ -42,7 +43,7 @@ module Minitest
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def color_up(string, color)
|
45
|
-
color? ? "\e\[#{
|
46
|
+
color? ? "\e\[#{color}m#{string}#{ANSI::Code::ENDCODE}" : string
|
46
47
|
end
|
47
48
|
|
48
49
|
def red(string)
|
@@ -61,4 +62,6 @@ module Minitest
|
|
61
62
|
end
|
62
63
|
|
63
64
|
reporter_options = { color: true, slow_count: 5 }
|
64
|
-
Minitest::Reporters.use!
|
65
|
+
Minitest::Reporters.use!(
|
66
|
+
[Minitest::Reporters::CustomReporter.new(reporter_options)]
|
67
|
+
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smtp_lw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Locaweb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: This is the ruby client for SMTP Locaweb product.
|
140
154
|
email:
|
141
155
|
- desenvolvedores@locaweb.com.br
|
@@ -145,9 +159,11 @@ extra_rdoc_files: []
|
|
145
159
|
files:
|
146
160
|
- ".env.sample"
|
147
161
|
- ".gitignore"
|
162
|
+
- ".rubocop.yml"
|
148
163
|
- ".ruby-version"
|
164
|
+
- CONTRIBUTING.md
|
149
165
|
- Gemfile
|
150
|
-
- LICENSE
|
166
|
+
- LICENSE
|
151
167
|
- README.md
|
152
168
|
- Rakefile
|
153
169
|
- lib/smtp_lw.rb
|
@@ -157,6 +173,9 @@ files:
|
|
157
173
|
- lib/smtp_lw/default.rb
|
158
174
|
- lib/smtp_lw/version.rb
|
159
175
|
- smtp_lw.gemspec
|
176
|
+
- test/fixtures/test_0001_find_messages_with_required_filters.yml
|
177
|
+
- test/fixtures/test_0002_will_send_a_message.yml
|
178
|
+
- test/fixtures/test_0003_returns_a_message.yml
|
160
179
|
- test/lib/smtp_lw/client/messages_test.rb
|
161
180
|
- test/lib/smtp_lw/client_test.rb
|
162
181
|
- test/lib/smtp_lw/configurable_test.rb
|
@@ -183,14 +202,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
202
|
version: '0'
|
184
203
|
requirements: []
|
185
204
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.4.
|
205
|
+
rubygems_version: 2.4.6
|
187
206
|
signing_key:
|
188
207
|
specification_version: 4
|
189
208
|
summary: This is the ruby client for SMTP Locaweb product.
|
190
209
|
test_files:
|
210
|
+
- test/fixtures/test_0001_find_messages_with_required_filters.yml
|
211
|
+
- test/fixtures/test_0002_will_send_a_message.yml
|
212
|
+
- test/fixtures/test_0003_returns_a_message.yml
|
191
213
|
- test/lib/smtp_lw/client/messages_test.rb
|
192
214
|
- test/lib/smtp_lw/client_test.rb
|
193
215
|
- test/lib/smtp_lw/configurable_test.rb
|
194
216
|
- test/lib/smtp_lw/default_test.rb
|
195
217
|
- test/lib/smtp_lw/version_test.rb
|
196
218
|
- test/test_helper.rb
|
219
|
+
has_rdoc:
|