tropo_message 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.
data/README.markdown CHANGED
@@ -1,16 +1,40 @@
1
1
  # tropo_message
2
2
 
3
+ tropo_message is a tiny gem that simplifies sending messages using [Tropo](http://www.tropo.com)
3
4
 
5
+ ## Usage
6
+ ### Create a new SMS ready for sending
7
+ message = Tropo::Message.new
8
+ message.token = "your_token"
9
+ message.to = "13118374750"
10
+ message.text = "message to send"
4
11
 
5
- ## Note on Patches/Pull Requests
12
+ ### Send the message to listener
13
+ post("http://api.tropo.com/1.0/sessions", message.request_xml)
6
14
 
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
15
+ See also: <http://blog.tropo.com/2010/09/10/how-to-sending-an-sms-using-webapi>
16
+
17
+ ### Receive message and respond to Tropo (inside your listener)
18
+ tropo_session = Tropo::Generator.parse(raw_json)
19
+
20
+ message = Tropo::Message.new(tropo_session)
21
+ text = message.text
22
+ tropo = Tropo::Generator.new
23
+ tropo.message(message.response_params) do
24
+ say :value => text
25
+ end
26
+ tropo.response
27
+
28
+ See also:
29
+ <http://github.com/voxeo/tropo-webapi-ruby>
30
+ <http://blog.tropo.com/2010/09/10/how-to-sending-an-sms-using-webapi>
31
+
32
+ ### More documentation?
33
+ Check out the [source](http://github.com/dwilkie/tropo_message/blob/master/lib/tropo_message.rb). It's tiny and easy to read.
34
+
35
+ ### Installation
36
+ gem install tropo_message
37
+ require 'tropo_message'
14
38
 
15
39
  ## Copyright
16
40
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
data/lib/tropo_message.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  module Tropo
2
2
  class Message
3
3
 
4
- attr_accessor :params
5
- attr_accessor :tropo_session
4
+ attr_accessor :params, :tropo_session
6
5
 
7
- def initialize(options = {})
8
- @params = options[:params] || {}
9
- @tropo_session = options[:tropo_session] || {}
6
+ def initialize(tropo_session = {})
7
+ @params = {}
8
+ @tropo_session = tropo_session
10
9
  end
11
10
 
12
11
  def parse(tropo_session)
@@ -17,20 +16,28 @@ module Tropo
17
16
  params["token"] || tropo_parameters["token"]
18
17
  end
19
18
 
19
+ def token=(value)
20
+ params["token"] = value
21
+ end
22
+
20
23
  def action
21
- tropo_parameters["action"] || "create"
24
+ tropo_parameters["action"]
22
25
  end
23
26
 
24
27
  def to
25
28
  params["to"] || tropo_parameters["to"]
26
29
  end
27
30
 
31
+ def to=(value)
32
+ params["to"] = value
33
+ end
34
+
28
35
  def channel
29
36
  params["channel"] || tropo_parameters["channel"] || 'TEXT'
30
37
  end
31
38
 
32
39
  def network
33
- params["channel"] || tropo_parameters["channel"] || 'SMS'
40
+ params["network"] || tropo_parameters["network"] || 'SMS'
34
41
  end
35
42
 
36
43
  def text
@@ -38,10 +45,19 @@ module Tropo
38
45
  end
39
46
  alias :msg :text
40
47
 
48
+ def text=(value)
49
+ params["text"] = value
50
+ end
51
+ alias :msg= :text=
52
+
41
53
  def from
42
54
  params["from"] || tropo_parameters["from"]
43
55
  end
44
56
 
57
+ def from=(value)
58
+ params["from"] = value
59
+ end
60
+
45
61
  def timeout
46
62
  params["timeout"] || tropo_parameters["timeout"]
47
63
  end
@@ -55,7 +71,7 @@ module Tropo
55
71
  end
56
72
 
57
73
  def recording
58
- params["headers"] || tropo_parameters["recording"]
74
+ params["recording"] || tropo_parameters["recording"]
59
75
  end
60
76
 
61
77
  def outgoing?
@@ -76,11 +92,14 @@ module Tropo
76
92
  params
77
93
  end
78
94
 
79
- def request_params
80
- response_params.merge(
81
- "token" => token,
82
- "action" => action
83
- )
95
+ def request_xml
96
+ request_params = @params.dup
97
+ token = request_params.delete("token")
98
+ xml = ""
99
+ request_params.each do |key, value|
100
+ xml << "<var name=\"#{key}\" value=\"#{value}\"/>"
101
+ end
102
+ "<sessions><token>#{token}</token>#{xml.to_s}</sessions>"
84
103
  end
85
104
 
86
105
  private
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tropo_message}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Wilkie"]
12
- s.date = %q{2010-10-11}
12
+ s.date = %q{2010-10-14}
13
13
  s.description = %q{A tiny wrapper for creating a Tropo message}
14
14
  s.email = %q{dwilkie@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Wilkie
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-11 00:00:00 +07:00
17
+ date: 2010-10-14 00:00:00 +07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20