authy 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +69 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/authy.gemspec +82 -0
- data/bin/authy-api-console +9 -0
- data/lib/authy.rb +8 -0
- data/lib/authy/api.rb +41 -0
- data/lib/authy/config.rb +21 -0
- data/lib/authy/models/user.rb +35 -0
- data/lib/authy/response.rb +52 -0
- data/spec/authy/api_spec.rb +37 -0
- data/spec/authy/response_spec.rb +31 -0
- data/spec/spec_helper.rb +34 -0
- metadata +169 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'typhoeus', '0.3.3'
|
4
|
+
gem 'pry', '0.9.8.1'
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "rspec", "~> 2.8.0"
|
8
|
+
gem "yard", "~> 0.7"
|
9
|
+
gem "rdoc", "~> 3.12"
|
10
|
+
gem "bundler", "~> 1.1.0"
|
11
|
+
gem "jeweler", "~> 1.8.3"
|
12
|
+
gem "simplecov", ">= 0"
|
13
|
+
gem "reek", "~> 1.2.8"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.6)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.8.3)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.6.6)
|
13
|
+
method_source (0.7.1)
|
14
|
+
mime-types (1.18)
|
15
|
+
multi_json (1.3.2)
|
16
|
+
pry (0.9.8.1)
|
17
|
+
coderay (~> 1.0.5)
|
18
|
+
method_source (~> 0.7)
|
19
|
+
slop (>= 2.4.3, < 3)
|
20
|
+
rake (0.9.2.2)
|
21
|
+
rdoc (3.12)
|
22
|
+
json (~> 1.4)
|
23
|
+
reek (1.2.8)
|
24
|
+
ruby2ruby (~> 1.2)
|
25
|
+
ruby_parser (~> 2.0)
|
26
|
+
sexp_processor (~> 3.0)
|
27
|
+
rspec (2.8.0)
|
28
|
+
rspec-core (~> 2.8.0)
|
29
|
+
rspec-expectations (~> 2.8.0)
|
30
|
+
rspec-mocks (~> 2.8.0)
|
31
|
+
rspec-core (2.8.0)
|
32
|
+
rspec-expectations (2.8.0)
|
33
|
+
diff-lcs (~> 1.1.2)
|
34
|
+
rspec-mocks (2.8.0)
|
35
|
+
ruby2ruby (1.3.1)
|
36
|
+
ruby_parser (~> 2.0)
|
37
|
+
sexp_processor (~> 3.0)
|
38
|
+
ruby_parser (2.3.1)
|
39
|
+
sexp_processor (~> 3.0)
|
40
|
+
sexp_processor (3.2.0)
|
41
|
+
simplecov (0.6.2)
|
42
|
+
multi_json (~> 1.3)
|
43
|
+
simplecov-html (~> 0.5.3)
|
44
|
+
simplecov-html (0.5.3)
|
45
|
+
slop (2.4.4)
|
46
|
+
typhoeus (0.3.3)
|
47
|
+
mime-types
|
48
|
+
yard (0.7.5)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 1.1.0)
|
55
|
+
jeweler (~> 1.8.3)
|
56
|
+
pry (= 0.9.8.1)
|
57
|
+
rdoc (~> 3.12)
|
58
|
+
reek (~> 1.2.8)
|
59
|
+
rspec (~> 2.8.0)
|
60
|
+
simplecov
|
61
|
+
typhoeus (= 0.3.3)
|
62
|
+
yard (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 David A. Cuadrado
|
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,69 @@
|
|
1
|
+
# Authy
|
2
|
+
|
3
|
+
Ruby library to access the Authy API
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
require 'authy'
|
8
|
+
|
9
|
+
Authy.api_key = 'your-api-key'
|
10
|
+
Authy.api_uri = 'https://api.authy.com/'
|
11
|
+
|
12
|
+
|
13
|
+
### Registering a user
|
14
|
+
|
15
|
+
`Authy::API.register_user` requires the user e-mail address and cellphone. Optionally you can pass in the country_code or we will asume
|
16
|
+
USA. The call will return you the authy id for the user that you need to store in your database.
|
17
|
+
|
18
|
+
Assuming you have a `users` database with a `authy_id` field in the `users` database.
|
19
|
+
|
20
|
+
authy = Authy::API.register_user(:email => 'users@email.com', :cellphone => "111-111-1111", :country_code => "1")
|
21
|
+
|
22
|
+
if authy.ok?
|
23
|
+
self.authy_id = authy.id # this will give you the user authy id to store it in your database
|
24
|
+
else
|
25
|
+
authy.errors # this will return an error hash
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
### Verifying a user
|
30
|
+
|
31
|
+
`Authy::API.verify` takes the authy_id that you are verifying and the token that you want to verify. You should have the authy_id in your database
|
32
|
+
|
33
|
+
response = Authy::API.verify(:id => user.authy_id, :token => 'token-user-entered')
|
34
|
+
|
35
|
+
if response.ok?
|
36
|
+
//token was valid, user can sign in
|
37
|
+
else
|
38
|
+
//token is invalid
|
39
|
+
|
40
|
+
|
41
|
+
### Requesting a SMS token
|
42
|
+
|
43
|
+
`Authy::API.request_sms` takes the authy_id that you want to send a SMS token. This requires Authy SMS plugin to be enabled.
|
44
|
+
|
45
|
+
response = Authy::API.request_sms(:id => user.authy_id)
|
46
|
+
|
47
|
+
if response.ok?
|
48
|
+
//sms was sent
|
49
|
+
else
|
50
|
+
response.
|
51
|
+
//sms failed to send
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
## Contributing to authy
|
56
|
+
|
57
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
58
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
59
|
+
* Fork the project.
|
60
|
+
* Start a feature/bugfix branch.
|
61
|
+
* Commit and push until you are happy with your contribution.
|
62
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
63
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
64
|
+
|
65
|
+
== Copyright
|
66
|
+
|
67
|
+
Copyright (c) 2012 David A. Cuadrado. See LICENSE.txt for
|
68
|
+
further details.
|
69
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "authy"
|
18
|
+
gem.homepage = "http://github.com/authy/authy"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby library to access Authy services}
|
21
|
+
gem.description = %Q{Ruby library to access Authy services}
|
22
|
+
gem.email = "krawek@gmail.com"
|
23
|
+
gem.authors = ["Authy", "David A. Cuadrado"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'reek/rake/task'
|
40
|
+
Reek::Rake::Task.new do |t|
|
41
|
+
t.fail_on_error = true
|
42
|
+
t.verbose = false
|
43
|
+
t.source_files = 'lib/**/*.rb'
|
44
|
+
end
|
45
|
+
|
46
|
+
task :default => :spec
|
47
|
+
|
48
|
+
require 'yard'
|
49
|
+
YARD::Rake::YardocTask.new
|
50
|
+
|
51
|
+
task :simplecov do
|
52
|
+
require 'simplecov'
|
53
|
+
ENV['COVERAGE'] = "true"
|
54
|
+
Rake::Task['spec'].execute
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.4
|
data/authy.gemspec
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "authy"
|
8
|
+
s.version = "0.0.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Authy", "David A. Cuadrado"]
|
12
|
+
s.date = "2012-05-21"
|
13
|
+
s.description = "Ruby library to access Authy services"
|
14
|
+
s.email = "krawek@gmail.com"
|
15
|
+
s.executables = ["authy-api-console"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"authy.gemspec",
|
30
|
+
"bin/authy-api-console",
|
31
|
+
"lib/authy.rb",
|
32
|
+
"lib/authy/api.rb",
|
33
|
+
"lib/authy/config.rb",
|
34
|
+
"lib/authy/models/user.rb",
|
35
|
+
"lib/authy/response.rb",
|
36
|
+
"spec/authy/api_spec.rb",
|
37
|
+
"spec/authy/response_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/authy/authy"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = "1.8.11"
|
44
|
+
s.summary = "Ruby library to access Authy services"
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<typhoeus>, ["= 0.3.3"])
|
51
|
+
s.add_runtime_dependency(%q<pry>, ["= 0.9.8.1"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
57
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<typhoeus>, ["= 0.3.3"])
|
61
|
+
s.add_dependency(%q<pry>, ["= 0.9.8.1"])
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
63
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
67
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
68
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<typhoeus>, ["= 0.3.3"])
|
72
|
+
s.add_dependency(%q<pry>, ["= 0.9.8.1"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
74
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
75
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
78
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
79
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
data/lib/authy.rb
ADDED
data/lib/authy/api.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Authy
|
2
|
+
#
|
3
|
+
# Authy.api_key = 'foo'
|
4
|
+
# Authy.api_uri = 'http://test-authy-api.heroku.com/'
|
5
|
+
#
|
6
|
+
class API
|
7
|
+
include Typhoeus
|
8
|
+
|
9
|
+
def self.register_user(attributes)
|
10
|
+
user_data = {
|
11
|
+
:user => attributes,
|
12
|
+
:api_key => Authy.api_key
|
13
|
+
}
|
14
|
+
|
15
|
+
response = Typhoeus::Request.post("#{Authy.api_uri}/protected/json/users/new", :params => user_data)
|
16
|
+
|
17
|
+
Authy::User.new(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
# options:
|
21
|
+
# :id user id
|
22
|
+
# :token authy token entered by the user
|
23
|
+
def self.verify(attributes)
|
24
|
+
token = attributes[:token] || attributes['token']
|
25
|
+
user_id = attributes[:id] || attributes['id']
|
26
|
+
response = Typhoeus::Request.get("#{Authy.api_uri}/protected/json/verify/#{token}/#{user_id}", :params => {:api_key => Authy.api_key})
|
27
|
+
|
28
|
+
Authy::Response.new(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
# options:
|
32
|
+
# :id user id
|
33
|
+
def self.request_sms(attributes)
|
34
|
+
user_id = attributes[:id] || attributes['id']
|
35
|
+
|
36
|
+
response = Typhoeus::Request.get("#{Authy.api_uri}/protected/json/sms/#{user_id}", :params => {:api_key => Authy.api_key})
|
37
|
+
|
38
|
+
Authy::Response.new(response)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/authy/config.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Authy
|
2
|
+
class << self
|
3
|
+
def api_key=(key)
|
4
|
+
@api_key = key
|
5
|
+
end
|
6
|
+
|
7
|
+
def api_key
|
8
|
+
@api_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_uri=(uri)
|
12
|
+
@api_uri = uri
|
13
|
+
end
|
14
|
+
alias :api_url= :api_key=
|
15
|
+
|
16
|
+
def api_uri
|
17
|
+
@api_uri || "https://api.authy.com"
|
18
|
+
end
|
19
|
+
alias :api_url :api_uri
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Authy
|
2
|
+
class User < Authy::Response
|
3
|
+
def id
|
4
|
+
self['id']
|
5
|
+
end
|
6
|
+
|
7
|
+
def errors
|
8
|
+
case
|
9
|
+
when self.ok?
|
10
|
+
{}
|
11
|
+
when !@errors.empty?
|
12
|
+
@errors
|
13
|
+
else
|
14
|
+
{"error" => error_msg}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def parse_body
|
20
|
+
begin
|
21
|
+
body = JSON.parse(@raw_response.body)
|
22
|
+
body = body['user'] if body['user']
|
23
|
+
|
24
|
+
if self.ok?
|
25
|
+
body.each do |k,v|
|
26
|
+
self[k] = v
|
27
|
+
end
|
28
|
+
else
|
29
|
+
@errors = body
|
30
|
+
end
|
31
|
+
rescue Exception => e
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Authy
|
2
|
+
class Response < Hash
|
3
|
+
attr_reader :raw_response
|
4
|
+
def initialize(response)
|
5
|
+
@raw_response = response
|
6
|
+
parse_body
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
self["id"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def ok?
|
14
|
+
@raw_response.code == 200
|
15
|
+
end
|
16
|
+
|
17
|
+
def body
|
18
|
+
@raw_response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
def code
|
22
|
+
@raw_response.code
|
23
|
+
end
|
24
|
+
|
25
|
+
def error_msg
|
26
|
+
(@raw_response.curl_error_message == "No error" && self.empty?) ? self.body : @raw_response.curl_error_message
|
27
|
+
end
|
28
|
+
|
29
|
+
def errors
|
30
|
+
self['errors'] || {}
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
def method_missing(name, *args, &block)
|
35
|
+
if self.include?(name.to_s)
|
36
|
+
self[name.to_s]
|
37
|
+
else
|
38
|
+
super(name, *args, &block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_body
|
43
|
+
begin
|
44
|
+
body = JSON.parse(@raw_response.body)
|
45
|
+
body.each do |k,v|
|
46
|
+
self[k] = v
|
47
|
+
end
|
48
|
+
rescue Exception => e
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Authy::API" do
|
4
|
+
it "should find or create a user" do
|
5
|
+
user = Authy::API.register_user(:email => generate_email, :cellphone => generate_cellphone, :country_code => 1)
|
6
|
+
user.should be_kind_of(Authy::Response)
|
7
|
+
|
8
|
+
user.should be_kind_of(Authy::User)
|
9
|
+
user.should_not be_nil
|
10
|
+
user.id.should_not be_nil
|
11
|
+
user.id.should be_kind_of(Integer)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should validate a given token" do
|
15
|
+
user = Authy::API.register_user(:email => generate_email, :cellphone => generate_cellphone, :country_code => 1)
|
16
|
+
response = Authy::API.verify(:token => 'invalid_token', :id => user['id'])
|
17
|
+
|
18
|
+
response.should be_kind_of(Authy::Response)
|
19
|
+
response.ok?.should be_true
|
20
|
+
response.body.should == 'valid token'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return the error messages as a hash" do
|
24
|
+
user = Authy::API.register_user(:email => generate_email, :cellphone => "abc-1234", :country_code => 1)
|
25
|
+
|
26
|
+
user.errors.should be_kind_of(Hash)
|
27
|
+
user.errors['cellphone'].should == ['must be a valid cellphone number.']
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should request a SMS token" do
|
31
|
+
user = Authy::API.register_user(:email => generate_email, :cellphone => generate_cellphone, :country_code => 1)
|
32
|
+
user.should be_ok
|
33
|
+
|
34
|
+
response = Authy::API.request_sms(:id => user.id)
|
35
|
+
response.should be_ok
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
describe "Authy::Response" do
|
2
|
+
before :each do
|
3
|
+
@fake_response = OpenStruct.new
|
4
|
+
@fake_response.body = {'v1' => 'r1','v2' => 42}.to_json
|
5
|
+
@fake_response.code = 200
|
6
|
+
@fake_response.curl_error_message = 'No error'
|
7
|
+
|
8
|
+
@response = Authy::Response.new(@fake_response)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse to json the body" do
|
12
|
+
@response['v2'].should == 42
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be ok if the return code is 200" do
|
16
|
+
@response.ok?.should be_true
|
17
|
+
|
18
|
+
@fake_response.code = 401
|
19
|
+
@response = Authy::Response.new(@fake_response)
|
20
|
+
@response.ok?.should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return the error message" do
|
24
|
+
@response.error_msg.should == "No error"
|
25
|
+
|
26
|
+
@fake_response.body = 'invalid json'
|
27
|
+
@response = Authy::Response.new(@fake_response)
|
28
|
+
|
29
|
+
@response.error_msg.should == "invalid json"
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'authy'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.before(:suite) do
|
14
|
+
Authy.api_uri = 'http://localhost:4567'
|
15
|
+
Authy.api_key = 'testing_ruby_api_key'
|
16
|
+
end
|
17
|
+
|
18
|
+
config.before(:each) do
|
19
|
+
end
|
20
|
+
|
21
|
+
config.after(:each) do
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_email
|
25
|
+
domain = "@authy.com"
|
26
|
+
user = (0...8).map{97.+(rand(25)).chr}.join
|
27
|
+
user + domain
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_cellphone
|
31
|
+
n = rand(999) + 1000
|
32
|
+
"305-967-#{n}"
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Authy
|
9
|
+
- David A. Cuadrado
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-05-21 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: typhoeus
|
17
|
+
requirement: &70133947788640 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - =
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70133947788640
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: pry
|
28
|
+
requirement: &70133947797280 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - =
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70133947797280
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &70133947829020 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.8.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70133947829020
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: yard
|
50
|
+
requirement: &70133947843780 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.7'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70133947843780
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rdoc
|
61
|
+
requirement: &70133947850600 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3.12'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70133947850600
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: &70133947848220 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *70133947848220
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: jeweler
|
83
|
+
requirement: &70133947871480 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.8.3
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *70133947871480
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: simplecov
|
94
|
+
requirement: &70133947883720 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *70133947883720
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: reek
|
105
|
+
requirement: &70133947909680 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.2.8
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *70133947909680
|
114
|
+
description: Ruby library to access Authy services
|
115
|
+
email: krawek@gmail.com
|
116
|
+
executables:
|
117
|
+
- authy-api-console
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files:
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.rdoc
|
122
|
+
files:
|
123
|
+
- .document
|
124
|
+
- .rspec
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- LICENSE.txt
|
128
|
+
- README.rdoc
|
129
|
+
- Rakefile
|
130
|
+
- VERSION
|
131
|
+
- authy.gemspec
|
132
|
+
- bin/authy-api-console
|
133
|
+
- lib/authy.rb
|
134
|
+
- lib/authy/api.rb
|
135
|
+
- lib/authy/config.rb
|
136
|
+
- lib/authy/models/user.rb
|
137
|
+
- lib/authy/response.rb
|
138
|
+
- spec/authy/api_spec.rb
|
139
|
+
- spec/authy/response_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
homepage: http://github.com/authy/authy
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
hash: 600584506253976133
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.8.11
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Ruby library to access Authy services
|
169
|
+
test_files: []
|