telstra-sms 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 110b3504af7e75bb48e0f5e038c14716d6a8d002
4
- data.tar.gz: e035ebc7741e3091d56fa7161dc7e31c1c5a1999
3
+ metadata.gz: 019256ff8183ac685b46ce271a047f8aaab33fb3
4
+ data.tar.gz: f7727e4569af9915d7e145e971f2479ecea8d862
5
5
  SHA512:
6
- metadata.gz: b360b15a603e47d0eb857e23d1e5250f2fed1d7d64b12c66af128611c9d6d360bb3b25155c99f7264f46d46db56e18ab9508e43caa1f999a54fb1a7d86bb5d6c
7
- data.tar.gz: 9ee67ed53e305d23d3b32e0e07ae7bdc31088b2d0d21f2336b834dd928aff810d9ec547c71dcb5ff257417740b85dbf464b6dc10893f957b3eec867aeae85a34
6
+ metadata.gz: 540bbd6770905786a089cad43dce0c0bb4dd83d67ba54bebeed62760d164de69d3702c7547578fea9510224a3a1df5a5c6f5bb366c87703397c6c44bb55255e8
7
+ data.tar.gz: cf4e1cf91158d08c76abce8e2e42050621bae92250a71e6cec8c132e7ffac73c7e6b210e69a2335d318760306acaa86bed9c3fb0bba14d93ca450b900bebcb4d
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ *This gem is currently in development and only has SMS send / status functionality right now*
2
+
3
+ [![Code Climate](https://codeclimate.com/github/soccerbrain/telstra-sms/badges/gpa.svg)](https://codeclimate.com/github/soccerbrain/telstra-sms)
4
+ [![Build Status](https://travis-ci.org/soccerbrain/telstra-sms.svg)](https://travis-ci.org/soccerbrain/telstra-sms)
5
+
1
6
  # Telstra::Sms
2
7
 
3
8
  Ruby gem for the Telstra SMS API at https://dev.telstra.com
@@ -22,7 +27,9 @@ Or install it yourself as:
22
27
 
23
28
  ```ruby
24
29
  t = Telstra::SMS.new(consumer_key, consumer_secret)
25
- t.send("SMS Body", "04XX XXX XXXX")
30
+ t.send_sms("SMS Body", "04XX XXX XXXX")
31
+ t.get_message_status(message_id)
32
+ t.get_message_response(message_id)
26
33
  ```
27
34
 
28
35
  ## Contributing
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
+ require "rspec/core/rake_task"
1
2
  require "bundler/gem_tasks"
2
3
 
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/lib/telstra/sms.rb CHANGED
@@ -13,24 +13,48 @@ module Telstra
13
13
  @consumer_secret = consumer_secret
14
14
  end
15
15
 
16
- #def call(url, params={})
17
- #params = JSON.generate(params)
18
- #curl "https://api.telstra.com/v1/oauth/token?client_id=#{@consumer_key}&client_secret=#{@consumer_secret}&grant_type=client_credentials&scope=SMS"
19
- #end
20
-
16
+ # OAuth 2.0 Token. This will expire every hour.
21
17
  def generate_token
22
18
  response = HTTParty.get("https://api.telstra.com/v1/oauth/token?client_id=#{@consumer_key}&client_secret=#{@consumer_secret}&grant_type=client_credentials&scope=SMS")
23
19
  @token = JSON.parse(response.body)['access_token']
24
20
  end
25
21
 
26
- def send(sms_body, sms_to)
22
+ # Receipient number should be in the format of 04xxxxxxxx where x is a digit.
23
+ # Authorization header value should be in the format of "Bearer xxx" where xxx
24
+ # is the access token returned from a token request.
25
+ def send_sms(sms_body, sms_to)
27
26
  generate_token
28
27
  options = { body: {
29
28
  body: sms_body,
30
29
  to: sms_to
31
30
  }.to_json,
32
31
  headers: { "Content-Type" => "application/json", "Authorization" => "Bearer #{@token}" }}
33
- HTTParty.post("https://api.telstra.com/v1/sms/messages", options)
32
+ response = HTTParty.post("https://api.telstra.com/v1/sms/messages", options)
33
+ return response.body
34
+ end
35
+
36
+ # Get the status of a previously sent SMS message
37
+ # May return:
38
+ #
39
+ # PEND -> The message is pending and has not yet been sent
40
+ # SENT -> Message has been send, but not delivered
41
+ # DELIVRD -> Message has been delivered
42
+ # READ -> The message has been read by the intended recipeitn
43
+ #
44
+ # Note: Some responses are dependent on the phone network of the user.
45
+ # Obviously, more info can be grabbed from those on the Telstra network.
46
+ def get_message_status(message_id)
47
+ generate_token
48
+ options = { headers: { "Authorization" => "Bearer #{@token}" } }
49
+ repsonse = HTTParty.post("https://api.telstra.com/v1/sms/messages/#{message_id}")
50
+ return response.body
51
+ end
52
+
53
+ def get_message_response(message_id)
54
+ generate_token
55
+ options = { headers: { "Authorization" => "Bearer #{@token}" } }
56
+ repsonse = HTTParty.post("https://api.telstra.com/v1/sms/messages/#{message_id}/response")
57
+ return response.body
34
58
  end
35
59
 
36
60
  end
@@ -1,5 +1,5 @@
1
1
  module Telstra
2
2
  module Sms
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ require 'telstra/sms'
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Telstra::SMS do
4
+
5
+ describe "Sending SMS" do
6
+ let(:telstra_api){ Telstra::SMS.new api_key: 'blah', api_secret: 'blah2' }
7
+
8
+ describe "#get_token" do
9
+ end
10
+
11
+ end
12
+
13
+ end
data/telstra-sms.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telstra-sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Millar
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
55
69
  description:
56
70
  email:
57
71
  - paul@digitaldawn.com.au
@@ -60,12 +74,15 @@ extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
76
  - ".gitignore"
77
+ - ".rspec"
63
78
  - Gemfile
64
79
  - LICENSE.txt
65
80
  - README.md
66
81
  - Rakefile
67
82
  - lib/telstra/sms.rb
68
83
  - lib/telstra/sms/version.rb
84
+ - spec/spec_helper.rb
85
+ - spec/telstra/sms_spec.rb
69
86
  - telstra-sms.gemspec
70
87
  homepage: https://github.com/soccerbrain/telstra-sms
71
88
  licenses:
@@ -91,4 +108,6 @@ rubygems_version: 2.2.2
91
108
  signing_key:
92
109
  specification_version: 4
93
110
  summary: Send SMS through the Telstra SMS API
94
- test_files: []
111
+ test_files:
112
+ - spec/spec_helper.rb
113
+ - spec/telstra/sms_spec.rb