pew_pew 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +22 -0
  6. data/README.md +84 -0
  7. data/Rakefile +3 -0
  8. data/lib/pew_pew.rb +32 -0
  9. data/lib/pew_pew/client.rb +90 -0
  10. data/lib/pew_pew/config.rb +15 -0
  11. data/lib/pew_pew/domain.rb +9 -0
  12. data/lib/pew_pew/resource.rb +52 -0
  13. data/lib/pew_pew/resources/bounces.rb +41 -0
  14. data/lib/pew_pew/resources/campaigns.rb +141 -0
  15. data/lib/pew_pew/resources/complaints.rb +40 -0
  16. data/lib/pew_pew/resources/lists.rb +121 -0
  17. data/lib/pew_pew/resources/logs.rb +12 -0
  18. data/lib/pew_pew/resources/mailboxes.rb +41 -0
  19. data/lib/pew_pew/resources/messages.rb +37 -0
  20. data/lib/pew_pew/resources/routes.rb +57 -0
  21. data/lib/pew_pew/resources/stats.rb +12 -0
  22. data/lib/pew_pew/resources/unsubscribes.rb +43 -0
  23. data/lib/pew_pew/response.rb +11 -0
  24. data/lib/pew_pew/version.rb +3 -0
  25. data/pew_pew.gemspec +20 -0
  26. data/spec/fixtures/bounces.yml +144 -0
  27. data/spec/fixtures/campaigns.yml +368 -0
  28. data/spec/fixtures/complaints.yml +142 -0
  29. data/spec/fixtures/image.png +0 -0
  30. data/spec/fixtures/lists.yml +403 -0
  31. data/spec/fixtures/logs.yml +133 -0
  32. data/spec/fixtures/mailboxes.yml +141 -0
  33. data/spec/fixtures/messages.yml +196 -0
  34. data/spec/fixtures/mime.eml +34 -0
  35. data/spec/fixtures/routes.yml +225 -0
  36. data/spec/fixtures/stats.yml +61 -0
  37. data/spec/fixtures/unsubscribes.yml +219 -0
  38. data/spec/pew_pew/client_spec.rb +51 -0
  39. data/spec/pew_pew/config_spec.rb +38 -0
  40. data/spec/pew_pew/resource_spec.rb +46 -0
  41. data/spec/pew_pew/resources/bounces_spec.rb +78 -0
  42. data/spec/pew_pew/resources/campaigns_spec.rb +228 -0
  43. data/spec/pew_pew/resources/complaints_spec.rb +69 -0
  44. data/spec/pew_pew/resources/lists_spec.rb +283 -0
  45. data/spec/pew_pew/resources/logs_spec.rb +28 -0
  46. data/spec/pew_pew/resources/mailboxes_spec.rb +59 -0
  47. data/spec/pew_pew/resources/messages_spec.rb +53 -0
  48. data/spec/pew_pew/resources/routes_spec.rb +135 -0
  49. data/spec/pew_pew/resources/stats_spec.rb +26 -0
  50. data/spec/pew_pew/resources/unsubscribes_spec.rb +99 -0
  51. data/spec/pew_pew/response_spec.rb +21 -0
  52. data/spec/pew_pew_spec.rb +13 -0
  53. data/spec/spec_helper.rb +17 -0
  54. data/spec/support/contexts/api_requests.rb +23 -0
  55. data/spec/support/contexts/domain_resource.rb +17 -0
  56. data/spec/support/vcr.rb +6 -0
  57. metadata +211 -0
@@ -0,0 +1,40 @@
1
+ module PewPew
2
+ module Resources
3
+ class Complaints
4
+ include Resource
5
+ include Domain
6
+
7
+ # Fetches all spam complaints.
8
+ #
9
+ # @return [Mash] the response body
10
+ def all
11
+ get("#{domain}/complaints")
12
+ end
13
+
14
+ # Fetch all spam complaints by address.
15
+ #
16
+ # @param address [String] the address to fetch spam complaints for
17
+ # @return [Mash] the response body
18
+ def find(address)
19
+ get("#{domain}/complaints/#{address}")
20
+ end
21
+
22
+ # Creates a new spam complaint.
23
+ #
24
+ # @option params [String] :address the email address to add
25
+ # @return [Mash] the response body
26
+ def create(params)
27
+ post("#{domain}/complaints", params)
28
+ end
29
+
30
+ # Removes existing spam complaints.
31
+ #
32
+ # @param address_or_id [String] the address to remove all the spam
33
+ # complaints for
34
+ # @return [Mash] the response body
35
+ def remove(address_or_id)
36
+ delete("#{domain}/complaints/#{address_or_id}")
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,121 @@
1
+ require 'json'
2
+
3
+ module PewPew
4
+ module Resources
5
+ class Lists
6
+ include Resource
7
+
8
+ # Fetches all defined mailing lists.
9
+ #
10
+ # @return [Mash] the response body
11
+ def all
12
+ get('lists')
13
+ end
14
+
15
+ # Fetch a mailing list by email address.
16
+ #
17
+ # @param address [String] the email address of the mailing list to fetch
18
+ # @return [Mash] the response body
19
+ def find(address)
20
+ get("lists/#{address}")
21
+ end
22
+
23
+ # Creates a new mailing list.
24
+ #
25
+ # @option params [String] :description optional list description
26
+ # @option params [String] :name optional mailing list name
27
+ # @option params [String] :address email address for the mailing list
28
+ # @return [Mash] the response body
29
+ def create(params)
30
+ post('lists', params)
31
+ end
32
+
33
+ # Updates an existing mailing list by email address.
34
+ #
35
+ # @param address [String] the email address of the mailing list to update
36
+ # @option params [String] :description optional list description
37
+ # @option params [String] :name optional mailing list name
38
+ # @option params [String] :address email address for the mailing list
39
+ # @return [Mash] the response body
40
+ def update(address, params)
41
+ put("lists/#{address}", params)
42
+ end
43
+
44
+ # Removes an existing mailing list by email address.
45
+ #
46
+ # @param address [String] the email address of the mailing list to remove
47
+ # @return [Mash] the response body
48
+ def remove(address)
49
+ delete("lists/#{address}")
50
+ end
51
+
52
+ # Fetches a summary of the results for a given mailing list, like numbers
53
+ # of clicks, opens, etc. Includes unique numbers (e.g. number of unique
54
+ # recipients who clicked) as well.
55
+ #
56
+ # @param address [String] the email address of the mailing list to fetch
57
+ # @return [Mash] the response body
58
+ def stats(address)
59
+ get("lists/#{address}/stats")
60
+ end
61
+
62
+ # Fetches all defined mailing list members.
63
+ #
64
+ # @param address [String] the email address of the mailing list
65
+ # @return [Mash] the response body
66
+ def all_members(address)
67
+ get("lists/#{address}/members")
68
+ end
69
+
70
+ # Fetch a mailing list member by email address.
71
+ #
72
+ # @param address [String] the email address of the mailing list
73
+ # @param member_address [String] the email address of the member to fetch
74
+ # @return [Mash] the response body
75
+ def find_member(address, member_address)
76
+ get("lists/#{address}/members/#{member_address}")
77
+ end
78
+
79
+ # Adds a new member to a mailing list.
80
+ #
81
+ # @param address [String] the email address of the mailing list
82
+ # @option params [String] :address the email address of the member
83
+ # @option params [String] :name optional member name
84
+ # @option params [Hash] :vars optional dictionary of arbitrary member
85
+ # parameters (will be encoded as JSON)
86
+ # @option params [Boolean] :subscribed if false, add the member as
87
+ # unsubscribed
88
+ # @option params [Boolean] :upsert if true, update an existing member
89
+ # instead of returning an error
90
+ # @return [Mash] the response body
91
+ def create_member(address, params)
92
+ params[:vars] = params[:vars].to_json
93
+ post("lists/#{address}/members", params)
94
+ end
95
+
96
+ # Updates an existing mailing list member by email address.
97
+ #
98
+ # @param address [String] the email address of the mailing list
99
+ # @param member_address [String] the email address of the member to update
100
+ # @option params [String] :address the email address of the member
101
+ # @option params [String] :name optional member name
102
+ # @option params [Hash] :vars optional dictionary of arbitrary member
103
+ # parameters (will be encoded as JSON)
104
+ # @option params [Boolean] :subscribed if false, add the member as
105
+ # unsubscribed
106
+ # @return [Mash] the response body
107
+ def update_member(address, member_address, params)
108
+ put("lists/#{address}/members/#{member_address}", params)
109
+ end
110
+
111
+ # Removes an existing mailing list member by email address.
112
+ #
113
+ # @param address [String] the email address of the mailing list
114
+ # @param member_address [String] the email address of the member to remove
115
+ # @return [Mash] the response body
116
+ def remove_member(address, member_address)
117
+ delete("lists/#{address}/members/#{member_address}")
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,12 @@
1
+ module PewPew
2
+ module Resources
3
+ class Logs
4
+ include Resource
5
+ include Domain
6
+
7
+ def all
8
+ get("#{domain}/log")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,41 @@
1
+ module PewPew
2
+ module Resources
3
+ class Mailboxes
4
+ include Resource
5
+ include Domain
6
+
7
+ # Fetches all defined mailboxes.
8
+ #
9
+ # @return [Mash] the response body
10
+ def all
11
+ get("#{domain}/mailboxes")
12
+ end
13
+
14
+ # Creates a new mailbox.
15
+ #
16
+ # @option params [String] :mailbox the name of the mailbox
17
+ # @option params [String] :password the mailbox password
18
+ # @return [Mash] the response body
19
+ def create(params)
20
+ post("#{domain}/mailboxes", params)
21
+ end
22
+
23
+ # Updates an existing mailbox by mailbox name.
24
+ #
25
+ # @param mailbox [String] the name of the mailbox to be updated
26
+ # @option params [String] :password the mailbox password
27
+ # @return [Mash] the response body
28
+ def update(mailbox, params)
29
+ put("#{domain}/mailboxes/#{mailbox}", params)
30
+ end
31
+
32
+ # Removes an existing mailbox by mailbox name.
33
+ #
34
+ # @param mailbox [String] the name of the mailbox to be deleted
35
+ # @return [Mash] the response body
36
+ def remove(mailbox)
37
+ delete("#{domain}/mailboxes/#{mailbox}")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ module PewPew
2
+ module Resources
3
+ class Messages
4
+ include Resource
5
+ include Domain
6
+
7
+ # Sends an email.
8
+ #
9
+ # @option params [String] :from email address to use for the `From` header
10
+ # @option params [String, Array<String>] :to recipient or list of
11
+ # recipient email addresses
12
+ # @option params [String] :cc same as `:to`, but for CC
13
+ # @option params [String] :bcc same as `:to`, but for BCC
14
+ # @option params [String] :subject message subject
15
+ # @option params [String] :text text version of the message body
16
+ # @option params [String] :html HTML version of the message body
17
+ # @option params [File, Array<File>] :attachment file attachments
18
+ # @option params [File, Array<File>] :inline inline file attachments
19
+ # @return [Mash] the response body
20
+ def send_email(params)
21
+ post("#{domain}/messages", params)
22
+ end
23
+
24
+ # Sends a MIME email.
25
+ #
26
+ # @option params [String, Array<String>] :to recipient or list of
27
+ # recipient email addresses
28
+ # @option params [File] :message file containing the full MIME content
29
+ # of the message
30
+ # @return [Mash] the response body
31
+ def send_mime(params)
32
+ headers = { content_type: 'multipart/form-data' }
33
+ post("#{domain}/messages.mime", params, headers)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,57 @@
1
+ module PewPew
2
+ module Resources
3
+ class Routes
4
+ include Resource
5
+
6
+ # Fetches all defined routes.
7
+ #
8
+ # @return [Mash] the response body
9
+ def all
10
+ get('routes')
11
+ end
12
+
13
+ # Fetch a route by ID.
14
+ #
15
+ # @param id [String] the ID of the route to be fetched
16
+ # @return [Mash] the response body
17
+ def find(id)
18
+ get("routes/#{id}")
19
+ end
20
+
21
+ # Creates a new route.
22
+ #
23
+ # @option params [Fixnum] :priority smaller number indicates higher
24
+ # priority; higher priority routes are handled first; Defaults to 0
25
+ # @option params [String] :description arbitrary description of the route
26
+ # @option params [String] :expression the filter expression
27
+ # @option params [String, Array<String>] :action the route action(s) to
28
+ # be executed when the expression evaluates to true
29
+ # @return [Mash] the response body
30
+ def create(params)
31
+ post('routes', params)
32
+ end
33
+
34
+ # Updates an existing route by ID.
35
+ #
36
+ # @param id [String] the ID of the route to be updated
37
+ # @option params [Fixnum] :priority smaller number indicates higher
38
+ # priority; higher priority routes are handled first; Defaults to 0
39
+ # @option params [String] :description arbitrary description of the route
40
+ # @option params [String] :expression the filter expression
41
+ # @option params [String, Array<String>] :action the route action(s) to
42
+ # be executed when the expression evaluates to true
43
+ # @return [Mash] the response body
44
+ def update(id, params)
45
+ put("routes/#{id}", params)
46
+ end
47
+
48
+ # Removes an existing route by ID.
49
+ #
50
+ # @param id [String] the ID of the route to be deleted
51
+ # @return [Mash] the response body
52
+ def remove(id)
53
+ delete("routes/#{id}")
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ module PewPew
2
+ module Resources
3
+ class Stats
4
+ include Resource
5
+ include Domain
6
+
7
+ def all
8
+ get("#{domain}/stats")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module PewPew
2
+ module Resources
3
+ class Unsubscribes
4
+ include Resource
5
+ include Domain
6
+
7
+ # Fetches all unsubscribe events.
8
+ #
9
+ # @return [Mash] the response body
10
+ def all
11
+ get("#{domain}/unsubscribes")
12
+ end
13
+
14
+ # Fetch all unsubscribe events by address.
15
+ #
16
+ # @param address [String] the address to fetch unsubscribe events for
17
+ # @return [Mash] the response body
18
+ def find(address)
19
+ get("#{domain}/unsubscribes/#{address}")
20
+ end
21
+
22
+ # Creates a new unsubscribe event.
23
+ #
24
+ # @option params [String] :address the email address to unsubscribe
25
+ # @option params [String] :tag optional tag to unsubscribe from (defaults
26
+ # to unsubscribing the address completely from the domain)
27
+ # @return [Mash] the response body
28
+ def create(params)
29
+ params[:tag] ||= '*'
30
+ post("#{domain}/unsubscribes", params)
31
+ end
32
+
33
+ # Removes existing unsubscribe events.
34
+ #
35
+ # @param address_or_id [String] the address to remove all the unsubscribe
36
+ # events for, or a single unsubscribe event ID to remove
37
+ # @return [Mash] the response body
38
+ def remove(address_or_id)
39
+ delete("#{domain}/unsubscribes/#{address_or_id}")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ require 'hashie'
2
+
3
+ module PewPew
4
+ class Response < Hashie::Mash
5
+ undef :count
6
+
7
+ def success?
8
+ status == 200
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module PewPew
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,20 @@
1
+ require './lib/pew_pew/version'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'pew_pew'
5
+ gem.version = PewPew::VERSION
6
+ gem.summary = 'A Ruby client library for using the Mailgun web service.'
7
+ gem.homepage = 'http://github.com/tylerhunt/pew_pew'
8
+ gem.author = 'Tyler Hunt'
9
+
10
+ gem.add_dependency 'faraday_middleware', '~> 0.8.0'
11
+ gem.add_dependency 'hashie', '~> 1.1'
12
+ gem.add_dependency 'relax', '~> 0.2.0'
13
+ gem.add_development_dependency 'rspec', '~> 2.6'
14
+ gem.add_development_dependency 'vcr', '~> 2.2'
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+ end
@@ -0,0 +1,144 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.mailgun.net/v2/<%= domain %>/bounces
6
+ body:
7
+ encoding: US-ASCII
8
+ string: address=test%40example.com&code=554&error=Relay+access+denied
9
+ headers:
10
+ User-Agent:
11
+ - PewPew Ruby Gem 0.0.1
12
+ Authorization:
13
+ - Basic <%= basic_auth %>
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx/1.0.14
23
+ date:
24
+ - Sat, 02 Jun 2012 07:24:08 GMT
25
+ content-type:
26
+ - application/json
27
+ connection:
28
+ - close
29
+ content-length:
30
+ - '96'
31
+ content-disposition:
32
+ - inline
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! "{\n \"message\": \"Address has been added to the bounces table\",
36
+ \n \"address\": \"test@example.com\"\n}"
37
+ http_version:
38
+ recorded_at: Sat, 02 Jun 2012 07:24:08 GMT
39
+ - request:
40
+ method: get
41
+ uri: https://api.mailgun.net/v2/<%= domain %>/bounces/test@example.com
42
+ body:
43
+ encoding: US-ASCII
44
+ string: ''
45
+ headers:
46
+ User-Agent:
47
+ - PewPew Ruby Gem 0.0.1
48
+ Authorization:
49
+ - Basic <%= basic_auth %>
50
+ response:
51
+ status:
52
+ code: 200
53
+ message:
54
+ headers:
55
+ server:
56
+ - nginx/1.0.14
57
+ date:
58
+ - Sat, 02 Jun 2012 07:24:33 GMT
59
+ content-type:
60
+ - application/json
61
+ connection:
62
+ - close
63
+ content-length:
64
+ - '161'
65
+ content-disposition:
66
+ - inline
67
+ body:
68
+ encoding: US-ASCII
69
+ string: ! "{\n \"bounce\": {\n \"code\": \"554\",\n \"created_at\": \"Sat,
70
+ 02 Jun 2012 07:24:08 GMT\",\n \"error\": \"Relay access denied\",\n \"address\":
71
+ \"test@example.com\"\n }\n}"
72
+ http_version:
73
+ recorded_at: Sat, 02 Jun 2012 07:24:33 GMT
74
+ - request:
75
+ method: get
76
+ uri: https://api.mailgun.net/v2/<%= domain %>/bounces
77
+ body:
78
+ encoding: US-ASCII
79
+ string: ''
80
+ headers:
81
+ User-Agent:
82
+ - PewPew Ruby Gem 0.0.1
83
+ Authorization:
84
+ - Basic <%= basic_auth %>
85
+ response:
86
+ status:
87
+ code: 200
88
+ message:
89
+ headers:
90
+ server:
91
+ - nginx/1.0.14
92
+ date:
93
+ - Sat, 02 Jun 2012 07:25:45 GMT
94
+ content-type:
95
+ - application/json
96
+ connection:
97
+ - close
98
+ content-length:
99
+ - '200'
100
+ content-disposition:
101
+ - inline
102
+ body:
103
+ encoding: US-ASCII
104
+ string: ! "{\n \"total_count\": 1,\n \"items\": [\n {\n \"code\":
105
+ \"554\",\n \"created_at\": \"Sat, 02 Jun 2012 07:24:08 GMT\",\n \"error\":
106
+ \"Relay access denied\",\n \"address\": \"test@example.com\"\n }\n
107
+ \ ]\n}"
108
+ http_version:
109
+ recorded_at: Sat, 02 Jun 2012 07:25:45 GMT
110
+ - request:
111
+ method: delete
112
+ uri: https://api.mailgun.net/v2/<%= domain %>/bounces/test@example.com
113
+ body:
114
+ encoding: US-ASCII
115
+ string: ''
116
+ headers:
117
+ User-Agent:
118
+ - PewPew Ruby Gem 0.0.1
119
+ Authorization:
120
+ - Basic <%= basic_auth %>
121
+ response:
122
+ status:
123
+ code: 200
124
+ message:
125
+ headers:
126
+ server:
127
+ - nginx/1.0.14
128
+ date:
129
+ - Sat, 02 Jun 2012 07:26:15 GMT
130
+ content-type:
131
+ - application/json
132
+ connection:
133
+ - close
134
+ content-length:
135
+ - '85'
136
+ content-disposition:
137
+ - inline
138
+ body:
139
+ encoding: US-ASCII
140
+ string: ! "{\n \"message\": \"Bounced address has been removed\", \n \"address\":
141
+ \"test@example.com\"\n}"
142
+ http_version:
143
+ recorded_at: Sat, 02 Jun 2012 07:26:15 GMT
144
+ recorded_with: VCR 2.2.0