sms160 0.0.1 → 1.0.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.
- checksums.yaml +4 -4
- data/lib/sms160.rb +8 -60
- data/lib/sms160/configuration.rb +5 -0
- data/lib/sms160/message.rb +65 -0
- data/lib/sms160/version.rb +1 -1
- data/spec/lib/sms160_spec.rb +14 -11
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9f115929a833454f3192db2153416d3349b8227
|
4
|
+
data.tar.gz: 1f60e86361f7f518c08efa1efc6c4555a0fb029e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cc37c65250d6992a7c6fb0c0b2aba934083fd65bd3a33878946169efce04877a1f514575f57e92d2f55dfc477894e925c953625a582e3264f5b1a7c122a3e51
|
7
|
+
data.tar.gz: 00619be27f32164a672839efac2bcae8326a6459090892d870b37f6517b4fe05fca9d98eac9fe296f8dcdd4eedc10621c648abfd5fe4aed8e941b944f5ef7a53
|
data/lib/sms160.rb
CHANGED
@@ -1,68 +1,16 @@
|
|
1
1
|
require "sms160/version"
|
2
2
|
require "sms160/constants"
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
require "rest_client"
|
3
|
+
require "sms160/configuration"
|
4
|
+
require "sms160/message"
|
6
5
|
|
7
6
|
module Sms160
|
8
|
-
class Message
|
9
|
-
attr_accessor :to, :body, :reply_to
|
10
|
-
attr_accessor :username, :password
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def credit_balance
|
19
|
-
response = RestClient.get(BALANCE_ENDPOINT, params: fetch_credentials)
|
20
|
-
Hash.from_xml(response)["string"]
|
21
|
-
end
|
22
|
-
|
23
|
-
def send_message
|
24
|
-
raise "Incomplete Parameters ERROR" unless to and body and reply_to
|
25
|
-
|
26
|
-
options = fetch_credentials.merge!(mobileNumber: to, messageText: body, sms2way: reply_to)
|
27
|
-
response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
|
28
|
-
|
29
|
-
if response.code.to_i == 200
|
30
|
-
response = Hash.from_xml(response)["string"]
|
31
|
-
|
32
|
-
if response.include?("ERR") or API_ERROR.include?(response)
|
33
|
-
false
|
34
|
-
else
|
35
|
-
response
|
36
|
-
end
|
37
|
-
else
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def bulk_send!
|
43
|
-
raise "Incomplete PARAMETERS errors" unless to and body and reply_to
|
44
|
-
|
45
|
-
options = fetch_credentials.merge!(messageText: body, sms2way: reply_to)
|
46
|
-
|
47
|
-
to.each do |recipient|
|
48
|
-
options.merge!("mobileNumber[#{recipient.object_id}]" => recipient)
|
49
|
-
end
|
50
|
-
|
51
|
-
response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
|
52
|
-
result = Hash.from_xml(response)["string"]["result"]["status"] rescue nil
|
53
|
-
|
54
|
-
result
|
55
|
-
end
|
56
|
-
|
57
|
-
def message_status(message_id)
|
58
|
-
response = RestClient.get(MESSAGE_STATUS_ENDPOINT, params: fetch_credentials.merge!(messageId: message_id))
|
59
|
-
Hash.from_xml(response)["string"]
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
8
|
+
def self.configuration
|
9
|
+
@configuration ||= Configuration.new
|
10
|
+
end
|
63
11
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
12
|
+
def self.configure
|
13
|
+
yield configuration
|
67
14
|
end
|
15
|
+
|
68
16
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "active_support/core_ext"
|
2
|
+
require "open-uri"
|
3
|
+
require "rest_client"
|
4
|
+
|
5
|
+
module Sms160
|
6
|
+
class Message
|
7
|
+
attr_accessor :to, :body, :reply_to
|
8
|
+
|
9
|
+
def initialize(attr = {})
|
10
|
+
attr.each do |k, v|
|
11
|
+
self.send("#{k}=", v)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def credit_balance
|
16
|
+
response = RestClient.get(BALANCE_ENDPOINT, params: fetch_credentials)
|
17
|
+
Hash.from_xml(response)["string"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_message
|
21
|
+
raise "Incomplete Parameters ERROR" unless to and body and reply_to
|
22
|
+
|
23
|
+
options = fetch_credentials.merge!(mobileNumber: to, messageText: body, sms2way: reply_to)
|
24
|
+
response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
|
25
|
+
|
26
|
+
if response.code.to_i == 200
|
27
|
+
response = Hash.from_xml(response)["string"]
|
28
|
+
|
29
|
+
if response.include?("ERR") or API_ERROR.include?(response)
|
30
|
+
false
|
31
|
+
else
|
32
|
+
response
|
33
|
+
end
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def bulk_send!
|
40
|
+
raise "Incomplete PARAMETERS errors" unless to and body and reply_to
|
41
|
+
|
42
|
+
options = fetch_credentials.merge!(messageText: body, sms2way: reply_to)
|
43
|
+
|
44
|
+
to.each do |recipient|
|
45
|
+
options.merge!("mobileNumber[#{recipient.object_id}]" => recipient)
|
46
|
+
end
|
47
|
+
|
48
|
+
response = RestClient.post(SEND_MESSAGE_ENDPOINT, options)
|
49
|
+
result = Hash.from_xml(response)["string"]["result"]["status"] rescue nil
|
50
|
+
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
def message_status(message_id)
|
55
|
+
response = RestClient.get(MESSAGE_STATUS_ENDPOINT, params: fetch_credentials.merge!(messageId: message_id))
|
56
|
+
Hash.from_xml(response)["string"]
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def fetch_credentials
|
62
|
+
{ username: Sms160.configuration.username, password: Sms160.configuration.password }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/sms160/version.rb
CHANGED
data/spec/lib/sms160_spec.rb
CHANGED
@@ -17,19 +17,22 @@ describe Sms160 do
|
|
17
17
|
sms = Sms160::Message.new(reply_to: "+639182390239")
|
18
18
|
expect(sms.reply_to).to eq "+639182390239"
|
19
19
|
end
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
describe "configuration block" do
|
23
|
+
before(:each) do
|
24
|
+
Sms160.configure do |config|
|
25
|
+
config.username = "username"
|
26
|
+
config.password = "password"
|
27
|
+
end
|
25
28
|
end
|
26
|
-
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
it "gets the credit balance" do
|
31
|
+
stub_request(:get, "#{Sms160::BALANCE_ENDPOINT}?username=username&password=password").
|
32
|
+
to_return(:status => 200, :body => "<?xml version='1.0' encoding='utf-8'?><string xmlns='www.160.com.au/api'>4621.00</string>", :headers => {})
|
33
|
+
|
34
|
+
sms = Sms160::Message.new
|
35
|
+
expect(sms.credit_balance).to eq "4621.00"
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sms160
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Chavez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,7 +110,9 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- bin/sms160
|
112
112
|
- lib/sms160.rb
|
113
|
+
- lib/sms160/configuration.rb
|
113
114
|
- lib/sms160/constants.rb
|
115
|
+
- lib/sms160/message.rb
|
114
116
|
- lib/sms160/version.rb
|
115
117
|
- sms160.gemspec
|
116
118
|
- spec/lib/sms160_spec.rb
|