octomail 0.1.0b
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 +7 -0
- data/.env.example +2 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/email_octopus.gemspec +29 -0
- data/lib/email_octopus.rb +33 -0
- data/lib/email_octopus/api.rb +44 -0
- data/lib/email_octopus/api/error.rb +14 -0
- data/lib/email_octopus/api/error/api_key_invalid.rb +10 -0
- data/lib/email_octopus/api/error/invalid_parameters.rb +10 -0
- data/lib/email_octopus/api/error/not_found.rb +11 -0
- data/lib/email_octopus/api/error/unauthorized.rb +9 -0
- data/lib/email_octopus/api/response.rb +51 -0
- data/lib/email_octopus/campaign.rb +11 -0
- data/lib/email_octopus/contact.rb +32 -0
- data/lib/email_octopus/list.rb +19 -0
- data/lib/email_octopus/model.rb +118 -0
- data/lib/email_octopus/query.rb +48 -0
- data/lib/email_octopus/version.rb +3 -0
- metadata +154 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8617969df0b86830f3c8e07d15e12fc49ed316a3ceb5249473b6496f5fae5c42
|
|
4
|
+
data.tar.gz: 724e11b9e76d8b77987e8349ef99c0e7d84cbb9e157ab32bba216606b8ae3fb7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d8020bb11b78b846fe263c7ee113faf40eb9f8cd45d4f48fa8534b25b1dee213f4c453cff9e3ede2d4fd539495922ec614bfee81dd5afcb0395c9cae2b3fc4a1
|
|
7
|
+
data.tar.gz: d62fd7fd054ccc129d2adc823cf46fcc3c837b9a828d4297c1947ba10501beeb8b06bcece2a7621968d638d25b521ad753a260e2d73fb387a90838f7a2399bab
|
data/.env.example
ADDED
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
|
7
|
+
|
|
8
|
+
We are committed to making participation in this project a harassment-free
|
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
|
12
|
+
|
|
13
|
+
Examples of unacceptable behavior by participants include:
|
|
14
|
+
|
|
15
|
+
* The use of sexualized language or imagery
|
|
16
|
+
* Personal attacks
|
|
17
|
+
* Trolling or insulting/derogatory comments
|
|
18
|
+
* Public or private harassment
|
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
|
20
|
+
addresses, without explicit permission
|
|
21
|
+
* Other unethical or unprofessional conduct
|
|
22
|
+
|
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
27
|
+
threatening, offensive, or harmful.
|
|
28
|
+
|
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
|
32
|
+
Conduct may be permanently removed from the project team.
|
|
33
|
+
|
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
|
35
|
+
when an individual is representing the project or its community.
|
|
36
|
+
|
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
38
|
+
reported by contacting a project maintainer at tscott@weblinc.com. All
|
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
|
42
|
+
incident.
|
|
43
|
+
|
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
45
|
+
version 1.3.0, available at
|
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
|
47
|
+
|
|
48
|
+
[homepage]: http://contributor-covenant.org
|
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Tom Scott
|
|
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,110 @@
|
|
|
1
|
+
# EmailOctopus
|
|
2
|
+
|
|
3
|
+
An API client for the [EmailOctopus][] email marketing service, allowing
|
|
4
|
+
you to create/view/update/destroy campaigns, lists, and contacts.
|
|
5
|
+
|
|
6
|
+
For more information on how to set up your account, read the [API docs][].
|
|
7
|
+
|
|
8
|
+
**NOTE:** This project is alpha software, tests are still being written
|
|
9
|
+
but most of the logic is there.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem "email_octopus", git: "https://github.com/gokaykucuk/email_octopus", branch: :master
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install email_octopus
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
First, configure the `EmailOctopus` library so it can be used with your
|
|
30
|
+
account. After obtaining your API key, add the following before your
|
|
31
|
+
application is initialized. For Rails apps, this might be
|
|
32
|
+
**config/initializers/email_octopus.rb**
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
EmailOctopus.configure do |config|
|
|
36
|
+
config.api_key = 'your-email-octopus-api-key'
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
You can now perform CRUD actions on the various resources that the API
|
|
41
|
+
provides.
|
|
42
|
+
|
|
43
|
+
Below is a short summary of what you can do with the library. For more
|
|
44
|
+
information, read the [RDoc][] documentation.
|
|
45
|
+
|
|
46
|
+
### Creating a new list
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
list = EmailOctopus::List.create name: 'Newsletter'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Adding a contact to that list
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
list = EmailOctopus::List.find 'previous-list-id'
|
|
56
|
+
contact = EmailOctopus::Contact.create(
|
|
57
|
+
first_name: 'Lester',
|
|
58
|
+
last_name: 'Tester',
|
|
59
|
+
email_address: 'lester.tester@example.com',
|
|
60
|
+
subscribed: true,
|
|
61
|
+
list_id: list.id
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Creating a new campaign for that list
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
list = EmailOctopus::List.find 'previous-list-id'
|
|
69
|
+
campaign = EmailOctopus::Campaign.new(
|
|
70
|
+
list_id: list.id,
|
|
71
|
+
name: 'hello world',
|
|
72
|
+
content: 'test'
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Removing a user from the contact list
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
contact = EmailOctopus::Contact.find 'previous-contact-id'
|
|
80
|
+
contact.destroy
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
86
|
+
Then, run `rake test` to run the tests. You can also run `bin/console`
|
|
87
|
+
for an interactive prompt that will allow you to experiment.
|
|
88
|
+
|
|
89
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
90
|
+
|
|
91
|
+
To release a new version, update the version number in `version.rb`, and then
|
|
92
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
|
93
|
+
push git commits and tags, and push the `.gem` file to
|
|
94
|
+
[rubygems.org](https://rubygems.org).
|
|
95
|
+
|
|
96
|
+
## Contributing
|
|
97
|
+
|
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tubbo/email_octopus.
|
|
99
|
+
This project is intended to be a safe, welcoming space for collaboration, and
|
|
100
|
+
contributors are expected to adhere to the [Contributor Covenant][] code of conduct.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
The gem is available as open source under the terms of the [MIT License][].
|
|
105
|
+
|
|
106
|
+
[EmailOctopus]: http://emailoctopus.com
|
|
107
|
+
[API docs]: http://emailoctopus.com/api-documentation
|
|
108
|
+
[Contributor Covenant]: http://contributor-covenant.org
|
|
109
|
+
[MIT License]: http://opensource.org/licenses/MIT
|
|
110
|
+
[RDoc]: http://rubydoc.info/github/tubbo/email_octopus/master/frames.html
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "email_octopus"
|
|
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,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'email_octopus/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "octomail"
|
|
8
|
+
spec.version = EmailOctopus::VERSION
|
|
9
|
+
spec.authors = ["Gokay Kucuk"]
|
|
10
|
+
spec.email = ["serdargokaykucuk@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = 'API Client for Email Octopus'
|
|
13
|
+
spec.description = 'API client for Email Octopus'
|
|
14
|
+
spec.homepage = 'https://github.com/gokaykucuk/octomail'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 12"
|
|
24
|
+
spec.add_development_dependency "minitest", "~> 5"
|
|
25
|
+
spec.add_development_dependency "dotenv", "~> 2.5"
|
|
26
|
+
|
|
27
|
+
spec.add_dependency 'activemodel'
|
|
28
|
+
spec.add_dependency 'httparty'
|
|
29
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'active_model'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'email_octopus/version'
|
|
6
|
+
|
|
7
|
+
# Client for the EmailOctopus API
|
|
8
|
+
#
|
|
9
|
+
# https://emailoctopus.com/api-documentation/
|
|
10
|
+
module EmailOctopus
|
|
11
|
+
include ActiveSupport::Configurable
|
|
12
|
+
|
|
13
|
+
extend ActiveSupport::Autoload
|
|
14
|
+
|
|
15
|
+
autoload :API
|
|
16
|
+
autoload :Model
|
|
17
|
+
autoload :Campaign
|
|
18
|
+
autoload :List
|
|
19
|
+
autoload :Contact
|
|
20
|
+
autoload :Query
|
|
21
|
+
|
|
22
|
+
autoload_under 'api' do
|
|
23
|
+
autoload :Response
|
|
24
|
+
autoload :Error
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
autoload_under 'api/error' do
|
|
28
|
+
autoload :ApiKeyInvalid
|
|
29
|
+
autoload :InvalidParameters
|
|
30
|
+
autoload :NotFound
|
|
31
|
+
autoload :Unauthorized
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'httparty'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'email_octopus/api/response'
|
|
5
|
+
|
|
6
|
+
module EmailOctopus
|
|
7
|
+
# HTTP API gateway to communicate with Email Octopus.
|
|
8
|
+
class API
|
|
9
|
+
include HTTParty
|
|
10
|
+
|
|
11
|
+
base_uri 'https://emailoctopus.com/api/1.5'
|
|
12
|
+
format :json
|
|
13
|
+
headers "Content-Type" => 'application/json'
|
|
14
|
+
|
|
15
|
+
def initialize(api_key)
|
|
16
|
+
@api_key = api_key
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get(path, url_params)
|
|
20
|
+
url_params['api_key'] = @api_key
|
|
21
|
+
Response.new self.class.get(path, query: url_params)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def post(path, body = {})
|
|
25
|
+
body['api_key'] = @api_key
|
|
26
|
+
Response.new self.class.post(path, body: body.to_json)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def patch(path, body = {})
|
|
30
|
+
body['api_key'] = @api_key
|
|
31
|
+
Response.new self.class.patch(path, body: body)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def put(path, body = {})
|
|
35
|
+
body['api_key'] = @api_key
|
|
36
|
+
Response.new self.class.put(path, body: body)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def delete(path, url_params)
|
|
40
|
+
url_params['api_key'] = @api_key
|
|
41
|
+
Response.new self.class.get(path, query: url_params)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EmailOctopus
|
|
4
|
+
class API
|
|
5
|
+
# Base error class, also thrown when unknown errors occur.
|
|
6
|
+
class Error < StandardError
|
|
7
|
+
# @param response [EmailOctopus::API::Response] Original response.
|
|
8
|
+
def initialize(response)
|
|
9
|
+
@response = response
|
|
10
|
+
super @response.body['message']
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EmailOctopus
|
|
4
|
+
class API
|
|
5
|
+
# Response object that parses out JSON.
|
|
6
|
+
class Response
|
|
7
|
+
delegate :status, :headers, to: :@raw
|
|
8
|
+
|
|
9
|
+
def initialize(response)
|
|
10
|
+
@raw = response
|
|
11
|
+
raise error_class, self if error?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def status
|
|
15
|
+
@raw.status
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def headers
|
|
19
|
+
@raw.headers
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def success?
|
|
23
|
+
@raw.is_a? HTTParty::Response
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def error?
|
|
27
|
+
!success?
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def body
|
|
31
|
+
JSON.parse @raw.body
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def error_class
|
|
35
|
+
return unless error?
|
|
36
|
+
case body['code']
|
|
37
|
+
when 'INVALID_PARAMETERS'
|
|
38
|
+
Error::InvalidParameters
|
|
39
|
+
when 'API_KEY_INVALID'
|
|
40
|
+
Error::ApiKeyInvalid
|
|
41
|
+
when 'UNAUTHORISED'
|
|
42
|
+
Error::Unauthorized
|
|
43
|
+
when 'NOT_FOUND'
|
|
44
|
+
Error::NotFound
|
|
45
|
+
else
|
|
46
|
+
Error
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EmailOctopus
|
|
4
|
+
# Contact of a list
|
|
5
|
+
class Contact < Model
|
|
6
|
+
attribute :id
|
|
7
|
+
attribute :list_id
|
|
8
|
+
attribute :first_name
|
|
9
|
+
attribute :last_name
|
|
10
|
+
attribute :email_address
|
|
11
|
+
attribute :subscribed
|
|
12
|
+
attribute :created_at
|
|
13
|
+
|
|
14
|
+
def self.where(list_id: '')
|
|
15
|
+
api = API.new EmailOctopus.config.api_key
|
|
16
|
+
api.get("/lists/#{list_id}/contacts", {}).body['data'].map do |params|
|
|
17
|
+
new(params)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def as_json
|
|
22
|
+
attributes.reject do |(key, _val)|
|
|
23
|
+
/#{key.to_s}/ =~ 'list_id'
|
|
24
|
+
end.to_h
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def base_path
|
|
28
|
+
"/lists/#{attributes[:list_id]}/contacts"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'email_octopus/contact'
|
|
3
|
+
|
|
4
|
+
module EmailOctopus
|
|
5
|
+
# Mailing list.
|
|
6
|
+
class List < Model
|
|
7
|
+
attribute :id
|
|
8
|
+
attribute :name
|
|
9
|
+
|
|
10
|
+
def contacts
|
|
11
|
+
Contact.where list_id: id
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_contact(params = {})
|
|
15
|
+
Contact.create params.merge(list_id: attributes[:id])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'email_octopus/api'
|
|
3
|
+
require 'active_model/naming'
|
|
4
|
+
|
|
5
|
+
module EmailOctopus
|
|
6
|
+
# Common code for model objects.
|
|
7
|
+
class Model
|
|
8
|
+
extend ActiveModel::Naming
|
|
9
|
+
|
|
10
|
+
# @!attribute attributes [r]
|
|
11
|
+
# @return [Hash] Attributes related to this model.
|
|
12
|
+
attr_reader :attributes
|
|
13
|
+
|
|
14
|
+
# @param params [Hash] Initial attributes for this model.
|
|
15
|
+
def initialize(params = {})
|
|
16
|
+
@attributes = params
|
|
17
|
+
@api = API.new(EmailOctopus.config.api_key)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Instantiate a new resource and immediately persist it on the API.
|
|
21
|
+
#
|
|
22
|
+
# @param params [Hash] Initial attributes to save.
|
|
23
|
+
def self.create(params = {})
|
|
24
|
+
new(params).tap(&:save)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Find a resource by its given ID.
|
|
28
|
+
#
|
|
29
|
+
# @param id [String] ID provided by EmailOctopus for this resource.
|
|
30
|
+
def self.find(id)
|
|
31
|
+
new(id: id).tap(&:persisted?)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Start a new query on a group of model resources.
|
|
35
|
+
#
|
|
36
|
+
# @return [Query] for this model class.
|
|
37
|
+
def self.all
|
|
38
|
+
Query.new self
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Delegate all class method calls that aren't defined on the model
|
|
42
|
+
# class to its +Query+.
|
|
43
|
+
#
|
|
44
|
+
# @param method [Symbol] Name of the method to call.
|
|
45
|
+
# @param arguments [Array] Arguments to pass to the method.
|
|
46
|
+
# @throws [NoMethodError] when method not defined on +all+
|
|
47
|
+
# @return [Query]
|
|
48
|
+
def self.method_missing(method, *arguments)
|
|
49
|
+
return super unless respond_to? method
|
|
50
|
+
all.public_send method, *arguments
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.respond_to_missing?(method, include_private = false)
|
|
54
|
+
true
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Define a new attribute method on the model that reads from the
|
|
58
|
+
# +attributes+ hash.
|
|
59
|
+
#
|
|
60
|
+
# @param name [Symbol] Name of the attribute
|
|
61
|
+
def self.attribute(name)
|
|
62
|
+
define_method name.to_s do
|
|
63
|
+
attributes[name.to_s]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
define_method "#{name}=" do |value|
|
|
67
|
+
attributes[name.to_s] = value
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
#
|
|
72
|
+
def persisted?
|
|
73
|
+
id.present? && reload!
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Run validations and persist to the database.
|
|
77
|
+
def save
|
|
78
|
+
persist!
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def as_json
|
|
82
|
+
attributes
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def destroy
|
|
86
|
+
@api.delete(path, {}).success?
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def reload!
|
|
90
|
+
@attributes = @api.get(path, {}).body
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
private
|
|
94
|
+
|
|
95
|
+
def create
|
|
96
|
+
# return true unless new_record?
|
|
97
|
+
@api.post(base_path, as_json).success?
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def update
|
|
101
|
+
return true unless persisted?
|
|
102
|
+
|
|
103
|
+
@api.patch(url, as_json).success?
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def persist!
|
|
107
|
+
create || update
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def base_path
|
|
111
|
+
"/#{model_name.collection.split('/').last}"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def path
|
|
115
|
+
"#{base_path}/#{id}"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EmailOctopus
|
|
4
|
+
# Runs a query on model data.
|
|
5
|
+
class Query
|
|
6
|
+
def initialize(model)
|
|
7
|
+
@model = model
|
|
8
|
+
@api = API.new(EmailOctopus.config.api_key)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def limit(num)
|
|
12
|
+
@limit = num
|
|
13
|
+
self
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def page(num)
|
|
17
|
+
@page = num
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def each
|
|
22
|
+
results.each { |result| yield result }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def first
|
|
26
|
+
results.first
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def results
|
|
32
|
+
@api.get(path, attributes).body['data'].map { |params| @model.new(params) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def path
|
|
36
|
+
"/#{@model.model_name.collection.split('/').last}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def attributes
|
|
40
|
+
{
|
|
41
|
+
limit: @limit,
|
|
42
|
+
page: @page
|
|
43
|
+
}.each_with_object({}) do |memo, (key, val)|
|
|
44
|
+
memo[key] = val unless val.nil?
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: octomail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0b
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Gokay Kucuk
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-12-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '12'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '12'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: dotenv
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '2.5'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '2.5'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: activemodel
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: httparty
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: API client for Email Octopus
|
|
98
|
+
email:
|
|
99
|
+
- serdargokaykucuk@gmail.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".env.example"
|
|
105
|
+
- ".gitignore"
|
|
106
|
+
- ".rubocop.yml"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- CODE_OF_CONDUCT.md
|
|
109
|
+
- Gemfile
|
|
110
|
+
- LICENSE.txt
|
|
111
|
+
- README.md
|
|
112
|
+
- Rakefile
|
|
113
|
+
- bin/console
|
|
114
|
+
- bin/setup
|
|
115
|
+
- email_octopus.gemspec
|
|
116
|
+
- lib/email_octopus.rb
|
|
117
|
+
- lib/email_octopus/api.rb
|
|
118
|
+
- lib/email_octopus/api/error.rb
|
|
119
|
+
- lib/email_octopus/api/error/api_key_invalid.rb
|
|
120
|
+
- lib/email_octopus/api/error/invalid_parameters.rb
|
|
121
|
+
- lib/email_octopus/api/error/not_found.rb
|
|
122
|
+
- lib/email_octopus/api/error/unauthorized.rb
|
|
123
|
+
- lib/email_octopus/api/response.rb
|
|
124
|
+
- lib/email_octopus/campaign.rb
|
|
125
|
+
- lib/email_octopus/contact.rb
|
|
126
|
+
- lib/email_octopus/list.rb
|
|
127
|
+
- lib/email_octopus/model.rb
|
|
128
|
+
- lib/email_octopus/query.rb
|
|
129
|
+
- lib/email_octopus/version.rb
|
|
130
|
+
homepage: https://github.com/gokaykucuk/octomail
|
|
131
|
+
licenses:
|
|
132
|
+
- MIT
|
|
133
|
+
metadata: {}
|
|
134
|
+
post_install_message:
|
|
135
|
+
rdoc_options: []
|
|
136
|
+
require_paths:
|
|
137
|
+
- lib
|
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
|
+
requirements:
|
|
140
|
+
- - ">="
|
|
141
|
+
- !ruby/object:Gem::Version
|
|
142
|
+
version: '0'
|
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
|
+
requirements:
|
|
145
|
+
- - ">"
|
|
146
|
+
- !ruby/object:Gem::Version
|
|
147
|
+
version: 1.3.1
|
|
148
|
+
requirements: []
|
|
149
|
+
rubyforge_project:
|
|
150
|
+
rubygems_version: 2.7.6
|
|
151
|
+
signing_key:
|
|
152
|
+
specification_version: 4
|
|
153
|
+
summary: API Client for Email Octopus
|
|
154
|
+
test_files: []
|