emailyak 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -0
- data/emailyak.gemspec +2 -2
- data/lib/emailyak/version.rb +1 -1
- data/lib/emailyak.rb +30 -10
- metadata +10 -8
data/Gemfile.lock
CHANGED
@@ -4,6 +4,7 @@ PATH
|
|
4
4
|
emailyak (0.0.1)
|
5
5
|
json
|
6
6
|
rest-client
|
7
|
+
yajl-ruby (>= 0.8.3)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
@@ -12,6 +13,7 @@ GEM
|
|
12
13
|
mime-types (1.16)
|
13
14
|
rest-client (1.6.7)
|
14
15
|
mime-types (>= 1.16)
|
16
|
+
yajl-ruby (0.8.3)
|
15
17
|
|
16
18
|
PLATFORMS
|
17
19
|
ruby
|
@@ -20,3 +22,4 @@ DEPENDENCIES
|
|
20
22
|
emailyak!
|
21
23
|
json
|
22
24
|
rest-client
|
25
|
+
yajl-ruby (>= 0.8.3)
|
data/emailyak.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Emailyak::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Scott Ballantyne", 'Greg Brockman']
|
10
|
-
s.email = ["ussballantyne@gmail.
|
10
|
+
s.email = ["ussballantyne@gmail.com", 'gdb@gregbrockman.com']
|
11
11
|
s.homepage = ""
|
12
12
|
s.summary = %q{making several different emailyak projects into a gem}
|
13
13
|
s.description = %q{making several different emailyak projects into a gem description}
|
@@ -19,5 +19,5 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
s.add_dependency(%q<rest-client>, [">= 0"])
|
22
|
-
s.add_dependency(
|
22
|
+
s.add_dependency('yajl-ruby', '>= 0.8.3')
|
23
23
|
end
|
data/lib/emailyak/version.rb
CHANGED
data/lib/emailyak.rb
CHANGED
@@ -2,7 +2,7 @@ require 'cgi'
|
|
2
2
|
require 'set'
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
-
require '
|
5
|
+
require 'yajl'
|
6
6
|
require 'openssl'
|
7
7
|
require 'rest_client'
|
8
8
|
|
@@ -12,6 +12,7 @@ require 'rest_client'
|
|
12
12
|
# Further adapted from https://github.com/gdb/emailyak-ruby
|
13
13
|
# because I couldn't get it to install on heroku and
|
14
14
|
# I wanted to add to it
|
15
|
+
|
15
16
|
module EmailYak
|
16
17
|
# @@version = '0.0.1'
|
17
18
|
@@ssl_bundle_path = File.join(File.dirname(__FILE__), 'data/ca-certificates.crt')
|
@@ -30,6 +31,20 @@ module EmailYak
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
34
|
+
|
35
|
+
def self.docs(url=self.api_docs_url)
|
36
|
+
begin
|
37
|
+
puts "opening api docs at #{self.api_docs_url} "
|
38
|
+
`open #{url}`
|
39
|
+
rescue
|
40
|
+
false
|
41
|
+
end
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.api_docs_url
|
46
|
+
"http://docs.emailyak.com/"
|
47
|
+
end
|
33
48
|
|
34
49
|
class EmailYakError < StandardError; end
|
35
50
|
class APIConnectionError < EmailYakError; end
|
@@ -69,13 +84,13 @@ module EmailYak
|
|
69
84
|
EmailYak.request(:get, 'get/new/email/', nil, params)
|
70
85
|
end
|
71
86
|
|
72
|
-
def self.delete(params={})
|
73
|
-
EmailYak.request(:post, 'delete/email/', nil, params)
|
74
|
-
end
|
75
|
-
|
76
87
|
def self.send(params={})
|
77
88
|
EmailYak.request(:post, 'send/email/', nil, params)
|
78
89
|
end
|
90
|
+
|
91
|
+
def self.delete(params={})
|
92
|
+
EmailYak.request(:post, 'delete/email/', nil, params)
|
93
|
+
end
|
79
94
|
end
|
80
95
|
|
81
96
|
module Address
|
@@ -119,7 +134,11 @@ module EmailYak
|
|
119
134
|
headers = { :params => params }.merge(headers)
|
120
135
|
payload = nil
|
121
136
|
else
|
122
|
-
|
137
|
+
|
138
|
+
|
139
|
+
headers = {:content_type => 'application/json'}
|
140
|
+
payload = Yajl::Encoder.encode(params)
|
141
|
+
puts payload
|
123
142
|
end
|
124
143
|
opts = {
|
125
144
|
:method => method,
|
@@ -130,7 +149,7 @@ module EmailYak
|
|
130
149
|
:payload => payload,
|
131
150
|
:timeout => 80
|
132
151
|
}.merge(ssl_opts)
|
133
|
-
|
152
|
+
# puts params.inspect
|
134
153
|
begin
|
135
154
|
response = execute_request(opts)
|
136
155
|
rescue SocketError => e
|
@@ -144,6 +163,7 @@ module EmailYak
|
|
144
163
|
raise
|
145
164
|
end
|
146
165
|
rescue RestClient::ExceptionWithResponse => e
|
166
|
+
puts e
|
147
167
|
if rcode = e.http_code and rbody = e.http_body
|
148
168
|
self.handle_api_error(rcode, rbody)
|
149
169
|
else
|
@@ -156,8 +176,8 @@ module EmailYak
|
|
156
176
|
rbody = response.body
|
157
177
|
rcode = response.code
|
158
178
|
begin
|
159
|
-
resp =
|
160
|
-
rescue
|
179
|
+
resp = Yajl::Parser.parse(rbody)
|
180
|
+
rescue
|
161
181
|
raise APIError.new("Invalid response object from API: #{rbody.inspect} (HTTP response code was #{rcode})")
|
162
182
|
end
|
163
183
|
|
@@ -195,7 +215,7 @@ module EmailYak
|
|
195
215
|
when 431
|
196
216
|
raise APIResponseCodeError.new('Invalid Response Format. In the url, specify ../json/.. or ../xml/..', rcode, rbody)
|
197
217
|
when 432
|
198
|
-
raise APIResponseCodeError.new('Invalid when 431
|
218
|
+
raise APIResponseCodeError.new('Invalid when 431 Request Format. Needs to be JSON or XML.', rcode, rbody)
|
199
219
|
when 503
|
200
220
|
raise APIResponseCodeError.new('Service is Temporarily Down. Please stand by.', rcode, rbody)
|
201
221
|
else
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emailyak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Ballantyne
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-10-
|
19
|
+
date: 2011-10-03 00:00:00 +08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -34,22 +34,24 @@ dependencies:
|
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: yajl-ruby
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 57
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
|
47
|
+
- 8
|
48
|
+
- 3
|
49
|
+
version: 0.8.3
|
48
50
|
type: :runtime
|
49
51
|
version_requirements: *id002
|
50
52
|
description: making several different emailyak projects into a gem description
|
51
53
|
email:
|
52
|
-
- ussballantyne@gmail.
|
54
|
+
- ussballantyne@gmail.com
|
53
55
|
- gdb@gregbrockman.com
|
54
56
|
executables: []
|
55
57
|
|