direct_sms 0.0.1 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f04ea0f7b6fddd268fa86242a77714acf8507370
4
- data.tar.gz: 1118444d144bb0b47209f92b5efc2d82f0223412
3
+ metadata.gz: 48444dde721065342314bd1c75df0e7fa9c05be3
4
+ data.tar.gz: e3e216b10101be0217e6243a2c751e0a3ded3bec
5
5
  SHA512:
6
- metadata.gz: 786f6aef3752547bf661eb2eb3145d1a0e49c1a9f6326c72c2a52621cf8d7ced34bed1e70fe95827d5e46dc09a6155a7b28e6f883aed12c7ff507e3d6c27ab37
7
- data.tar.gz: 4c37f07dc4ff1486a406fe0ddadeafb800fa1c0f708e08069a9485fccd2035f42211e7aabec69b6b6439b304f1e7f6d55fd89162d58a3acab997e972c6fad342
6
+ metadata.gz: 0d797e9a70867444ba43e4b48380450eb33913c906b48935ce1ae871a57945c313479d33df78c4fcaf495f7468f7702befbb426db22e891f2ab24b99f8a1b245
7
+ data.tar.gz: 066ddda4b80b359cd01eaf76cf8bf4f16769924741a828ef368ecae3c8a72b9c619aad01dd373c5b833e30021d840d94282c962bf4f65c97072516b3091231eb
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # DirectSms
2
2
 
3
- TODO: Write a gem description
3
+ DirectSms is a wrapper for using the api offered by directsms.com.au. The complete documentation can be downloaded
4
+ here: http://www.directsms.com.au/api/HTTP_API.pdf
4
5
 
5
- ## Installation
6
+ ## Installation & Usage
6
7
 
7
8
  Add this line to your application's Gemfile:
8
9
 
@@ -16,9 +17,37 @@ Or install it yourself as:
16
17
 
17
18
  $ gem install direct_sms
18
19
 
19
- ## Usage
20
+ To start using DirectSms, you'll need a username and a password. If you read the directsms docs, they support passing a
21
+ connectionid as well. This is not supported for now.
20
22
 
21
- TODO: Write usage instructions here
23
+ ### Getting your remaining balance
24
+
25
+ To get your account's balance, simply:
26
+
27
+ sms = DirectSms::Message.new(username, password)
28
+ response = sms.balance
29
+ response.body # -> credits: 300.00
30
+
31
+ ### Sending an SMS
32
+
33
+ To send an sms, you need to set the ff. attributes:
34
+
35
+ * message - The content of your sms message
36
+ * type - Only accepts two values; "1-way" & "2-way"
37
+ * to - The recipient/s of the message
38
+ * message_id - A unique identifier for the message. Used for tracking the reply of the receiver.
39
+ * sender_id - Used for 1-way sms sending
40
+
41
+ sms = DirectSms::Message.new(username, password)
42
+ sms.message = "Hello, world!"
43
+ sms.type = "2-way" # -> enables the receiver to reply
44
+ sms.to = "+639919302930" # -> to send to multiple recipients, use "," as delimiter.
45
+ sms.messageid = "<id>"
46
+ sms.send_message
47
+
48
+ ### Errors
49
+
50
+ If you've found any errors on the documentation as well as the code, feel free to contact me on my email.
22
51
 
23
52
  ## Contributing
24
53
 
data/direct_sms.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["markchav3z@gmail.com"]
11
11
  spec.summary = %q{Wrapper for DirectSMS API}
12
12
  spec.description = %q{Wrapper for DirectSMS API}
13
- spec.homepage = "https://github.com/mrkjlchvz/directsms"
13
+ spec.homepage = "https://github.com/mrkjlchvz/directsms_ruby"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,3 +1,3 @@
1
1
  module DirectSms
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/direct_sms.rb CHANGED
@@ -7,27 +7,36 @@ module DirectSms
7
7
 
8
8
  base_uri "api.directsms.com.au"
9
9
  attr_accessor :message, :to, :max_segments, :type, :message_id
10
+ attr_accessor :username, :password
10
11
 
11
- def initialize(username, password, attrs = {})
12
- @options = { username: username, password: password }
12
+ def initialize(attrs = {})
13
13
  attrs.each { |k, v| self.send("#{k}=", v) }
14
14
  end
15
15
 
16
- def balance
17
- options = { query: @options }
18
- self.class.get("/s3/http/get_balance", options)
16
+ def credit_balance
17
+ options = { query: fetch_credentials }
18
+ response = self.class.get("/s3/http/get_balance", options) # returns credit: 50.0
19
+ response = response.split(" ").last
20
+
21
+ response
19
22
  end
20
23
 
21
24
  def send_message
22
25
  options = {
23
- query: @options.merge(message: @message,
24
- to: @to,
25
- max_segments: @max_segments,
26
- type: @type,
27
- messageid: @message_id)
26
+ query: fetch_credentials.merge(message: message,
27
+ to: to,
28
+ max_segments: max_segments,
29
+ type: type,
30
+ messageid: message_id)
28
31
  }
29
32
 
30
33
  self.class.get("/s3/http/send_message", options)
31
34
  end
35
+
36
+ private
37
+
38
+ def fetch_credentials
39
+ { username: username, password: password }
40
+ end
32
41
  end
33
42
  end
@@ -10,14 +10,14 @@ describe DirectSms do
10
10
  stub_request(:get, "http://api.directsms.com.au/s3/http/get_balance?password=#{password}&username=#{username}").
11
11
  to_return(:status => 200, :body => "credit: 300.00", :headers => {})
12
12
 
13
- sms = DirectSms::Message.new(username, password)
14
- expect(sms.balance.body).to eq "credit: 300.00"
13
+ sms = DirectSms::Message.new(username: username, password: password)
14
+ expect(sms.credit_balance.body).to eq "credit: 300.00"
15
15
  end
16
16
  end
17
17
 
18
18
  describe "sending sms" do
19
19
  it 'attributes can be set on new' do
20
- sms = DirectSms::Message.new(username, password, :type => "2-way", :max_segments => 20)
20
+ sms = DirectSms::Message.new(username: username, password: password, :type => "2-way", :max_segments => 20)
21
21
 
22
22
  expect(sms.max_segments).to eq 20
23
23
  expect(sms.type).to eq "2-way"
@@ -27,7 +27,7 @@ describe DirectSms do
27
27
  stub_request(:get, "http://api.directsms.com.au/s3/http/send_message?max_segments=10&message=This%20is%20a%20test&password=password&to=%2B639178574111&messageid=&type=2-way&username=username").
28
28
  to_return(:status => 200, :body => "id: 1234567890", :headers => {})
29
29
 
30
- sms = DirectSms::Message.new(username, password, :type => "2-way", :max_segments => 10)
30
+ sms = DirectSms::Message.new(username: username, password: password, :type => "2-way", :max_segments => 10)
31
31
  sms.message = "This is a test"
32
32
  sms.to = "+639178574111"
33
33
 
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direct_sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
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-09-03 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: httparty
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Wrapper for DirectSMS API
@@ -88,8 +88,8 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
- - .gitignore
92
- - .rspec
91
+ - ".gitignore"
92
+ - ".rspec"
93
93
  - Gemfile
94
94
  - LICENSE
95
95
  - LICENSE.txt
@@ -101,7 +101,7 @@ files:
101
101
  - lib/direct_sms/version.rb
102
102
  - spec/lib/direct_sms_spec.rb
103
103
  - spec/spec_helper.rb
104
- homepage: https://github.com/mrkjlchvz/directsms
104
+ homepage: https://github.com/mrkjlchvz/directsms_ruby
105
105
  licenses:
106
106
  - MIT
107
107
  metadata: {}
@@ -111,17 +111,17 @@ require_paths:
111
111
  - lib
112
112
  required_ruby_version: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '>='
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.2.0
124
+ rubygems_version: 2.2.1
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Wrapper for DirectSMS API