Class: GatlingGun

Inherits:
Object
  • Object
show all
Defined in:
lib/gatling_gun.rb,
lib/gatling_gun/api_call.rb,
lib/gatling_gun/response.rb

Defined Under Namespace

Classes: ApiCall, Response

Constant Summary collapse

VERSION =
'0.0.4'

Instance Method Summary collapse

Constructor Details

#initialize(api_user, api_key) ⇒ GatlingGun

Returns a new instance of GatlingGun.



13
14
15
16
# File 'lib/gatling_gun.rb', line 13

def initialize(api_user, api_key)
  @api_user = api_user
  @api_key  = api_key
end

Instance Method Details

#add_category(category, name) ⇒ Object



195
196
197
# File 'lib/gatling_gun.rb', line 195

def add_category(category, name)
  make_api_call('category/add', category: category, name: name)
end

#add_email(list, data) ⇒ Object Also known as: add_emails

Emails ###



86
87
88
89
90
91
92
93
94
# File 'lib/gatling_gun.rb', line 86

def add_email(list, data)
  json_data = case data
              when Hash  then data.to_json
              when Array then data.map(&:to_json)
              else            fail ArgumentError,
                                   'details must be a Hash or Array'
              end
  make_api_call('lists/email/add', list: list, data: json_data)
end

#add_identity(identity, details) ⇒ Object

Identity ###



114
115
116
117
118
119
120
121
122
# File 'lib/gatling_gun.rb', line 114

def add_identity(identity, details)
  fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
  %w(name email address city state zip country).each do |field|
    unless details[field.to_sym] || details[field]
      fail ArgumentError, "#{field} is a required detail"
    end
  end
  make_api_call('identity/add', details.merge(identity: identity))
end

#add_list(list, details = {}) ⇒ Object

Lists ###



60
61
62
63
# File 'lib/gatling_gun.rb', line 60

def add_list(list, details = {})
  fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
  make_api_call('lists/add', details.merge(list: list))
end

#add_newsletter(newsletter, details) ⇒ Object

Newsletters ###



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gatling_gun.rb', line 22

def add_newsletter(newsletter, details)
  fail ArgumentError, 'details must be a Hash' unless details.is_a? Hash
  %w(identity subject).each do |field|
    unless details[field.to_sym] || details[field]
      fail ArgumentError, "#{field} is a required detail"
    end
  end
  unless details[:text] || details['text'] ||
         details[:html] || details['html']
    fail ArgumentError, 'either text or html must be provided as a detail'
  end
  make_api_call('add', details.merge(name: newsletter))
end

#add_recipient(newsletter, list) ⇒ Object Also known as: add_recipients

Recipients ###



148
149
150
# File 'lib/gatling_gun.rb', line 148

def add_recipient(newsletter, list)
  make_api_call('recipients/add', name: newsletter, list: list)
end

#add_schedule(newsletter, details = {}) ⇒ Object

Schedules ###



168
169
170
171
172
173
174
175
176
177
# File 'lib/gatling_gun.rb', line 168

def add_schedule(newsletter, details = {})
  parameters      = { after: details[:after] }
  parameters[:at] = details[:at].iso8601.sub('T', ' ') \
    if details[:at].respond_to? :iso8601
  if !details[:after].nil? && ( !details[:after].is_a?(Integer) ||
                                    details[:after] < 1)
    fail ArgumentError, 'after must be a positive integer'
  end
  make_api_call('schedule/add', parameters.merge(name: newsletter))
end

#create_category(category) ⇒ Object

Categories ###



191
192
193
# File 'lib/gatling_gun.rb', line 191

def create_category(category)
  make_api_call('category/create', category: category)
end

#delete_email(list, emails) ⇒ Object Also known as: delete_emails



105
106
107
# File 'lib/gatling_gun.rb', line 105

def delete_email(list, emails)
  make_api_call('lists/email/delete', list: list, email: emails)
end

#delete_identity(identity) ⇒ Object



140
141
142
# File 'lib/gatling_gun.rb', line 140

def delete_identity(identity)
  make_api_call('identity/delete', identity: identity)
end

#delete_list(list) ⇒ Object



78
79
80
# File 'lib/gatling_gun.rb', line 78

def delete_list(list)
  make_api_call('lists/delete', list: list)
end

#delete_newsletter(newsletter) ⇒ Object



52
53
54
# File 'lib/gatling_gun.rb', line 52

def delete_newsletter(newsletter)
  make_api_call('delete', name: newsletter)
end

#delete_recipient(newsletter, list) ⇒ Object Also known as: delete_recipients



159
160
161
# File 'lib/gatling_gun.rb', line 159

def delete_recipient(newsletter, list)
  make_api_call('recipients/delete', name: newsletter, list: list)
end

#delete_schedule(newsletter) ⇒ Object



183
184
185
# File 'lib/gatling_gun.rb', line 183

def delete_schedule(newsletter)
  make_api_call('schedule/delete', name: newsletter)
end

#edit_identity(identity, details) ⇒ Object



124
125
126
127
128
# File 'lib/gatling_gun.rb', line 124

def edit_identity(identity, details)
  fail ArgumentError, 'details must be a Hash'  unless details.is_a? Hash
  fail ArgumentError, 'details cannot be empty' if     details.empty?
  make_api_call('identity/edit', details.merge(identity: identity))
end

#edit_list(list, details = {}) ⇒ Object



65
66
67
68
69
# File 'lib/gatling_gun.rb', line 65

def edit_list(list, details = {})
  fail ArgumentError, 'details must be a Hash'  unless details.is_a? Hash
  fail ArgumentError, 'details cannot be empty' if     details.empty?
  make_api_call('lists/edit', details.merge(list: list))
end

#edit_newsletter(newsletter, details) ⇒ Object



36
37
38
39
40
# File 'lib/gatling_gun.rb', line 36

def edit_newsletter(newsletter, details)
  fail ArgumentError, 'details must be a Hash'  unless details.is_a? Hash
  fail ArgumentError, 'details cannot be empty' if     details.empty?
  make_api_call('edit', details.merge(name: newsletter))
end

#get_email(list, emails = nil) ⇒ Object Also known as: get_emails, list_emails



97
98
99
100
101
# File 'lib/gatling_gun.rb', line 97

def get_email(list, emails = nil)
  parameters         = { list: list }
  parameters[:email] = emails if emails
  make_api_call('lists/email/get', parameters)
end

#get_identity(identity) ⇒ Object



130
131
132
# File 'lib/gatling_gun.rb', line 130

def get_identity(identity)
  make_api_call('identity/get', identity: identity)
end

#get_list(list = nil) ⇒ Object Also known as: list_lists



71
72
73
74
75
# File 'lib/gatling_gun.rb', line 71

def get_list(list = nil)
  parameters        = {}
  parameters[:list] = list if list
  make_api_call('lists/get', parameters)
end

#get_newsletter(newsletter) ⇒ Object



42
43
44
# File 'lib/gatling_gun.rb', line 42

def get_newsletter(newsletter)
  make_api_call('get', name: newsletter)
end

#get_recipient(newsletter) ⇒ Object Also known as: get_recipients, list_recipients



153
154
155
# File 'lib/gatling_gun.rb', line 153

def get_recipient(newsletter)
  make_api_call('recipients/get', name: newsletter)
end

#get_schedule(newsletter) ⇒ Object



179
180
181
# File 'lib/gatling_gun.rb', line 179

def get_schedule(newsletter)
  make_api_call('schedule/get', name: newsletter)
end

#list_categories(category = nil) ⇒ Object



205
206
207
208
209
# File 'lib/gatling_gun.rb', line 205

def list_categories(category = nil)
  parameters = {}
  parameters[:category] = category if category
  make_api_call('category/list', parameters)
end

#list_identities(identity = nil) ⇒ Object



134
135
136
137
138
# File 'lib/gatling_gun.rb', line 134

def list_identities(identity = nil)
  parameters            = {}
  parameters[:identity] = identity if identity
  make_api_call('identity/list', parameters)
end

#list_newsletters(newsletter = nil) ⇒ Object



46
47
48
49
50
# File 'lib/gatling_gun.rb', line 46

def list_newsletters(newsletter = nil)
  parameters        = {}
  parameters[:name] = newsletter if newsletter
  make_api_call('list', parameters)
end

#remove_category(name, category = nil) ⇒ Object



199
200
201
202
203
# File 'lib/gatling_gun.rb', line 199

def remove_category(name, category = nil)
  parameters = { name: name }
  parameters[:category] = category if category
  make_api_call('category/remove', parameters)
end