mailtrain 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/mailtrain.rb +15 -0
- data/lib/mailtrain/client.rb +78 -0
- data/lib/mailtrain/response.rb +31 -0
- data/lib/mailtrain/version.rb +3 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc264ff8c90cd947c9ac98ff7ad4ab16c19b71e4
|
4
|
+
data.tar.gz: 7c6309da53bd914afbfe281e41a7aa8a756c2ff8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00a8d8dd59ff875cef1c93c5a20232458d37239f5f1eefe566c52d2c3ba0ebade062c1a483b9237dd452c98ac8add84ef8fd8a0bed2d2e9c12cd6d52e6cf4602
|
7
|
+
data.tar.gz: 834475ca373bcbba1bab05f15a2d8d598f018d67b389a944931e882142c29ab8c0213a3a05a9c0188de94d6339878d5f2055b6973ea5b48768d4b471bf68f5eb
|
data/lib/mailtrain.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'mailtrain/response'
|
4
|
+
|
5
|
+
module Mailtrain
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def initialize(host_url, access_token = nil)
|
9
|
+
@url = host_url
|
10
|
+
@access_token = access_token || ENV['MAILTRAIN_ACCESS_TOKEN']
|
11
|
+
@response = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
# Add subscription
|
15
|
+
def subscribe(list_id, email, first_name = nil, last_name = nil, timezone = nil, force_subscribe = true)
|
16
|
+
response = connection.post "/api/subscribe/#{list_id}?access_token=#{@access_token}" do |req|
|
17
|
+
params = {email: email, first_name: first_name, last_name: last_name, timezone: timezone, force_subscribe: force_subscribe}.select { |_, value| !value.nil? }
|
18
|
+
req.body = params
|
19
|
+
end
|
20
|
+
|
21
|
+
@response = Response.new response.body
|
22
|
+
success?
|
23
|
+
end
|
24
|
+
|
25
|
+
def unsubscribe(list_id, email)
|
26
|
+
response = connection.post "/api/unsubscribe/#{list_id}?access_token=#{@access_token}", {list: list_id, email: email}
|
27
|
+
|
28
|
+
@response = Response.new response.body
|
29
|
+
success?
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get list of blacklisted emails
|
33
|
+
def blacklist(start=0, limit=10000, search='')
|
34
|
+
response = connection.get "/api/blacklist/get?access_token=#{@access_token}&start=#{start}&limit=#{limit}&search=#{search}"
|
35
|
+
|
36
|
+
@response = Response.new response.body
|
37
|
+
data
|
38
|
+
end
|
39
|
+
|
40
|
+
# Add email to blacklist
|
41
|
+
def block(email)
|
42
|
+
response = connection.post "/api/blacklist/add?access_token=#{@access_token}", {email: email}
|
43
|
+
|
44
|
+
@response = Response.new response.body
|
45
|
+
success?
|
46
|
+
end
|
47
|
+
|
48
|
+
# delete email to blacklist
|
49
|
+
def unblock(email)
|
50
|
+
response = connection.post "/api/blacklist/delete?access_token=#{@access_token}", {email: email}
|
51
|
+
|
52
|
+
@response = Response.new response.body
|
53
|
+
success?
|
54
|
+
end
|
55
|
+
|
56
|
+
def success?
|
57
|
+
@response.respond_to?(:success?) ? @response.success? : false
|
58
|
+
end
|
59
|
+
|
60
|
+
def error
|
61
|
+
@response.error_message
|
62
|
+
end
|
63
|
+
|
64
|
+
def data
|
65
|
+
@response.data
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def connection
|
71
|
+
@connection ||= Faraday.new(:url => @url) do |faraday|
|
72
|
+
faraday.request :url_encoded
|
73
|
+
faraday.adapter :excon
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Mailtrain
|
4
|
+
class Response
|
5
|
+
def initialize(json)
|
6
|
+
@res = symbolize_keys(JSON.parse(json))
|
7
|
+
end
|
8
|
+
|
9
|
+
def success?
|
10
|
+
@res[:error].nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def error_message
|
14
|
+
@res[:error]
|
15
|
+
end
|
16
|
+
|
17
|
+
def data
|
18
|
+
@res[:data]
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def symbolize_keys(hash)
|
24
|
+
hash.inject({}) do |options, (key, value)|
|
25
|
+
options[(key.to_sym rescue key) || key] = value.is_a?(Hash) ? symbolize_keys(value) : value
|
26
|
+
options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailtrain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- benko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
description: A simple MailTrain API
|
28
|
+
email: benko.b@shopperplus.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/mailtrain.rb
|
34
|
+
- lib/mailtrain/client.rb
|
35
|
+
- lib/mailtrain/response.rb
|
36
|
+
- lib/mailtrain/version.rb
|
37
|
+
homepage:
|
38
|
+
licenses: []
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.6.11
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: Sendy!
|
60
|
+
test_files: []
|