classy_plivo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 319d9a4ada1a05f394bd3d77fb4f4d55862a8038
4
+ data.tar.gz: 236e725fd6da9f8b19673c247ccbf98a3eb4153f
5
+ SHA512:
6
+ metadata.gz: 79738e1a4a175f6656045006caed17b0982342f9ff8a4ed2a1f8f3e02de3157569369ef18a5aae54ae6c5ff1990ed886617e55da696678490e7fe8a39027c1a2
7
+ data.tar.gz: 0ba13573698a1ca99d002263e9c276f7d43029b03f912254954f2692fc52bb54df2d03833a0afb7a41440edbd501178563c68ec653b419e280cfd7ce5f64859f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ script: bundle exec rake test
3
+ rvm:
4
+ - 2.2.0
5
+ - 1.9.3
6
+ - jruby
7
+ - rbx-2
8
+ addons:
9
+ code_climate:
10
+ repo_token: c89e613dddb046253964e38324882d2e18082b23446e0ec944d5cfc761f97ad4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in classy_plivo.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Faraz Yashar
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,63 @@
1
+ # ClassyPlivo :phone:
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/classy_plivo.svg)](http://badge.fury.io/rb/classy_plivo)
4
+ [![Build Status](https://travis-ci.org/fny/classy_plivo.svg?branch=master)](https://travis-ci.org/fny/classy_plivo)
5
+ [![Test Coverage](https://codeclimate.com/github/fny/classy_plivo/badges/coverage.svg)](https://codeclimate.com/github/fny/classy_plivo)
6
+ [![Code Climate](https://codeclimate.com/github/fny/classy_plivo/badges/gpa.svg)](https://codeclimate.com/github/fny/classy_plivo)
7
+ [![Dependency Status](https://gemnasium.com/fny/classy_plivo.svg)](https://gemnasium.com/fny/classy_plivo)
8
+
9
+ A classy and minimalistic wrapper for the [Plivo Ruby library](https://github.com/plivo/plivo-ruby).
10
+
11
+ ## Overview
12
+
13
+ ```ruby
14
+ # This matches Plivo::RestAPI signature
15
+ classy_api = ClassyPlivo::RestAPI.new('auth_id', 'auth_token')
16
+ classy_response = classy_api.get_account
17
+
18
+ # => ClassyPlivo::Response
19
+ classy_response.nonsense
20
+ # => NoMethodError
21
+ classy_response.error?
22
+ # => true for 4XX and 5XX errors
23
+ classy_response.http_status
24
+ # => Integer response code
25
+ classy_response.payload
26
+ # => Twilio payload hash: { api_id: '1', 'message' => 'success' }
27
+ classy_response.payload_key
28
+ # => Value of payload['payload_key'] or ClassyPlivo::Response:::NoPayloadKeyError
29
+ classy_response.has_payload_key?('whatever')
30
+ # => true if the payload provides the requested key
31
+ ```
32
+
33
+ A lot of this behavior relies on overriding `#method_missing`. For more details, check out the tests in the `test` directory and the source code.
34
+
35
+ ## Installation
36
+
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'classy_plivo'
41
+ ```
42
+
43
+ And then execute:
44
+
45
+ $ bundle
46
+
47
+ Or install it yourself as:
48
+
49
+ $ gem install classy_plivo
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec rake test` to run the test suite.
54
+
55
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/fny/classy_plivo/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test_*.rb']
7
+ t.verbose = true
8
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'classy_plivo'
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'classy_plivo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'classy_plivo'
8
+ spec.version = ClassyPlivo::VERSION
9
+ spec.authors = ['Faraz Yashar']
10
+ spec.email = ['faraz.yashar@gmail.com']
11
+
12
+ spec.summary = 'A classy wrapper for the Plivo Ruby library'
13
+ spec.description = 'A minimalistic and classy wrapper for the Plivo Ruby library.'
14
+ spec.homepage = 'https://github.com/fny/classy_plivo'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'plivo', '~> 0.3.16'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'minitest', '~> 5.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
@@ -0,0 +1,34 @@
1
+ module ClassyPlivo
2
+ class Response
3
+ attr_reader :http_status, :payload
4
+
5
+ # Raised when attempting to access a key that does not exist in Plivo's
6
+ # response payload
7
+ NoPayloadKeyError = Class.new(NoMethodError)
8
+
9
+ def initialize(response)
10
+ @http_status = response[0]
11
+ @payload = response[1]
12
+ end
13
+
14
+ # True if 4XX or 5XX status code is received
15
+ def error?
16
+ http_status >= 400 && http_status <= 599
17
+ end
18
+
19
+ def has_payload_key?(key)
20
+ payload.has_key?(key)
21
+ end
22
+
23
+ # Delegate all other method calls to the payload hash
24
+ def method_missing(method, *args, &block)
25
+ payload_key = method.to_s
26
+ if has_payload_key?(payload_key)
27
+ payload[payload_key]
28
+ else
29
+ fail NoPayloadKeyError,
30
+ "Key '#{payload_key}' not found in response payload: #{payload}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ module ClassyPlivo
2
+ class RestAPI
3
+ attr_reader :plivo_api
4
+
5
+ def initialize(*args)
6
+ @plivo_api = Plivo::RestAPI.new(*args)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ Response.new(plivo_api.send(method, args, &block))
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ClassyPlivo
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'plivo'
2
+
3
+ require 'classy_plivo/version'
4
+ require 'classy_plivo/rest_api'
5
+ require 'classy_plivo/response'
6
+
7
+ module ClassyPlivo
8
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: classy_plivo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Faraz Yashar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: plivo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.16
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.16
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.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: A minimalistic and classy wrapper for the Plivo Ruby library.
70
+ email:
71
+ - faraz.yashar@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - classy_plivo.gemspec
85
+ - lib/classy_plivo.rb
86
+ - lib/classy_plivo/response.rb
87
+ - lib/classy_plivo/rest_api.rb
88
+ - lib/classy_plivo/version.rb
89
+ homepage: https://github.com/fny/classy_plivo
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: A classy wrapper for the Plivo Ruby library
113
+ test_files: []