mailigen 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +27 -0
- data/Gemfile +2 -0
- data/README.md +29 -0
- data/lib/mailigen.rb +1 -1
- data/lib/mailigen/api.rb +21 -7
- data/lib/mailigen/version.rb +1 -1
- data/mailigen.gemspec +0 -1
- data/spec/mailigen/api_spec.rb +79 -19
- data/spec/mailigen_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -2
- metadata +4 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12e6e7d0978cd90bd64f01aef3319d4b30aa50d8
|
4
|
+
data.tar.gz: 97b985164bef8bd02b10750927b98e21d908561f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced7cf6662e323fe715469e41f28a210500ad628db5dbc5ff94fd5f00bdb440a8a603f9599eab1a9f1b7d205e1da2fe358b2a881816bc7dc014c55745e2c3724
|
7
|
+
data.tar.gz: 6889e48d23edae77f61af93605e8af3021031de846bea3ca2645f894739d7e2eccc14a8bd5192c9c5ded688e3128d514db4965d23b58e1f01ed2d6a44789ef8e
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## 0.0.2
|
2
|
+
|
3
|
+
### Features & Enhancements
|
4
|
+
|
5
|
+
* Replace addressable gem with active_support/core_ext/object methods
|
6
|
+
* Add some few tests for lists
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
## 0.0.1
|
11
|
+
|
12
|
+
* Initial release
|
13
|
+
|
14
|
+
### Features & Enhancements
|
15
|
+
|
16
|
+
* Basic API wrapper
|
17
|
+
|
18
|
+
### Bug Fixes
|
19
|
+
|
20
|
+
### Test Suite
|
21
|
+
|
22
|
+
* RSpec
|
23
|
+
|
24
|
+
### Contributors
|
25
|
+
|
26
|
+
* Arturs Braucs
|
27
|
+
* Creative Mobile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Mailigen
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/mailigen)
|
4
|
+
[](https://travis-ci.org/artursbraucs/mailigen)
|
5
|
+
[](https://coveralls.io/r/artursbraucs/mailigen)
|
6
|
+
|
3
7
|
API wrapper for mailigen.com .
|
4
8
|
|
5
9
|
## Installation
|
@@ -18,11 +22,36 @@ Or install it yourself as:
|
|
18
22
|
|
19
23
|
## Usage
|
20
24
|
|
25
|
+
Create your mailigen instance and call 'call' method. First param - API method, seconds param - parameters (api_key included by default).
|
26
|
+
|
27
|
+
Few examples:
|
28
|
+
|
21
29
|
require "mailigen"
|
22
30
|
|
23
31
|
mailigen = Mailigen::Api.new YOUR_MAILIGEN_API_KEY
|
32
|
+
|
33
|
+
# Ping to check apy key
|
24
34
|
mailigen.call :ping # returns "Everything's Ok!" if API KEY is correct
|
25
35
|
|
36
|
+
# Creates a list
|
37
|
+
list_id = mailigen.call :listCreate, {title: "testListRspec", options: {permission_reminder: "Your in", notify_to: "foo@bar.com", subscription_notify: false}}
|
38
|
+
|
39
|
+
# Adds extra var to list
|
40
|
+
mailigen.call :listMergeVarAdd, {id: list_id, tag: "NAME", name: "Name of user"}
|
41
|
+
|
42
|
+
# Adds contacts batch to list
|
43
|
+
contacts_array_hash = {
|
44
|
+
"0" => {EMAIL: "foo@sample.com", EMAIL_TYPE: 'plain', NAME: 'Foo'},
|
45
|
+
"1" => {EMAIL: "bar@sample.com", EMAIL_TYPE: 'html', NAME: 'Bar'},
|
46
|
+
"2" => {EMAIL: "foo@sample.com", EMAIL_TYPE: 'html', NAME: 'Foo Dublicate'}
|
47
|
+
}
|
48
|
+
|
49
|
+
resp = mailigen.call :listBatchSubscribe, {id: list_id, batch: contacts_array_hash, double_optin: false}
|
50
|
+
|
51
|
+
puts resp["success_count"] # Output should be 3
|
52
|
+
|
53
|
+
For more: [Mailigen API documentation](http://dev.mailigen.com/display/AD/API+Documentation)
|
54
|
+
|
26
55
|
## Testing
|
27
56
|
|
28
57
|
Gem using RSpec tests. You must add spec/keys/api.yml:
|
data/lib/mailigen.rb
CHANGED
data/lib/mailigen/api.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'net/http'
|
3
3
|
require 'net/https'
|
4
|
-
require "addressable/uri"
|
5
4
|
require 'json'
|
6
5
|
require 'active_support/core_ext/object'
|
7
6
|
|
@@ -11,10 +10,9 @@ module Mailigen
|
|
11
10
|
attr_accessor :api_key, :secure
|
12
11
|
|
13
12
|
# Initialize API wrapper.
|
14
|
-
# Options:
|
15
13
|
#
|
16
|
-
# api_key - from mailigen.com . Required.
|
17
|
-
# secure - use SSL. By default FALSE
|
14
|
+
# @param api_key - from mailigen.com . Required.
|
15
|
+
# @param secure - use SSL. By default FALSE
|
18
16
|
#
|
19
17
|
def initialize api_key = nil, secure = false
|
20
18
|
self.api_key = api_key
|
@@ -22,9 +20,20 @@ module Mailigen
|
|
22
20
|
raise NoApiKeyError, "You must have Mailigen API key." unless self.api_key
|
23
21
|
end
|
24
22
|
|
23
|
+
# Call Mailigen api method (Documented in http://dev.mailigen.com/display/AD/Mailigen+API )
|
24
|
+
#
|
25
|
+
# @param method - method name
|
26
|
+
# @param params - params if required for API
|
27
|
+
#
|
28
|
+
# @return
|
29
|
+
# JSON, String data if all goes well.
|
30
|
+
# Exception if somethnigs goes wrong.
|
31
|
+
#
|
25
32
|
def call method, params = {}
|
26
33
|
url = "#{api_url}&method=#{method}"
|
34
|
+
|
27
35
|
params = {apikey: self.api_key}.merge params
|
36
|
+
|
28
37
|
resp = post_api(url, params)
|
29
38
|
begin
|
30
39
|
return JSON.parse(resp)
|
@@ -34,7 +43,7 @@ module Mailigen
|
|
34
43
|
end
|
35
44
|
|
36
45
|
|
37
|
-
#
|
46
|
+
# @return default api url with version included
|
38
47
|
#
|
39
48
|
def api_url
|
40
49
|
protocol = self.secure ? "https" : "http"
|
@@ -45,12 +54,17 @@ module Mailigen
|
|
45
54
|
|
46
55
|
# All api calls throught POST method.
|
47
56
|
#
|
57
|
+
# @param url - url to post
|
58
|
+
# @param params - params in hash
|
59
|
+
#
|
60
|
+
# @return
|
61
|
+
# response body
|
48
62
|
def post_api url, params
|
49
63
|
uri = URI.parse(url)
|
50
64
|
http = Net::HTTP.new(uri.host, uri.port)
|
51
65
|
http.use_ssl = self.secure
|
52
|
-
|
53
|
-
res = http.post(uri.request_uri,
|
66
|
+
form_params = params.to_query
|
67
|
+
res = http.post(uri.request_uri, form_params)
|
54
68
|
res.body
|
55
69
|
end
|
56
70
|
|
data/lib/mailigen/version.rb
CHANGED
data/mailigen.gemspec
CHANGED
data/spec/mailigen/api_spec.rb
CHANGED
@@ -31,44 +31,104 @@ describe Mailigen::Api do
|
|
31
31
|
|
32
32
|
it "return url" do
|
33
33
|
obj = Mailigen::Api.new "fookey", true
|
34
|
-
expect(obj.api_url).to eq("https://api.mailigen.com/1.
|
34
|
+
expect(obj.api_url).to eq("https://api.mailigen.com/1.3/?output=json")
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context "default (unsecure)" do
|
40
40
|
it "return url" do
|
41
|
-
expect(@invalid_mailigen.api_url).to eq("http://api.mailigen.com/1.
|
41
|
+
expect(@invalid_mailigen.api_url).to eq("http://api.mailigen.com/1.3/?output=json")
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
if valid_mailigen_obj
|
48
|
+
describe "call" do
|
48
49
|
|
49
|
-
|
50
|
+
describe "ping" do
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
context "invalide mailigen key" do
|
53
|
+
it "returns error" do
|
54
|
+
resp = @invalid_mailigen.call :ping
|
55
|
+
expect(resp["code"]).to eq(104)
|
56
|
+
expect(resp["error"]).to eq("Invalid Mailigen API Key: fookey")
|
57
|
+
end
|
56
58
|
end
|
57
|
-
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
context "valide mailigen key" do
|
61
|
+
it "returns OK" do
|
62
|
+
resp = @mailigen.call :ping
|
63
|
+
expect(resp).to eq("Everything's Ok!")
|
64
|
+
end
|
63
65
|
end
|
66
|
+
|
64
67
|
end
|
65
68
|
|
66
|
-
|
69
|
+
describe "lists" do
|
70
|
+
before(:all) do
|
71
|
+
# Creates list
|
72
|
+
create_list_params = {title: "testListRspec", options: {permission_reminder: "Your in", notify_to: "foo@bar.com", subscription_notify: false}}
|
73
|
+
|
74
|
+
resp = @mailigen.call(:listCreate, create_list_params)
|
75
|
+
@list_id = resp
|
76
|
+
|
77
|
+
@lists_with_email = {
|
78
|
+
"0" => {EMAIL: "foo@sample.com", EMAIL_TYPE: 'plain', NAME: 'Foo'},
|
79
|
+
"1" => {EMAIL: "bar@sample.com", EMAIL_TYPE: 'html', NAME: 'Bar'},
|
80
|
+
"2" => {EMAIL: "foo@sample.com", EMAIL_TYPE: 'html', NAME: 'Foo Dublicate'}
|
81
|
+
}
|
82
|
+
end
|
83
|
+
after(:all) do
|
84
|
+
# Removes list
|
85
|
+
@mailigen.call :listDelete, {id: @list_id}
|
86
|
+
end
|
87
|
+
|
88
|
+
context "createList" do
|
89
|
+
it "returns list id" do
|
90
|
+
expect(@list_id).not_to be(nil)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "lists" do
|
95
|
+
it "returns lists containg testListRspec" do
|
96
|
+
exists = false
|
97
|
+
resp = @mailigen.call :lists
|
98
|
+
selected_lists = resp.select { |list| list["name"] == "testListRspec" }
|
99
|
+
expect(selected_lists.size).to eq(1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "listMergeVars" do
|
104
|
+
it "returns array with vars" do
|
105
|
+
resp = @mailigen.call :listMergeVars, {id: @list_id}
|
106
|
+
expect(resp.size).to eq(3)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "listMergeVarAdd" do
|
111
|
+
it "returns true" do
|
112
|
+
params = {id: @list_id, tag: "FOO", name: "FooName"}
|
113
|
+
resp = @mailigen.call :listMergeVarAdd, params
|
114
|
+
expect(resp).to eq("true")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "listBatchSubscribe" do
|
119
|
+
it "returns success count and fail count" do
|
120
|
+
# Add name var
|
121
|
+
params = {id: @list_id, tag: "NAME", name: "Name of user"}
|
122
|
+
resp = @mailigen.call :listMergeVarAdd, params
|
123
|
+
|
124
|
+
params = {id: @list_id, batch: @lists_with_email, double_optin: false}
|
125
|
+
|
126
|
+
resp = @mailigen.call :listBatchSubscribe, params
|
127
|
+
expect(resp["success_count"]).to eq(3)
|
128
|
+
expect(resp["error_count"]).to eq(0)
|
129
|
+
end
|
130
|
+
end
|
67
131
|
|
68
|
-
context "creates list" do
|
69
|
-
it "returns list id" do
|
70
|
-
resp = @mailigen.call :listCreate, {title: "testListRspec", options: {permission_reminder: "Your in", notify_to: "foo@bar.com", subscription_notify: false}}
|
71
|
-
expect(resp).not_to be(nil)
|
72
132
|
end
|
73
133
|
end
|
74
134
|
|
data/spec/mailigen_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'mailigen'
|
2
|
-
|
3
2
|
require 'rspec/autorun'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
Coveralls.wear!
|
4
6
|
|
5
7
|
RSpec.configure do |config|
|
6
8
|
end
|
@@ -11,5 +13,7 @@ end
|
|
11
13
|
|
12
14
|
def valid_mailigen_obj
|
13
15
|
hash = YAML.load(File.read("#{File.dirname(__FILE__)}/keys/api.yml"))
|
14
|
-
Mailigen::Api.new hash["mailigen"]["api_key"]
|
16
|
+
return Mailigen::Api.new hash["mailigen"]["api_key"]
|
17
|
+
rescue
|
18
|
+
return nil
|
15
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailigen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arturs Braucs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: addressable
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +75,8 @@ extra_rdoc_files: []
|
|
89
75
|
files:
|
90
76
|
- .gitignore
|
91
77
|
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- CHANGELOG.md
|
92
80
|
- Gemfile
|
93
81
|
- LICENSE.txt
|
94
82
|
- README.md
|