amerine-btexty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ lib/testrun.rb
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mark Turner <mark@amerine.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = btexty
2
+
3
+ btexty is a ruby gem for accessing the http://btexty.com/ API.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Mark Turner. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "btexty"
8
+ gem.summary = "super simple ruby interface for the btexty api"
9
+ gem.email = "mark@amerine.net"
10
+ gem.homepage = "http://github.com/amerine/btexty"
11
+ gem.authors = ["Mark Turner"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "btexty #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/btexty.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ gem 'httparty'
3
+ require 'httparty'
4
+ require File.dirname(__FILE__) + '/btexty/data'
5
+
6
+ class BTexty
7
+ include HTTParty
8
+ format :json
9
+
10
+ attr_accessor :phone_number, :pin, :method
11
+
12
+ def initialize(phone_number, pin, method='json')
13
+ clean_phone_number(phone_number)
14
+ @phone_number, @pin, @method = phone_number, pin, method
15
+ end
16
+
17
+ def get(path, options={})
18
+ options.merge!({:basic_auth => {:username => @phone_number, :password => @pin},
19
+ :method => @method})
20
+ self.class.get("http://www.btexty.com/api/#{options[:method]}/#{path}", options)
21
+ end
22
+
23
+ def unread
24
+ get('inbox/unread')['response']['body']['unread']
25
+ end
26
+
27
+ def messages
28
+ get('inbox/index')
29
+ end
30
+
31
+ private
32
+
33
+ def clean_phone_number(phone_number)
34
+ phone_number.gsub!(/\W/,'')
35
+ phone_number.gsub!(/\A/, '1') if phone_number.length == 10
36
+ phone_number.gsub!(/\A/,'+')
37
+ phone_number
38
+ end
39
+ end
File without changes
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class BTextyTest < Test::Unit::TestCase
4
+ context "Initialization"do
5
+ should "require a phone number and pin code" do
6
+ lambda { BTexty.new }.should raise_error
7
+ lambda { BTexty.new('15413063365')}.should raise_error
8
+ end
9
+
10
+ should "handle various types of number inputs" do
11
+ #Assumes a US phone number length of 10 digits & +1 country code.
12
+ assert_equal '+15413063355', BTexty.new('15413063355','12345').phone_number
13
+ assert_equal '+15413063355', BTexty.new('541-306-3355','12345').phone_number
14
+ assert_equal '+15413063355', BTexty.new('(541) 306-3355', '12345').phone_number
15
+ assert_equal '+15413063355', BTexty.new('1-541-306-3355', '12345').phone_number
16
+ end
17
+
18
+ should "keep your pin exactly as you type it" do
19
+ assert_equal '12345', BTexty.new('15413061122', '12345').pin
20
+ end
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'matchy'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'btexty'
9
+
10
+ class Test::Unit::TestCase
11
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amerine-btexty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Turner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-11 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: mark@amerine.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/btexty.rb
33
+ - lib/btexty/data.rb
34
+ - test/btexty_test.rb
35
+ - test/test_helper.rb
36
+ has_rdoc: false
37
+ homepage: http://github.com/amerine/btexty
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --charset=UTF-8
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: super simple ruby interface for the btexty api
62
+ test_files:
63
+ - test/btexty_test.rb
64
+ - test/test_helper.rb