prove 0.0.2

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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nick Baugh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,162 @@
1
+
2
+ # prove-ruby <sup>0.0.1</sup>
3
+
4
+ [Prove](https://getprove.com/) API wrapper for Ruby.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'prove'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```bash
17
+ bundle
18
+ ```
19
+
20
+ Or install it yourself:
21
+
22
+ ```bash
23
+ gem install prove
24
+ ```
25
+
26
+ And require:
27
+
28
+ ```ruby
29
+ require 'prove'
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Quick Start
35
+ ```ruby
36
+ #initialize client
37
+ Prove.api_key="test_APIKEY123"
38
+
39
+ #get existing verifications
40
+ verifications = Prove::Verification.list
41
+
42
+ #create verification
43
+ v = Prove::Verification.create(tel: "1234567890")
44
+
45
+ #verify with pin
46
+ v = v.verify(pin: 1337) #or Prove::Verification.verify(id: v.id, pin: 1337)
47
+
48
+ #get existing verification
49
+ v = v.retrieve #or Prove::Verification.retrieve(id: v.id)
50
+
51
+ #verification result object
52
+ v.id # "awoeif128912938"
53
+ v.tel # "1234567890"
54
+ v.text # true
55
+ v.call # false
56
+ v.verified # true
57
+
58
+ #create a verification object from scratch
59
+ v = Prove::Verification.new(id: "awoeif128912938",
60
+ tel:"1234567890",
61
+ text: true,
62
+ call: false,
63
+ verified: true)
64
+ ```
65
+
66
+ ### Configuration
67
+ Default config
68
+ ```ruby
69
+ Prove.api_key="test_APIKEY123"
70
+ ```
71
+
72
+ Config with options
73
+ ```ruby
74
+
75
+ Prove.configure(api_key: "test_APIKEY123",
76
+ logger: Rails.logger,
77
+ log_level: :debug,
78
+ faraday_adapter: :em_http)
79
+ ```
80
+
81
+ Advanced config with direct access to faraday connection. ( **Advanced Users Only** See: [faraday middleware](https://github.com/lostisland/faraday#advanced-middleware-usage))
82
+
83
+ ```ruby
84
+ Prove.configure(api_key: "test_APIKEY123") do |cxn|
85
+ cxn.request :url_encoded #required
86
+ cxn.response :logger, Rails.logger
87
+ cxn.response :json #required
88
+ cxn.response :raise_error
89
+ cxn.adapter Faraday.default_adapter
90
+ end
91
+ ```
92
+
93
+
94
+ ### Method Flavors
95
+
96
+ Support for either positional params
97
+
98
+ ```ruby
99
+ Prove::Verification.verify(v.id, 1337)
100
+ ```
101
+
102
+ or named params ( **recommended** )
103
+
104
+ ```ruby
105
+ Prove::Verification.verify(id: v.id, pin: 1337)
106
+ ```
107
+
108
+ ## Testing
109
+
110
+ Install dependencies
111
+
112
+ ```bash
113
+ bundle
114
+ ```
115
+
116
+ To run tests setup an env variable with your key
117
+
118
+ ```bash
119
+ export PROVE=test_APIKEY123
120
+ ```
121
+
122
+ and run:
123
+
124
+ ```bash
125
+ bundle exec rspec spec
126
+ ```
127
+
128
+ or
129
+
130
+ ```bash
131
+ PROVE=test_KUrW834WfoDFlNMNN5FC53Z1Xb4 bundle exec rspec spec
132
+ ```
133
+
134
+ ## Contributors
135
+
136
+ * Grant Warman <grant.warman@gmail.com>
137
+ * Nick Baugh <niftylettuce@gmail.com>
138
+
139
+
140
+ ## License
141
+
142
+ The MIT License
143
+
144
+ Copyright (c) 2013- Prove <support@getprove.com> (https://getprove.com/)
145
+
146
+ Permission is hereby granted, free of charge, to any person obtaining a copy
147
+ of this software and associated documentation files (the "Software"), to deal
148
+ in the Software without restriction, including without limitation the rights
149
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
150
+ copies of the Software, and to permit persons to whom the Software is
151
+ furnished to do so, subject to the following conditions:
152
+
153
+ The above copyright notice and this permission notice shall be included in
154
+ all copies or substantial portions of the Software.
155
+
156
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
158
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
159
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
160
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
161
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
162
+ THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ require 'prove/client'
2
+ require 'prove/verification'
3
+ module Prove
4
+ class << self
5
+ attr_reader :client
6
+ def api_key=(key)
7
+ if @client
8
+ @client.api_key = key
9
+ else
10
+ @client = Client.new(api_key: key)
11
+ end
12
+ end
13
+
14
+ def configure(options, &block)
15
+ @client = Client.new(options, &block)
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,54 @@
1
+ require "faraday"
2
+ require 'faraday_middleware'
3
+ require "logger"
4
+
5
+ module Prove
6
+ class Client
7
+ attr_accessor :api_key, :connection
8
+
9
+ DEFAULTS = {faraday_adapter: Faraday.default_adapter,
10
+ log_level: :warn,
11
+ logger: Logger.new(STDOUT),
12
+ scheme: :https,
13
+ port: 443,
14
+ host: 'getprove.com'}
15
+
16
+ def initialize(options={}, &block)
17
+ config = DEFAULTS.merge(options)
18
+
19
+ if !options.has_key?(:logger) or (options.has_key?(:log_level) and options.has_key?(:logger))
20
+ config[:logger].level = Logger.const_get(config[:log_level].to_s.upcase)
21
+ end
22
+
23
+
24
+ block = block_given? ? block : Proc.new do |cxn|
25
+ cxn.request :url_encoded
26
+ cxn.response :logger, config[:logger]
27
+ cxn.response :json
28
+ # cxn.response :raise_error # raise exceptions on 40x, 50x responses
29
+ cxn.adapter config[:faraday_adapter]
30
+ end
31
+
32
+ url_builder = config[:scheme] == :http ? URI::HTTP : URI::HTTPS
33
+ url = url_builder.build(host: config[:host], port: config[:port])
34
+
35
+ @connection = Faraday.new(url, &block)
36
+ @connection.headers['User-Agent'] = "Prove-Ruby"
37
+
38
+ self.api_key = config[:api_key]
39
+ end
40
+
41
+ def api_key=(key)
42
+ @api_key = key
43
+ @connection.basic_auth(@api_key, '')
44
+ end
45
+
46
+ def get(url, options = {}, &block)
47
+ return @connection.get(url, options, &block)
48
+ end
49
+
50
+ def post(url, options = {}, &block)
51
+ return @connection.post(url, options, &block)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,62 @@
1
+ module Prove
2
+ class Verification
3
+ ACCESSORS = [:id, :tel, :text, :call, :verified]
4
+ attr_accessor *ACCESSORS
5
+
6
+ def initialize(attr_hash={})
7
+ attr_hash.each do |key, val|
8
+ self.instance_variable_set("@#{key}", val)
9
+ end
10
+ end
11
+
12
+ def self.create(*args)
13
+ options = args.last.is_a?(Hash) ? args.pop : {}
14
+ tel = args[0] || options[:tel]
15
+ from_json Prove.client.post('/api/v1/verify', {tel: tel}).body
16
+ end
17
+
18
+ def self.list
19
+ from_json_array Prove.client.get('/api/v1/verify').body
20
+ end
21
+
22
+ def self.verify(*args)
23
+ options = args.last.is_a?(Hash) ? args.pop : {}
24
+ id = args[0] || options[:id]
25
+ pin = args[1] || options[:pin]
26
+
27
+ from_json Prove.client.post('/api/v1/verify/' + id + '/pin', {pin: pin}).body
28
+ end
29
+
30
+ def self.retrieve(*args)
31
+ options = args.last.is_a?(Hash) ? args.pop : {}
32
+ id = args[0] || options[:id]
33
+ from_json Prove.client.get('/api/v1/verify/' + id).body
34
+ end
35
+
36
+ def verify(*args)
37
+ options = args.last.is_a?(Hash) ? args.pop : {}
38
+ pin = args[0] || options[:pin]
39
+ self.class.verify(self.id, pin)
40
+ end
41
+
42
+ def retrieve
43
+ self.class.retrieve(self.id)
44
+ end
45
+
46
+ def to_json
47
+ return {id: self.id,
48
+ tel: self.tel,
49
+ text: self.text,
50
+ call: self.call,
51
+ verified: self.verified}.to_json
52
+ end
53
+
54
+ def self.from_json(verification_hash)
55
+ return Verification.new(verification_hash)
56
+ end
57
+
58
+ def self.from_json_array(verifications)
59
+ return verifications.map{|attr_hash| Verification.new(attr_hash)}
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Prove
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prove/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "prove"
8
+ gem.version = Prove::VERSION
9
+ gem.platform = Gem::Platform::RUBY
10
+ gem.authors = ["Nick Baugh", "Grant Warman"]
11
+ gem.email = ["niftylettuce@gmail.com"]
12
+ gem.homepage = "https://github.com/getprove/prove-ruby"
13
+ gem.description = %q{Prove makes it easy to verify phone numbers with voice and SMS.}
14
+ gem.summary = %q{Phone verification for developers.}
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency("faraday", '>= 0.8.6')
20
+ gem.add_dependency("faraday_middleware", '~> 0.9.0')
21
+ gem.add_development_dependency "rspec", "~> 2.6"
22
+ end
@@ -0,0 +1,6 @@
1
+ require 'prove'
2
+ describe Prove::Client do
3
+ it "should be initializable" do
4
+ expect(Prove::Client.new).to_not be_nil
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ require 'prove'
2
+ describe Prove do
3
+ it "should have an env variable with secret key" do
4
+ expect(ENV['PROVE']).to_not be_nil
5
+ end
6
+
7
+ it "should be initializable with an api key" do
8
+ Prove.api_key = ENV['PROVE']
9
+ expect(Prove.client).to_not be_nil
10
+ end
11
+
12
+ it "should be configurable with an api key" do
13
+ Prove.configure(api_key: ENV['PROVE'])
14
+ expect(Prove.client).to_not be_nil
15
+ end
16
+ end
@@ -0,0 +1,93 @@
1
+ require 'prove'
2
+ describe Prove::Verification do
3
+ RSpec::Matchers.define :be_a_populated_verification do
4
+ match do |v|
5
+ any_nil_attr = Prove::Verification::ACCESSORS.map{|i| v.send(i)}.any?(&:nil?)
6
+ !v.nil? and v.kind_of?(Prove::Verification) and !any_nil_attr
7
+ end
8
+
9
+ failure_message_for_should do |v|
10
+ if v.nil?
11
+ "expected that #{v} would not be nil"
12
+ elsif !v.kind_of?(Prove::Verification)
13
+ "expected that #{v} was a kind of Prove::Verification"
14
+ else
15
+ nil_attr = Prove::Verification::ACCESSORS.map{|i| v.send(i)}.select(&:nil?)
16
+ "expected that #{v} would not have nil attributes #{nil_attr}"
17
+ end
18
+ end
19
+ end
20
+
21
+ before(:all) do
22
+ Prove.api_key = ENV['PROVE']
23
+ end
24
+
25
+ it "should be initializable" do
26
+ v = Prove::Verification.new({
27
+ id: "awoeif128912938",
28
+ tel: "1234567890",
29
+ text: true,
30
+ call: false,
31
+ verified: false
32
+ })
33
+ expect(v).to be_a_populated_verification
34
+ end
35
+
36
+ it "Verification#list should return a list of Verifications" do
37
+ verifications = Prove::Verification.list
38
+ expect(verifications).to_not be_nil
39
+ expect(verifications).to be_kind_of Array
40
+ end
41
+
42
+ it "Verification#create should return a populated verification" do
43
+ v = Prove::Verification.create("1234567890")
44
+ expect(v).to be_a_populated_verification
45
+ expect(v.verified).to be_false
46
+ end
47
+
48
+ it "Verification#create with hash should return a populated verification" do
49
+ v = Prove::Verification.create(tel: "1234567890")
50
+ expect(v).to be_a_populated_verification
51
+ expect(v.verified).to be_false
52
+ end
53
+
54
+ it "Verification#verify with ordered params should return a populated verification" do
55
+ v = Prove::Verification.create("1234567890")
56
+ v = Prove::Verification.verify(v.id, 1337)
57
+ expect(v).to be_a_populated_verification
58
+ expect(v.verified).to be_true
59
+ end
60
+
61
+ it "Verification#verify with hash params should return a populated verification" do
62
+ v = Prove::Verification.create("1234567890")
63
+ v = Prove::Verification.verify(id: v.id, pin: 1337)
64
+ expect(v).to be_a_populated_verification
65
+ expect(v.verified).to be_true
66
+ end
67
+
68
+ it "#retrieve should return a populated verification" do
69
+ v = Prove::Verification.create("1234567890")
70
+ v = v.retrieve
71
+ expect(v).to be_a_populated_verification
72
+ end
73
+
74
+ it "#verify should return a populated verification" do
75
+ v = Prove::Verification.create("1234567890")
76
+ v = v.verify(1337)
77
+ expect(v).to be_a_populated_verification
78
+ expect(v.verified).to be_true
79
+ end
80
+
81
+ it "#verify should return a populated verification" do
82
+ v = Prove::Verification.create("1234567890")
83
+ v = v.verify(pin: 1337)
84
+ expect(v).to be_a_populated_verification
85
+ expect(v.verified).to be_true
86
+ end
87
+
88
+ it "#retrieve should return a populated verification" do
89
+ v = Prove::Verification.create("1234567890")
90
+ v = v.retrieve
91
+ expect(v).to be_a_populated_verification
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prove
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Nick Baugh
14
+ - Grant Warman
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2013-05-09 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: faraday
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 51
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 6
34
+ version: 0.8.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: faraday_middleware
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 59
46
+ segments:
47
+ - 0
48
+ - 9
49
+ - 0
50
+ version: 0.9.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 2
64
+ - 6
65
+ version: "2.6"
66
+ type: :development
67
+ version_requirements: *id003
68
+ description: Prove makes it easy to verify phone numbers with voice and SMS.
69
+ email:
70
+ - niftylettuce@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - Rakefile
83
+ - Readme.md
84
+ - lib/prove.rb
85
+ - lib/prove/client.rb
86
+ - lib/prove/verification.rb
87
+ - lib/prove/version.rb
88
+ - prove.gemspec
89
+ - spec/client_spec.rb
90
+ - spec/prove_spec.rb
91
+ - spec/verification_spec.rb
92
+ homepage: https://github.com/getprove/prove-ruby
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.15
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Phone verification for developers.
125
+ test_files:
126
+ - spec/client_spec.rb
127
+ - spec/prove_spec.rb
128
+ - spec/verification_spec.rb