smtpapi 0.0.11 → 0.0.12

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: e949a527b106a2ad0ec5530c0b305bcf568c5f0d
4
- data.tar.gz: 521f1c2cd08b6eba6e8759741d2639cd11324af4
3
+ metadata.gz: 7d0cf9cd0aedd6c845663105d15cd861e5992876
4
+ data.tar.gz: 983fb09ac9fab4ce5d893bf4643a9878ceac29a9
5
5
  SHA512:
6
- metadata.gz: 254df808552bb9c2f296379a6a9a0c45d902e82d0cf2bd1bfbefafbd19564ebbf66cb9a2916a0e78eeef1d89b250b38d2028cc27e99acf53e177eb9a6676ad48
7
- data.tar.gz: 0d3a6acb3a98a89e938f3a94a0d35f047c5a8cd3b0e1c817962bf0d0977a8e7830a968baa6eb79825b4a78c2c4a9df11b006f2c22d536b6dc7fbb4f6ef5fa638
6
+ metadata.gz: 22673f984c4f7d320ff054f2ee921c20d560a34fbde5e58ebc7c6757c6dd2733f17eb7be1c059923bce7f9d1c3351a983de7db60cd8afbc6f9d2cd742054da23
7
+ data.tar.gz: 79078fd61f6585749873b938a7217ec833abd7b0ce5f6a5ce3ec6641331041da41449f011049c110db08cc0c1c927095f90851c381d275b25a134937ad1a7fe9
@@ -0,0 +1,31 @@
1
+ # メソッド名のprefixに「set_」「get_」を許可
2
+ AccessorMethodName:
3
+ Enabled: false
4
+
5
+ # メソッドの行数上限を変更
6
+ MethodLength:
7
+ CountComments: true # count full line comments?
8
+ Max: 20
9
+
10
+ # 引数上限を変更
11
+ ParameterLists:
12
+ Max: 6
13
+ CountKeywordArgs: true
14
+
15
+ # AbcSizeの上限を変更
16
+ AbcSize:
17
+ Max: 34
18
+
19
+ # %r 内で利用できるスラッシュの数の制限変更
20
+ RegexpLiteral:
21
+ MaxSlashes: 0
22
+
23
+ ClassLength:
24
+ Max: 200
25
+ CountComments: true
26
+
27
+ CyclomaticComplexity:
28
+ Max: 11
29
+
30
+ PerceivedComplexity:
31
+ Max: 11
@@ -1,10 +1,14 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.2"
4
3
  - "1.9.3"
5
4
  - "2.0.0"
6
5
  - "2.1.0"
6
+ - "2.1.2"
7
+ - "2.1.3"
8
+ - "2.1.4"
9
+ - "2.1.5"
7
10
  before_script:
8
11
  - bundle install
9
12
  script:
13
+ - rubocop --fail-level=W
10
14
  - rake test
data/Rakefile CHANGED
@@ -1,9 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
- t.libs << "test"
5
+ t.libs << 'test'
6
6
  t.test_files = FileList['test/test*.rb']
7
7
  t.verbose = true
8
8
  end
9
-
@@ -1,12 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.unshift File.dirname(__FILE__)
3
- require "smtpapi/version"
4
- require "json"
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+ require 'smtpapi/version'
4
+ require 'json'
5
5
 
6
6
  module Smtpapi
7
+ #
8
+ # SendGrid smtpapi header implementation
9
+ #
7
10
  class Header
8
-
9
- attr_reader :to, :sub, :section, :category, :unique_args, :filters, :send_at, :send_each_at, :asm_group_id, :ip_pool
11
+ attr_reader :to, :sub, :section, :category, :unique_args, :filters
12
+ attr_reader :send_at, :send_each_at, :asm_group_id, :ip_pool
10
13
 
11
14
  def initialize
12
15
  @to = []
@@ -21,12 +24,12 @@ module Smtpapi
21
24
  @ip_pool = nil
22
25
  end
23
26
 
24
- def add_to(address, name=nil)
27
+ def add_to(address, name = nil)
25
28
  if address.is_a?(Array)
26
29
  @to.concat(address)
27
30
  else
28
31
  value = address
29
- value = "#{name} <#{address}>" if name != nil
32
+ value = "#{name} <#{address}>" unless name.nil?
30
33
  @to.push(value)
31
34
  end
32
35
  self
@@ -78,8 +81,10 @@ module Smtpapi
78
81
  end
79
82
 
80
83
  def add_filter(filter_name, parameter_name, parameter_value)
81
- @filters[filter_name] = {} if @filters[filter_name] == nil
82
- @filters[filter_name]['settings'] = {} if @filters[filter_name]['settings'] == nil
84
+ @filters[filter_name] = {} if @filters[filter_name].nil?
85
+ if @filters[filter_name]['settings'].nil?
86
+ @filters[filter_name]['settings'] = {}
87
+ end
83
88
  @filters[filter_name]['settings'][parameter_name] = parameter_value
84
89
  self
85
90
  end
@@ -91,56 +96,61 @@ module Smtpapi
91
96
 
92
97
  def set_send_at(send_at)
93
98
  @send_at = send_at
99
+ self
94
100
  end
95
101
 
96
102
  def set_send_each_at(send_each_at)
97
103
  @send_each_at = send_each_at
104
+ self
98
105
  end
99
106
 
100
107
  def set_asm_group(group_id)
101
108
  @asm_group_id = group_id
109
+ self
102
110
  end
103
111
 
104
112
  def set_ip_pool(pool_name)
105
113
  @ip_pool = pool_name
114
+ self
106
115
  end
107
116
 
108
117
  def to_array
109
118
  data = {}
110
- data["to"] = @to if @to.length > 0
111
- data["sub"] = @sub if @sub.length > 0
112
- data["section"] = @section if @section.length > 0
113
- data["unique_args"] = @unique_args if @unique_args.length > 0
114
- data["category"] = @category if @category.length > 0
115
- data["filters"] = @filters if @filters.length > 0
116
- data["send_at"] = @send_at.to_i if @send_at != nil
117
- data["asm_group_id"] = @asm_group_id.to_i if @asm_group_id != nil
118
- data["ip_pool"] = @ip_pool if @ip_pool != nil
119
+ data['to'] = @to if @to.length > 0
120
+ data['sub'] = @sub if @sub.length > 0
121
+ data['section'] = @section if @section.length > 0
122
+ data['unique_args'] = @unique_args if @unique_args.length > 0
123
+ data['category'] = @category if @category.length > 0
124
+ data['filters'] = @filters if @filters.length > 0
125
+ data['send_at'] = @send_at.to_i unless @send_at.nil?
126
+ data['asm_group_id'] = @asm_group_id.to_i unless @asm_group_id.nil?
127
+ data['ip_pool'] = @ip_pool unless @ip_pool.nil?
119
128
  str_each_at = []
120
- @send_each_at.each {|val|
129
+ @send_each_at.each do |val|
121
130
  str_each_at.push(val.to_i)
122
- }
123
- data["send_each_at"] = str_each_at if str_each_at.length > 0
131
+ end
132
+ data['send_each_at'] = str_each_at if str_each_at.length > 0
124
133
  data
125
134
  end
135
+
126
136
  protected :to_array
127
137
 
128
138
  def json_string
129
- escape_unicode(self.to_array.to_json)
139
+ escape_unicode(to_array.to_json)
130
140
  end
131
141
  alias_method :to_json, :json_string
132
142
 
133
143
  def escape_unicode(str)
134
- str.unpack('U*').map{|i|
135
- if i > 65535 then
136
- "\\u#{"%04x" % ((i - 0x10000) / 0x400 + 0xD800)}\\u#{"%04x" % ((i - 0x10000) % 0x400 + 0xDC00)}" if i > 65535
137
- elsif i > 127 then
138
- "\\u#{"%04x" % i}"
144
+ str.unpack('U*').map do |i|
145
+ if i > 65_535
146
+ "\\u#{format('%04x', ((i - 0x10000) / 0x400 + 0xD800))}"\
147
+ "\\u#{format('%04x', ((i - 0x10000) % 0x400 + 0xDC00))}" if i > 65_535
148
+ elsif i > 127
149
+ "\\u#{format('%04x', i)}"
139
150
  else
140
- i.chr("UTF-8")
151
+ i.chr('UTF-8')
141
152
  end
142
- }.join
153
+ end.join
143
154
  end
144
-
145
155
  end
146
156
  end
@@ -1,3 +1,6 @@
1
+ #
2
+ # SendGrid smtpapi
3
+ #
1
4
  module Smtpapi
2
- VERSION = "0.0.11"
5
+ VERSION = '0.0.12'
3
6
  end
@@ -4,20 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'smtpapi/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "smtpapi"
7
+ spec.name = 'smtpapi'
8
8
  spec.version = Smtpapi::VERSION
9
- spec.authors = ["Wataru Sato"]
10
- spec.email = ["awwa500@gmail.com"]
11
- spec.summary = %q{Smtpapi library for SendGrid.}
12
- spec.description = %q{Smtpapi library for SendGrid.}
13
- spec.homepage = "https://github.com/sendgridjp/smtpapi-ruby"
14
- spec.license = "MIT"
9
+ spec.authors = ['Wataru Sato']
10
+ spec.email = ['awwa500@gmail.com']
11
+ spec.summary = 'Smtpapi library for SendGrid.'
12
+ spec.description = 'Smtpapi library for SendGrid.'
13
+ spec.homepage = 'https://github.com/sendgridjp/smtpapi-ruby'
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($/)
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 = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency('rubocop', '>=0.29.0', '<0.30.0')
23
24
  end
@@ -1,94 +1,122 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require "test/unit"
3
- require "./lib/smtpapi"
2
+ require 'test/unit'
3
+ require './lib/smtpapi'
4
4
 
5
+ #
6
+ # SmtpapiTest implementation
7
+ #
5
8
  class SmtpapiTest < Test::Unit::TestCase
6
-
7
9
  def test_version
8
- assert_equal("0.0.11", Smtpapi::VERSION)
10
+ assert_equal('0.0.12', Smtpapi::VERSION)
9
11
  end
10
12
 
11
13
  def test_empty
12
14
  header = Smtpapi::Header.new
13
- assert_equal("{}",header.json_string)
15
+ assert_equal('{}', header.json_string)
14
16
  end
15
17
 
16
18
  def test_add_to
17
19
  header = Smtpapi::Header.new
18
20
  header.add_to('you@youremail.com')
19
21
  header.add_to('other@otheremail.com', 'Other Name')
20
- assert_equal("{\"to\":[\"you@youremail.com\",\"Other Name <other@otheremail.com>\"]}",header.json_string)
22
+ assert_equal(
23
+ '{"to":["you@youremail.com","Other Name <other@otheremail.com>"]}',
24
+ header.json_string)
21
25
  end
22
26
 
23
27
  def test_add_to_array
24
28
  header = Smtpapi::Header.new
25
29
  header.add_to(['you@youremail.com', 'my@myemail.com'])
26
- assert_equal("{\"to\":[\"you@youremail.com\",\"my@myemail.com\"]}",header.json_string)
30
+ assert_equal(
31
+ '{"to":["you@youremail.com","my@myemail.com"]}',
32
+ header.json_string)
27
33
  end
28
34
 
29
35
  def test_set_tos
30
36
  header = Smtpapi::Header.new
31
37
  header.set_tos(['you@youremail.com', 'other@otheremail.com'])
32
- assert_equal("{\"to\":[\"you@youremail.com\",\"other@otheremail.com\"]}",header.json_string)
38
+ assert_equal(
39
+ '{"to":["you@youremail.com","other@otheremail.com"]}',
40
+ header.json_string)
33
41
  end
34
42
 
35
43
  def test_add_substitution
36
44
  header = Smtpapi::Header.new
37
- header.add_substitution('keep', ['secret']) # sub = {keep: ['secret']}
38
- header.add_substitution('other', ['one', 'two']) # sub = {keep: ['secret'], other: ['one', 'two']}
39
- assert_equal("{\"sub\":{\"keep\":[\"secret\"],\"other\":[\"one\",\"two\"]}}",header.json_string)
45
+ header.add_substitution('keep', ['secret'])
46
+ header.add_substitution('other', %w(one two))
47
+ assert_equal(
48
+ '{"sub":{"keep":["secret"],"other":["one","two"]}}',
49
+ header.json_string)
40
50
  end
41
51
 
42
52
  def test_set_substitutions
43
53
  header = Smtpapi::Header.new
44
- header.set_substitutions({'keep' => ['secret']}) # sub = {'keep': ['secret']}
45
- assert_equal("{\"sub\":{\"keep\":[\"secret\"]}}",header.json_string)
54
+ header.set_substitutions('keep' => ['secret'])
55
+ assert_equal('{"sub":{"keep":["secret"]}}', header.json_string)
46
56
  end
47
57
 
48
58
  def test_add_section
49
59
  header = Smtpapi::Header.new
50
60
  header.add_section('-charge-', 'This ship is useless.')
51
61
  header.add_section('-bomber-', 'Only for sad vikings.')
52
- assert_equal("{\"section\":{\"-charge-\":\"This ship is useless.\",\"-bomber-\":\"Only for sad vikings.\"}}",header.json_string)
62
+ assert_equal(
63
+ '{"section":'\
64
+ '{"-charge-":"This ship is useless.",'\
65
+ '"-bomber-":"Only for sad vikings."}}',
66
+ header.json_string)
53
67
  end
54
68
 
55
69
  def test_set_sections
56
70
  header = Smtpapi::Header.new
57
- header.set_sections({'-charge-' => 'This ship is useless.'})
58
- assert_equal("{\"section\":{\"-charge-\":\"This ship is useless.\"}}",header.json_string)
71
+ header.set_sections('-charge-' => 'This ship is useless.')
72
+ assert_equal(
73
+ '{"section":{"-charge-":"This ship is useless."}}',
74
+ header.json_string
75
+ )
59
76
  end
60
77
 
61
78
  def test_add_unique_arg
62
79
  header = Smtpapi::Header.new
63
80
  header.add_unique_arg('cat', 'dogs')
64
- assert_equal("{\"unique_args\":{\"cat\":\"dogs\"}}",header.json_string)
81
+ assert_equal('{"unique_args":{"cat":"dogs"}}', header.json_string)
65
82
  end
66
83
 
67
84
  def test_set_unique_args
68
85
  header = Smtpapi::Header.new
69
- header.set_unique_args({'cow' => 'chicken'})
70
- header.set_unique_args({'dad' => 'proud'})
71
- assert_equal("{\"unique_args\":{\"dad\":\"proud\"}}",header.json_string)
86
+ header.set_unique_args('cow' => 'chicken')
87
+ header.set_unique_args('dad' => 'proud')
88
+ assert_equal('{"unique_args":{"dad":"proud"}}', header.json_string)
72
89
  end
73
90
 
74
91
  def test_add_category
75
92
  header = Smtpapi::Header.new
76
- header.add_category('tactics') # category = ['tactics']
77
- header.add_category('advanced') # category = ['tactics', 'advanced']
78
- assert_equal("{\"category\":[\"tactics\",\"advanced\"]}",header.json_string)
93
+ header.add_category('tactics')
94
+ header.add_category('advanced')
95
+ assert_equal('{"category":["tactics","advanced"]}', header.json_string)
79
96
  end
80
97
 
81
98
  def test_set_categories
82
99
  header = Smtpapi::Header.new
83
- header.set_categories(['tactics', 'advanced']) # category = ['tactics', 'advanced']
84
- assert_equal("{\"category\":[\"tactics\",\"advanced\"]}",header.json_string)
100
+ header.set_categories(%w(tactics advanced))
101
+ assert_equal('{"category":["tactics","advanced"]}', header.json_string)
85
102
  end
86
103
 
87
104
  def test_add_filter
88
105
  header = Smtpapi::Header.new
89
106
  header.add_filter('footer', 'enable', 1)
90
107
  header.add_filter('footer', 'text/html', '<strong>boo</strong>')
91
- assert_equal("{\"filters\":{\"footer\":{\"settings\":{\"enable\":1,\"text/html\":\"<strong>boo</strong>\"}}}}",header.json_string)
108
+ assert_equal(
109
+ '{"filters":'\
110
+ '{"footer":'\
111
+ '{"settings":'\
112
+ '{"enable":1,'\
113
+ '"text/html":"<strong>boo</strong>"'\
114
+ '}'\
115
+ '}'\
116
+ '}'\
117
+ '}',
118
+ header.json_string
119
+ )
92
120
  end
93
121
 
94
122
  def test_set_filters
@@ -97,22 +125,44 @@ class SmtpapiTest < Test::Unit::TestCase
97
125
  'footer' => {
98
126
  'setting' => {
99
127
  'enable' => 1,
100
- "text/plain" => 'You can haz footers!'
128
+ 'text/plain' => 'You can haz footers!'
101
129
  }
102
130
  }
103
131
  }
104
132
  header.set_filters(filter)
105
- assert_equal("{\"filters\":{\"footer\":{\"setting\":{\"enable\":1,\"text/plain\":\"You can haz footers!\"}}}}",header.json_string)
133
+ assert_equal(
134
+ '{"filters":'\
135
+ '{"footer":'\
136
+ '{"setting":'\
137
+ '{"enable":1,"text/plain":"You can haz footers!"}'\
138
+ '}'\
139
+ '}'\
140
+ '}',
141
+ header.json_string
142
+ )
106
143
  end
107
144
 
108
145
  def test_add_category_unicode
109
146
  header = Smtpapi::Header.new
110
147
  header.add_category('Martí')
111
- header.add_category('天破活殺') # category = ['天破活殺']
112
- header.add_category('天翔十字鳳') # category = ['天破活殺', '天翔十字鳳']
113
- assert_equal("{\"category\":[\"Mart\\u00ed\",\"\\u5929\\u7834\\u6d3b\\u6bba\",\"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3\"]}",header.json_string)
114
- header.add_category('鼖') # category = ['天破活殺', '天翔十字鳳', '鼖']
115
- assert_equal("{\"category\":[\"Mart\\u00ed\",\"\\u5929\\u7834\\u6d3b\\u6bba\",\"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3\",\"\\ud87e\\ude1b\"]}",header.json_string)
148
+ header.add_category('天破活殺')
149
+ header.add_category('天翔十字鳳')
150
+ assert_equal(
151
+ '{"category":'\
152
+ '["Mart\\u00ed",'\
153
+ '"\\u5929\\u7834\\u6d3b\\u6bba",'\
154
+ '"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3"]}',
155
+ header.json_string
156
+ )
157
+ header.add_category('鼖')
158
+ assert_equal(
159
+ '{"category":'\
160
+ '["Mart\\u00ed",'\
161
+ '"\\u5929\\u7834\\u6d3b\\u6bba",'\
162
+ '"\\u5929\\u7fd4\\u5341\\u5b57\\u9cf3",'\
163
+ '"\\ud87e\\ude1b"]}',
164
+ header.json_string
165
+ )
116
166
  end
117
167
 
118
168
  def test_sent_send_at
@@ -130,20 +180,25 @@ class SmtpapiTest < Test::Unit::TestCase
130
180
  localtime3 = Time.local(2015, 9, 1, 4, 5, 6)
131
181
  header.set_send_each_at([localtime1, localtime2, localtime3])
132
182
 
133
- assert_equal("{\"send_each_at\":[#{localtime1.to_i},#{localtime2.to_i},#{localtime3.to_i}]}", header.json_string)
183
+ assert_equal(
184
+ '{"send_each_at":'\
185
+ "[#{localtime1.to_i},#{localtime2.to_i},#{localtime3.to_i}]"\
186
+ '}',
187
+ header.json_string
188
+ )
134
189
  end
135
190
 
136
191
  def test_asm_group_id
137
192
  header = Smtpapi::Header.new
138
193
  header.set_asm_group(2)
139
194
 
140
- assert_equal("{\"asm_group_id\":2}", header.json_string)
195
+ assert_equal('{"asm_group_id":2}', header.json_string)
141
196
  end
142
197
 
143
198
  def test_ip_pool
144
199
  header = Smtpapi::Header.new
145
- header.set_ip_pool("test_pool")
200
+ header.set_ip_pool('test_pool')
146
201
 
147
- assert_equal("{\"ip_pool\":\"test_pool\"}", header.json_string)
202
+ assert_equal('{"ip_pool":"test_pool"}', header.json_string)
148
203
  end
149
204
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smtpapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wataru Sato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,26 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.29.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 0.30.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 0.29.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.30.0
41
61
  description: Smtpapi library for SendGrid.
42
62
  email:
43
63
  - awwa500@gmail.com
@@ -46,6 +66,7 @@ extensions: []
46
66
  extra_rdoc_files: []
47
67
  files:
48
68
  - ".gitignore"
69
+ - ".rubocop.yml"
49
70
  - ".travis.yml"
50
71
  - Gemfile
51
72
  - LICENSE.txt
@@ -75,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
96
  version: '0'
76
97
  requirements: []
77
98
  rubyforge_project:
78
- rubygems_version: 2.4.2
99
+ rubygems_version: 2.4.3
79
100
  signing_key:
80
101
  specification_version: 4
81
102
  summary: Smtpapi library for SendGrid.