em-plivo 0.0.1

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: bd4e11b9919862250b866cda9a118aeeb3bb9929
4
+ data.tar.gz: 21876aadd8022cd2bc9a4dfc1b3a2c2b35e87fa4
5
+ SHA512:
6
+ metadata.gz: 0215768d87e437aac56f8e6d04afe007ddb14880ec43989193e122b89cb30ef04f693008cb23a79df955dd5aa94a91bd1287f137cc86623f6aa3a15b0744e11b
7
+ data.tar.gz: 7d1737e4ff59c990024015346dde95a44590a56a275944223c83af0b0306169e21354c3cacd80cfbe602b1c39826e92f12212efcef44377464e5627d9c5dcb29
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dmitry Panin
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.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # EventMachine::Plivo
2
+
3
+ An EventMachine port of [PlivoRuby](https://github.com/plivo/plivo-ruby).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'em-plivo'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install em-plivo
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'eventmachine'
25
+ require 'em-plivo'
26
+
27
+ EM.run do
28
+ client = EM::Plivo::RestAPI.new(YOUR_AUTH_ID, YOUR_AUTH_TOKEN, :keepalive => true)
29
+
30
+ sms = client.send_message(
31
+ :src => '+70000000000',
32
+ :dst => '+71111111111',
33
+ :text => 'I can!',
34
+ :type => 'sms',
35
+ )
36
+
37
+ sms.callback do |http_status, http_response|
38
+ p [http_status, http_response]
39
+ EM.stop
40
+ end
41
+
42
+ sms.errback do |error|
43
+ p "Error: #{error}"
44
+ EM.stop
45
+ end
46
+ end
47
+ ```
48
+
49
+ ## Documentation
50
+ * [Plivo API documentation](https://www.plivo.com/docs/api/).
51
+ * [Available methods](https://github.com/plivo/plivo-ruby/blob/master/lib/plivo.rb).
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/bjorn-tf/em-plivo/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/em-plivo.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'em-plivo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "em-plivo"
8
+ spec.version = EventMachine::Plivo::VERSION
9
+ spec.authors = ["Dmitry Panin"]
10
+ spec.email = ["dmitry.panin@yahoo.com"]
11
+ spec.summary = %q{An EventMachine port of PlivoRuby.}
12
+ spec.homepage = "https://github.com/bjorn-tf/em-plivo"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "plivo", "~> 0.3"
21
+ spec.add_dependency "multi_json", '~> 1.0'
22
+ spec.add_dependency "eventmachine", "~> 1.0"
23
+ spec.add_dependency "em-http-request", "~> 1.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
data/lib/em-plivo.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'plivo'
2
+
3
+ require 'multi_json'
4
+ require 'eventmachine'
5
+ require 'em-http-request'
6
+
7
+ require 'em-plivo/version'
8
+ require 'em-plivo/rest_api'
9
+
10
+ module EventMachine
11
+ module Plivo
12
+ end
13
+ end
@@ -0,0 +1,68 @@
1
+ module EventMachine
2
+ module Plivo
3
+ class RestAPI < ::Plivo::RestAPI
4
+ def initialize(*args)
5
+ if args.last.is_a? Hash
6
+ opts = args.pop
7
+ args += opts.values_at(:url, :version).compact
8
+ @keepalive = opts[:keepalive] == true
9
+ else
10
+ @keepalive = false
11
+ end
12
+
13
+ super(*args)
14
+ end
15
+
16
+ def request(method, path, params = nil)
17
+ params ||= {}
18
+ method = method.downcase
19
+
20
+ full_path = File.join(@version, 'Account', @auth_id, path)
21
+ options = {
22
+ :keepalive => @keepalive,
23
+ :path => full_path,
24
+ :head => {
25
+ 'User-Agent' => 'RubyPlivo',
26
+ 'Authorization' => [@auth_id, @auth_token]
27
+ }
28
+ }
29
+
30
+ deferrable = EM::DefaultDeferrable.new
31
+
32
+ case method
33
+ when 'post'
34
+ options[:head]['Content-Type'] = 'application/json'
35
+ options[:body] = MultiJson.dump(params)
36
+ when 'get', 'delete'
37
+ options[:query] = params
38
+ else
39
+ EM.next_tick{deferrable.fail('Method Not Supported')}
40
+ return deferrable
41
+ end
42
+
43
+ connection = if @keepalive
44
+ @alive_connection ||= EM::HttpRequest.new(@url)
45
+ else
46
+ EM::HttpRequest.new(@url)
47
+ end
48
+
49
+ http = connection.public_send(method, options)
50
+
51
+ http.callback do
52
+ response = begin
53
+ MultiJson.load(http.response)
54
+ rescue MultiJson::ParseError
55
+ nil
56
+ end
57
+ deferrable.succeed(http.response_header.status, response)
58
+ end
59
+
60
+ http.errback do
61
+ deferrable.fail(http.error)
62
+ end
63
+
64
+ deferrable
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,5 @@
1
+ module EventMachine
2
+ module Plivo
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-plivo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Panin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-20 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'
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: em-http-request
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description:
98
+ email:
99
+ - dmitry.panin@yahoo.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - em-plivo.gemspec
110
+ - lib/em-plivo.rb
111
+ - lib/em-plivo/rest_api.rb
112
+ - lib/em-plivo/version.rb
113
+ homepage: https://github.com/bjorn-tf/em-plivo
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.2.2
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: An EventMachine port of PlivoRuby.
137
+ test_files: []