gatling_gun 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 720840ea4789f10af01fed82114a0b7b35e9100c
4
+ data.tar.gz: 6018e0b11b67eee0cc9f214533346deaf4563536
5
+ SHA512:
6
+ metadata.gz: 60f345655d88720db97a6318ad41f3d08096a5db9cb67e31f0dc8fc9a63506eb56e1ac36c2bef60ae7c5ee33c27045423d957b87ad44337a81c995dfb40a87a4
7
+ data.tar.gz: dbfc985229161a8ab2feb416d743106c1b895c8e5669927800439713cca7cd0025ed625145dd5876755529b125b751662bb5f5c38f25d455e45d2259c471fc18
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
+ Gemfile.lock
2
+ .ruby-gemset
3
+ .ruby-version
1
4
  pkg
2
-
3
5
  .DS_Store
4
6
  **/.DS_Store
@@ -0,0 +1,95 @@
1
+ AndOr:
2
+ Enabled: false
3
+
4
+ StringLiterals:
5
+ Enabled: false
6
+
7
+ AccessorMethodName:
8
+ Enabled: false
9
+
10
+ ClassLength:
11
+ Max: 300
12
+
13
+ Documentation:
14
+ Enabled: false
15
+
16
+ Encoding:
17
+ Enabled: false
18
+
19
+ BracesAroundHashParameters:
20
+ Enabled: false
21
+
22
+ Blocks:
23
+ Enabled: false
24
+
25
+ ClassVars:
26
+ Enabled: false
27
+
28
+ CollectionMethods:
29
+ Enabled: false
30
+
31
+ CyclomaticComplexity:
32
+ Max: 16
33
+
34
+ HandleExceptions:
35
+ Enabled: false
36
+
37
+ HashSyntax:
38
+ Enabled: false
39
+
40
+ IfUnlessModifier:
41
+ Enabled: false
42
+
43
+ LineLength:
44
+ Max: 183
45
+
46
+ MethodLength:
47
+ Max: 40
48
+
49
+ Metrics/PerceivedComplexity:
50
+ Max: 8
51
+
52
+ MultilineBlockChain:
53
+ Enabled: false
54
+
55
+ NestedTernaryOperator:
56
+ Enabled: false
57
+
58
+ Not:
59
+ Enabled: false
60
+
61
+ NumericLiterals:
62
+ Enabled: false
63
+
64
+ ParameterLists:
65
+ Enabled: false
66
+
67
+ ParenthesesAroundCondition:
68
+ Enabled: false
69
+
70
+ ParenthesesAsGroupedExpression:
71
+ Enabled: false
72
+
73
+ RedundantBegin:
74
+ Enabled: false
75
+
76
+ RedundantSelf:
77
+ Enabled: false
78
+
79
+ RescueException:
80
+ Enabled: false
81
+
82
+ RescueModifier:
83
+ Enabled: false
84
+
85
+ Semicolon:
86
+ Enabled: false
87
+
88
+ SignalException:
89
+ Enabled: false
90
+
91
+ SingleLineBlockParams:
92
+ Enabled: false
93
+
94
+ WordArray:
95
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 James Edward Gray II and Brian Muller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -5,29 +5,30 @@ Gatling Gun is a library that helps you blast out a group of emails. It's a
5
5
  simple wrapper over
6
6
  [SendGrid's Newsletter API](http://docs.sendgrid.com/documentation/api/newsletter-api/).
7
7
 
8
- Install
8
+ Installation
9
9
  -------
10
10
 
11
- If you want to use this code in a Rails application, just add it to your
12
- Gemfile:
11
+ Add this line to your application's Gemfile:
13
12
 
14
- gem "gatling_gun"
15
-
16
- To use the code in a non-Rails application, first install the gem:
17
-
18
- gem install gatling_gun
13
+ ```ruby
14
+ gem "gatling_gun"
15
+ ```
19
16
 
20
17
  Then require the library in your code:
21
18
 
22
- require "gatling_gun"
19
+ ```ruby
20
+ require "gatling_gun"
21
+ ```
23
22
 
24
- Either way, you will want to setup Gatling Gun as your application loads. I
23
+ You will probably want to setup Gatling Gun as your application loads. I
25
24
  recommend just setting a constant you can then refer to throughout your
26
25
  application. In Rails, I would put the following code in
27
26
  `config/initializers/gatling_gun.rb`. Setup is easy, just add you SendGrid
28
27
  credentials:
29
28
 
30
- SendGrid = GatlingGun.new("USERNAME", "PASSWORD")
29
+ ```ruby
30
+ SendGrid = GatlingGun.new("USERNAME", "PASSWORD")
31
+ ```
31
32
 
32
33
  Usage
33
34
  -----
@@ -35,37 +36,45 @@ Usage
35
36
  The minimal steps to create and send a newsletter would be something like the
36
37
  following. First, you need an identity to send from:
37
38
 
38
- SendGrid.add_identity( "test", name: "Test User",
39
- email: "test@subinterest.com",
40
- address: "513 Cinnamon Dr.",
41
- city: "Edmond",
42
- state: "OK",
43
- zip: "73003",
44
- country: "USA" )
39
+ ```ruby
40
+ SendGrid.add_identity( "test", name: "Test User",
41
+ email: "test@subinterest.com",
42
+ address: "513 Cinnamon Dr.",
43
+ city: "Edmond",
44
+ state: "OK",
45
+ zip: "73003",
46
+ country: "USA" )
47
+ ```
45
48
 
46
49
  Then you can create a newsletter using that identity:
47
50
 
48
- SendGrid.add_newsletter( "episode1", identity: "test",
49
- subject: "Episode 1",
50
- text: "The Text Body",
51
- html: "<h1>The HTML Body</h1>" )
51
+ ```ruby
52
+ SendGrid.add_newsletter( "episode1", identity: "test",
53
+ subject: "Episode 1",
54
+ text: "The Text Body",
55
+ html: "<h1>The HTML Body</h1>" )
56
+ ```
52
57
 
53
58
  Next you need to create a list of recipients, add some emails to it, and attach
54
59
  that list to the newsletter:
55
60
 
56
- SendGrid.add_list("subscribers")
57
- SendGrid.add_emails( "subscribers", [ { name: "James Edward Gray II",
58
- email: "james@graysoftinc.com" },
59
- { name: "Admin",
60
- email: "admin@graysoftinc.com" } ] )
61
- SendGrid.add_recipients("episode1", "subscribers")
61
+ ```ruby
62
+ SendGrid.add_list("subscribers")
63
+ SendGrid.add_emails("subscribers", [ { name: "James Edward Gray II",
64
+ email: "james@graysoftinc.com" },
65
+ { name: "Admin",
66
+ email: "admin@graysoftinc.com" } ] )
67
+ SendGrid.add_recipients("episode1", "subscribers")
68
+ ```
62
69
 
63
70
  Of course, you could reuse identities and recipient lists for future newsletter
64
71
  messages without needing to recreate them.
65
72
 
66
73
  Finally, you can schedule when to have the message sent:
67
74
 
68
- SendGrid.add_schedule("episode1", at: Time.now + 10 * 60)
75
+ ```ruby
76
+ SendGrid.add_schedule("episode1", at: Time.now + 10 * 60)
77
+ ```
69
78
 
70
79
  That would sent it 10 minutes from now, but you can adjust the time to whenever
71
80
  you desire or even leave it out to send now.
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
- require "rubygems/package_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rdoc/task'
3
+ require 'rake/testtask'
2
4
 
3
- load(File.join(File.dirname(__FILE__), "gatling_gun.gemspec"))
4
- Gem::PackageTask.new(SPEC) do |package|
5
- # do nothing: I just need a gem but this block is required
5
+ # need some tests!
6
+ # task :default => [:test]
7
+
8
+ desc 'Create documentation'
9
+ Rake::RDocTask.new('doc') do |rdoc|
10
+ rdoc.title = "A Ruby library wrapping SendGrid's Newsletter API."
11
+ rdoc.rdoc_dir = 'docs'
12
+ rdoc.rdoc_files.include('README.markdown')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
6
14
  end
@@ -1,30 +1,18 @@
1
- DIR = File.dirname(__FILE__)
2
- LIB = File.join(DIR, *%w[lib gatling_gun.rb])
3
- VERSION = open(LIB) { |lib|
4
- lib.each { |line|
5
- if v = line[/^\s*VERSION\s*=\s*(['"])(\d\.\d\.\d)\1/, 2]
6
- break v
7
- end
8
- }
9
- }
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'gatling_gun'
10
3
 
11
- SPEC = Gem::Specification.new do |s|
12
- s.name = "gatling_gun"
13
- s.version = VERSION
14
- s.platform = Gem::Platform::RUBY
15
- s.authors = ["James Edward Gray II"]
16
- s.email = ["james@graysoftinc.com"]
17
- s.homepage = "https://github.com/okrb/gatling_gun"
4
+ Gem::Specification.new do |s|
5
+ s.name = 'gatling_gun'
6
+ s.version = GatlingGun::VERSION
7
+ s.authors = ['James Edward Gray II', 'Brian Muller']
8
+ s.email = ['bamuller@gmail.com']
9
+ s.homepage = 'https://github.com/bmuller/gatling_gun'
18
10
  s.summary = "A Ruby library wrapping SendGrid's Newsletter API."
19
- s.description = <<-END_DESCRIPTION.gsub(/\s+/, " ").strip
20
- A library for working with SendGrid's Newsletter API. The code is intended
21
- for managing and sending newletters.
22
- END_DESCRIPTION
23
-
24
- s.required_ruby_version = ">= 1.9.2"
25
- s.required_rubygems_version = ">= 1.3.7"
11
+ s.description = "A Ruby library wrapping SendGrid's Newsletter API."
26
12
 
27
13
  s.files = `git ls-files`.split("\n")
28
- # s.test_files = `git ls-files -- test/*.rb`.split("\n")
29
- s.require_paths = %w[lib]
14
+ s.require_paths = ['lib']
15
+ s.add_development_dependency('rdoc')
16
+ s.add_development_dependency('rake')
17
+ s.add_development_dependency('rubocop')
30
18
  end
@@ -1,195 +1,221 @@
1
- require "json"
2
- require "net/https"
3
- require "openssl"
4
- require "time"
5
- require "uri"
1
+ require 'json'
2
+ require 'net/https'
3
+ require 'openssl'
4
+ require 'time'
5
+ require 'uri'
6
6
 
7
- require "gatling_gun/api_call"
8
- require "gatling_gun/response"
7
+ require 'gatling_gun/api_call'
8
+ require 'gatling_gun/response'
9
9
 
10
10
  class GatlingGun
11
- VERSION = "0.0.3"
12
-
11
+ VERSION = '0.0.4'
12
+
13
13
  def initialize(api_user, api_key)
14
14
  @api_user = api_user
15
15
  @api_key = api_key
16
16
  end
17
-
17
+
18
18
  ###################
19
19
  ### Newsletters ###
20
20
  ###################
21
-
21
+
22
22
  def add_newsletter(newsletter, details)
23
- fail ArgumentError, "details must be a Hash" unless details.is_a? Hash
24
- %w[identity subject].each do |field|
25
- unless details[field.to_sym] or details[field]
23
+ fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
24
+ %w(identity subject).each do |field|
25
+ unless details[field.to_sym] || details[field]
26
26
  fail ArgumentError, "#{field} is a required detail"
27
27
  end
28
28
  end
29
- unless details[:text] or details["text"] or
30
- details[:html] or details["html"]
31
- fail ArgumentError, "either text or html must be provided as a detail"
29
+ unless details[:text] || details['text'] ||
30
+ details[:html] || details['html']
31
+ fail ArgumentError, 'either text or html must be provided as a detail'
32
32
  end
33
- make_api_call("add", details.merge(name: newsletter))
33
+ make_api_call('add', details.merge(name: newsletter))
34
34
  end
35
35
 
36
36
  def edit_newsletter(newsletter, details)
37
- fail ArgumentError, "details must be a Hash" unless details.is_a? Hash
38
- fail ArgumentError, "details cannot be empty" if details.empty?
39
- make_api_call("edit", details.merge(name: newsletter))
37
+ fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
38
+ fail ArgumentError, 'details cannot be empty' if details.empty?
39
+ make_api_call('edit', details.merge(name: newsletter))
40
40
  end
41
41
 
42
42
  def get_newsletter(newsletter)
43
- make_api_call("get", name: newsletter)
43
+ make_api_call('get', name: newsletter)
44
44
  end
45
45
 
46
46
  def list_newsletters(newsletter = nil)
47
- parameters = { }
47
+ parameters = {}
48
48
  parameters[:name] = newsletter if newsletter
49
- make_api_call("list", parameters)
49
+ make_api_call('list', parameters)
50
50
  end
51
-
51
+
52
52
  def delete_newsletter(newsletter)
53
- make_api_call("delete", name: newsletter)
53
+ make_api_call('delete', name: newsletter)
54
54
  end
55
-
55
+
56
56
  #############
57
57
  ### Lists ###
58
58
  #############
59
-
60
- def add_list(list, details = { })
61
- fail ArgumentError, "details must be a Hash" unless details.is_a? Hash
62
- make_api_call("lists/add", details.merge(list: list))
63
- end
64
-
65
- def edit_list(list, details = { })
66
- fail ArgumentError, "details must be a Hash" unless details.is_a? Hash
67
- fail ArgumentError, "details cannot be empty" if details.empty?
68
- make_api_call("lists/edit", details.merge(list: list))
69
- end
70
-
59
+
60
+ def add_list(list, details = {})
61
+ fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
62
+ make_api_call('lists/add', details.merge(list: list))
63
+ end
64
+
65
+ def edit_list(list, details = {})
66
+ fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
67
+ fail ArgumentError, 'details cannot be empty' if details.empty?
68
+ make_api_call('lists/edit', details.merge(list: list))
69
+ end
70
+
71
71
  def get_list(list = nil)
72
- parameters = { }
72
+ parameters = {}
73
73
  parameters[:list] = list if list
74
- make_api_call("lists/get", parameters)
74
+ make_api_call('lists/get', parameters)
75
75
  end
76
76
  alias_method :list_lists, :get_list
77
-
77
+
78
78
  def delete_list(list)
79
- make_api_call("lists/delete", list: list)
79
+ make_api_call('lists/delete', list: list)
80
80
  end
81
-
81
+
82
82
  ##############
83
83
  ### Emails ###
84
84
  ##############
85
-
85
+
86
86
  def add_email(list, data)
87
87
  json_data = case data
88
88
  when Hash then data.to_json
89
89
  when Array then data.map(&:to_json)
90
90
  else fail ArgumentError,
91
- "details must be a Hash or Array"
91
+ 'details must be a Hash or Array'
92
92
  end
93
- make_api_call("lists/email/add", list: list, data: json_data)
93
+ make_api_call('lists/email/add', list: list, data: json_data)
94
94
  end
95
95
  alias_method :add_emails, :add_email
96
-
96
+
97
97
  def get_email(list, emails = nil)
98
- parameters = {list: list}
98
+ parameters = { list: list }
99
99
  parameters[:email] = emails if emails
100
- make_api_call("lists/email/get", parameters)
100
+ make_api_call('lists/email/get', parameters)
101
101
  end
102
102
  alias_method :get_emails, :get_email
103
103
  alias_method :list_emails, :get_email
104
-
104
+
105
105
  def delete_email(list, emails)
106
- make_api_call("lists/email/delete", list: list, email: emails)
106
+ make_api_call('lists/email/delete', list: list, email: emails)
107
107
  end
108
108
  alias_method :delete_emails, :delete_email
109
-
109
+
110
110
  ################
111
111
  ### Identity ###
112
112
  ################
113
-
113
+
114
114
  def add_identity(identity, details)
115
- fail ArgumentError, "details must be a Hash" unless details.is_a? Hash
116
- %w[name email address city state zip country].each do |field|
117
- unless details[field.to_sym] or details[field]
115
+ fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
116
+ %w(name email address city state zip country).each do |field|
117
+ unless details[field.to_sym] || details[field]
118
118
  fail ArgumentError, "#{field} is a required detail"
119
119
  end
120
120
  end
121
- make_api_call("identity/add", details.merge(identity: identity))
121
+ make_api_call('identity/add', details.merge(identity: identity))
122
122
  end
123
-
123
+
124
124
  def edit_identity(identity, details)
125
- fail ArgumentError, "details must be a Hash" unless details.is_a? Hash
126
- fail ArgumentError, "details cannot be empty" if details.empty?
127
- make_api_call("identity/edit", details.merge(identity: identity))
125
+ fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
126
+ fail ArgumentError, 'details cannot be empty' if details.empty?
127
+ make_api_call('identity/edit', details.merge(identity: identity))
128
128
  end
129
-
129
+
130
130
  def get_identity(identity)
131
- make_api_call("identity/get", identity: identity)
131
+ make_api_call('identity/get', identity: identity)
132
132
  end
133
-
133
+
134
134
  def list_identities(identity = nil)
135
- parameters = { }
135
+ parameters = {}
136
136
  parameters[:identity] = identity if identity
137
- make_api_call("identity/list", parameters)
137
+ make_api_call('identity/list', parameters)
138
138
  end
139
-
139
+
140
140
  def delete_identity(identity)
141
- make_api_call("identity/delete", identity: identity)
141
+ make_api_call('identity/delete', identity: identity)
142
142
  end
143
-
143
+
144
144
  ##################
145
145
  ### Recipients ###
146
146
  ##################
147
-
147
+
148
148
  def add_recipient(newsletter, list)
149
- make_api_call("recipients/add", name: newsletter, list: list)
149
+ make_api_call('recipients/add', name: newsletter, list: list)
150
150
  end
151
151
  alias_method :add_recipients, :add_recipient
152
152
 
153
153
  def get_recipient(newsletter)
154
- make_api_call("recipients/get", name: newsletter)
154
+ make_api_call('recipients/get', name: newsletter)
155
155
  end
156
156
  alias_method :get_recipients, :get_recipient
157
157
  alias_method :list_recipients, :get_recipient
158
-
158
+
159
159
  def delete_recipient(newsletter, list)
160
- make_api_call("recipients/delete", name: newsletter, list: list)
160
+ make_api_call('recipients/delete', name: newsletter, list: list)
161
161
  end
162
162
  alias_method :delete_recipients, :delete_recipient
163
-
163
+
164
164
  #################
165
165
  ### Schedules ###
166
166
  #################
167
-
168
- def add_schedule(newsletter, details = { })
169
- parameters = {after: details[:after]}
170
- parameters[:at] = details[:at].iso8601.sub("T", " ") \
167
+
168
+ def add_schedule(newsletter, details = {})
169
+ parameters = { after: details[:after] }
170
+ parameters[:at] = details[:at].iso8601.sub('T', ' ') \
171
171
  if details[:at].respond_to? :iso8601
172
- if not details[:after].nil? and ( not details[:after].is_a?(Integer) or
173
- details[:after] < 1 )
174
- fail ArgumentError, "after must be a positive integer"
172
+ if !details[:after].nil? && ( !details[:after].is_a?(Integer) ||
173
+ details[:after] < 1)
174
+ fail ArgumentError, 'after must be a positive integer'
175
175
  end
176
- make_api_call("schedule/add", parameters.merge(name: newsletter))
176
+ make_api_call('schedule/add', parameters.merge(name: newsletter))
177
177
  end
178
-
178
+
179
179
  def get_schedule(newsletter)
180
- make_api_call("schedule/get", name: newsletter)
180
+ make_api_call('schedule/get', name: newsletter)
181
181
  end
182
-
182
+
183
183
  def delete_schedule(newsletter)
184
- make_api_call("schedule/delete", name: newsletter)
184
+ make_api_call('schedule/delete', name: newsletter)
185
+ end
186
+
187
+ ##################
188
+ ### Categories ###
189
+ ##################
190
+
191
+ def create_category(category)
192
+ make_api_call('category/create', category: category)
185
193
  end
186
-
194
+
195
+ def add_category(category, name)
196
+ make_api_call('category/add', category: category, name: name)
197
+ end
198
+
199
+ def remove_category(name, category = nil)
200
+ parameters = { name: name }
201
+ parameters[:category] = category if category
202
+ make_api_call('category/remove', parameters)
203
+ end
204
+
205
+ def list_categories(category = nil)
206
+ parameters = {}
207
+ parameters[:category] = category if category
208
+ make_api_call('category/list', parameters)
209
+ end
210
+
187
211
  #######
212
+
188
213
  private
214
+
189
215
  #######
190
-
191
- def make_api_call(action, parameters = { })
192
- ApiCall.new( action, parameters.merge( api_user: @api_user,
193
- api_key: @api_key ) ).response
216
+
217
+ def make_api_call(action, parameters = {})
218
+ ApiCall.new(action, parameters.merge(api_user: @api_user,
219
+ api_key: @api_key)).response
194
220
  end
195
221
  end