smtpcom_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +20 -0
- data/README.md +110 -0
- data/Rakefile +43 -0
- data/examples/usage.rb +61 -0
- data/lib/smtpcom_api.rb +4 -0
- data/lib/smtpcom_api/account.rb +34 -0
- data/lib/smtpcom_api/client.rb +33 -0
- data/lib/smtpcom_api/helpers.rb +21 -0
- data/lib/smtpcom_api/request.rb +65 -0
- data/lib/smtpcom_api/request/urls.rb +25 -0
- data/lib/smtpcom_api/sender.rb +56 -0
- data/lib/smtpcom_api/version.rb +10 -0
- data/smtpcom_api.gemspec +89 -0
- data/spec/account_spec.rb +45 -0
- data/spec/client_spec.rb +7 -0
- data/spec/fixtures/vcr_cassettes/client.yml +559 -0
- data/spec/helpers_spec.rb +21 -0
- data/spec/request_spec.rb +60 -0
- data/spec/sender_spec.rb +57 -0
- data/spec/shared.rb +22 -0
- data/spec/spec_helper.rb +24 -0
- metadata +218 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SmtpcomApi::Helpers" do
|
4
|
+
before(:all) {
|
5
|
+
RSpec::Mocks::Mock.const_set(:ATTRIBUTES, [:first, :second])
|
6
|
+
}
|
7
|
+
let(:obj){ mock("Obj").extend(SmtpcomApi::Helpers) }
|
8
|
+
|
9
|
+
it "should return hash with attributes" do
|
10
|
+
obj.instance_variable_set(:@first, 1)
|
11
|
+
obj.instance_variable_set(:@second, 2)
|
12
|
+
obj.to_hash.should == {:first => 1, :second => 2}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set attributes from hash" do
|
16
|
+
obj.set_attributes 'first' => 1, 'second' => 2
|
17
|
+
obj.instance_variable_get(:@first).should == 1
|
18
|
+
obj.instance_variable_get(:@second).should == 2
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SmtpcomApi::Request" do
|
4
|
+
let(:client){ mock("Client").extend(SmtpcomApi::Request) }
|
5
|
+
|
6
|
+
it "could get" do
|
7
|
+
client.respond_to? :get
|
8
|
+
end
|
9
|
+
|
10
|
+
it "could put" do
|
11
|
+
client.respond_to? :put
|
12
|
+
end
|
13
|
+
|
14
|
+
it "could post" do
|
15
|
+
client.respond_to? :post
|
16
|
+
end
|
17
|
+
|
18
|
+
it "could delete" do
|
19
|
+
client.respond_to? :delete
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should convert time closures to int" do
|
23
|
+
time = Time.now
|
24
|
+
client.send(:process_params, {:time_start => time})[:time_start].should == time.to_i
|
25
|
+
client.send(:process_params, {:time_end => time})[:time_end].should == time.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should make call when get/post/put/delete" do
|
29
|
+
SmtpcomApi::Request::Urls::SOMEKEY = "/test"
|
30
|
+
client.stub(:_call).and_return(1)
|
31
|
+
|
32
|
+
client.get(:somekey).should == 1
|
33
|
+
client.put(:somekey).should == 1
|
34
|
+
client.post(:somekey).should == 1
|
35
|
+
client.delete(:somekey).should == 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should make correct path" do
|
39
|
+
SmtpcomApi::Request::Urls::SOMEPATH = "/account/senders/%s/statistics/campaigns/%s"
|
40
|
+
path = client.send(:get_path, :somepath, ['label', 'campaign_id'])
|
41
|
+
path.should == "/account/senders/label/statistics/campaigns/campaign_id"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should make correct path 2" do
|
45
|
+
SmtpcomApi::Request::Urls::SOMEPATH2 = "/account/senders/%s/statistics/delivery"
|
46
|
+
path = client.send(:get_path, :somepath2, 'label')
|
47
|
+
path.should == "/account/senders/label/statistics/delivery"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should combine correct url" do
|
51
|
+
host = 'http://myapi.com'
|
52
|
+
path = '/account/senders/label/statistics/delivery'
|
53
|
+
api_path = '/v1'
|
54
|
+
format = 'json'
|
55
|
+
client.instance_variable_set(:@api_host, host)
|
56
|
+
client.stub(:get_path).and_return(path)
|
57
|
+
client.send(:get_url, :somekey).should == [host,api_path,path,".#{format}"].join
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/spec/sender_spec.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "SmtpcomApi::Sender" do
|
4
|
+
describe "sender" do
|
5
|
+
|
6
|
+
use_vcr_cassette 'client'
|
7
|
+
let(:sender) { SmtpcomApi::Sender.new('vasiliy', API_KEY, API_HOST) }
|
8
|
+
|
9
|
+
describe "like a client" do
|
10
|
+
let(:client) { sender }
|
11
|
+
it_behaves_like "a client"
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "attributes" do
|
15
|
+
subject { sender }
|
16
|
+
|
17
|
+
it { should respond_to :label }
|
18
|
+
it { should respond_to :login }
|
19
|
+
it { should respond_to :id }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "statistics" do
|
23
|
+
subject { sender }
|
24
|
+
[:summary, :delivery, :campaigns, :complaints, :queue, :campaign].each do |key|
|
25
|
+
it {sender.should respond_to key }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to reload attributes" do
|
31
|
+
sender.reload.should be_an_instance_of(SmtpcomApi::Sender)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to save attributes" do
|
35
|
+
sender.save.should be_an_instance_of(SmtpcomApi::Sender)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "allowed ips" do
|
40
|
+
use_vcr_cassette 'client'
|
41
|
+
before(:all) {
|
42
|
+
VCR.use_cassette 'client' do
|
43
|
+
@ipauth = SmtpcomApi::Sender.new('ipauth', API_KEY, API_HOST)
|
44
|
+
end
|
45
|
+
}
|
46
|
+
it "should add allowed ip" do
|
47
|
+
@ipauth.add_allowed_ip('233.221.1.2')
|
48
|
+
@ipauth.allowed_ips.map{|aip| aip['range']}.should include '233.221.1.2'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should remove allowed ip" do
|
52
|
+
@ipauth.remove_allowed_ip('233.221.1.2')
|
53
|
+
@ipauth.allowed_ips.map{|aip| aip['range']}.should_not include '233.221.1.2'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/spec/shared.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
shared_examples_for "a client" do
|
2
|
+
it ".account should be instance of SmtpcomApi::Account" do
|
3
|
+
client.account.should be_an_instance_of(SmtpcomApi::Account)
|
4
|
+
end
|
5
|
+
|
6
|
+
it ".sender should be instanse of SmtpcomApi::Sender" do
|
7
|
+
client.sender(:vasiliy).should be_an_instance_of(SmtpcomApi::Sender)
|
8
|
+
end
|
9
|
+
|
10
|
+
it ".senders should be array of senders" do
|
11
|
+
senders = client.senders
|
12
|
+
senders.should be_an_instance_of Array
|
13
|
+
senders.each do |s|
|
14
|
+
s.should be_an_instance_of SmtpcomApi::Sender
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it ".add_sender should return instanse of SmtpcomApi::Sender" do
|
19
|
+
s = {:label => 'my_new_sender11', :login => 'my_new_sender11', :password => 'my_pass1'}
|
20
|
+
client.add_sender(s).should be_an_instance_of(SmtpcomApi::Sender)
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'smtpcom_api'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/mocks'
|
8
|
+
require 'vcr'
|
9
|
+
|
10
|
+
require 'shared'
|
11
|
+
|
12
|
+
VCR.configure do |c|
|
13
|
+
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
14
|
+
c.hook_into :faraday
|
15
|
+
c.default_cassette_options = { :record => :new_episodes }
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |c|
|
19
|
+
c.extend VCR::RSpec::Macros
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
API_KEY = '373da51f9faa9bcac214cebe2a3b460c3697825d'
|
24
|
+
API_HOST = 'http://rest.smtp.com'
|
metadata
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smtpcom_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vasiliy Sablin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday_middleware
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
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.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.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: 1.8.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '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: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.8.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.8.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec-mocks
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: webmock
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: vcr
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: ''
|
159
|
+
email: vasiliy.sablin@gmail.com
|
160
|
+
executables: []
|
161
|
+
extensions: []
|
162
|
+
extra_rdoc_files:
|
163
|
+
- LICENSE.txt
|
164
|
+
- README.md
|
165
|
+
files:
|
166
|
+
- .DS_Store
|
167
|
+
- .document
|
168
|
+
- .rspec
|
169
|
+
- Gemfile
|
170
|
+
- Gemfile.lock
|
171
|
+
- LICENSE.txt
|
172
|
+
- README.md
|
173
|
+
- Rakefile
|
174
|
+
- examples/usage.rb
|
175
|
+
- lib/smtpcom_api.rb
|
176
|
+
- lib/smtpcom_api/account.rb
|
177
|
+
- lib/smtpcom_api/client.rb
|
178
|
+
- lib/smtpcom_api/helpers.rb
|
179
|
+
- lib/smtpcom_api/request.rb
|
180
|
+
- lib/smtpcom_api/request/urls.rb
|
181
|
+
- lib/smtpcom_api/sender.rb
|
182
|
+
- lib/smtpcom_api/version.rb
|
183
|
+
- smtpcom_api.gemspec
|
184
|
+
- spec/account_spec.rb
|
185
|
+
- spec/client_spec.rb
|
186
|
+
- spec/fixtures/vcr_cassettes/client.yml
|
187
|
+
- spec/helpers_spec.rb
|
188
|
+
- spec/request_spec.rb
|
189
|
+
- spec/sender_spec.rb
|
190
|
+
- spec/shared.rb
|
191
|
+
- spec/spec_helper.rb
|
192
|
+
homepage: http://github.com/smtpcom/smtpcom_api
|
193
|
+
licenses:
|
194
|
+
- MIT
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options: []
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
none: false
|
201
|
+
requirements:
|
202
|
+
- - ! '>='
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
none: false
|
207
|
+
requirements:
|
208
|
+
- - ! '>='
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
requirements: []
|
212
|
+
rubyforge_project:
|
213
|
+
rubygems_version: 1.8.24
|
214
|
+
signing_key:
|
215
|
+
specification_version: 3
|
216
|
+
summary: Ruby wrapper for the http://smtp.com API (http://api.smtp.com)
|
217
|
+
test_files: []
|
218
|
+
has_rdoc:
|