ruby-vonage 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ruby-vonage.rb +9 -0
- data/lib/vonage/authentication.rb +21 -0
- data/lib/vonage/client.rb +23 -0
- data/lib/vonage/error.rb +25 -0
- data/lib/vonage/http.rb +46 -0
- data/lib/vonage/rest.rb +10 -0
- data/lib/vonage/version.rb +3 -0
- data/ruby-vonage.gemspec +26 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aaa1ad6c60f26ce3ac9414dbac7626c8da2eb5e5
|
4
|
+
data.tar.gz: c7d5bb95ea24dbcc46edbb9984dda11228abccda
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e756db126a7a71a6750783b1482f0cc2cf1ddb28422d4baee0db95828ee54fb77fd984d9369a6ee2269e51b9383eca83ca3936b65bf63fc3d1fef11905cd4c32
|
7
|
+
data.tar.gz: 8e1f07c53e1815c7d2f7440914b5d1592ba4a809a7ad29050bbb1fc70cee7370e10cef37aff9bdd7d7098c01f7b47f83dd63dd933d4d224d24cda1d4a0fc813c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alex Watt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# ruby-vonage
|
2
|
+
|
3
|
+
This is a Ruby client for the Vonage Business API, version 1.5.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruby-vonage'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruby-vonage
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client = Vonage::Client("myusername", "mypassword")
|
25
|
+
|
26
|
+
# Manual authentication is optional.
|
27
|
+
# (Client automatically authenticates before other API calls.)
|
28
|
+
client.authenticate
|
29
|
+
```
|
30
|
+
|
31
|
+
### Click to Call
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
client.click_to_call("1234567890")
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alexcwatt/ruby-vonage.
|
46
|
+
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby-vonage"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ruby-vonage.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Vonage
|
2
|
+
module Authentication
|
3
|
+
|
4
|
+
def authenticate
|
5
|
+
params = {login: @login, password: @password}
|
6
|
+
get_response = get "/appserver/rest/user/null", params
|
7
|
+
|
8
|
+
@cookies = parse_cookies(get_response)
|
9
|
+
end
|
10
|
+
|
11
|
+
def authenticated?
|
12
|
+
!@cookies.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def reauthenticate
|
16
|
+
@cookies = CookieHash.new
|
17
|
+
authenticate
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "vonage/version"
|
2
|
+
|
3
|
+
module Vonage
|
4
|
+
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
base_uri 'https://my.vonagebusiness.com'
|
8
|
+
|
9
|
+
include Authentication
|
10
|
+
include Http
|
11
|
+
|
12
|
+
include Rest
|
13
|
+
|
14
|
+
attr_accessor :login, :password, :cookies
|
15
|
+
|
16
|
+
def initialize login, password
|
17
|
+
@login = login
|
18
|
+
@password = password
|
19
|
+
|
20
|
+
@cookies = CookieHash.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/vonage/error.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Vonage
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class AuthenticationError < Error; end
|
5
|
+
class NetError < Error; end
|
6
|
+
class InvalidPhoneNumber < Error; end
|
7
|
+
|
8
|
+
class ResponseError < Error
|
9
|
+
def initialize(res)
|
10
|
+
@res = res
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@res.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def code
|
18
|
+
@res.code.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
@res.inspect.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/vonage/http.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Vonage
|
2
|
+
module Http
|
3
|
+
|
4
|
+
def get action, params = {}, num_retries = 0
|
5
|
+
options = {query: params, headers: {'Cookie': @cookies.to_cookie_string}}
|
6
|
+
check_response self.class.get(action, options)
|
7
|
+
|
8
|
+
rescue Vonage::AuthenticationError => e
|
9
|
+
handle_expired_cookies :get, action, params, num_retries, e
|
10
|
+
|
11
|
+
rescue SocketError, Interrupt, EOFError, SystemCallError, Timeout::Error => e
|
12
|
+
raise Vonage::NetError.new(e)
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse_cookies resp
|
16
|
+
cookie_hash = HTTParty::CookieHash.new
|
17
|
+
resp.get_fields('Set-Cookie').each { |c| cookie_hash.add_cookies(c) }
|
18
|
+
cookie_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def handle_expired_cookies method, action, params, num_retries, e
|
24
|
+
raise e unless num_retries == 0
|
25
|
+
|
26
|
+
reauthenticate
|
27
|
+
|
28
|
+
send(method, object, path, params, 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_response http_response
|
32
|
+
case http_response.code
|
33
|
+
when 400
|
34
|
+
throw Vonage::InvalidPhoneNumber
|
35
|
+
when 403
|
36
|
+
throw Vonage::AuthenticationError if http_response.include?("USER NOT LOGGED IN")
|
37
|
+
throw Vonage::Error
|
38
|
+
when (401..600)
|
39
|
+
throw Vonage::Error("Status Code: #{http_response.code}")
|
40
|
+
end
|
41
|
+
|
42
|
+
http_response
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/vonage/rest.rb
ADDED
data/ruby-vonage.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vonage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-vonage"
|
8
|
+
spec.version = Vonage::VERSION
|
9
|
+
spec.author = "Alex Watt"
|
10
|
+
spec.email = "alexcwatt@gmail.com"
|
11
|
+
|
12
|
+
spec.summary = "Use the Vonage Business API with Ruby"
|
13
|
+
spec.homepage = "https://github.com/alexcwatt/ruby-vonage"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-vonage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Watt
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email: alexcwatt@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- ".gitignore"
|
76
|
+
- ".rspec"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/ruby-vonage.rb
|
85
|
+
- lib/vonage/authentication.rb
|
86
|
+
- lib/vonage/client.rb
|
87
|
+
- lib/vonage/error.rb
|
88
|
+
- lib/vonage/http.rb
|
89
|
+
- lib/vonage/rest.rb
|
90
|
+
- lib/vonage/version.rb
|
91
|
+
- ruby-vonage.gemspec
|
92
|
+
homepage: https://github.com/alexcwatt/ruby-vonage
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Use the Vonage Business API with Ruby
|
116
|
+
test_files: []
|