tropo-webapi-ruby 0.1.5 → 0.1.6

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/HISTORY.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  = Tropo Release History
2
2
 
3
- == Version 0.1.0
3
+ == Version 0.1.5
4
4
 
5
- - Alpha release
5
+ - First public release
6
+
7
+ == Version 0.1.6
8
+
9
+ - Added the appropriate ActiveSupport dependency for 'instance_exec' for Ruby 1.8.6 support.
10
+ - Added a dependency and support for Hashie.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Tropo Web API Ruby Library
2
2
 
3
- A Ruby library for interaction with the Tropo Web API using JSON.
3
+ A Ruby library for interaction with the Tropo Web API (http://tropo.com) using JSON.
4
4
 
5
5
  == Tropo Web API Overview
6
6
 
@@ -12,6 +12,8 @@ your own web servers.
12
12
  * Ruby v1.8.6+ or JRuby v1.4.0+
13
13
  * RubyGems
14
14
 
15
+ Note: If using with ActiveSupport, v2.3.5 or better of ActiveSupport is required.
16
+
15
17
  == Installation
16
18
 
17
19
  $ sudo gem install tropo-webapi-ruby
@@ -187,6 +189,22 @@ Using the great RESTful Web Services framework Sinatra for Ruby.
187
189
 
188
190
  May be found by checking out the project from Github, and then looking in $PROJECT_HOME/examples and $PROJECT_HOME/spec/tropo-webapi-ruby_spec.rb.
189
191
 
192
+ === Documentation
193
+
194
+ * API Documentation:
195
+
196
+ http://voxeo.github.com/tropo-webapi-ruby
197
+
198
+ * Tropo Web API Documentation
199
+
200
+ http://docs.tropo.com/webapi/2.0/home.htm
201
+
202
+ == Notes
203
+
204
+ In order to maintain compatibility between Ruby MRI and JRuby the gem requires 'json_pure'. If you are using the Ruby MRI and would prefer to use the C version of 'json', simply install the 'json' gem as follows:
205
+
206
+ sudo gem install json
207
+
190
208
  == Copyright
191
209
 
192
210
  Copyright (c) 2010 Voxeo, Corporation. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
+ require 'yard'
3
4
 
4
5
  begin
5
6
  require 'jeweler'
@@ -12,7 +13,10 @@ begin
12
13
  gem.authors = ["Jason Goecke"]
13
14
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
15
  gem.files.include %w(lib/tropo-webapi-ruby.rb lib/tropo-webapi-ruby/tropo-webapi-ruby.rb lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb LICENSE VERSION README.markdown)
15
- gem.add_dependency('json', '>= 1.2.0')
16
+ #gem.add_dependency('json', '>= 1.2.0')
17
+ gem.add_dependency('json_pure', '>= 1.2.0')
18
+ gem.add_dependency('hashie', '>= 0.2.0')
19
+ gem.required_ruby_version = '>= 1.8.6'
16
20
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
21
  end
18
22
  Jeweler::GemcutterTasks.new
@@ -46,8 +50,6 @@ Rake::RDocTask.new do |rdoc|
46
50
  rdoc.rdoc_files.include('lib/**/*.rb')
47
51
  end
48
52
 
49
- # require 'yardoc'
50
- # YARD::Rake::YardocTask.new do |t|
51
- # t.files = ['lib/**/*.rb', OTHER_PATHS] # optional
52
- # t.options = ['--any', '--extra', '--opts'] # optional
53
- # end
53
+ YARD::Rake::YardocTask.new do |t|
54
+ t.files = ['lib/tropo-webapi-ruby/*.rb', 'lib/*.rb', 'README']
55
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -1,6 +1,2 @@
1
1
  $: << File.expand_path(File.dirname(__FILE__))
2
- require 'uri'
3
- require 'json'
4
- require 'time'
5
- require 'tropo-webapi-ruby/tropo-webapi-ruby-helpers'
6
- require 'tropo-webapi-ruby/tropo-webapi-ruby'
2
+ %w(uri json hashie time tropo-webapi-ruby/tropo-webapi-ruby-helpers tropo-webapi-ruby/tropo-webapi-ruby).each { |lib| require lib }
@@ -161,8 +161,8 @@ module Tropo
161
161
 
162
162
  array.each_with_index do |ele, i|
163
163
  # Set the key to the value of the respresentative key
164
- key = ele['key'].to_sym if ele['key']
165
- key = ele['name'].to_sym if ele['name']
164
+ key = ele['key'] if ele['key']
165
+ key = ele['name'] if ele['name']
166
166
 
167
167
  # Merge this new key into the hash
168
168
  transformed_to_hash.merge!({ key => Hash.new })
@@ -196,16 +196,16 @@ module Tropo
196
196
  # @param[String] the key to be decamelized and symobolized
197
197
  # @param[Hash] the newly created hash that contins the properly formatted key
198
198
  def transform_pair(key, value)
199
- hash = { decamelize(key).to_sym => value }
200
- hash[:timestamp] = Time.parse(value) if hash[:timestamp]
201
- if hash[:actions]
202
- if hash[:actions][:name]
203
- key_name = hash[:actions][:name]
204
- hash[:actions].delete(:name)
205
- hash[:actions] = { key_name.to_sym => hash[:actions] }
199
+ hash = { decamelize(key) => value }
200
+ hash['timestamp'] = Time.parse(value) if hash['timestamp']
201
+ if hash['actions']
202
+ if hash['actions']['name']
203
+ key_name = hash['actions']['name']
204
+ hash['actions'].delete('name')
205
+ hash['actions'] = { key_name => hash['actions'] }
206
206
  end
207
207
  end
208
- set_session_type(hash) if hash[:channel]
208
+ set_session_type(hash) if hash['channel']
209
209
  hash
210
210
  end
211
211
 
@@ -215,7 +215,7 @@ module Tropo
215
215
  # @param[Hash] the key, value pair of the channel
216
216
  # @return nil
217
217
  def set_session_type(hash)
218
- case hash[:channel]
218
+ case hash['channel']
219
219
  when "VOICE"
220
220
  @voice_session = true
221
221
  @text_session = false
@@ -186,28 +186,28 @@ module Tropo
186
186
  # @param [String] a JSON string
187
187
  # @return [Hash] a Hash representing the response from Tropo
188
188
  def parse(json_string)
189
- response = JSON.parse json_string
190
-
189
+ response = JSON.parse(json_string)
190
+
191
191
  # Check to see what type of response we are working with
192
192
  if response['session']
193
- transformed_response = { :session => { } }
193
+ transformed_response = { 'session' => { } }
194
194
 
195
195
  response['session'].each_pair do |key, value|
196
196
  value = transform_hash value if value.kind_of? Hash
197
- transformed_response[:session].merge!(transform_pair(key, value))
197
+ transformed_response['session'].merge!(transform_pair(key, value))
198
198
  end
199
199
 
200
200
  elsif response['result']
201
- transformed_response = { :result => { :actions => { } } }
201
+ transformed_response = { 'result' => { } }
202
202
 
203
203
  response['result'].each_pair do |key, value|
204
204
  value = transform_hash value if value.kind_of? Hash
205
205
  value = transform_array value if value.kind_of? Array
206
- transformed_response[:result].merge!(transform_pair(key, value))
206
+ transformed_response['result'].merge!(transform_pair(key, value))
207
207
  end
208
208
  end
209
-
210
- transformed_response
209
+
210
+ transformed_response = Hashie::Mash.new(transformed_response)
211
211
  end
212
212
 
213
213
  ##
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rubygems'
4
- require 'tropo-webapi-ruby'
5
- require 'spec'
6
- require 'spec/autorun'
3
+ %w(rubygems tropo-webapi-ruby hashie spec spec/autorun).each { |lib| require lib }
7
4
 
8
5
  Spec::Runner.configure do |config|
9
6
 
@@ -212,7 +212,7 @@ describe "Tropo" do
212
212
  it "should accept a valid email address when a 'record' action is called" do
213
213
  response = Tropo::Generator.record({ :name => 'bar',
214
214
  :url => 'foo@bar.com' })
215
- response.should == "{\"tropo\":[{\"record\":{\"url\":\"foo@bar.com\",\"name\":\"bar\"}}]}"
215
+ JSON.parse(response).should == JSON.parse("{\"tropo\":[{\"record\":{\"url\":\"foo@bar.com\",\"name\":\"bar\"}}]}")
216
216
  end
217
217
 
218
218
  # Redirect action tests
@@ -334,12 +334,12 @@ describe "Tropo" do
334
334
 
335
335
  it "should build a Ruby hash object when a result arrives in JSON" do
336
336
  json_result = "{\"result\":{\"sessionId\":\"sessionId\",\"callState\":\"ANSWERED\",\"sessionDuration\":10,\"sequence\":1,\"complete\":true,\"error\":\"error\",\"properties\":[{\"key\":\"foo\",\"value\":\"bar\"},{\"key\":\"charlie\",\"value\":\"foxtrot\"}],\"actions\":{\"name\":\"pin\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"}}}"
337
- Tropo::Generator.parse(json_result).should == {:result=>{:session_id=>"sessionId", :properties=>{:foo=>{:value=>"bar"}, :charlie=>{:value=>"foxtrot"}}, :complete=>true, :call_state=>"ANSWERED", :actions=>{:pin=>{:disposition=>"SUCCESS", :utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100}}, :session_duration=>10, :error=>"error", :sequence=>1}}
337
+ Tropo::Generator.parse(json_result).should == Hashie::Mash.new({:result=>{:session_id=>"sessionId", :properties=>{:foo=>{:value=>"bar"}, :charlie=>{:value=>"foxtrot"}}, :complete=>true, :call_state=>"ANSWERED", :actions=>{:pin=>{:disposition=>"SUCCESS", :utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100}}, :session_duration=>10, :error=>"error", :sequence=>1}})
338
338
  end
339
339
 
340
340
  it "should build a ruby hash object when a realworld JSON string arrives" do
341
341
  json_result = "{\"result\":{\"sessionId\":\"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20\",\"callState\":\"ANSWERED\",\"sessionDuration\":2,\"sequence\":1,\"complete\":true,\"error\":null,\"actions\":[{\"name\":\"zip\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"},{\"name\":\"days\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"1\",\"utterance\":\"1\"}]}}"
342
- Tropo::Generator.parse(json_result).should == {:result=>{:call_state=>"ANSWERED", :complete=>true, :actions=>{:zip=>{:disposition=>"SUCCESS", :utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100}, :days=>{:disposition=>"SUCCESS", :utterance=>"1", :attempts=>1, :interpretation=>"1", :confidence=>100}}, :session_duration=>2, :sequence=>1, :session_id=>"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20", :error=>nil}}
342
+ Tropo::Generator.parse(json_result).should == Hashie::Mash.new({:result=>{:call_state=>"ANSWERED", :complete=>true, :actions=>{:zip=>{:disposition=>"SUCCESS", :utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100}, :days=>{:disposition=>"SUCCESS", :utterance=>"1", :attempts=>1, :interpretation=>"1", :confidence=>100}}, :session_duration=>2, :sequence=>1, :session_id=>"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20", :error=>nil}})
343
343
  end
344
344
 
345
345
  it "should see an object delcared outside of a block" do
@@ -409,7 +409,15 @@ describe "Tropo" do
409
409
  it "should build a Ruby hash object when a result arrives in JSON with one action returned in an array" do
410
410
  json_result = "{\"result\":{\"sessionId\":\"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20\",\"callState\":\"ANSWERED\",\"sessionDuration\":2,\"sequence\":1,\"complete\":true,\"error\":null,\"actions\":{\"name\":\"zip\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"}}}"
411
411
  hash = Tropo::Generator.parse(json_result)
412
- hash.should == {:result=>{:call_state=>"ANSWERED", :complete=>true, :actions=>{:zip=>{:utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100, :disposition=>"SUCCESS"}}, :session_id=>"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20", :session_duration=>2, :error=>nil, :sequence=>1}}
412
+ hash.should == Hashie::Mash.new({:result=>{:call_state=>"ANSWERED", :complete=>true, :actions=>{:zip=>{:utterance=>"1 2 3 4 5", :attempts=>1, :interpretation=>"12345", :confidence=>100, :disposition=>"SUCCESS"}}, :session_id=>"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20", :session_duration=>2, :error=>nil, :sequence=>1}})
413
+ end
414
+
415
+ it "should build a Hashie object when a result arrives in JSON" do
416
+ json_result = "{\"result\":{\"sessionId\":\"CCFD9C86-1DD1-11B2-B76D-B9B253E4B7FB@161.253.55.20\",\"callState\":\"ANSWERED\",\"sessionDuration\":2,\"sequence\":1,\"complete\":true,\"error\":null,\"actions\":{\"name\":\"zip\",\"attempts\":1,\"disposition\":\"SUCCESS\",\"confidence\":100,\"interpretation\":\"12345\",\"utterance\":\"1 2 3 4 5\"}}}"
417
+ hash = Tropo::Generator.parse(json_result)
418
+ hash.result.call_state.should == 'ANSWERED'
419
+ hash[:result][:call_state].should == 'ANSWERED'
420
+ hash['result']['call_state'].should == 'ANSWERED'
413
421
  end
414
422
 
415
423
  it "should generate valid JSON when a startRecording is used" do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tropo-webapi-ruby}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Goecke"]
12
- s.date = %q{2010-01-20}
12
+ s.date = %q{2010-04-26}
13
13
  s.description = %q{Ruby library for interacting with the Tropo Web API via REST & JSON}
14
14
  s.email = %q{jsgoecke@voxeo.com}
15
15
  s.extra_rdoc_files = [
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
- ".yardoc",
23
22
  "HISTORY.rdoc",
24
23
  "LICENSE",
25
24
  "README.rdoc",
@@ -37,6 +36,7 @@ Gem::Specification.new do |s|
37
36
  s.homepage = %q{http://tropo.com}
38
37
  s.rdoc_options = ["--charset=UTF-8"]
39
38
  s.require_paths = ["lib"]
39
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
40
40
  s.rubygems_version = %q{1.3.5}
41
41
  s.summary = %q{Tropo Web API Ruby Gem}
42
42
  s.test_files = [
@@ -51,14 +51,17 @@ Gem::Specification.new do |s|
51
51
 
52
52
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
53
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
54
- s.add_runtime_dependency(%q<json>, [">= 1.2.0"])
54
+ s.add_runtime_dependency(%q<json_pure>, [">= 1.2.0"])
55
+ s.add_runtime_dependency(%q<hashie>, [">= 0.2.0"])
55
56
  else
56
57
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
- s.add_dependency(%q<json>, [">= 1.2.0"])
58
+ s.add_dependency(%q<json_pure>, [">= 1.2.0"])
59
+ s.add_dependency(%q<hashie>, [">= 0.2.0"])
58
60
  end
59
61
  else
60
62
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
61
- s.add_dependency(%q<json>, [">= 1.2.0"])
63
+ s.add_dependency(%q<json_pure>, [">= 1.2.0"])
64
+ s.add_dependency(%q<hashie>, [">= 0.2.0"])
62
65
  end
63
66
  end
64
67
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tropo-webapi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Goecke
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-20 00:00:00 -05:00
12
+ date: 2010-04-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  version: 1.2.9
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: json
26
+ name: json_pure
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.0
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hashie
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.0
44
+ version:
35
45
  description: Ruby library for interacting with the Tropo Web API via REST & JSON
36
46
  email: jsgoecke@voxeo.com
37
47
  executables: []
@@ -44,7 +54,6 @@ extra_rdoc_files:
44
54
  files:
45
55
  - .document
46
56
  - .gitignore
47
- - .yardoc
48
57
  - HISTORY.rdoc
49
58
  - LICENSE
50
59
  - README.rdoc
@@ -71,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
80
  requirements:
72
81
  - - ">="
73
82
  - !ruby/object:Gem::Version
74
- version: "0"
83
+ version: 1.8.6
75
84
  version:
76
85
  required_rubygems_version: !ruby/object:Gem::Requirement
77
86
  requirements:
data/.yardoc DELETED
Binary file