mailflow-ruby 0.1.0

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: 73f1f3042f8801bba568a43951114904f8c6f287
4
+ data.tar.gz: b6ed8ff54bedf61f2d734a92aa1116529bd274a2
5
+ SHA512:
6
+ metadata.gz: 42f2caa96efd688b31de2e0d202a0ef01328f9ab8fde1a5c68b4af96017870bed26dcd27606b00deee96e576e110d40880f6d648ddddae17174f6d1db76a7972
7
+ data.tar.gz: ee3a1999bfdde6f07b03c26c258f5f4be8d088eb4630f4d5fdb5c0548f8ac5c826f2ff3773ef7a112dbf8b53a5a5fb11030c94e9cff2a9256a8b57a993d9864c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailflow-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ ### TODO
2
+
3
+ * Write a readme
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mailflow-ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ require 'httparty'
2
+ require 'byebug'
3
+
4
+ module Mailflow
5
+ module APIOperations
6
+ module ClassMethods
7
+
8
+ def url(endpoint)
9
+ "https://mailflow.com/api/#{endpoint}"
10
+ end
11
+
12
+ def get_request(endpoint, params = {})
13
+ options = base_params.merge({query: params})
14
+ HTTParty.get(url(endpoint), options)
15
+ end
16
+
17
+ def post_request(endpoint, params = {})
18
+ options = base_params.merge({ body: params.to_json, headers: { "Content-Type" => "application/json", 'Accept'=>'application/json'} })
19
+ HTTParty.post(url(endpoint), options)
20
+ end
21
+
22
+ def delete_request(endpoint, params = {})
23
+ options = base_params.merge({ body: params.to_json, headers: { "Content-Type" => "application/json", 'Accept'=>'application/json'} })
24
+ HTTParty.delete(url(endpoint), options)
25
+ end
26
+
27
+ def base_params
28
+ (Mailflow.test_mode) ? {} : {digest_auth: {username: Mailflow.config.api_key, password: Mailflow.config.api_secret}}
29
+ end
30
+
31
+ end
32
+
33
+ def self.included(base)
34
+ base.extend(ClassMethods)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ module Mailflow
2
+
3
+ class UnprocessableError < StandardError; end
4
+
5
+ class Attribute
6
+
7
+ include Mailflow::APIOperations
8
+
9
+ attr_accessor :name
10
+
11
+ class << self
12
+ def list(options = {})
13
+ response = get_request('attributes', options)
14
+ response.parsed_response.map do |params|
15
+ Attribute.new(params)
16
+ end
17
+ end
18
+
19
+ def update(attributes, params)
20
+ body = {attributes: attributes}.merge(params)
21
+ response = post_request('attributes', body)
22
+ raise UnprocessableError if (response.code == 422 || response.code == 404)
23
+ response.parsed_response.map do |attributes|
24
+ Attribute.new(attributes)
25
+ end
26
+ end
27
+
28
+ def delete(attributes, params = {})
29
+ body = {attributes: attributes}.merge(params)
30
+ response = delete_request('attributes', body)
31
+ raise UnprocessableError if (response.code == 422 || response.code == 404)
32
+ return true
33
+ end
34
+
35
+ end
36
+
37
+ def initialize(attributes)
38
+ @key = attributes["key"]
39
+ @label = attributes["label"]
40
+ @value = attributes["value"]
41
+ end
42
+
43
+ def ==(other)
44
+ self.name == other.name
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,22 @@
1
+ require 'base64'
2
+ require 'json'
3
+ require 'httparty'
4
+ require 'byebug'
5
+
6
+ module Mailflow
7
+
8
+ class << self
9
+ attr_accessor :test_mode
10
+ end
11
+
12
+ class Client
13
+
14
+ include Mailflow::APIOperations
15
+
16
+ def self.test
17
+ get('test')
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,32 @@
1
+ require 'hashie'
2
+
3
+ module Configurable
4
+ def self.included(base)
5
+ base.const_set(:Configuration, Class.new(Hashie::Mash))
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ protected
10
+
11
+ module ClassMethods
12
+ def configuration_class
13
+ self.const_get(:Configuration)
14
+ end
15
+
16
+ def configuration
17
+ @configuration ||= configuration_class.new
18
+ end
19
+
20
+ def configuration=(configuration)
21
+ @configuration = configuration_class.new(configuration)
22
+ end
23
+
24
+ alias_method :config, :configuration
25
+
26
+ def configure(configuration = {}, &block)
27
+ self.configuration = configuration unless configuration.empty?
28
+ block.call(self.configuration) if block_given?
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,74 @@
1
+ module Mailflow
2
+
3
+ class UnprocessableError < StandardError; end
4
+
5
+ class Contact
6
+
7
+ include Mailflow::APIOperations
8
+
9
+ attr_accessor :id, :email, :created_at, :confirmed
10
+
11
+ class << self
12
+ def list
13
+ response = get_request('contacts')
14
+ response.parsed_response.map do |attributes|
15
+ Contact.new(attributes)
16
+ end
17
+ end
18
+
19
+ def get(options = {})
20
+ response = get_request('contacts', options)
21
+ Contact.new(response.parsed_response) if response.code == 200
22
+ end
23
+
24
+ def create(attributes)
25
+ response = post_request('contacts', attributes)
26
+ raise UnprocessableError if (response.code == 422 || response.code == 404)
27
+ Contact.new(response.parsed_response)
28
+ end
29
+ end
30
+
31
+ def initialize(attributes)
32
+ @id = attributes["id"]
33
+ @email = attributes["email"]
34
+ @created_at = attributes["created_at"]
35
+ @confirmed = attributes["confirmed"]
36
+ end
37
+
38
+ def ==(other)
39
+ self.id == other.id &&
40
+ self.email == other.email &&
41
+ self.confirmed == other.confirmed
42
+ end
43
+
44
+ def delete
45
+ Mailflow::Contact.delete_request('contacts', {contact_id: id}).parsed_response
46
+ end
47
+
48
+ def tags
49
+ Mailflow::Tag.list(contact_id: id)
50
+ end
51
+
52
+ def tag(tags)
53
+ Mailflow::Tag.create(tags, {contact_id: id})
54
+ end
55
+
56
+ def untag(tags)
57
+ Mailflow::Tag.untag(tags, {contact_id: id})
58
+ end
59
+
60
+ def attributes
61
+ Mailflow::Attribute.list(contact_id: id)
62
+ end
63
+
64
+ def set_attributes(attributes)
65
+ attributes = attributes.map do |key, value|
66
+ {key: key.to_s, value: value}
67
+ end
68
+
69
+ Mailflow::Attribute.update(attributes, {contact_id: id})
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,54 @@
1
+ module Mailflow
2
+
3
+ class UnprocessableError < StandardError; end
4
+
5
+ class Tag
6
+
7
+ include Mailflow::APIOperations
8
+
9
+ attr_accessor :name
10
+
11
+ class << self
12
+ def list(options = {})
13
+ response = get_request('tags', options)
14
+ response.parsed_response.map do |attributes|
15
+ Tag.new(attributes)
16
+ end
17
+ end
18
+
19
+ def create(tags, params = {}, trigger = false)
20
+ tags = tags.map { |tag| {name: tag}}
21
+ body = {tags: tags}
22
+ body.merge!(params)
23
+ body.merge!({trigger: trigger}) if trigger
24
+
25
+ response = post_request('tags', body)
26
+ raise UnprocessableError if (response.code == 422 || response.code == 404)
27
+ response.parsed_response.map do |attributes|
28
+ Tag.new(attributes)
29
+ end
30
+ end
31
+
32
+ def untag(tags, params = {})
33
+ tags = tags.map { |tag| {name: tag}}
34
+ delete_request('tags', {tags: tags}.merge(params))
35
+ end
36
+
37
+ end
38
+
39
+ def initialize(attributes)
40
+ @name = attributes["name"]
41
+ end
42
+
43
+ def ==(other)
44
+ self.name == other.name
45
+ end
46
+
47
+ def delete
48
+ Mailflow::Tag.delete_request('tags', {tags: [{name: name}]})
49
+ return true
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,3 @@
1
+ module Mailflow
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,17 @@
1
+ require "mailflow-ruby/configurable.rb"
2
+ require "mailflow-ruby/api_operations.rb"
3
+ require "mailflow-ruby/contact.rb"
4
+ require "mailflow-ruby/attribute.rb"
5
+ require "mailflow-ruby/tag.rb"
6
+ require "mailflow-ruby/client.rb"
7
+ require "mailflow-ruby/version.rb"
8
+
9
+ module Mailflow
10
+
11
+ include Configurable
12
+
13
+ def self.setup(api_key, api_secret)
14
+ Mailflow.configure({api_key: api_key, api_secret: api_secret})
15
+ end
16
+
17
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailflow-ruby/version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mailflow-ruby"
8
+ spec.version = Mailflow::VERSION
9
+ spec.authors = ["Chris Wickett", "Alex Rowan"]
10
+ spec.email = ["admin@mailflow.com"]
11
+
12
+ spec.summary = "Mailflow's Ruby API Wrapper"
13
+ spec.homepage = "https://mailflow.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ # Gems for production
22
+ spec.add_dependency "httparty"
23
+ spec.add_dependency "hashie"
24
+
25
+ # Gems for dev
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "webmock"
30
+ spec.add_development_dependency "byebug"
31
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailflow-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Wickett
8
+ - Alex Rowan
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-02-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: hashie
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.10'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.10'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: webmock
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: byebug
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description:
113
+ email:
114
+ - admin@mailflow.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/mailflow-ruby.rb
129
+ - lib/mailflow-ruby/api_operations.rb
130
+ - lib/mailflow-ruby/attribute.rb
131
+ - lib/mailflow-ruby/client.rb
132
+ - lib/mailflow-ruby/configurable.rb
133
+ - lib/mailflow-ruby/contact.rb
134
+ - lib/mailflow-ruby/tag.rb
135
+ - lib/mailflow-ruby/version.rb
136
+ - mailflow-ruby.gemspec
137
+ homepage: https://mailflow.com
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.8
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Mailflow's Ruby API Wrapper
161
+ test_files: []