aninipot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/Gemfile +5 -0
- data/README.md +46 -0
- data/Rakefile +8 -0
- data/aninipot.gemspec +22 -0
- data/lib/aninipot.rb +12 -0
- data/lib/aninipot/client.rb +49 -0
- data/lib/aninipot/config.rb +20 -0
- data/lib/aninipot/response.rb +57 -0
- data/lib/aninipot/support.rb +30 -0
- data/lib/aninipot/version.rb +3 -0
- data/test/.DS_Store +0 -0
- data/test/test_aninipot.rb +24 -0
- data/test/test_helper.rb +9 -0
- data/travis.yml +3 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
aninipot
|
2
|
+
============
|
3
|
+
|
4
|
+
#Aninipot
|
5
|
+
|
6
|
+
A ruby gem for consuming Firefly API. Aninipot is a Cebuano term of Firefly.
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
Ruby 1.9.x
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
$ gem install aninipot
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
The configuration below will be provided by Smart Devnet. Apply for access (http://www.smart.com.ph/developer)
|
18
|
+
|
19
|
+
client = Aninipot::Client.configure do |config|
|
20
|
+
config.api = ''
|
21
|
+
config.from = 2337
|
22
|
+
end
|
23
|
+
|
24
|
+
## Sending SMS
|
25
|
+
|
26
|
+
response = client.send_sms(number, message)
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
35
|
+
|
36
|
+
## MIT Open Source License
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
43
|
+
|
44
|
+
## Acknowledgements
|
45
|
+
|
46
|
+
Authored by: <a href="http://iantusil.com" target="_blank">Ian Bert Tusil</a>
|
data/Rakefile
ADDED
data/aninipot.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'aninipot'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.date = '2012-11-24'
|
8
|
+
s.email = 'me@iantusil.com'
|
9
|
+
|
10
|
+
s.summary = "A ruby gem for consuming Firefly API"
|
11
|
+
s.description = "A ruby gem for consuming Firefly API (currently supports SMS only)."
|
12
|
+
s.author = "Ian Bert Tusil"
|
13
|
+
s.homepage = 'http://www.fireflyapi.com/'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.require_paths = %w[lib]
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = Dir['test/*.rb']
|
20
|
+
|
21
|
+
s.add_development_dependency 'minitest', '~> 4.3.3'
|
22
|
+
end
|
data/lib/aninipot.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require_relative 'aninipot/support'
|
8
|
+
require_relative 'aninipot/version'
|
9
|
+
require_relative 'aninipot/response'
|
10
|
+
require_relative 'aninipot/config'
|
11
|
+
require_relative 'aninipot/client'
|
12
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Aninipot
|
2
|
+
class Client
|
3
|
+
include ClassSupportMixin
|
4
|
+
include Aninipot::Configuration
|
5
|
+
|
6
|
+
set_attributes :host => 'fireflyapi.com',
|
7
|
+
:port => '80',
|
8
|
+
:api => '',
|
9
|
+
:from => ''
|
10
|
+
|
11
|
+
attr_reader :api, :from
|
12
|
+
|
13
|
+
def send_sms(mobile, message)
|
14
|
+
request = setup_connection(valid_sms_data(mobile, message))
|
15
|
+
response = connect(request)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def valid_sms_data(mobile, message)
|
21
|
+
{"api" => self.api, "number" => mobile, "message" => message, "from" => self.from}
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_sms_outbound_endpoint
|
25
|
+
"http://#{self.host}/api/sms"
|
26
|
+
end
|
27
|
+
|
28
|
+
def setup_connection(args)
|
29
|
+
uri = URI.parse(setup_sms_outbound_endpoint)
|
30
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
31
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
32
|
+
request.set_form_data(args)
|
33
|
+
request
|
34
|
+
end
|
35
|
+
|
36
|
+
def connect(request)
|
37
|
+
response = @http.request(request)
|
38
|
+
|
39
|
+
if response.body and !response.body.empty?
|
40
|
+
object = JSON.parse(response.body)
|
41
|
+
end
|
42
|
+
if response.kind_of? Net::HTTPClientError
|
43
|
+
error = Aninipot::Response.new object["code"]
|
44
|
+
raise error.to_s
|
45
|
+
end
|
46
|
+
response
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Aninipot
|
2
|
+
module Configuration
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def configure(&block)
|
9
|
+
config = self.new
|
10
|
+
raise ArgumentError, "Please provide configuration block" unless block_given?
|
11
|
+
yield config
|
12
|
+
|
13
|
+
[:api].each do |required|
|
14
|
+
raise "#{required} is required" unless config.send(required)
|
15
|
+
end
|
16
|
+
config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Aninipot
|
2
|
+
class Response
|
3
|
+
attr_reader :response_code
|
4
|
+
#TODO:
|
5
|
+
# Service Exception Extension
|
6
|
+
# Policy Exceptions
|
7
|
+
# Policy Exception Extension
|
8
|
+
@@error_map = {
|
9
|
+
:sent? => 200,
|
10
|
+
:queued? => 201,
|
11
|
+
:not_authorized? => 100,
|
12
|
+
:not_enough_balance? => 101,
|
13
|
+
:featured_not_allowed? => 102,
|
14
|
+
:invalid_option? => 103,
|
15
|
+
:gateway_down? => 104
|
16
|
+
}
|
17
|
+
|
18
|
+
@@status_messages = {
|
19
|
+
200 => "Successfully Sent",
|
20
|
+
201 => "Message Queued",
|
21
|
+
100 => "Not Authorized",
|
22
|
+
101 => "Not Enough Balance",
|
23
|
+
102 => "Feature Not Allowed",
|
24
|
+
103 => "Invalid Options",
|
25
|
+
104 => "Gateway Down"
|
26
|
+
}
|
27
|
+
|
28
|
+
def initialize(code)
|
29
|
+
@response_code = code
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
[200, 201].include?(self.response_code)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
#"#{self.response_code} - #{msg}"
|
38
|
+
msg
|
39
|
+
end
|
40
|
+
|
41
|
+
def msg(code = self.response_code)
|
42
|
+
if msg = @@status_messages[code]
|
43
|
+
msg
|
44
|
+
else
|
45
|
+
raise ArgumentError, "#{code} - undefined response code"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing(method_id)
|
50
|
+
if code = @@error_map[method_id.to_sym]
|
51
|
+
self.response_code == code
|
52
|
+
else
|
53
|
+
raise NoMethodError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ClassSupportMixin
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, InstanceMethods)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def set_attributes(attrs)
|
9
|
+
attr_accessor *attrs.keys
|
10
|
+
define_method(:default_attributes) { attrs }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
def initialize(options={})
|
16
|
+
init = if self.respond_to?(:default_attributes)
|
17
|
+
self.default_attributes.merge(options)
|
18
|
+
else
|
19
|
+
options
|
20
|
+
end
|
21
|
+
init.each { |k, v| self.send("#{k}=", v) if self.respond_to?(k) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def attributes
|
25
|
+
attrs = {}
|
26
|
+
self.default_attributes.keys.each {|k| attrs[k] = self.send(k) if self.respond_to?(k)}
|
27
|
+
attrs
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require_relative '../lib/aninipot'
|
3
|
+
|
4
|
+
describe Aninipot do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@client = initialize_rest_client
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize_rest_client
|
11
|
+
Aninipot::Client.configure do |config|
|
12
|
+
config.api = config_file['api'].to_s
|
13
|
+
config.from = config_file['from']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should be able to send sms' do
|
18
|
+
begin
|
19
|
+
response = @client.send_sms("+639275866897", "Test Data")
|
20
|
+
rescue Exception => e
|
21
|
+
e.message.must_equal Aninipot::Response.new(200).to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
data/travis.yml
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aninipot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ian Bert Tusil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
16
|
+
requirement: &319170 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.3.3
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *319170
|
25
|
+
description: A ruby gem for consuming Firefly API (currently supports SMS only).
|
26
|
+
email: me@iantusil.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- aninipot.gemspec
|
36
|
+
- lib/aninipot.rb
|
37
|
+
- lib/aninipot/client.rb
|
38
|
+
- lib/aninipot/config.rb
|
39
|
+
- lib/aninipot/response.rb
|
40
|
+
- lib/aninipot/support.rb
|
41
|
+
- lib/aninipot/version.rb
|
42
|
+
- test/.DS_Store
|
43
|
+
- test/test_aninipot.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
- travis.yml
|
46
|
+
homepage: http://www.fireflyapi.com/
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.17
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: A ruby gem for consuming Firefly API
|
71
|
+
test_files:
|
72
|
+
- test/test_aninipot.rb
|
73
|
+
- test/test_helper.rb
|