pdsphil-ruby-whatcounts 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.
- data/README +50 -0
- data/lib/ruby-whatcounts.rb +26 -0
- data/lib/whatcounts/api.rb +24 -0
- data/lib/whatcounts/api_request.rb +33 -0
- data/lib/whatcounts/api_response.rb +28 -0
- data/lib/whatcounts/base.rb +119 -0
- data/lib/whatcounts/certs/cacert.pem +7815 -0
- data/lib/whatcounts/spec/api_request_spec.rb +22 -0
- data/lib/whatcounts/spec/api_response_spec.rb +24 -0
- data/lib/whatcounts/spec/base_spec.rb +89 -0
- data/lib/whatcounts/spec/spec_helper.rb +31 -0
- metadata +68 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
include API::Base
|
4
|
+
include API::WhatCounts
|
5
|
+
|
6
|
+
describe OneOffMessageRequest do
|
7
|
+
include RequestSpecHelper
|
8
|
+
|
9
|
+
it "should initialize with an API url to call" do
|
10
|
+
OneOffMessageRequest.new.url.should eql("https://secure.whatcounts.com/bin/api_web")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept data for the message and store internally in the data hash" do
|
14
|
+
test_attrs = {:pwd => 'test', :list_id => 1, :realm => 'test', :format => 1, :to => 'test@test.com', :template_id => 1, :data => {:first => 'Test'}}
|
15
|
+
|
16
|
+
message_request = OneOffMessageRequest.new
|
17
|
+
message_request.set_data(mock_one_off_message)
|
18
|
+
|
19
|
+
message_request.data.should == test_attrs.merge({:cmd => 'send'}) # the 'send' command is added internallly for the API call
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
include API::Base
|
4
|
+
include API::WhatCounts
|
5
|
+
|
6
|
+
describe OneOffMessageResponse do
|
7
|
+
include ResponseSpecHelper
|
8
|
+
|
9
|
+
it "should initialize and determine if the result is a success" do
|
10
|
+
OneOffMessageResponse.new(mock_success_response).result.should eql(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should initialize and determine if the result is a failure" do
|
14
|
+
OneOffMessageResponse.new(mock_failure_response).result.should eql(false)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should handle and unknown result" do
|
18
|
+
OneOffMessageResponse.new("some unknown response that makes no sense").result.should eql(false)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should store the raw_response" do
|
22
|
+
OneOffMessageResponse.new(mock_success_response).raw_response.should eql("SUCCESS: mail will be sent to test@example.com")
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
include API::Base
|
4
|
+
include API::WhatCounts
|
5
|
+
|
6
|
+
describe Service do
|
7
|
+
include ResponseSpecHelper
|
8
|
+
include RequestSpecHelper
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@service = API::WhatCounts::Service.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to handle an Exception in send_one_off_message() when calling the API" do
|
15
|
+
@service.stub!(:ssl_post).and_raise(Exception)
|
16
|
+
lambda { @service.send_one_off_message(mock_one_off_message) }.should raise_error(ServiceError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be able to handle a successful API response" do
|
20
|
+
@service.stub!(:ssl_post).and_return(mock_success_response)
|
21
|
+
|
22
|
+
@service.send_one_off_message(mock_one_off_message).should be_an_instance_of(API::WhatCounts::OneOffMessageResponse)
|
23
|
+
@service.api_message_response.should be_an_instance_of(API::WhatCounts::OneOffMessageResponse)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to handle a failed API response" do
|
27
|
+
@service.stub!(:ssl_post).and_return(mock_failure_response)
|
28
|
+
|
29
|
+
@service.send_one_off_message(mock_one_off_message).should be_an_instance_of(API::WhatCounts::OneOffMessageResponse)
|
30
|
+
@service.api_message_response.should be_an_instance_of(API::WhatCounts::OneOffMessageResponse)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
describe OneOffMessage do
|
38
|
+
include ResponseSpecHelper
|
39
|
+
include RequestSpecHelper
|
40
|
+
|
41
|
+
before(:each) do
|
42
|
+
@test_attrs = {:pwd => 'test', :list_id => 1, :realm => 'test', :format => 1, :to => 'test@test.com', :template_id => 1, :data => {:first => 'Test'}}
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should initialize with configuration values in a hash" do
|
46
|
+
msg = OneOffMessage.new(@test_attrs)
|
47
|
+
|
48
|
+
msg.api_service.should be_an_instance_of(API::WhatCounts::Service)
|
49
|
+
msg.pwd.should eql(@test_attrs[:pwd])
|
50
|
+
msg.list_id.should eql(@test_attrs[:list_id])
|
51
|
+
msg.realm.should eql(@test_attrs[:realm])
|
52
|
+
msg.format.should eql(@test_attrs[:format])
|
53
|
+
msg.to.should eql(@test_attrs[:to])
|
54
|
+
msg.template_id.should eql(@test_attrs[:template_id])
|
55
|
+
msg.data.should eql('first^Test')
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise and exception if the requried values are not present on initialization" do
|
59
|
+
lambda { OneOffMessage.new }.should raise_error(ServiceError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should receive a true value back from a succesful message sent" do
|
63
|
+
serv = API::WhatCounts::Service.new
|
64
|
+
serv.stub!(:ssl_post).and_return(mock_success_response)
|
65
|
+
msg = OneOffMessage.new(@test_attrs)
|
66
|
+
msg.api_service = serv
|
67
|
+
|
68
|
+
msg.send.should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should receive a false value back from a failed message sent" do
|
72
|
+
serv = API::WhatCounts::Service.new
|
73
|
+
serv.stub!(:ssl_post).and_return(mock_failure_response)
|
74
|
+
msg = OneOffMessage.new(@test_attrs)
|
75
|
+
msg.api_service = serv
|
76
|
+
|
77
|
+
msg.send.should be_false
|
78
|
+
end
|
79
|
+
|
80
|
+
it "sould receive a false value back from an error during message sending" do
|
81
|
+
serv = API::WhatCounts::Service.new
|
82
|
+
serv.stub!(:send_one_off_message).and_raise(ServiceError)
|
83
|
+
msg = OneOffMessage.new(@test_attrs)
|
84
|
+
msg.api_service = serv
|
85
|
+
|
86
|
+
msg.send.should be_false
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + "/../../ruby-whatcounts"
|
5
|
+
|
6
|
+
module ResponseSpecHelper
|
7
|
+
|
8
|
+
def mock_success_response
|
9
|
+
"SUCCESS: mail will be sent to test@example.com"
|
10
|
+
end
|
11
|
+
|
12
|
+
def mock_failure_response
|
13
|
+
"FAILURE: Something went wrong"
|
14
|
+
end
|
15
|
+
|
16
|
+
def mock_invalid_password_response
|
17
|
+
"Password (asdf) doesn't match entry for API user credentials in database"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
module RequestSpecHelper
|
23
|
+
|
24
|
+
def mock_one_off_message
|
25
|
+
test_attrs = {:pwd => 'test', :list_id => 1, :realm => 'test', :format => 1, :to => 'test@test.com', :template_id => 1, :data => {:first => 'Test'}}
|
26
|
+
message = mock("message", test_attrs)
|
27
|
+
|
28
|
+
return message
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pdsphil-ruby-whatcounts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phil Ripperger, Kevin Weller
|
8
|
+
autorequire: ruby-whatcounts
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: This library allows you to send a message using the WhatCounts HTTP API. It uses the One-Off-Message 'send' method.
|
17
|
+
email: pdsphil@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- lib/ruby-whatcounts.rb
|
26
|
+
- lib/whatcounts
|
27
|
+
- lib/whatcounts/api.rb
|
28
|
+
- lib/whatcounts/api_request.rb
|
29
|
+
- lib/whatcounts/api_response.rb
|
30
|
+
- lib/whatcounts/base.rb
|
31
|
+
- lib/whatcounts/certs
|
32
|
+
- lib/whatcounts/certs/cacert.pem
|
33
|
+
- lib/whatcounts/log
|
34
|
+
- lib/whatcounts/log/error.log
|
35
|
+
- lib/whatcounts/spec
|
36
|
+
- lib/whatcounts/spec/api_request_spec.rb
|
37
|
+
- lib/whatcounts/spec/api_response_spec.rb
|
38
|
+
- lib/whatcounts/spec/base_spec.rb
|
39
|
+
- lib/whatcounts/spec/spec_helper.rb
|
40
|
+
- README
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/pdsphil/ruby-whatcounts
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.0.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: Ruby library for the WhatCounts HTTP API
|
67
|
+
test_files: []
|
68
|
+
|