smspilot 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.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +10 -0
- data/lib/smspilot.rb +20 -0
- data/lib/smspilot/api.rb +78 -0
- data/lib/smspilot/client.rb +6 -0
- data/lib/smspilot/configuration.rb +42 -0
- data/lib/smspilot/connection.rb +30 -0
- data/lib/smspilot/errors.rb +92 -0
- data/lib/smspilot/request.rb +37 -0
- data/lib/smspilot/version.rb +3 -0
- data/log/.gitignore +0 -0
- data/smspilot.gemspec +29 -0
- data/spec/lib/smspilot_spec.rb +121 -0
- data/spec/spec_helper.rb +14 -0
- metadata +160 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Rake
|
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,54 @@
|
|
1
|
+
# Smspilot
|
2
|
+
|
3
|
+
Ruby gem for smspilot.ru API
|
4
|
+
|
5
|
+
http://www.smspilot.ru/download/SMSPilotRu-HTTP-v2.1.2.rtf
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'smspilot'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install smspilot
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
create
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Smspilot.new api_token
|
27
|
+
```
|
28
|
+
|
29
|
+
api methods
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
result = client.send_sms(sms_id, sms_from, sms_to, message_text)
|
33
|
+
|
34
|
+
result = client.check_sms_status(sms_server_id)
|
35
|
+
|
36
|
+
result = client.check_balance
|
37
|
+
```
|
38
|
+
|
39
|
+
Use bang! methods if you want errors to be raised.
|
40
|
+
Otherwise access them through
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
result.error
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
53
|
+
|
54
|
+
|
data/Rakefile
ADDED
data/lib/smspilot.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "smspilot/client"
|
2
|
+
require "smspilot/configuration"
|
3
|
+
|
4
|
+
module Smspilot
|
5
|
+
|
6
|
+
extend Configuration
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def new options = {}
|
10
|
+
if options.is_a? String
|
11
|
+
Smspilot::Client.new :api_key => options
|
12
|
+
elsif options.is_a? Hash
|
13
|
+
Smspilot::Client.new options
|
14
|
+
else
|
15
|
+
raise ArgumentError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/smspilot/api.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'smspilot/connection'
|
2
|
+
require 'smspilot/configuration'
|
3
|
+
require 'smspilot/request'
|
4
|
+
require 'smspilot/errors'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Smspilot
|
8
|
+
class Api
|
9
|
+
include Connection
|
10
|
+
include Request
|
11
|
+
|
12
|
+
NOT_FOUND_STATUS = "-2"
|
13
|
+
NOT_DELIVERED_STATUS = "-1"
|
14
|
+
ACCEPTED_STATUS = "0"
|
15
|
+
AT_OPERATOR_STATUS = "1"
|
16
|
+
DELIVERED_STATUS = "2"
|
17
|
+
|
18
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
19
|
+
|
20
|
+
def initialize options = {}
|
21
|
+
options = Smspilot.options.merge(options)
|
22
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
23
|
+
send("#{key}=", options[key])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def send_sms(sms_id, sms_from, sms_to, message_text)
|
28
|
+
body = {:send => [{:id => sms_id.to_s, :from => sms_from.to_s, :to => sms_to.to_s, :text => message_text.to_s}]}
|
29
|
+
response = send_request body
|
30
|
+
enhance_response(response, "send")
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_sms_status(sms_server_id)
|
34
|
+
body = {"check" => [{"server_id" => sms_server_id}]}
|
35
|
+
response = send_request body
|
36
|
+
enhance_response(response, "check")
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_balance
|
40
|
+
body = {"balance" => [{"balance" => true}]}
|
41
|
+
send_request body
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def send_sms!(sms_id, sms_from, sms_to, message_text)
|
46
|
+
response = send_sms(sms_id, sms_from, sms_to, message_text)
|
47
|
+
raise response.error if response.error.kind_of? StandardError
|
48
|
+
response
|
49
|
+
end
|
50
|
+
|
51
|
+
def check_sms_status! (sms_server_id)
|
52
|
+
response = check_sms_status (sms_server_id)
|
53
|
+
raise response.error if response.error.kind_of? StandardError
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_balance!
|
58
|
+
response = check_balance
|
59
|
+
raise response.error if response.error.kind_of? StandardError
|
60
|
+
response
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def enhance_response(response, request_type)
|
65
|
+
unless response.error
|
66
|
+
response.instance_eval <<-RESP
|
67
|
+
def not_found?; #{response.body[request_type].first["status"].eql? NOT_FOUND_STATUS} end
|
68
|
+
def not_delivered?; #{response.body[request_type].first["status"].eql? NOT_DELIVERED_STATUS} end
|
69
|
+
def accepted?; #{response.body[request_type].first["status"].eql? ACCEPTED_STATUS} end
|
70
|
+
def at_operator?; #{response.body[request_type].first["status"].eql? AT_OPERATOR_STATUS} end
|
71
|
+
def delivered?; #{response.body[request_type].first["status"].eql? DELIVERED_STATUS} end
|
72
|
+
RESP
|
73
|
+
end
|
74
|
+
|
75
|
+
response
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'smspilot/version'
|
3
|
+
|
4
|
+
module Smspilot
|
5
|
+
module Configuration
|
6
|
+
VALID_OPTIONS_KEYS = [:endpoint, :user_agent, :adapter, :timeout, :api_key, :logger]
|
7
|
+
|
8
|
+
DEFAULT_ADAPTER = :net_http
|
9
|
+
DEFAULT_ENDPOINT = 'http://smspilot.ru/api2.php'
|
10
|
+
DEFAULT_USER_AGENT = "smspilot gem #{Smspilot::VERSION}".freeze
|
11
|
+
DEFAULT_TIMEOUT = 5
|
12
|
+
DEFAILT_API_KEY = nil
|
13
|
+
DEFAILT_LOGGER = Logger.new("log/smspilot.log")
|
14
|
+
|
15
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.extended(base)
|
22
|
+
base.reset
|
23
|
+
end
|
24
|
+
|
25
|
+
def options
|
26
|
+
options = {}
|
27
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
28
|
+
options
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
self.adapter = DEFAULT_ADAPTER
|
33
|
+
self.endpoint = DEFAULT_ENDPOINT
|
34
|
+
self.user_agent = DEFAULT_USER_AGENT
|
35
|
+
self.timeout = DEFAULT_TIMEOUT
|
36
|
+
self.api_key = DEFAILT_API_KEY
|
37
|
+
self.logger = DEFAILT_LOGGER
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
|
4
|
+
module Smspilot
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
|
8
|
+
def connection
|
9
|
+
options = {
|
10
|
+
:headers => {
|
11
|
+
:user_agent => user_agent
|
12
|
+
},
|
13
|
+
:url => endpoint,
|
14
|
+
:timeout => timeout,
|
15
|
+
:open_timeout => timeout
|
16
|
+
}
|
17
|
+
|
18
|
+
Faraday.new options do |conn|
|
19
|
+
# conn.request :url_encoded
|
20
|
+
conn.request :json
|
21
|
+
|
22
|
+
conn.response :json
|
23
|
+
conn.response :mashify
|
24
|
+
conn.response :logger
|
25
|
+
|
26
|
+
conn.adapter(adapter)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Smspilot
|
2
|
+
module Error
|
3
|
+
|
4
|
+
API_ERROR_CODES = {
|
5
|
+
"10" => "InputDataRequiredError",
|
6
|
+
"11" => "UnknownInputFormatError",
|
7
|
+
"12" => "InvalidJsonError",
|
8
|
+
"14" => "UnknownCommandError",
|
9
|
+
"100" => "ApiKeyRequired",
|
10
|
+
"101" => "ApiKeyInvalid",
|
11
|
+
"106" => "ApiKeyBlocked",
|
12
|
+
"110" => "SystemError",
|
13
|
+
"113" => "IpRestrictionError",
|
14
|
+
"201" => "FromInvalidError",
|
15
|
+
"202" => "FromDeprecatedError",
|
16
|
+
"210" => "ToRequiredError",
|
17
|
+
"211" => "ToInvalidError",
|
18
|
+
"212" => "ToDeprecatedError",
|
19
|
+
"213" => "UnsupportedZoneError",
|
20
|
+
"220" => "TextRequiredError",
|
21
|
+
"221" => "TextTooLongError",
|
22
|
+
"230" => "IdInvalidError",
|
23
|
+
"231" => "PacketIdInvalidError",
|
24
|
+
"240" => "InputListInvalidError",
|
25
|
+
"241" => "NotEnoughCreditsError",
|
26
|
+
"242" => "SmsCountLimitError",
|
27
|
+
"300" => "ServerIdRequiredError",
|
28
|
+
"301" => "ServerIdInvalidError",
|
29
|
+
"302" => "ServerIdNotFoundError",
|
30
|
+
"303" => "InvalidSmsCheckListError",
|
31
|
+
"304" => "ServerPacketIdInvalidError",
|
32
|
+
"400" => "UserNotFoundError"
|
33
|
+
}
|
34
|
+
|
35
|
+
class ApiError < StandardError
|
36
|
+
|
37
|
+
def self.raise_by_code(code=nil)
|
38
|
+
if API_ERROR_CODES[code].nil?
|
39
|
+
raise UnknownApiError
|
40
|
+
else
|
41
|
+
raise Smspilot::Error.const_get(API_ERROR_CODES[code])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.get_by_code(code=nil)
|
46
|
+
if API_ERROR_CODES[code].nil?
|
47
|
+
UnknownApiError
|
48
|
+
else
|
49
|
+
Smspilot::Error.const_get(API_ERROR_CODES[code])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
class InputDataRequiredError < ApiError; end # 10
|
56
|
+
class UnknownInputFormatError < ApiError; end # 11
|
57
|
+
class InvalidJsonError < ApiError; end # 12
|
58
|
+
class UnknownCommandError < ApiError; end # 14
|
59
|
+
class ApiKeyRequired < ApiError; end # 100
|
60
|
+
class ApiKeyInvalid < ApiError; end # 101
|
61
|
+
class ApiKeyBlocked < ApiError; end # 106
|
62
|
+
class SystemError < ApiError; end # 110
|
63
|
+
class IpRestrictionError < ApiError; end # 113
|
64
|
+
class FromInvalidError < ApiError; end # 201
|
65
|
+
class FromDeprecatedError < ApiError; end # 202
|
66
|
+
class ToRequiredError < ApiError; end # 210
|
67
|
+
class ToInvalidError < ApiError; end # 211
|
68
|
+
class ToDeprecatedError < ApiError; end # 212
|
69
|
+
class UnsupportedZoneError < ApiError; end # 213
|
70
|
+
class TextRequiredError < ApiError; end # 220
|
71
|
+
class TextTooLongError < ApiError; end # 221
|
72
|
+
class IdInvalidError < ApiError; end # 230
|
73
|
+
class PacketIdInvalidError < ApiError; end # 231
|
74
|
+
class InputListInvalidError < ApiError; end # 240
|
75
|
+
class NotEnoughCreditsError < ApiError; end # 241
|
76
|
+
class SmsCountLimitError < ApiError; end # 242
|
77
|
+
class ServerIdRequiredError < ApiError; end # 300
|
78
|
+
class ServerIdInvalidError < ApiError; end # 301
|
79
|
+
class ServerIdNotFoundError < ApiError; end # 302
|
80
|
+
class InvalidSmsCheckListError < ApiError; end # 303
|
81
|
+
class ServerPacketIdInvalidError < ApiError; end # 304
|
82
|
+
class UserNotFoundError < ApiError; end # 400
|
83
|
+
class UnknownApiError < ApiError; end # unknown codes
|
84
|
+
|
85
|
+
|
86
|
+
class TimeoutError < StandardError; end;
|
87
|
+
class InvalidJsonResponseError < StandardError; end;
|
88
|
+
class InvalidResposeStatusError < StandardError; end;
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday'
|
4
|
+
require 'smspilot/errors'
|
5
|
+
|
6
|
+
module Smspilot
|
7
|
+
module Request
|
8
|
+
|
9
|
+
def send_request(body)
|
10
|
+
json_body = {"apikey" => api_key}.merge(body).to_json
|
11
|
+
begin
|
12
|
+
response = connection.post do |req|
|
13
|
+
req.body = json_body
|
14
|
+
end
|
15
|
+
|
16
|
+
response_error = (response.status == 200) ? Smspilot::Error::WrongStatusError : nil
|
17
|
+
|
18
|
+
rescue Exception => e
|
19
|
+
if e.kind_of? Faraday::Error::TimeoutError
|
20
|
+
response_error = Smspilot::Error::TimeoutError
|
21
|
+
elsif e.kind_of? Faraday::Error::ParsingError
|
22
|
+
response_error = Smspilot::Error::ParsingError
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless response.body["error"].nil?
|
27
|
+
response_error = Error::ApiError.get_by_code(response.body["error"]["code"]).new()
|
28
|
+
end
|
29
|
+
|
30
|
+
response.instance_eval <<-RESP
|
31
|
+
def error; #{response_error} end
|
32
|
+
RESP
|
33
|
+
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/log/.gitignore
ADDED
File without changes
|
data/smspilot.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/smspilot/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Rake"]
|
6
|
+
gem.email = ["blazesolo@gmail.com"]
|
7
|
+
gem.description = %q{}
|
8
|
+
gem.summary = %q{}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "smspilot"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Smspilot::VERSION
|
17
|
+
|
18
|
+
|
19
|
+
gem.add_runtime_dependency "faraday", '~> 0.8.1'
|
20
|
+
gem.add_runtime_dependency "faraday_middleware", '~> 0.8.8'
|
21
|
+
gem.add_runtime_dependency 'hashie', '~> 1.2.0'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.5'
|
24
|
+
gem.add_development_dependency 'webmock'
|
25
|
+
gem.add_development_dependency 'pry'
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Smspilot do
|
6
|
+
|
7
|
+
let(:sms_id) {'12345'}
|
8
|
+
let(:sms_server_id) {'10005'}
|
9
|
+
let(:sms_from) {'SMSPILOT'}
|
10
|
+
let(:sms_to) {79091112233}
|
11
|
+
let(:message_text) {"Тест"}
|
12
|
+
let(:json_failure_response) {'{"error":{"code":"1337","description":"leeterror"}}'}
|
13
|
+
|
14
|
+
|
15
|
+
#TODO add specs for sms delivery statuses
|
16
|
+
#TODO add specs for parameter validations
|
17
|
+
|
18
|
+
|
19
|
+
before do
|
20
|
+
@client = Smspilot.new "XXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZ"
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#send_sms" do
|
24
|
+
|
25
|
+
let(:json_send_response) { {"send"=> [{"id"=>"12345", "server_id"=>"10005", "from"=>"SMSPILOT", "to"=>"79091112233", "text"=>"Тест", "zone"=>"1", "parts"=>"1", "credits"=>"1", "status"=>"0", "error"=>"0"}], "server_packet_id"=>"1234", "balance"=>"10000"}.to_json}
|
26
|
+
|
27
|
+
it "should return correct result when succeeded" do
|
28
|
+
stub_normal_request(json_send_response)
|
29
|
+
result = @client.send_sms(sms_id, sms_from, sms_to, message_text)
|
30
|
+
result.body.should == {"send"=> [{"id"=>"12345", "server_id"=>"10005", "from"=>"SMSPILOT", "to"=>"79091112233", "text"=>"Тест", "zone"=>"1", "parts"=>"1", "credits"=>"1", "status"=>"0", "error"=>"0"}], "server_packet_id"=>"1234", "balance"=>"10000"}
|
31
|
+
result.status.should eql(200)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
describe "#check_sms_status" do
|
38
|
+
|
39
|
+
let (:check_response_hash) { {"check"=> [{"id"=>"12345", "server_id"=>"10005", "status"=>"1", "modified"=>"2011-08-11 14:35:00"}]} }
|
40
|
+
|
41
|
+
it "should return correct hash when succeeded" do
|
42
|
+
stub_normal_request(check_response_hash.to_json)
|
43
|
+
|
44
|
+
result = @client.check_sms_status(sms_server_id)
|
45
|
+
result.body.should == {"check"=> [{"id"=>"12345", "server_id"=>"10005", "status"=>"1", "modified"=>"2011-08-11 14:35:00"}]}
|
46
|
+
result.status.should eql(200)
|
47
|
+
end
|
48
|
+
it "should return correct sms status when succeeded" do
|
49
|
+
check_response_hash["check"].first["status"] = Smspilot::Api::NOT_FOUND_STATUS
|
50
|
+
stub_normal_request(check_response_hash.to_json)
|
51
|
+
|
52
|
+
result = @client.check_sms_status(sms_server_id)
|
53
|
+
result.not_found?.should be_true
|
54
|
+
end
|
55
|
+
it "should return correct sms status when succeeded" do
|
56
|
+
check_response_hash["check"].first["status"] = Smspilot::Api::NOT_DELIVERED_STATUS
|
57
|
+
stub_normal_request(check_response_hash.to_json)
|
58
|
+
|
59
|
+
result = @client.check_sms_status(sms_server_id)
|
60
|
+
result.not_delivered?.should be_true
|
61
|
+
end
|
62
|
+
it "should return correct sms status when succeeded" do
|
63
|
+
check_response_hash["check"].first["status"] = Smspilot::Api::ACCEPTED_STATUS
|
64
|
+
stub_normal_request(check_response_hash.to_json)
|
65
|
+
|
66
|
+
result = @client.check_sms_status(sms_server_id)
|
67
|
+
result.accepted?.should be_true
|
68
|
+
end
|
69
|
+
it "should return correct sms status when succeeded" do
|
70
|
+
check_response_hash["check"].first["status"] = Smspilot::Api::AT_OPERATOR_STATUS
|
71
|
+
stub_normal_request(check_response_hash.to_json)
|
72
|
+
|
73
|
+
result = @client.check_sms_status(sms_server_id)
|
74
|
+
result.at_operator?.should be_true
|
75
|
+
end
|
76
|
+
it "should return correct sms status when succeeded" do
|
77
|
+
check_response_hash["check"].first["status"] = Smspilot::Api::DELIVERED_STATUS
|
78
|
+
stub_normal_request(check_response_hash.to_json)
|
79
|
+
|
80
|
+
result = @client.check_sms_status(sms_server_id)
|
81
|
+
result.delivered?.should be_true
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#check_balance" do
|
87
|
+
|
88
|
+
let(:json_balance_response) {'{"balance":31337}'}
|
89
|
+
|
90
|
+
it "should return correct hash when succeeded" do
|
91
|
+
stub_normal_request(json_balance_response)
|
92
|
+
|
93
|
+
result = @client.check_balance
|
94
|
+
result.body.should == {"balance"=> 31337}
|
95
|
+
result.status.should eql(200)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "send_request errors" do
|
101
|
+
|
102
|
+
before do
|
103
|
+
stub_normal_request(json_failure_response)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should be unknown apierror when there is correct error response" do
|
107
|
+
result = @client.send_request({})
|
108
|
+
result.error.should eql(Smspilot::Error::UnknownApiError)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should be correct apierror type when there is correct error response" do
|
112
|
+
Smspilot::Error::API_ERROR_CODES["1337"] = "LeetError"
|
113
|
+
class Smspilot::Error::LeetError < Smspilot::Error::ApiError; end
|
114
|
+
|
115
|
+
result = @client.send_request({})
|
116
|
+
result.error.should eql(Smspilot::Error::LeetError)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'smspilot'
|
4
|
+
require 'smspilot/errors'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.color_enabled = true
|
9
|
+
config.formatter = 'documentation'
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub_normal_request(body)
|
13
|
+
stub_request(:post, Smspilot::Configuration::DEFAULT_ENDPOINT).to_return(:body => body, :status => 200, :headers => {:content_type => 'application/json'} )
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smspilot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rake
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.8.8
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.8
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: hashie
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.5'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.5'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: webmock
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: ''
|
111
|
+
email:
|
112
|
+
- blazesolo@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/smspilot.rb
|
123
|
+
- lib/smspilot/api.rb
|
124
|
+
- lib/smspilot/client.rb
|
125
|
+
- lib/smspilot/configuration.rb
|
126
|
+
- lib/smspilot/connection.rb
|
127
|
+
- lib/smspilot/errors.rb
|
128
|
+
- lib/smspilot/request.rb
|
129
|
+
- lib/smspilot/version.rb
|
130
|
+
- log/.gitignore
|
131
|
+
- smspilot.gemspec
|
132
|
+
- spec/lib/smspilot_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: ''
|
135
|
+
licenses: []
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 1.8.24
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: ''
|
158
|
+
test_files:
|
159
|
+
- spec/lib/smspilot_spec.rb
|
160
|
+
- spec/spec_helper.rb
|