simple_spark 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +123 -1
- data/lib/simple_spark/client.rb +22 -4
- data/lib/simple_spark/endpoints/inbound_domains.rb +4 -4
- data/lib/simple_spark/endpoints/message_events.rb +2 -2
- data/lib/simple_spark/endpoints/metrics.rb +86 -0
- data/lib/simple_spark/endpoints/relay_webhooks.rb +5 -5
- data/lib/simple_spark/endpoints/sending_domains.rb +6 -6
- data/lib/simple_spark/endpoints/subaccounts.rb +50 -0
- data/lib/simple_spark/endpoints/templates.rb +6 -6
- data/lib/simple_spark/endpoints/transmissions.rb +2 -2
- data/lib/simple_spark/endpoints/webhooks.rb +8 -8
- data/lib/simple_spark/version.rb +1 -1
- data/lib/simple_spark.rb +2 -0
- data/spec/simple_spark/client_spec.rb +41 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd347b4dc4e50f6b0ee4b2d8679bbad9f70cc6c5
|
4
|
+
data.tar.gz: 4c1c0584b9bb8fd021823a57ceac610e26815797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd54320ae089dad8d23a9b8ead92bab3fe8475bef7d4d8e0d2822b0e5203a288ad223de4ab2b27b6dfc7bb88a239e9fec179d7e4cc252ff04a8d166c76ecc70a
|
7
|
+
data.tar.gz: 8ffdad3040e019cde03055e5dd2da7cc4d0160e94aaa0304744a86113d2884619c7561e4d40519bd3a51438dca437f79cbcf105a2bc51c36d14103028bcd8ccf
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SimpleSpark
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/leadmachineapp/simple_spark.png?branch=master)](https://travis-ci.org/leadmachineapp/simple_spark)
|
3
|
+
[![Build Status](https://travis-ci.org/leadmachineapp/simple_spark.png?branch=master)](https://travis-ci.org/leadmachineapp/simple_spark) [![Gem Version](https://badge.fury.io/rb/simple_spark.svg)](https://badge.fury.io/rb/simple_spark)
|
4
4
|
|
5
5
|
This gem is an alternative to the [official Ruby gem](https://github.com/SparkPost/ruby-sparkpost) provided by [SparkPost](http://www.sparkpost.com)
|
6
6
|
|
@@ -86,6 +86,78 @@ Should you have any need to override the headers that are sent by default, then
|
|
86
86
|
simple_spark = SimpleSpark::Client.new(api_key: 'your_api_key', headers: { 'NewSparkpostHeader' => 'hello'})
|
87
87
|
```
|
88
88
|
|
89
|
+
|
90
|
+
### Metrics
|
91
|
+
|
92
|
+
#### Discoverability Links
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
simple_spark.metrics.discoverability_links
|
96
|
+
```
|
97
|
+
|
98
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/metrics-discoverability-links" target="_blank">see SparkPost API Documentation</a>
|
99
|
+
|
100
|
+
#### Deliverability Metrics Summary
|
101
|
+
|
102
|
+
Summary of metrics
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
simple_spark.metrics.deliverability_metrics_summary(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
106
|
+
```
|
107
|
+
|
108
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/discoverability-links/deliverability-metrics-summary" target="_blank">see SparkPost API Documentation</a>
|
109
|
+
|
110
|
+
#### Deliverability Metrics by Domain
|
111
|
+
|
112
|
+
Metrics grouped by Domain
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
simple_spark.metrics.deliverability_metrics_by_domain(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
116
|
+
```
|
117
|
+
|
118
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-domain" target="_blank">see SparkPost API Documentation</a>
|
119
|
+
|
120
|
+
#### Deliverability Metrics by Sending Domain
|
121
|
+
|
122
|
+
Metrics grouped by Sending Domain
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
simple_spark.metrics.deliverability_metrics_by_sending_domain(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
126
|
+
```
|
127
|
+
|
128
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-sending-domain" target="_blank">see SparkPost API Documentation</a>
|
129
|
+
|
130
|
+
#### Deliverability Metrics by Subaccount
|
131
|
+
|
132
|
+
Metrics grouped by Subaccount
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
simple_spark.metrics.deliverability_metrics_by_subaccount(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
136
|
+
```
|
137
|
+
|
138
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-subaccount" target="_blank">see SparkPost API Documentation</a>
|
139
|
+
|
140
|
+
#### Deliverability Metrics by Campaign
|
141
|
+
|
142
|
+
Metrics grouped by Campaign
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
simple_spark.metrics.deliverability_metrics_by_campaign(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
146
|
+
```
|
147
|
+
|
148
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-campaign" target="_blank">see SparkPost API Documentation</a>
|
149
|
+
|
150
|
+
#### Deliverability Metrics by Template
|
151
|
+
|
152
|
+
Metrics grouped by Template
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
simple_spark.metrics.deliverability_metrics_by_template(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
156
|
+
```
|
157
|
+
|
158
|
+
<a href="https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-template" target="_blank">see SparkPost API Documentation</a>
|
159
|
+
|
160
|
+
|
89
161
|
### Transmissions
|
90
162
|
|
91
163
|
#### List
|
@@ -153,6 +225,51 @@ simple_spark.transmissions.create(properties)
|
|
153
225
|
|
154
226
|
<a href="https://developers.sparkpost.com/api/#/reference/transmissions/create" target="_blank">see SparkPost API Documentation</a>
|
155
227
|
|
228
|
+
|
229
|
+
### Subaccounts
|
230
|
+
|
231
|
+
#### List
|
232
|
+
|
233
|
+
List all Subaccounts
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
simple_spark.subaccounts.list
|
237
|
+
```
|
238
|
+
|
239
|
+
<a href="https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-collection/list-subaccounts" target="_blank">see SparkPost API Documentation</a>
|
240
|
+
|
241
|
+
#### Create
|
242
|
+
|
243
|
+
Create a new Subaccount
|
244
|
+
|
245
|
+
```ruby
|
246
|
+
simple_spark.subaccounts.create({ "name": "Sparkle Ponies", "key_label": "API Key for Sparkle Ponies Subaccount", "key_grants": ["smtp/inject", "sending_domains/manage", "message_events/view", "suppression_lists/manage"] })
|
247
|
+
```
|
248
|
+
|
249
|
+
<a href="hhttps://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-collection/create-new-subaccount" target="_blank">see SparkPost API Documentation</a>
|
250
|
+
|
251
|
+
#### Retrieve
|
252
|
+
|
253
|
+
Retrieves a Subaccount by its id
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
simple_spark.subaccounts.retrieve(123)
|
257
|
+
```
|
258
|
+
|
259
|
+
<a href="https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-entity/list-specific-subaccount" target="_blank">see SparkPost API Documentation</a>
|
260
|
+
|
261
|
+
#### Update
|
262
|
+
|
263
|
+
Updates a Subaccount with new values
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
properties = { name: "new name" }
|
267
|
+
simple_spark.subaccounts.update('mail.mydomain.com', properties)
|
268
|
+
```
|
269
|
+
|
270
|
+
<a href="https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-entity/edit-a-subaccount" target="_blank">see SparkPost API Documentation</a>
|
271
|
+
|
272
|
+
|
156
273
|
### Messsage Events
|
157
274
|
|
158
275
|
#### Samples
|
@@ -509,6 +626,11 @@ simple_spark.templates.delete(yourtemplateid)
|
|
509
626
|
|
510
627
|
## Changelog
|
511
628
|
|
629
|
+
### 0.0.5
|
630
|
+
|
631
|
+
- Subaccounts endpoint added
|
632
|
+
- Metrics main endpoints added
|
633
|
+
|
512
634
|
### 0.0.4
|
513
635
|
|
514
636
|
- Merged pull request to fix Rails development check for debug
|
data/lib/simple_spark/client.rb
CHANGED
@@ -23,7 +23,13 @@ module SimpleSpark
|
|
23
23
|
@session = Excon.new(@api_host, debug: @debug)
|
24
24
|
end
|
25
25
|
|
26
|
-
def call(
|
26
|
+
def call(opts)
|
27
|
+
method = opts[:method]
|
28
|
+
path = opts[:path]
|
29
|
+
body_values = opts[:body_values] || {}
|
30
|
+
query_params = opts[:query_values] || {}
|
31
|
+
extract_results = opts[:extract_results].nil? ? true : opts[:extract_results]
|
32
|
+
|
27
33
|
fail Exceptions::InvalidConfiguration.new(method: method), 'Only GET, POST, PUT and DELETE are supported' unless [:get, :post, :put, :delete].include?(method)
|
28
34
|
|
29
35
|
path = "#{@base_path}#{path}"
|
@@ -32,17 +38,21 @@ module SimpleSpark
|
|
32
38
|
params[:query] = query_params unless query_params.empty?
|
33
39
|
response = @session.send(method.to_s, params)
|
34
40
|
|
35
|
-
process_response(response)
|
41
|
+
process_response(response, extract_results)
|
36
42
|
end
|
37
43
|
|
38
|
-
def process_response(response)
|
44
|
+
def process_response(response, extract_results)
|
39
45
|
return true if response.status == 204
|
40
46
|
|
41
47
|
response_body = JSON.parse(response.body)
|
42
48
|
if response_body['errors']
|
43
49
|
Exceptions::Error.fail_with_exception_for_status(response.status, response_body['errors'])
|
44
50
|
else
|
45
|
-
|
51
|
+
if extract_results
|
52
|
+
response_body['results'] ? response_body['results'] : true
|
53
|
+
else
|
54
|
+
response_body
|
55
|
+
end
|
46
56
|
end
|
47
57
|
end
|
48
58
|
|
@@ -63,6 +73,14 @@ module SimpleSpark
|
|
63
73
|
defaults
|
64
74
|
end
|
65
75
|
|
76
|
+
def metrics
|
77
|
+
Endpoints::Metrics.new(self)
|
78
|
+
end
|
79
|
+
|
80
|
+
def subaccounts
|
81
|
+
Endpoints::Subaccounts.new(self)
|
82
|
+
end
|
83
|
+
|
66
84
|
def inbound_domains
|
67
85
|
Endpoints::InboundDomains.new(self)
|
68
86
|
end
|
@@ -13,14 +13,14 @@ module SimpleSpark
|
|
13
13
|
# @return [Array] a list of Inbound Domain hash objects
|
14
14
|
# @note See: https://developers.sparkpost.com/api/#/reference/inbound-domains/create-and-list
|
15
15
|
def list
|
16
|
-
@client.call(:get, 'inbound-domains')
|
16
|
+
@client.call(method: :get, path: 'inbound-domains')
|
17
17
|
end
|
18
18
|
|
19
19
|
# Create an inbound domain
|
20
20
|
# @param domain_name [String] the domain name to create
|
21
21
|
# @note See: https://developers.sparkpost.com/api/#/reference/inbound-domains/create-and-list
|
22
22
|
def create(domain_name)
|
23
|
-
@client.call(:post, 'inbound-domains', domain: domain_name)
|
23
|
+
@client.call(method: :post, path: 'inbound-domains', query_values: { domain: domain_name })
|
24
24
|
end
|
25
25
|
|
26
26
|
# Retrieve an inbound domain
|
@@ -29,7 +29,7 @@ module SimpleSpark
|
|
29
29
|
# @note See: https://developers.sparkpost.com/api/#/reference/inbound-domains/retrieve-and-delete
|
30
30
|
def retrieve(domain_name)
|
31
31
|
domain_name = @client.url_encode(domain_name)
|
32
|
-
@client.call(:get, "inbound-domains/#{domain_name}")
|
32
|
+
@client.call(method: :get, path: "inbound-domains/#{domain_name}")
|
33
33
|
end
|
34
34
|
|
35
35
|
# Delete an inbound domain
|
@@ -37,7 +37,7 @@ module SimpleSpark
|
|
37
37
|
# @note See: https://developers.sparkpost.com/api/#/reference/inbound-domains/retrieve-and-delete
|
38
38
|
def delete(domain_name)
|
39
39
|
domain_name = @client.url_encode(domain_name)
|
40
|
-
@client.call(:delete, "inbound-domains/#{domain_name}")
|
40
|
+
@client.call(method: :delete, path: "inbound-domains/#{domain_name}")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -16,7 +16,7 @@ module SimpleSpark
|
|
16
16
|
# @note See: https://developers.sparkpost.com/api/#/reference/message-events/events-samples
|
17
17
|
def samples(events = nil)
|
18
18
|
query_params = events.nil? ? {} : { events: events }
|
19
|
-
@client.call(:get, 'message-events/events/samples',
|
19
|
+
@client.call(method: :get, path: 'message-events/events/samples', query_values: query_params)
|
20
20
|
end
|
21
21
|
|
22
22
|
# Perform a filtered search for message event data. The response is sorted by descending timestamp.
|
@@ -24,7 +24,7 @@ module SimpleSpark
|
|
24
24
|
# @return [Array] a list of MessageEvent hash objects
|
25
25
|
# @note See: https://developers.sparkpost.com/api/#/reference/message-events/search-for-message-events
|
26
26
|
def search(params = {})
|
27
|
-
@client.call(:get, 'message-events',
|
27
|
+
@client.call(method: :get, path: 'message-events', query_values: params)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module SimpleSpark
|
2
|
+
module Endpoints
|
3
|
+
# Provides access to the /metrics endpoint
|
4
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics
|
5
|
+
class Metrics
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
# The Metrics API is designed for discoverability of child links. Calling the API root displays a list of URIs that exists within the Metrics API.
|
13
|
+
# @return [Hash] containg a Metrics hash, the 'links' key will contain the links
|
14
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/metrics-discoverability-links
|
15
|
+
def discoverability_links
|
16
|
+
@client.call(method: :get, path: 'metrics', extract_results: false)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Deliverability Metrics Summary
|
20
|
+
# @param values [Hash] the values to query with
|
21
|
+
# @note dates from and to should be converted using strftime('%Y-%m-%dT%H:%M')
|
22
|
+
# @return [Hash] containg a Metrics hash, the 'results' key will contain the metrics, the 'links' key will contain discoverability links
|
23
|
+
# @note Example:
|
24
|
+
# client.metrics.deliverability_metrics_summary(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York')
|
25
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/discoverability-links/deliverability-metrics-summary
|
26
|
+
def deliverability_metrics_summary(values)
|
27
|
+
@client.call(method: :get, path: 'metrics/deliverability', query_values: values, extract_results: false)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Deliverability Metrics By Domain
|
31
|
+
# @param values [Hash] the values to query with
|
32
|
+
# @note dates from and to should be converted using strftime('%Y-%m-%dT%H:%M')
|
33
|
+
# @return [Array] containg Metrics results i.e. { "count_accepted": 66, "domain": "gmail.com" }
|
34
|
+
# @note Example:
|
35
|
+
# client.metrics.deliverability_metrics_by_domain(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York', domains: 'gmail.com')
|
36
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-domain
|
37
|
+
def deliverability_metrics_by_domain(values)
|
38
|
+
@client.call(method: :get, path: 'metrics/deliverability/domain', query_values: values)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Deliverability Metrics By Sending Domain
|
42
|
+
# @param values [Hash] the values to query with
|
43
|
+
# @note dates from and to should be converted using strftime('%Y-%m-%dT%H:%M')
|
44
|
+
# @return [Array] containg Metrics results i.e. { "count_accepted": 66, "sending_domain": "gmail.com" }
|
45
|
+
# @note Example:
|
46
|
+
# client.metrics.deliverability_metrics_by_sending_domain(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York', sending_domains: 'mydomain.com')
|
47
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-sending-domain
|
48
|
+
def deliverability_metrics_by_sending_domain(values)
|
49
|
+
@client.call(method: :get, path: 'metrics/deliverability/sending-domain', query_values: values)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Deliverability Metrics By Campaign
|
53
|
+
# @param values [Hash] the values to query with
|
54
|
+
# @note dates from and to should be converted using strftime('%Y-%m-%dT%H:%M')
|
55
|
+
# @return [Array] containg Metrics results i.e. { "count_accepted": 66, "campaign_id": "Summer Sale" }
|
56
|
+
# @note Example:
|
57
|
+
# client.metrics.deliverability_metrics_by_campaign(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York', campaigns: 'Summer Sale')
|
58
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-campaign
|
59
|
+
def deliverability_metrics_by_campaign(values)
|
60
|
+
@client.call(method: :get, path: 'metrics/deliverability/campaign', query_values: values)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Deliverability Metrics By Subaccount
|
64
|
+
# @param values [Hash] the values to query with
|
65
|
+
# @note dates from and to should be converted using strftime('%Y-%m-%dT%H:%M')
|
66
|
+
# @return [Array] containg Metrics results i.e. { "count_accepted": 66, "subaccount_id": "acc123" }
|
67
|
+
# @note Example:
|
68
|
+
# client.metrics.deliverability_metrics_by_subaccount(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York', subaccounts: 'acc123')
|
69
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-subaccount
|
70
|
+
def deliverability_metrics_by_subaccount(values)
|
71
|
+
@client.call(method: :get, path: 'metrics/deliverability/subaccount', query_values: values)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Deliverability Metrics By Template
|
75
|
+
# @param values [Hash] the values to query with
|
76
|
+
# @note dates from and to should be converted using strftime('%Y-%m-%dT%H:%M')
|
77
|
+
# @return [Array] containg Metrics results i.e. { "count_accepted": 66, "template": "My Template" }
|
78
|
+
# @note Example:
|
79
|
+
# client.metrics.deliverability_metrics_by_template(from: '2013-04-20T07:12', to: '2018-04-20T07:12', metrics: 'count_accepted', timezone: 'America/New_York', subaccounts: 'acc123')
|
80
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/metrics/deliverability-metrics/deliverability-metrics-by-template
|
81
|
+
def deliverability_metrics_by_template(values)
|
82
|
+
@client.call(method: :get, path: 'metrics/deliverability/template', query_values: values)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -13,7 +13,7 @@ module SimpleSpark
|
|
13
13
|
# @return [Array] a list of Relay Webhook hash objects
|
14
14
|
# @note See: https://developers.sparkpost.com/api/#/reference/relay-webhooks/create-and-list/list-all-relay-webhooks
|
15
15
|
def list
|
16
|
-
@client.call(:get, 'relay-webhooks')
|
16
|
+
@client.call(method: :get, path: 'relay-webhooks')
|
17
17
|
end
|
18
18
|
|
19
19
|
# Create a relay webhook
|
@@ -30,7 +30,7 @@ module SimpleSpark
|
|
30
30
|
# }
|
31
31
|
# }
|
32
32
|
def create(values)
|
33
|
-
@client.call(:post, 'relay-webhooks', values)
|
33
|
+
@client.call(method: :post, path: 'relay-webhooks', body_values: values)
|
34
34
|
end
|
35
35
|
|
36
36
|
# Retrieve a relay webhook
|
@@ -38,7 +38,7 @@ module SimpleSpark
|
|
38
38
|
# @return [Hash] an Relay Webhook hash object
|
39
39
|
# @note See: https://developers.sparkpost.com/api/#/reference/relay-webhooks/retrieve-update-and-delete/retrieve-a-relay-webhook
|
40
40
|
def retrieve(webhook_id)
|
41
|
-
@client.call(:get, "relay-webhooks/#{webhook_id}")
|
41
|
+
@client.call(method: :get, path: "relay-webhooks/#{webhook_id}")
|
42
42
|
end
|
43
43
|
|
44
44
|
# Update a relay webhook
|
@@ -52,14 +52,14 @@ module SimpleSpark
|
|
52
52
|
# }
|
53
53
|
# @note See: https://developers.sparkpost.com/api/#/reference/relay-webhooks/create-and-list/update-a-relay-webhook
|
54
54
|
def update(webhook_id, values)
|
55
|
-
@client.call(:put, "relay-webhooks/#{webhook_id}", values)
|
55
|
+
@client.call(method: :put, path: "relay-webhooks/#{webhook_id}", body_values: values)
|
56
56
|
end
|
57
57
|
|
58
58
|
# Delete a relay webhook
|
59
59
|
# @param webhook_id [String] the id to retrieve
|
60
60
|
# @note See: https://developers.sparkpost.com/api/#/reference/relay-webhooks/retrieve-update-and-delete/delete-a-relay-webhook
|
61
61
|
def delete(webhook_id)
|
62
|
-
@client.call(:delete, "relay-webhooks/#{webhook_id}")
|
62
|
+
@client.call(method: :delete, path: "relay-webhooks/#{webhook_id}")
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -17,7 +17,7 @@ module SimpleSpark
|
|
17
17
|
# @return [Array] a list of Sending Domain hash objects
|
18
18
|
# @note See: https://developers.sparkpost.com/api/#/reference/sending-domains/create-and-list/list-all-sending-domains
|
19
19
|
def list
|
20
|
-
@client.call(:get, 'sending-domains')
|
20
|
+
@client.call(method: :get, path: 'sending-domains')
|
21
21
|
end
|
22
22
|
|
23
23
|
# Create a sending domain
|
@@ -25,7 +25,7 @@ module SimpleSpark
|
|
25
25
|
# @param tracking_domain [String] the domain name to track this domain against
|
26
26
|
# @note See: https://developers.sparkpost.com/api/#/reference/sending-domains/create-and-list
|
27
27
|
def create(values)
|
28
|
-
@client.call(:post, 'sending-domains', values)
|
28
|
+
@client.call(method: :post, path: 'sending-domains', body_values: values)
|
29
29
|
end
|
30
30
|
|
31
31
|
# Retrieve a sending domain
|
@@ -34,7 +34,7 @@ module SimpleSpark
|
|
34
34
|
# @note See: https://developers.sparkpost.com/api/#/reference/sending-domains/retrieve-update-and-delete
|
35
35
|
def retrieve(domain_name)
|
36
36
|
domain_name = @client.url_encode(domain_name)
|
37
|
-
@client.call(:get, "sending-domains/#{domain_name}")
|
37
|
+
@client.call(method: :get, path: "sending-domains/#{domain_name}")
|
38
38
|
end
|
39
39
|
|
40
40
|
# Update a Sending Domain by its domain name
|
@@ -44,7 +44,7 @@ module SimpleSpark
|
|
44
44
|
# @note See: https://developers.sparkpost.com/api/#/reference/sending-domains/retrieve-update-and-delete
|
45
45
|
def update(domain_name, values)
|
46
46
|
domain_name = @client.url_encode(domain_name)
|
47
|
-
@client.call(:put, "sending-domains/#{domain_name}", values)
|
47
|
+
@client.call(method: :put, path: "sending-domains/#{domain_name}", body_values: values)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Verify a Sending Domain by its domain name
|
@@ -59,7 +59,7 @@ module SimpleSpark
|
|
59
59
|
# @note See: https://developers.sparkpost.com/api/#/reference/sending-domains/verify
|
60
60
|
def verify(domain_name, values)
|
61
61
|
domain_name = @client.url_encode(domain_name)
|
62
|
-
@client.call(:post, "sending-domains/#{domain_name}/verify", values)
|
62
|
+
@client.call(method: :post, path: "sending-domains/#{domain_name}/verify", body_values: values)
|
63
63
|
end
|
64
64
|
|
65
65
|
# Delete a sending domain
|
@@ -67,7 +67,7 @@ module SimpleSpark
|
|
67
67
|
# @note See: https://developers.sparkpost.com/api/#/reference/sending-domains/retrieve-update-and-delete
|
68
68
|
def delete(domain_name)
|
69
69
|
domain_name = @client.url_encode(domain_name)
|
70
|
-
@client.call(:delete, "sending-domains/#{domain_name}")
|
70
|
+
@client.call(method: :delete, path: "sending-domains/#{domain_name}")
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module SimpleSpark
|
2
|
+
module Endpoints
|
3
|
+
# Provides access to the /subaccounts endpoint
|
4
|
+
# @note Example subaccount
|
5
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/subaccounts
|
6
|
+
class Subaccounts
|
7
|
+
attr_accessor :client
|
8
|
+
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
# List subaccounts
|
14
|
+
# @return [Array] a list of Subaccount hash objects
|
15
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-collection/list-subaccounts
|
16
|
+
def list
|
17
|
+
@client.call(method: :get, path: 'subaccounts')
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a subaccount
|
21
|
+
# @param values [Hash] the values to create the subaccount with
|
22
|
+
# @note Example:
|
23
|
+
# values = {
|
24
|
+
# "name": "Sparkle Ponies",
|
25
|
+
# "key_label": "API Key for Sparkle Ponies Subaccount",
|
26
|
+
# "key_grants": ["smtp/inject", "sending_domains/manage", "message_events/view", "suppression_lists/manage"]
|
27
|
+
# }
|
28
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-collection/create-new-subaccount
|
29
|
+
def create(values)
|
30
|
+
@client.call(method: :post, path: 'subaccounts', body_values: values)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Retrieve details about a subaccount by specifying its id
|
34
|
+
# @param id [Integer] the ID of the subaccount
|
35
|
+
# @return [Hash] an Subaccount hash object
|
36
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-entity/list-specific-subaccount
|
37
|
+
def retrieve(id)
|
38
|
+
@client.call(method: :get, path: "subaccounts/#{id}")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Update a Subaccount by its ID
|
42
|
+
# @param id [Integer] the ID of the subaccount
|
43
|
+
# @param values [Hash] the values to update the subaccount with
|
44
|
+
# @note See: https://developers.sparkpost.com/api/#/reference/subaccounts/subaccounts-entity/edit-a-subaccount
|
45
|
+
def update(id, values)
|
46
|
+
@client.call(method: :put, path: "subaccounts/#{id}", body_values: values)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -17,7 +17,7 @@ module SimpleSpark
|
|
17
17
|
# @return [Array] a list of Template hash objects
|
18
18
|
# @note See: https://developers.sparkpost.com/api/#/reference/templates/create-and-list
|
19
19
|
def list
|
20
|
-
@client.call(:get, 'templates')
|
20
|
+
@client.call(method: :get, path: 'templates')
|
21
21
|
end
|
22
22
|
|
23
23
|
# Create a template by providing values for the template object.
|
@@ -27,7 +27,7 @@ module SimpleSpark
|
|
27
27
|
# @return [boolean] true if success
|
28
28
|
# @note See: https://developers.sparkpost.com/api/#/reference/templates/create-and-list
|
29
29
|
def create(values)
|
30
|
-
@client.call(:post, 'templates', values)
|
30
|
+
@client.call(method: :post, path: 'templates', body_values: values)
|
31
31
|
end
|
32
32
|
|
33
33
|
# Retrieve a Template by its ID
|
@@ -40,7 +40,7 @@ module SimpleSpark
|
|
40
40
|
def retrieve(id, draft = nil)
|
41
41
|
path = "templates/#{id}"
|
42
42
|
query_params = draft.nil? ? {} : { draft: draft }
|
43
|
-
@client.call(:get, path
|
43
|
+
@client.call(method: :get, path: path, query_values: query_params)
|
44
44
|
end
|
45
45
|
|
46
46
|
# Update a Template by its ID
|
@@ -51,7 +51,7 @@ module SimpleSpark
|
|
51
51
|
#
|
52
52
|
# @note See: https://developers.sparkpost.com/api/#/reference/templates/update
|
53
53
|
def update(id, values, update_published = false)
|
54
|
-
@client.call(:put, "templates/#{id}", values, update_published: update_published)
|
54
|
+
@client.call(method: :put, path: "templates/#{id}", body_values: values, query_values: { update_published: update_published })
|
55
55
|
end
|
56
56
|
|
57
57
|
# Preview a Template by its ID
|
@@ -65,7 +65,7 @@ module SimpleSpark
|
|
65
65
|
# @note See: https://developers.sparkpost.com/api/#/reference/templates/preview
|
66
66
|
def preview(id, substitutions, draft = nil)
|
67
67
|
query_params = draft.nil? ? {} : { draft: draft }
|
68
|
-
@client.call(:post, "templates/#{id}/preview", substitutions, query_params)
|
68
|
+
@client.call(method: :post, path: "templates/#{id}/preview", body_values: substitutions, query_values: query_params)
|
69
69
|
end
|
70
70
|
|
71
71
|
# Delete a Template by its ID
|
@@ -73,7 +73,7 @@ module SimpleSpark
|
|
73
73
|
#
|
74
74
|
# @note See: https://developers.sparkpost.com/api/#/reference/templates/delete
|
75
75
|
def delete(id)
|
76
|
-
@client.call(:delete, "templates/#{id}")
|
76
|
+
@client.call(method: :delete, path: "templates/#{id}")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -37,7 +37,7 @@ module SimpleSpark
|
|
37
37
|
# }
|
38
38
|
def create(values, num_rcpt_errors = nil)
|
39
39
|
query_params = num_rcpt_errors.nil? ? {} : { num_rcpt_errors: num_rcpt_errors }
|
40
|
-
@client.call(:post, 'transmissions', values, query_params)
|
40
|
+
@client.call(method: :post, path: 'transmissions', body_values: values, query_values: query_params)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Sends an email message
|
@@ -50,7 +50,7 @@ module SimpleSpark
|
|
50
50
|
query_params = {}
|
51
51
|
query_params[:campaign_id] = campaign_id if campaign_id
|
52
52
|
query_params[:template_id] = template_id if template_id
|
53
|
-
@client.call(:get, 'transmissions',
|
53
|
+
@client.call(method: :get, path: 'transmissions', query_values: query_params)
|
54
54
|
end
|
55
55
|
|
56
56
|
# send_message to be reserved as a 'quick' helper method to avoid using hash for Create
|
@@ -15,14 +15,14 @@ module SimpleSpark
|
|
15
15
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/list
|
16
16
|
def list(timezone = nil)
|
17
17
|
query_params = timezone.nil? ? {} : { timezone: timezone }
|
18
|
-
@client.call(:get, 'webhooks',
|
18
|
+
@client.call(method: :get, path: 'webhooks', query_values: query_params)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Create a webhook
|
22
22
|
# @param values [Hash] the values to create the webhook with
|
23
23
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/create
|
24
24
|
def create(values)
|
25
|
-
@client.call(:post, 'webhooks', values)
|
25
|
+
@client.call(method: :post, path: 'webhooks', body_values: values)
|
26
26
|
end
|
27
27
|
|
28
28
|
# Retrieve details about a webhook by specifying its id
|
@@ -30,7 +30,7 @@ module SimpleSpark
|
|
30
30
|
# @return [Hash] an Webhook hash object
|
31
31
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/retrieve
|
32
32
|
def retrieve(id)
|
33
|
-
@client.call(:get, "webhooks/#{id}")
|
33
|
+
@client.call(method: :get, path: "webhooks/#{id}")
|
34
34
|
end
|
35
35
|
|
36
36
|
# Update a Webhook by its ID
|
@@ -38,14 +38,14 @@ module SimpleSpark
|
|
38
38
|
# @param values [Hash] the values to update the webhook with
|
39
39
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/update-and-delete
|
40
40
|
def update(id, values)
|
41
|
-
@client.call(:put, "webhooks/#{id}", values)
|
41
|
+
@client.call(method: :put, path: "webhooks/#{id}", body_values: values)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Validates a Webhook by sending an example message event batch from the Webhooks API to the target URL
|
45
45
|
# @param id [String] the ID of the webhook
|
46
46
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/validate
|
47
47
|
def validate(id)
|
48
|
-
@client.call(:post, "webhooks/#{id}/validate")
|
48
|
+
@client.call(method: :post, path: "webhooks/#{id}/validate")
|
49
49
|
end
|
50
50
|
|
51
51
|
# Batch status information
|
@@ -54,7 +54,7 @@ module SimpleSpark
|
|
54
54
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/batch-status
|
55
55
|
def batch_status(id, limit = nil)
|
56
56
|
query_params = limit.nil? ? {} : { limit: limit }
|
57
|
-
@client.call(:get, "webhooks/#{id}/batch-status",
|
57
|
+
@client.call(method: :get, path: "webhooks/#{id}/batch-status", query_values: query_params)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Returns sample event data
|
@@ -63,14 +63,14 @@ module SimpleSpark
|
|
63
63
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/events-samples
|
64
64
|
def samples(events = nil)
|
65
65
|
query_params = events.nil? ? {} : { events: events }
|
66
|
-
@client.call(:get, 'webhooks/events/samples',
|
66
|
+
@client.call(method: :get, path: 'webhooks/events/samples', query_values: query_params)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Delete a webhook
|
70
70
|
# @param id [String] the ID
|
71
71
|
# @note See: https://developers.sparkpost.com/api/#/reference/webhooks/update-and-delete
|
72
72
|
def delete(id)
|
73
|
-
@client.call(:delete, "webhooks/#{id}")
|
73
|
+
@client.call(method: :delete, path: "webhooks/#{id}")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
data/lib/simple_spark/version.rb
CHANGED
data/lib/simple_spark.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'simple_spark/version'
|
2
2
|
require 'simple_spark/client'
|
3
3
|
require 'simple_spark/exceptions'
|
4
|
+
require 'simple_spark/endpoints/metrics'
|
4
5
|
require 'simple_spark/endpoints/transmissions'
|
5
6
|
require 'simple_spark/endpoints/templates'
|
6
7
|
require 'simple_spark/endpoints/inbound_domains'
|
@@ -8,4 +9,5 @@ require 'simple_spark/endpoints/sending_domains'
|
|
8
9
|
require 'simple_spark/endpoints/message_events'
|
9
10
|
require 'simple_spark/endpoints/webhooks'
|
10
11
|
require 'simple_spark/endpoints/relay_webhooks'
|
12
|
+
require 'simple_spark/endpoints/subaccounts'
|
11
13
|
|
@@ -52,5 +52,46 @@ describe SimpleSpark::Client do
|
|
52
52
|
it 'will raise when headers is not a Hash' do
|
53
53
|
expect { SimpleSpark::Client.new(api_key: 'mykey', headers: 'wrong') }.to raise_error(SimpleSpark::Exceptions::InvalidConfiguration, 'The headers options provided must be a valid Hash')
|
54
54
|
end
|
55
|
+
|
56
|
+
context 'endpoints' do
|
57
|
+
let(:client) { SimpleSpark::Client.new(api_key: 'mykey') }
|
58
|
+
|
59
|
+
context 'metrics' do
|
60
|
+
specify { expect(client.metrics.class).to eq(SimpleSpark::Endpoints::Metrics) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'subaccounts' do
|
64
|
+
specify { expect(client.subaccounts.class).to eq(SimpleSpark::Endpoints::Subaccounts) }
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'inbound_domains' do
|
68
|
+
specify { expect(client.inbound_domains.class).to eq(SimpleSpark::Endpoints::InboundDomains) }
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'message_events' do
|
72
|
+
specify { expect(client.message_events.class).to eq(SimpleSpark::Endpoints::MessageEvents) }
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'relay_webhooks' do
|
76
|
+
specify { expect(client.relay_webhooks.class).to eq(SimpleSpark::Endpoints::RelayWebhooks) }
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'sending_domains' do
|
80
|
+
specify { expect(client.sending_domains.class).to eq(SimpleSpark::Endpoints::SendingDomains) }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'templates' do
|
84
|
+
specify { expect(client.templates.class).to eq(SimpleSpark::Endpoints::Templates) }
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'transmissions' do
|
88
|
+
specify { expect(client.transmissions.class).to eq(SimpleSpark::Endpoints::Transmissions) }
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'webhooks' do
|
92
|
+
specify { expect(client.webhooks.class).to eq(SimpleSpark::Endpoints::Webhooks) }
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
55
96
|
end
|
56
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_spark
|
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
|
- Jak Charlton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -209,8 +209,10 @@ files:
|
|
209
209
|
- lib/simple_spark/client.rb
|
210
210
|
- lib/simple_spark/endpoints/inbound_domains.rb
|
211
211
|
- lib/simple_spark/endpoints/message_events.rb
|
212
|
+
- lib/simple_spark/endpoints/metrics.rb
|
212
213
|
- lib/simple_spark/endpoints/relay_webhooks.rb
|
213
214
|
- lib/simple_spark/endpoints/sending_domains.rb
|
215
|
+
- lib/simple_spark/endpoints/subaccounts.rb
|
214
216
|
- lib/simple_spark/endpoints/templates.rb
|
215
217
|
- lib/simple_spark/endpoints/transmissions.rb
|
216
218
|
- lib/simple_spark/endpoints/webhooks.rb
|