cindy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +6 -0
- data/cindy.gemspec +25 -0
- data/lib/cindy.rb +16 -0
- data/lib/cindy/client.rb +59 -0
- data/lib/cindy/error.rb +54 -0
- data/lib/cindy/version.rb +3 -0
- data/lib/faraday/response/raise_cindy_error.rb +21 -0
- data/spec/cindy_spec.rb +13 -0
- data/spec/spec_helper.rb +7 -0
- metadata +147 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Richard Lee
|
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,29 @@
|
|
1
|
+
# Cindy
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cindy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cindy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/cindy.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cindy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "cindy"
|
8
|
+
gem.version = Cindy::VERSION
|
9
|
+
gem.authors = ["Richard Lee"]
|
10
|
+
gem.email = ["rl@polydice.com"]
|
11
|
+
gem.description = %q{A lightweight, flexible Ruby SDK for Sendy, a self-hosted email newsletter app.}
|
12
|
+
gem.summary = %q{Simple Ruby wrapper for Sendy API.}
|
13
|
+
gem.homepage = "https://github.com/polydice/cindy"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^spec/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency("faraday", "~> 0.8.5")
|
20
|
+
gem.add_dependency('faraday_middleware', '~> 0.9')
|
21
|
+
gem.add_dependency('hashie', '~> 1.0')
|
22
|
+
|
23
|
+
gem.add_development_dependency("rake", "~> 10.0.3")
|
24
|
+
gem.add_development_dependency("rspec", "~> 2.12.0")
|
25
|
+
end
|
data/lib/cindy.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "cindy/version"
|
2
|
+
require "cindy/client"
|
3
|
+
require "cindy/error"
|
4
|
+
|
5
|
+
module Cindy
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def new(sendy_url, api_key = nil)
|
10
|
+
# Alias method for Cindy::Client
|
11
|
+
Cindy::Client.new(sendy_url, api_key)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/cindy/client.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday/response/raise_cindy_error'
|
4
|
+
|
5
|
+
module Cindy
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def initialize(sendy_url, api_key = nil)
|
9
|
+
@url = sendy_url
|
10
|
+
@key = api_key || ENV['SENDY_API_KEY']
|
11
|
+
end
|
12
|
+
|
13
|
+
def subscribe(list_id, email, name = nil)
|
14
|
+
response = connection.post "/subscribe" do |req|
|
15
|
+
params = {list: list_id, email: email, boolean: true}
|
16
|
+
params[:name] = name if name
|
17
|
+
req.body = params
|
18
|
+
end
|
19
|
+
|
20
|
+
!!(response.body =~ /^1$/)
|
21
|
+
end
|
22
|
+
|
23
|
+
def unsubscribe(list_id, email)
|
24
|
+
response = connection.post "/unsubscribe", {list: list_id, email: email, boolean: true}
|
25
|
+
|
26
|
+
!!(response.body =~ /^1$/)
|
27
|
+
end
|
28
|
+
|
29
|
+
def subscription_status(list_id, email)
|
30
|
+
response = connection.post "/api/subscribers/subscription-status.php" do |req|
|
31
|
+
req.body = {list_id: list_id, email: email, api_key: @key}
|
32
|
+
end
|
33
|
+
|
34
|
+
response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def active_subscriber_count(list_id)
|
38
|
+
response = connection.post "/api/subscribers/active-subscriber-count.php" do |req|
|
39
|
+
req.body = {list_id: list_id, api_key: @key}
|
40
|
+
end
|
41
|
+
|
42
|
+
response.body.to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def connection
|
48
|
+
@connection ||= Faraday.new(:url => @url) do |faraday|
|
49
|
+
faraday.request :url_encoded
|
50
|
+
faraday.adapter Faraday.default_adapter
|
51
|
+
|
52
|
+
faraday.use ::Faraday::Response::RaiseCindyError
|
53
|
+
faraday.use ::FaradayMiddleware::FollowRedirects
|
54
|
+
faraday.use ::FaradayMiddleware::Mashify
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/lib/cindy/error.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Cindy
|
2
|
+
# Generic error
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class NoDataPasssed < Error; end
|
6
|
+
|
7
|
+
class APIKeyNotPassed < Error; end
|
8
|
+
|
9
|
+
class InvalidAPIKey < Error; end
|
10
|
+
|
11
|
+
class EmailNotPassed < Error; end
|
12
|
+
|
13
|
+
class ListIDNotPassed < Error; end
|
14
|
+
|
15
|
+
class ListDoesNotExist < Error; end
|
16
|
+
|
17
|
+
class EmailDoesNotExistInList < Error; end
|
18
|
+
|
19
|
+
class SomeFieldsAreMissing < Error; end
|
20
|
+
|
21
|
+
class InvalidEmailAddress < Error; end
|
22
|
+
|
23
|
+
class AlreadySubscribed < Error; end
|
24
|
+
|
25
|
+
# Raised when Sendy returns a 400 HTTP status code
|
26
|
+
class BadRequest < Error; end
|
27
|
+
|
28
|
+
# Raised when Sendy returns a 401 HTTP status code
|
29
|
+
class Unauthorized < Error; end
|
30
|
+
|
31
|
+
# Raised when Sendy returns a 403 HTTP status code
|
32
|
+
class Forbidden < Error; end
|
33
|
+
|
34
|
+
# Raised when Sendy returns a 404 HTTP status code
|
35
|
+
class NotFound < Error; end
|
36
|
+
|
37
|
+
# Raised when Sendy returns a 406 HTTP status code
|
38
|
+
class NotAcceptable < Error; end
|
39
|
+
|
40
|
+
# Raised when Sendy returns a 422 HTTP status code
|
41
|
+
class UnprocessableEntity < Error; end
|
42
|
+
|
43
|
+
# Raised when Sendy returns a 500 HTTP status code
|
44
|
+
class InternalServerError < Error; end
|
45
|
+
|
46
|
+
# Raised when Sendy returns a 501 HTTP status code
|
47
|
+
class NotImplemented < Error; end
|
48
|
+
|
49
|
+
# Raised when Sendy returns a 502 HTTP status code
|
50
|
+
class BadGateway < Error; end
|
51
|
+
|
52
|
+
# Raised when Sendy returns a 503 HTTP status code
|
53
|
+
class ServiceUnavailable < Error; end
|
54
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'cindy/error'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class Response::RaiseCindyError < Response::Middleware
|
6
|
+
|
7
|
+
def on_complete(response)
|
8
|
+
case response[:body]
|
9
|
+
when /No data passed/i
|
10
|
+
when /Already subscribed./i
|
11
|
+
raise ::Cindy::AlreadySubscribed
|
12
|
+
when /Invalid email address./i
|
13
|
+
raise ::Cindy::InvalidEmailAddress
|
14
|
+
end
|
15
|
+
|
16
|
+
# key = response[:status].to_i
|
17
|
+
# raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/spec/cindy_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cindy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Richard Lee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.9'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.9'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: hashie
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 10.0.3
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 10.0.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.12.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.12.0
|
94
|
+
description: A lightweight, flexible Ruby SDK for Sendy, a self-hosted email newsletter
|
95
|
+
app.
|
96
|
+
email:
|
97
|
+
- rl@polydice.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- cindy.gemspec
|
108
|
+
- lib/cindy.rb
|
109
|
+
- lib/cindy/client.rb
|
110
|
+
- lib/cindy/error.rb
|
111
|
+
- lib/cindy/version.rb
|
112
|
+
- lib/faraday/response/raise_cindy_error.rb
|
113
|
+
- spec/cindy_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: https://github.com/polydice/cindy
|
116
|
+
licenses: []
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -3277110265652980216
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: -3277110265652980216
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.8.23
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: Simple Ruby wrapper for Sendy API.
|
145
|
+
test_files:
|
146
|
+
- spec/cindy_spec.rb
|
147
|
+
- spec/spec_helper.rb
|