digitsend 0.0.6 → 0.0.8
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/lib/digitsend/client.rb +14 -1
- data/lib/digitsend/exception.rb +10 -0
- data/lib/digitsend/message.rb +27 -7
- data/lib/digitsend/missing_phone_numbers.rb +7 -0
- data/lib/digitsend/version.rb +1 -1
- data/lib/digitsend.rb +2 -0
- metadata +3 -1
data/lib/digitsend/client.rb
CHANGED
@@ -14,7 +14,13 @@ module DigitSend
|
|
14
14
|
'Accept' => 'application/vnd.digitsend.v1',
|
15
15
|
'Authorization' => %Q[Token token="#{Config.api_token}"]
|
16
16
|
|
17
|
-
|
17
|
+
hash = JSON.parse(response.body)
|
18
|
+
|
19
|
+
if response.code != "200"
|
20
|
+
raise exception_for_response(hash)
|
21
|
+
else
|
22
|
+
hash["data"]
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
def upload_s3_file(path, data)
|
@@ -57,6 +63,13 @@ module DigitSend
|
|
57
63
|
data
|
58
64
|
end
|
59
65
|
end
|
66
|
+
|
67
|
+
def exception_for_response!(hash)
|
68
|
+
raise case hash["message"]
|
69
|
+
when "Missing phone numbers" then MissingPhoneNumbers.new(hash)
|
70
|
+
else DigitSend::Exception.new(hash)
|
71
|
+
end
|
72
|
+
end
|
60
73
|
end
|
61
74
|
end
|
62
75
|
end
|
data/lib/digitsend/message.rb
CHANGED
@@ -1,26 +1,46 @@
|
|
1
1
|
module DigitSend
|
2
2
|
class Message
|
3
3
|
def initialize
|
4
|
+
@to = []
|
5
|
+
@cc = []
|
4
6
|
@attachments = []
|
7
|
+
@phone_numbers = {}
|
5
8
|
end
|
6
9
|
|
7
10
|
def self.send(&block)
|
8
11
|
new.tap { |m| yield(m) }.send
|
9
12
|
end
|
10
13
|
|
11
|
-
|
14
|
+
def to(email, phone = nil)
|
15
|
+
@to << email
|
16
|
+
@phone_numbers[email] = phone if phone
|
17
|
+
end
|
18
|
+
|
19
|
+
def cc(email, phone = nil)
|
20
|
+
@cc << email
|
21
|
+
@phone_numbers[email] = phone if phone
|
22
|
+
end
|
23
|
+
|
24
|
+
def subject(text)
|
25
|
+
@subject = text
|
26
|
+
end
|
27
|
+
|
28
|
+
def body(text)
|
29
|
+
@body = text
|
30
|
+
end
|
12
31
|
|
13
|
-
def
|
32
|
+
def attach(filename, data = nil)
|
14
33
|
@attachments << [ filename, data ]
|
15
34
|
end
|
16
35
|
|
17
36
|
def send
|
18
37
|
Client.call '/messages', message: {
|
19
|
-
to: to,
|
20
|
-
cc: cc,
|
21
|
-
subject: subject,
|
22
|
-
body: body,
|
23
|
-
s3_file_uuids: s3_file_uuids
|
38
|
+
to: @to.join(', '),
|
39
|
+
cc: @cc.join(', '),
|
40
|
+
subject: @subject,
|
41
|
+
body: @body,
|
42
|
+
s3_file_uuids: s3_file_uuids,
|
43
|
+
phone_numbers: @phone_numbers
|
24
44
|
}
|
25
45
|
end
|
26
46
|
|
data/lib/digitsend/version.rb
CHANGED
data/lib/digitsend.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: digitsend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,7 +27,9 @@ files:
|
|
27
27
|
- lib/digitsend.rb
|
28
28
|
- lib/digitsend/client.rb
|
29
29
|
- lib/digitsend/config.rb
|
30
|
+
- lib/digitsend/exception.rb
|
30
31
|
- lib/digitsend/message.rb
|
32
|
+
- lib/digitsend/missing_phone_numbers.rb
|
31
33
|
- lib/digitsend/repository.rb
|
32
34
|
- lib/digitsend/version.rb
|
33
35
|
homepage: ''
|