newslettre 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -10
- data/features/step_definitions/recipients_steps.rb +13 -21
- data/features/support/env.rb +2 -2
- data/lib/newslettre/api.rb +57 -0
- data/lib/newslettre/api_module.rb +4 -4
- data/lib/newslettre/api_module_proxy.rb +22 -0
- data/lib/newslettre/client.rb +12 -37
- data/lib/newslettre/letter.rb +29 -3
- data/lib/newslettre/lists.rb +36 -9
- data/lib/newslettre/version.rb +1 -1
- data/lib/newslettre.rb +4 -1
- data/spec/cassettes/Newslettre/http_actions.yml +2 -2
- data/spec/cassettes/upon_raising_errors.yml +1 -1
- data/spec/high_level_api_spec.rb +89 -0
- data/spec/{newslettre_spec.rb → low_level_spec.rb} +22 -24
- metadata +20 -16
data/README.md
CHANGED
@@ -15,10 +15,10 @@ progress, scheduling etc.).
|
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
18
|
-
this is definitely going to change since it's tedious to pass the client
|
18
|
+
<del>this is definitely going to change since it's tedious to pass the client
|
19
19
|
instance around. Maybe there will be a top-level wrapper to give you
|
20
20
|
access to all the _modules_ the API defines (Identity, Newsletter,
|
21
|
-
Recipients)
|
21
|
+
Recipients)</del>
|
22
22
|
|
23
23
|
Right now it works like this…
|
24
24
|
|
@@ -26,21 +26,33 @@ Right now it works like this…
|
|
26
26
|
|
27
27
|
require 'newslettre'
|
28
28
|
|
29
|
-
client = Newslettre::Client.new
|
30
|
-
|
29
|
+
client = Newslettre::Client.new "somebody@yourdomain.com", "reallygoodpassword"
|
30
|
+
|
31
|
+
# Accessing newsletters
|
32
|
+
|
33
|
+
client.newsletters.to_a # => [{ "name" => "webdev" }]
|
34
|
+
|
35
|
+
client.newsletters.get("webdev") # => { "name", "subject" => "Latest Web Development News", "html" => "<html>...</html>" }
|
31
36
|
|
32
|
-
|
37
|
+
client.newsletters.delete "webdev"
|
33
38
|
|
34
|
-
|
39
|
+
# Accessing recipients of a newsletter
|
35
40
|
|
41
|
+
client.newsletters.get("webdev").recipients.to_a # => [{ "list" => "web-developers" }]
|
42
|
+
|
43
|
+
client.newsletters.get("webdev").recipients.delete "web-developers"
|
44
|
+
|
45
|
+
```
|
36
46
|
|
37
|
-
|
47
|
+
<del>nearly the same goes for `Identity`, `Lists`, `Lists::Email` and `Letter::Recipients`</del>
|
38
48
|
|
39
|
-
|
49
|
+
You can also use `#lists` and `#identities` as well as the nested emails in recipient lists.
|
40
50
|
|
41
|
-
```
|
51
|
+
``` ruby
|
42
52
|
|
43
|
-
|
53
|
+
client.lists.get("web-developers").emails.delete "selective@hosted.com", "programmatic@failure.com"
|
54
|
+
|
55
|
+
```
|
44
56
|
|
45
57
|
## Development
|
46
58
|
|
@@ -1,33 +1,33 @@
|
|
1
1
|
Given /^there is no Newsletter named '([^']+)'$/ do |name|
|
2
2
|
begin
|
3
|
-
|
4
|
-
rescue Newslettre::
|
3
|
+
newslettre.newsletters.delete name
|
4
|
+
rescue Newslettre::API::ClientFailure
|
5
5
|
nil
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
Given /^there is no '([^']+)' Recipient List$/ do |list|
|
10
10
|
begin
|
11
|
-
|
12
|
-
rescue Newslettre::
|
11
|
+
newslettre.lists.delete list
|
12
|
+
rescue Newslettre::API::ClientFailure
|
13
13
|
nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
Given /^there is no identity named '([^']+)'$/ do |identity|
|
18
18
|
begin
|
19
|
-
|
20
|
-
rescue Newslettre::
|
19
|
+
newslettre.identities.delete identity
|
20
|
+
rescue Newslettre::API::ClientFailure
|
21
21
|
nil
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
Given /^I add the '([^']+)' Identity$/ do |identity|
|
26
|
-
|
26
|
+
newslettre.identities.add identity, NEWSLETTRE_CONFIG['identity']
|
27
27
|
end
|
28
28
|
|
29
29
|
Given /^I add a Newsletter named '([^']+)' written by '([^']+)'$/ do |name, identity|
|
30
|
-
|
30
|
+
newslettre.newsletters.add name,
|
31
31
|
:identity => identity,
|
32
32
|
:subject => name,
|
33
33
|
:text => "Super Cool!",
|
@@ -35,29 +35,21 @@ Given /^I add a Newsletter named '([^']+)' written by '([^']+)'$/ do |name, iden
|
|
35
35
|
end
|
36
36
|
|
37
37
|
Given /^I add a Recipient List named '([^']+)'$/ do |list|
|
38
|
-
|
38
|
+
newslettre.lists.add list
|
39
39
|
end
|
40
40
|
|
41
41
|
When /^I add '([^']+)' to '([^']+)'$/ do |list, name|
|
42
|
-
recipients
|
43
|
-
|
44
|
-
recipients.add list
|
42
|
+
newslettre.newsletters.get(name).recipients.add list
|
45
43
|
end
|
46
44
|
|
47
45
|
When /^I remove '([^']+)' from '([^']+)'$/ do |list, name|
|
48
|
-
recipients
|
49
|
-
|
50
|
-
recipients.delete list
|
46
|
+
newslettre.newsletters.get(name).recipients.delete list
|
51
47
|
end
|
52
48
|
|
53
49
|
Then /^'([^']+)' will be notified when '([^']+)' is delivered$/ do |list, name|
|
54
|
-
recipients
|
55
|
-
lists = recipients.get
|
56
|
-
lists.should =~ [{ "list" => list }]
|
50
|
+
newslettre.newsletters.get(name).recipients.to_a.should =~ [{ "list" => list }]
|
57
51
|
end
|
58
52
|
|
59
53
|
Then /^no one will be notified when '([^']+)' is delivered$/ do |name|
|
60
|
-
recipients
|
61
|
-
lists = recipients.get
|
62
|
-
lists.should be_empty
|
54
|
+
newslettre.newsletters.get(name).recipients.to_a.should be_empty
|
63
55
|
end
|
data/features/support/env.rb
CHANGED
@@ -17,8 +17,8 @@ end
|
|
17
17
|
|
18
18
|
class OuterWorld
|
19
19
|
def newslettre
|
20
|
-
@newslettre ||= Newslettre::Client.new(
|
21
|
-
|
20
|
+
@newslettre ||= Newslettre::Client.new(NEWSLETTRE_CONFIG['sendgrid']['username'],
|
21
|
+
NEWSLETTRE_CONFIG['sendgrid']['password'])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Newslettre::API
|
2
|
+
include HTTParty
|
3
|
+
format :json
|
4
|
+
attr_accessor :email, :password
|
5
|
+
|
6
|
+
base_uri "https://sendgrid.com/api/newsletter"
|
7
|
+
|
8
|
+
def initialize options = {}
|
9
|
+
@email = options.delete :email
|
10
|
+
@password = options.delete :password
|
11
|
+
end
|
12
|
+
|
13
|
+
def url
|
14
|
+
@url ||= self.class.default_options[:base_uri]
|
15
|
+
end
|
16
|
+
|
17
|
+
def format
|
18
|
+
@format ||= self.class.default_options[:format]
|
19
|
+
end
|
20
|
+
|
21
|
+
def authenticated?
|
22
|
+
not email.nil? and not password.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
%w{get list add delete edit}.each do |m|
|
26
|
+
define_method m do |*args|
|
27
|
+
raise NotAuthenticatedFailure unless authenticated?
|
28
|
+
params, options = args
|
29
|
+
params ||= {}
|
30
|
+
options ||= {}
|
31
|
+
response = self.class.post url_for(m, options), :query => params.merge(credentials)
|
32
|
+
raise ClientFailure if response.code > 399 and response.code < 500
|
33
|
+
raise EndpointFailure if response.code > 499
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :post, :add
|
39
|
+
alias_method :put, :edit
|
40
|
+
|
41
|
+
class NotAuthenticatedFailure < StandardError; end
|
42
|
+
class ClientFailure < StandardError; end
|
43
|
+
class EndpointFailure < StandardError; end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def credentials
|
48
|
+
{
|
49
|
+
:api_user => email,
|
50
|
+
:api_key => password
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def url_for path, options = {}
|
55
|
+
"#{options[:prefix]}/#{path}.#{format}"
|
56
|
+
end
|
57
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Newslettre::APIModule
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :api
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@
|
4
|
+
def initialize api
|
5
|
+
@api = api
|
6
6
|
end
|
7
7
|
|
8
8
|
protected
|
@@ -12,6 +12,6 @@ class Newslettre::APIModule
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def request method, data = {}
|
15
|
-
|
15
|
+
@api.send method, data, { :prefix => api_prefix }
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Newslettre::APIModuleProxy
|
2
|
+
extend ::Forwardable
|
3
|
+
|
4
|
+
attr_reader :owner, :target
|
5
|
+
def initialize owner, target
|
6
|
+
@owner = owner
|
7
|
+
@target = target
|
8
|
+
end
|
9
|
+
|
10
|
+
def_delegator :@target, :get
|
11
|
+
def_delegator :@target, :edit
|
12
|
+
def_delegator :@target, :delete
|
13
|
+
def_delegator :@target, :add
|
14
|
+
|
15
|
+
def to_a
|
16
|
+
target.list
|
17
|
+
end
|
18
|
+
|
19
|
+
def == other
|
20
|
+
target == other
|
21
|
+
end
|
22
|
+
end
|
data/lib/newslettre/client.rb
CHANGED
@@ -1,49 +1,24 @@
|
|
1
1
|
class Newslettre::Client
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def initialize options = {}
|
8
|
-
self.class.base_uri "https://sendgrid.com/api/newsletter"
|
9
|
-
@email = options.delete :email
|
10
|
-
@password = options.delete :password
|
11
|
-
@format = "json"
|
2
|
+
attr_reader :api
|
3
|
+
def initialize email, password
|
4
|
+
@api = Newslettre::API.new :email => email, :password => password
|
12
5
|
end
|
13
6
|
|
14
|
-
|
15
|
-
|
16
|
-
@url ||= self.class.default_options[:base_uri]
|
7
|
+
def newsletters
|
8
|
+
@newsletters ||= proxy_for Newslettre::Letter
|
17
9
|
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
params, options = args
|
22
|
-
params ||= {}
|
23
|
-
options ||= {}
|
24
|
-
response = self.class.post url_for(m, options), :query => params.merge(credentials)
|
25
|
-
raise ClientFailure if response.code > 399 and response.code < 500
|
26
|
-
raise EndpointFailure if response.code > 499
|
27
|
-
response
|
28
|
-
end
|
11
|
+
def identities
|
12
|
+
@identities ||= proxy_for Newslettre::Identity
|
29
13
|
end
|
30
14
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
class ClientFailure < StandardError; end
|
35
|
-
class EndpointFailure < StandardError; end
|
15
|
+
def lists
|
16
|
+
@lists ||= proxy_for Newslettre::Lists
|
17
|
+
end
|
36
18
|
|
37
19
|
protected
|
38
20
|
|
39
|
-
def
|
40
|
-
|
41
|
-
:api_user => email,
|
42
|
-
:api_key => password
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def url_for path, options = {}
|
47
|
-
"#{options[:prefix]}/#{path}.#{format}"
|
21
|
+
def proxy_for klass
|
22
|
+
Newslettre::APIModuleProxy.new self, klass.new(@api)
|
48
23
|
end
|
49
24
|
end
|
data/lib/newslettre/letter.rb
CHANGED
@@ -1,4 +1,29 @@
|
|
1
1
|
class Newslettre::Letter < Newslettre::APIModule
|
2
|
+
class Object < Struct.new(:owner, :name, :data)
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegator :owner, :request
|
6
|
+
def_delegator :owner, :api
|
7
|
+
|
8
|
+
def == other
|
9
|
+
self.to_hash == other
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_data
|
13
|
+
self.data ||= request('get', :name => self.name).to_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
load_data
|
18
|
+
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
def recipients
|
23
|
+
@recipients ||= Newslettre::APIModuleProxy.new self, Recipients.new(self.name, self.api)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
2
27
|
def list
|
3
28
|
request 'list'
|
4
29
|
end
|
@@ -8,7 +33,7 @@ class Newslettre::Letter < Newslettre::APIModule
|
|
8
33
|
end
|
9
34
|
|
10
35
|
def get name
|
11
|
-
|
36
|
+
Object.new self, name
|
12
37
|
end
|
13
38
|
|
14
39
|
def delete name
|
@@ -22,9 +47,9 @@ class Newslettre::Letter < Newslettre::APIModule
|
|
22
47
|
class Recipients < Newslettre::APIModule
|
23
48
|
attr_reader :letter
|
24
49
|
|
25
|
-
def initialize letter,
|
50
|
+
def initialize letter, api
|
26
51
|
@letter = letter
|
27
|
-
@
|
52
|
+
@api = api
|
28
53
|
end
|
29
54
|
|
30
55
|
def add list
|
@@ -34,6 +59,7 @@ class Newslettre::Letter < Newslettre::APIModule
|
|
34
59
|
def get
|
35
60
|
request 'get', { :name => letter }
|
36
61
|
end
|
62
|
+
alias_method :list, :get
|
37
63
|
|
38
64
|
def delete list
|
39
65
|
request 'delete', { :list => list, :name => letter }
|
data/lib/newslettre/lists.rb
CHANGED
@@ -1,16 +1,43 @@
|
|
1
1
|
class Newslettre::Lists < Newslettre::APIModule
|
2
|
+
class Object < Struct.new(:owner, :list, :data)
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegator :owner, :request
|
6
|
+
def_delegator :owner, :api
|
7
|
+
|
8
|
+
def == other
|
9
|
+
self.to_hash == other
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_data
|
13
|
+
self.data ||= request('get', :list => self.list).first.to_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
load_data
|
18
|
+
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
def emails
|
23
|
+
@emails ||= Newslettre::APIModuleProxy.new self, Email.new(self.list, self.api)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
2
27
|
def add list, data = {}
|
3
28
|
request 'add', data.merge(:list => list)
|
4
29
|
end
|
5
30
|
|
6
|
-
def get list
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
31
|
+
def get list
|
32
|
+
Object.new self, list
|
33
|
+
end
|
34
|
+
|
35
|
+
def list
|
36
|
+
request('get').map {|r|
|
37
|
+
Object.new self, r["list"]
|
38
|
+
}
|
12
39
|
end
|
13
|
-
|
40
|
+
|
14
41
|
|
15
42
|
def edit list, data = {}
|
16
43
|
request 'edit', data.merge(:list => list)
|
@@ -23,9 +50,9 @@ class Newslettre::Lists < Newslettre::APIModule
|
|
23
50
|
class Email < Newslettre::APIModule
|
24
51
|
attr_reader :list
|
25
52
|
|
26
|
-
def initialize list,
|
27
|
-
@client = client
|
53
|
+
def initialize list, api
|
28
54
|
@list = list
|
55
|
+
@api = api
|
29
56
|
end
|
30
57
|
|
31
58
|
def add *recipients
|
data/lib/newslettre/version.rb
CHANGED
data/lib/newslettre.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
|
3
3
|
module Newslettre
|
4
|
-
autoload :
|
4
|
+
autoload :API, 'newslettre/api'
|
5
5
|
autoload :APIModule, 'newslettre/api_module'
|
6
|
+
autoload :APIModuleProxy, 'newslettre/api_module_proxy'
|
7
|
+
autoload :Client, 'newslettre/client'
|
6
8
|
autoload :Letter, 'newslettre/letter'
|
7
9
|
autoload :Identity, 'newslettre/identity'
|
8
10
|
autoload :Lists, 'newslettre/lists'
|
9
11
|
end
|
12
|
+
|
@@ -13,12 +13,12 @@
|
|
13
13
|
server:
|
14
14
|
- nginx/0.7.65
|
15
15
|
date:
|
16
|
-
-
|
16
|
+
- Wed, 21 Sep 2011 07:09:02 GMT
|
17
17
|
content-type:
|
18
18
|
- text/html
|
19
19
|
transfer-encoding:
|
20
20
|
- chunked
|
21
21
|
connection:
|
22
22
|
- keep-alive
|
23
|
-
body: ! '[]'
|
23
|
+
body: ! '[{"name": "Superior Soy Beans Discount!"}]'
|
24
24
|
http_version: '1.1'
|
@@ -0,0 +1,89 @@
|
|
1
|
+
describe "The higher-level API" do
|
2
|
+
before :each do
|
3
|
+
@client = Newslettre::Client.new(
|
4
|
+
NEWSLETTRE_CONFIG['sendgrid']['username'],
|
5
|
+
NEWSLETTRE_CONFIG['sendgrid']['password']
|
6
|
+
)
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples_for "an association proxy" do |association|
|
10
|
+
let(:proxy) { subject.send(association) }
|
11
|
+
|
12
|
+
it "should return an instance of `APIModuleProxy`" do
|
13
|
+
proxy.should be_kind_of(Newslettre::APIModuleProxy)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set the API on the target" do
|
17
|
+
proxy.target.api.should == subject.api
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have the correct target" do
|
21
|
+
proxy.target.should be_kind_of(described_class)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context Newslettre::Identity do
|
26
|
+
subject { @client }
|
27
|
+
it_should_behave_like "an association proxy", :identities
|
28
|
+
end
|
29
|
+
|
30
|
+
context Newslettre::Lists do
|
31
|
+
subject { @client }
|
32
|
+
it_should_behave_like "an association proxy", :lists
|
33
|
+
|
34
|
+
it "should allow get on the proxy and return a wrapped `Object`" do
|
35
|
+
subject.lists.get('test-list').should be_kind_of(Newslettre::Lists::Object)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "Lists::Email" do
|
40
|
+
subject { @client.lists.get("test-list") }
|
41
|
+
|
42
|
+
it "should cast to_hash" do
|
43
|
+
subject.owner.should_receive(:request).and_return([{ "fields" => "some stuff" }])
|
44
|
+
|
45
|
+
subject.to_hash == { "fields" => "some stuff" }
|
46
|
+
end
|
47
|
+
|
48
|
+
context Newslettre::Lists::Email do
|
49
|
+
it_should_behave_like "an association proxy", :emails
|
50
|
+
|
51
|
+
it "should have set the correct list on the target" do
|
52
|
+
subject.emails.target.list.should == "test-list"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context Newslettre::Letter do
|
58
|
+
subject { @client }
|
59
|
+
it_should_behave_like "an association proxy", :newsletters
|
60
|
+
|
61
|
+
it "should, when casted to array, return a `list` of elements" do
|
62
|
+
subject.newsletters.target.should_receive(:list).and_return([1,2,3])
|
63
|
+
|
64
|
+
subject.newsletters.to_a.should == [1,2,3]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should allow get on the proxy and return an `Object`" do
|
68
|
+
subject.newsletters.get('test').should be_kind_of(Newslettre::Letter::Object)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "Letter::Object" do
|
73
|
+
subject { @client.newsletters.get("Foobar") }
|
74
|
+
|
75
|
+
it "should cast to_hash" do
|
76
|
+
subject.owner.should_receive(:request).and_return({ "text" => "some stuff" })
|
77
|
+
|
78
|
+
subject.to_hash == { "text" => "some stuff" }
|
79
|
+
end
|
80
|
+
|
81
|
+
context Newslettre::Letter::Recipients do
|
82
|
+
it_should_behave_like "an association proxy", :recipients
|
83
|
+
|
84
|
+
it "should have set the correct letter on the target" do
|
85
|
+
subject.recipients.target.letter.should == "Foobar"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,48 +1,46 @@
|
|
1
1
|
describe Newslettre do
|
2
2
|
before :each do
|
3
|
-
@
|
3
|
+
@api = Newslettre::API.new :email => NEWSLETTRE_CONFIG['sendgrid']['username'],
|
4
4
|
:password => NEWSLETTRE_CONFIG['sendgrid']['password']
|
5
5
|
end
|
6
6
|
|
7
7
|
describe "#initialize" do
|
8
8
|
it "should accept an email and password" do
|
9
|
-
@
|
9
|
+
@api.should be_kind_of(Newslettre::API)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should set email" do
|
13
|
-
@
|
13
|
+
@api.email.should == NEWSLETTRE_CONFIG['sendgrid']['username']
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should set password" do
|
17
|
-
@
|
17
|
+
@api.password.should == NEWSLETTRE_CONFIG['sendgrid']['password']
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should target `https://sendgrid.com/api/newsletter/`" do
|
21
|
-
@
|
21
|
+
@api.url.should == "https://sendgrid.com/api/newsletter"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "http actions" do
|
26
26
|
use_vcr_cassette
|
27
27
|
|
28
|
+
it "should raise on unauthenticated requests" do
|
29
|
+
lambda {
|
30
|
+
Newslettre::API.new.list
|
31
|
+
}.should raise_error(Newslettre::API::NotAuthenticatedFailure)
|
32
|
+
end
|
33
|
+
|
28
34
|
it "should auth requests" do
|
29
|
-
@
|
35
|
+
@api.list
|
30
36
|
end
|
31
37
|
|
32
38
|
it "should raise NotFound on missing resource" do
|
33
39
|
lambda {
|
34
40
|
VCR.use_cassette('upon raising errors') do
|
35
|
-
@
|
41
|
+
@api.delete :name => "A Newsletter that will _hopefully_ never, ever exist!"
|
36
42
|
end
|
37
|
-
}.should raise_error(Newslettre::
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#newsletters" do
|
42
|
-
it "should be a list" do
|
43
|
-
pending {
|
44
|
-
@client.newsletters.should be_respond_to(:<<)
|
45
|
-
}
|
43
|
+
}.should raise_error(Newslettre::API::ClientFailure)
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
@@ -50,7 +48,7 @@ describe Newslettre do
|
|
50
48
|
use_vcr_cassette
|
51
49
|
|
52
50
|
before :each do
|
53
|
-
@identity = Newslettre::Identity.new @
|
51
|
+
@identity = Newslettre::Identity.new @api
|
54
52
|
end
|
55
53
|
|
56
54
|
it "should list zero identities" do
|
@@ -81,7 +79,7 @@ describe Newslettre do
|
|
81
79
|
use_vcr_cassette
|
82
80
|
|
83
81
|
before :each do
|
84
|
-
@lists = Newslettre::Lists.new @
|
82
|
+
@lists = Newslettre::Lists.new @api
|
85
83
|
end
|
86
84
|
|
87
85
|
it "should list zero test lists" do
|
@@ -110,10 +108,10 @@ describe Newslettre do
|
|
110
108
|
use_vcr_cassette
|
111
109
|
|
112
110
|
before :each do
|
113
|
-
@lists = Newslettre::Lists.new @
|
111
|
+
@lists = Newslettre::Lists.new @api
|
114
112
|
@lists.add('test-list')
|
115
113
|
|
116
|
-
@emails = Newslettre::Lists::Email.new 'test-list', @
|
114
|
+
@emails = Newslettre::Lists::Email.new 'test-list', @api
|
117
115
|
|
118
116
|
@emails.add *NEWSLETTRE_CONFIG['emails']
|
119
117
|
end
|
@@ -134,11 +132,11 @@ describe Newslettre do
|
|
134
132
|
use_vcr_cassette
|
135
133
|
|
136
134
|
before :each do
|
137
|
-
@newsletter = Newslettre::Letter.new @
|
135
|
+
@newsletter = Newslettre::Letter.new @api
|
138
136
|
end
|
139
137
|
|
140
|
-
it "should have
|
141
|
-
@newsletter.
|
138
|
+
it "should have an API" do
|
139
|
+
@newsletter.api.should == @api
|
142
140
|
end
|
143
141
|
|
144
142
|
it "should list zero test letters" do
|
@@ -151,7 +149,7 @@ describe Newslettre do
|
|
151
149
|
use_vcr_cassette
|
152
150
|
|
153
151
|
before :each do
|
154
|
-
@identity = Newslettre::Identity.new @
|
152
|
+
@identity = Newslettre::Identity.new @api
|
155
153
|
@identity.add "test-identity", NEWSLETTRE_CONFIG['identity']
|
156
154
|
|
157
155
|
@newsletter.add 'test', NEWSLETTRE_CONFIG['letter']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newslettre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-21 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153366660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0.8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153366660
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rake
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153365360 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0.9'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153365360
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153363440 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '2'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153363440
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: webmock
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153362080 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '1.7'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153362080
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: vcr
|
61
|
-
requirement: &
|
61
|
+
requirement: &2153360040 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '1.11'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *2153360040
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: cucumber
|
72
|
-
requirement: &
|
72
|
+
requirement: &2153358380 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: '1'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *2153358380
|
81
81
|
description: Create and Manage Newsletters using the Sendgrid API
|
82
82
|
email:
|
83
83
|
- l@melzer.it
|
@@ -96,7 +96,9 @@ files:
|
|
96
96
|
- features/step_definitions/recipients_steps.rb
|
97
97
|
- features/support/env.rb
|
98
98
|
- lib/newslettre.rb
|
99
|
+
- lib/newslettre/api.rb
|
99
100
|
- lib/newslettre/api_module.rb
|
101
|
+
- lib/newslettre/api_module_proxy.rb
|
100
102
|
- lib/newslettre/client.rb
|
101
103
|
- lib/newslettre/identity.rb
|
102
104
|
- lib/newslettre/letter.rb
|
@@ -112,7 +114,8 @@ files:
|
|
112
114
|
- spec/cassettes/Newslettre/Newslettre_Lists_Email.yml
|
113
115
|
- spec/cassettes/Newslettre/http_actions.yml
|
114
116
|
- spec/cassettes/upon_raising_errors.yml
|
115
|
-
- spec/
|
117
|
+
- spec/high_level_api_spec.rb
|
118
|
+
- spec/low_level_spec.rb
|
116
119
|
- spec/spec_helper.rb
|
117
120
|
has_rdoc: true
|
118
121
|
homepage: ''
|
@@ -154,5 +157,6 @@ test_files:
|
|
154
157
|
- spec/cassettes/Newslettre/Newslettre_Lists_Email.yml
|
155
158
|
- spec/cassettes/Newslettre/http_actions.yml
|
156
159
|
- spec/cassettes/upon_raising_errors.yml
|
157
|
-
- spec/
|
160
|
+
- spec/high_level_api_spec.rb
|
161
|
+
- spec/low_level_spec.rb
|
158
162
|
- spec/spec_helper.rb
|