mailigen 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4702b01ebf3fb2519a1af3332e126c3d5fcb664c
4
+ data.tar.gz: 5d1fc92dfc32273b6e6d3c3392732abeaa8f9971
5
+ SHA512:
6
+ metadata.gz: 39ddd7772e45f9c33878002897c20c862d6414edac0643921f73b2655e1bd80014669a5c7859159e6772269465ce8732b7787aaece2060f33dc2c5350467c85f
7
+ data.tar.gz: e6ec3ef331c98396f8bd0238515a91bd89cc94e4059f239e2240f16d69019c37f0bad86728d555ddb031f5bbea604e4ad810c26c84edbbd02021117233fdd22a
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/keys
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailigen.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Arturs Braucs
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Mailigen
2
+
3
+ API wrapper for mailigen.com .
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mailigen'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mailigen
18
+
19
+ ## Usage
20
+
21
+ require "mailigen"
22
+
23
+ mailigen = Mailigen::Api.new YOUR_MAILIGEN_API_KEY
24
+ mailigen.call :ping # returns "Everything's Ok!" if API KEY is correct
25
+
26
+ ## Testing
27
+
28
+ Gem using RSpec tests. You must add spec/keys/api.yml:
29
+
30
+ mailigen:
31
+ api_key: "YOUR_MAILIGEN_API_KEY"
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,58 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'net/https'
4
+ require "addressable/uri"
5
+ require 'json'
6
+ require 'active_support/core_ext/object'
7
+
8
+ module Mailigen
9
+ class Api
10
+
11
+ attr_accessor :api_key, :secure
12
+
13
+ # Initialize API wrapper.
14
+ # Options:
15
+ #
16
+ # api_key - from mailigen.com . Required.
17
+ # secure - use SSL. By default FALSE
18
+ #
19
+ def initialize api_key = nil, secure = false
20
+ self.api_key = api_key
21
+ self.secure = secure
22
+ raise NoApiKeyError, "You must have Mailigen API key." unless self.api_key
23
+ end
24
+
25
+ def call method, params = {}
26
+ url = "#{api_url}&method=#{method}"
27
+ params = {apikey: self.api_key}.merge params
28
+ resp = post_api(url, params)
29
+ begin
30
+ return JSON.parse(resp)
31
+ rescue
32
+ return resp.tr('"','')
33
+ end
34
+ end
35
+
36
+
37
+ # Returns default api url with version included
38
+ #
39
+ def api_url
40
+ protocol = self.secure ? "https" : "http"
41
+ "#{protocol}://#{Mailigen::api_host}/#{Mailigen::api_version}/?output=json"
42
+ end
43
+
44
+ private
45
+
46
+ # All api calls throught POST method.
47
+ #
48
+ def post_api url, params
49
+ uri = URI.parse(url)
50
+ http = Net::HTTP.new(uri.host, uri.port)
51
+ http.use_ssl = self.secure
52
+
53
+ res = http.post(uri.request_uri, params.to_query)
54
+ res.body
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module Mailigen
2
+
3
+ class NoApiKeyError < RuntimeError
4
+ end
5
+
6
+ end
@@ -0,0 +1,3 @@
1
+ module Mailigen
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mailigen.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "active_support/dependencies"
2
+
3
+ require "mailigen/version"
4
+ require "mailigen/no_api_key_error"
5
+ require "mailigen/api"
6
+
7
+ module Mailigen
8
+
9
+ mattr_accessor :api_host
10
+ @@api_host = "api.mailigen.com"
11
+
12
+ mattr_accessor :api_version
13
+ @@api_version = "1.1"
14
+
15
+ end
data/mailigen.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailigen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mailigen"
8
+ spec.version = Mailigen::VERSION
9
+ spec.authors = ["Arturs Braucs"]
10
+ spec.email = ["arturs@creo.mobi"]
11
+ spec.description = %q{Mailigen.com API wrapper}
12
+ spec.summary = %q{Mailigen.com API wrapper}
13
+ spec.homepage = "http://dev.mailigen.com/pages/viewpage.action?pageId=327689"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activesupport"
22
+ spec.add_dependency "addressable"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailigen::Api do
4
+ describe Mailigen::Api do
5
+
6
+ before(:all) do
7
+ @invalid_mailigen = invalid_mailigen_obj
8
+ @mailigen = valid_mailigen_obj
9
+ end
10
+
11
+ context "initialize with no api key" do
12
+
13
+ it "raise error" do
14
+ expect { Mailigen::Api.new }.to raise_error(Mailigen::NoApiKeyError)
15
+ end
16
+
17
+ end
18
+
19
+ context "initialize" do
20
+
21
+ it "returns object with api key" do
22
+ expect(@invalid_mailigen).not_to be(nil)
23
+ expect(@invalid_mailigen.api_key).to eq("fookey")
24
+ end
25
+
26
+ end
27
+
28
+ describe "api_url" do
29
+
30
+ context "secure" do
31
+
32
+ it "return url" do
33
+ obj = Mailigen::Api.new "fookey", true
34
+ expect(obj.api_url).to eq("https://api.mailigen.com/1.1/?output=json")
35
+ end
36
+
37
+ end
38
+
39
+ context "default (unsecure)" do
40
+ it "return url" do
41
+ expect(@invalid_mailigen.api_url).to eq("http://api.mailigen.com/1.1/?output=json")
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ describe "call" do
48
+
49
+ context "ping" do
50
+
51
+ context "invalide mailigen key" do
52
+ it "returns error" do
53
+ resp = @invalid_mailigen.call :ping
54
+ expect(resp["code"]).to eq(104)
55
+ expect(resp["error"]).to eq("Invalid Mailigen API Key: fookey")
56
+ end
57
+ end
58
+
59
+ context "valide mailigen key" do
60
+ it "returns OK" do
61
+ resp = @mailigen.call :ping
62
+ expect(resp).to eq("Everything's Ok!")
63
+ end
64
+ end
65
+
66
+ end
67
+
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
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mailigen do
4
+
5
+ context "module" do
6
+
7
+ it "exists" do
8
+ expect(Mailigen).not_to be(nil)
9
+ end
10
+
11
+ end
12
+
13
+ context "defaults" do
14
+
15
+ it "has api_host" do
16
+ expect(Mailigen::api_host).to eq("api.mailigen.com")
17
+ end
18
+
19
+ it "has api_version" do
20
+ expect(Mailigen::api_version).to eq("1.1")
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'mailigen'
2
+
3
+ require 'rspec/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ end
7
+
8
+ def invalid_mailigen_obj
9
+ Mailigen::Api.new "fookey"
10
+ end
11
+
12
+ def valid_mailigen_obj
13
+ hash = YAML.load(File.read("#{File.dirname(__FILE__)}/keys/api.yml"))
14
+ Mailigen::Api.new hash["mailigen"]["api_key"]
15
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailigen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arturs Braucs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Mailigen.com API wrapper
84
+ email:
85
+ - arturs@creo.mobi
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/mailigen.rb
97
+ - lib/mailigen/api.rb
98
+ - lib/mailigen/no_api_key_error.rb
99
+ - lib/mailigen/version.rb
100
+ - mailigen.gemspec
101
+ - spec/mailigen/api_spec.rb
102
+ - spec/mailigen_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: http://dev.mailigen.com/pages/viewpage.action?pageId=327689
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Mailigen.com API wrapper
128
+ test_files:
129
+ - spec/mailigen/api_spec.rb
130
+ - spec/mailigen_spec.rb
131
+ - spec/spec_helper.rb