little_sms 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/little_sms.rb +3 -5
- data/lib/little_sms/component.rb +7 -8
- data/lib/little_sms/enumerable.rb +12 -5
- data/lib/little_sms/responce.rb +3 -3
- data/little_sms.gemspec +5 -6
- data/test/helper.rb +37 -0
- data/test/test_component.rb +19 -24
- data/test/test_little_sms.rb +20 -23
- data/test/test_responce.rb +38 -43
- metadata +15 -16
- data/Gemfile.lock +0 -22
- data/test/auth.rb +0 -10
data/Gemfile
CHANGED
@@ -3,11 +3,11 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
gem "json_pure"
|
6
|
+
gem "rbx-require-relative", :platform => [:ruby_18]
|
6
7
|
|
7
8
|
# Add dependencies to develop your gem here.
|
8
9
|
# Include everything needed to run rake, tests, features, etc.
|
9
10
|
group :development do
|
10
|
-
gem "shoulda"
|
11
11
|
gem "bundler"
|
12
12
|
gem "jeweler"
|
13
13
|
gem "rcov"
|
data/README.md
CHANGED
data/lib/little_sms.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
-
|
4
|
-
require "#{libdir}/little_sms/component"
|
5
|
-
require "#{libdir}/little_sms/little_sms"
|
1
|
+
require "require_relative" unless Kernel.respond_to?(:require_relative)
|
6
2
|
|
3
|
+
require_relative "./little_sms/component"
|
4
|
+
require_relative "./little_sms/little_sms"
|
7
5
|
|
8
6
|
class LittleSMS; end
|
9
7
|
|
data/lib/little_sms/component.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require "json"
|
2
2
|
require "net/http"
|
3
3
|
require "net/https"
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "digest/md5"
|
5
|
+
require "digest/sha1"
|
6
6
|
require_relative "responce"
|
7
7
|
|
8
8
|
class LittleSMS
|
@@ -23,9 +23,7 @@ class LittleSMS
|
|
23
23
|
|
24
24
|
private
|
25
25
|
def request_api_method(method, options = {})
|
26
|
-
options
|
27
|
-
options = Hash[options.sort]
|
28
|
-
options[:sign] = sign_request(options)
|
26
|
+
options[:sign] = sign_request(options || {})
|
29
27
|
options[:user] = @api_user
|
30
28
|
|
31
29
|
uri = @api_uri.merge("#{@component}/#{method}")
|
@@ -33,9 +31,9 @@ class LittleSMS
|
|
33
31
|
req.set_form_data(options.delete_if {|k, v| k == :key})
|
34
32
|
|
35
33
|
uri.scheme, uri.port, use_ssl = if LittleSMS.use_ssl
|
36
|
-
[
|
34
|
+
["https", 443, true]
|
37
35
|
else
|
38
|
-
[
|
36
|
+
["http", 80, false]
|
39
37
|
end
|
40
38
|
res = Net::HTTP.new(uri.host, uri.port)
|
41
39
|
res.use_ssl = use_ssl
|
@@ -49,7 +47,8 @@ class LittleSMS
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def sign_request(options)
|
52
|
-
|
50
|
+
sorted_options = options.map{|k, v| [k.to_s, v]}.sort.inject(""){|str, value| str += value[1].to_s}
|
51
|
+
Digest::MD5.hexdigest(Digest::SHA1.hexdigest("#{@api_user}#{sorted_options}#{@api_key}"))
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
@@ -1,11 +1,18 @@
|
|
1
1
|
# Convert all keys to symbols
|
2
2
|
module Enumerable
|
3
|
-
def
|
4
|
-
symbolize = lambda { |v| v.respond_to?(:map) ? v.
|
5
|
-
|
6
|
-
|
3
|
+
def symbolize_keys
|
4
|
+
symbolize = lambda { |v| v.respond_to?(:map) ? v.symbolize_keys : v }
|
5
|
+
case self
|
6
|
+
when Hash
|
7
|
+
Hash[ self.map { |key, value|
|
8
|
+
k = key.kind_of?(String) ? key.to_sym : key
|
9
|
+
v = symbolize.call(value)
|
10
|
+
[k, v]
|
11
|
+
}]
|
12
|
+
when Array
|
13
|
+
self.map { |value| symbolize.call(value) }
|
7
14
|
else
|
8
|
-
self
|
15
|
+
self
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
data/lib/little_sms/responce.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative "enumerable"
|
|
3
3
|
class LittleSMS
|
4
4
|
class Responce
|
5
5
|
def initialize(json)
|
6
|
-
@json = json.
|
6
|
+
@json = json.symbolize_keys
|
7
7
|
end
|
8
8
|
|
9
9
|
def success?
|
@@ -15,11 +15,11 @@ class LittleSMS
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def error
|
18
|
-
|
18
|
+
@json[:error] if error?
|
19
19
|
end
|
20
20
|
|
21
21
|
def message
|
22
|
-
|
22
|
+
@json[:message] if error?
|
23
23
|
end
|
24
24
|
|
25
25
|
def method_missing(name, *args)
|
data/little_sms.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{little_sms}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Artyom Bolshakov"]
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
21
|
"LICENSE.txt",
|
23
22
|
"README.md",
|
24
23
|
"Rakefile",
|
@@ -29,7 +28,7 @@ Gem::Specification.new do |s|
|
|
29
28
|
"lib/little_sms/little_sms.rb",
|
30
29
|
"lib/little_sms/responce.rb",
|
31
30
|
"little_sms.gemspec",
|
32
|
-
"test/
|
31
|
+
"test/helper.rb",
|
33
32
|
"test/test_component.rb",
|
34
33
|
"test/test_little_sms.rb",
|
35
34
|
"test/test_responce.rb"
|
@@ -45,20 +44,20 @@ Gem::Specification.new do |s|
|
|
45
44
|
|
46
45
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
46
|
s.add_runtime_dependency(%q<json_pure>, [">= 0"])
|
48
|
-
s.
|
47
|
+
s.add_runtime_dependency(%q<rbx-require-relative>, [">= 0"])
|
49
48
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
50
49
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
51
50
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
52
51
|
else
|
53
52
|
s.add_dependency(%q<json_pure>, [">= 0"])
|
54
|
-
s.add_dependency(%q<
|
53
|
+
s.add_dependency(%q<rbx-require-relative>, [">= 0"])
|
55
54
|
s.add_dependency(%q<bundler>, [">= 0"])
|
56
55
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
57
56
|
s.add_dependency(%q<rcov>, [">= 0"])
|
58
57
|
end
|
59
58
|
else
|
60
59
|
s.add_dependency(%q<json_pure>, [">= 0"])
|
61
|
-
s.add_dependency(%q<
|
60
|
+
s.add_dependency(%q<rbx-require-relative>, [">= 0"])
|
62
61
|
s.add_dependency(%q<bundler>, [">= 0"])
|
63
62
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
64
63
|
s.add_dependency(%q<rcov>, [">= 0"])
|
data/test/helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "require_relative" unless Kernel.respond_to?(:require_relative)
|
2
|
+
require "test/unit"
|
3
|
+
require_relative "../lib/little_sms"
|
4
|
+
|
5
|
+
module Auth
|
6
|
+
def self.included(other)
|
7
|
+
other.class_eval do
|
8
|
+
def auth
|
9
|
+
[:"acc-4fe53b2b", :"OZkgGZ7g"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# https://github.com/sandal/rbp/blob/master/testing/test_unit_extensions.rb
|
16
|
+
module Test::Unit
|
17
|
+
# Used to fix a minor minitest/unit incompatibility in flexmock
|
18
|
+
AssertionFailedError = Class.new(StandardError)
|
19
|
+
|
20
|
+
class TestCase
|
21
|
+
|
22
|
+
def self.must(name, &block)
|
23
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
24
|
+
defined = instance_method(test_name) rescue false
|
25
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
26
|
+
if block_given?
|
27
|
+
define_method(test_name, &block)
|
28
|
+
else
|
29
|
+
define_method(test_name) do
|
30
|
+
flunk "No implementation provided for #{name}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/test/test_component.rb
CHANGED
@@ -1,33 +1,28 @@
|
|
1
|
-
require
|
2
|
-
require 'shoulda'
|
3
|
-
require_relative '../lib/little_sms'
|
4
|
-
require_relative "auth"
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
5
2
|
|
6
3
|
class ComponentTest < Test::Unit::TestCase
|
7
4
|
include Auth
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@options = {:message=>"test", :recipients=>"+79213752462", :user=>@api_user, :key=>@api_key}
|
12
|
-
@component = LittleSMS::Component.new(:message, "Christ", "Jesus")
|
13
|
-
end
|
5
|
+
def setup
|
6
|
+
@api_user, @api_key = self.auth
|
7
|
+
end
|
14
8
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
must "sign request" do
|
10
|
+
options = {:message=>"test", :recipients=>"+79213752462"}
|
11
|
+
component = LittleSMS::Component.new(:message, @api_user, @api_key)
|
12
|
+
sign = component.method(:sign_request).call(options)
|
13
|
+
assert_equal "da7a3ceb9f29874825b7451d40117adb", sign
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
must "format output" do
|
17
|
+
out = {"recipients"=>["911", "112"], "messages_id"=>[], "count"=>1, "parts"=>1, "price"=>0.5, "balance"=>9, "test"=>1, "status"=>"success"}
|
18
|
+
formatted = {:recipients=>["911", "112"], :messages_id=>[], :count=>1, :parts=>1, :price=>0.5, :balance=>9, :test=>1, :status=>"success"}
|
19
|
+
assert_equal formatted, out.symbolize_keys
|
20
|
+
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
22
|
+
must "return LittleSMS::Responce object" do
|
23
|
+
api = LittleSMS.new(@api_user, @api_key)
|
24
|
+
resp = api.message.send(:recipients => "+79213752462", :message => "Test", :test => "1")
|
25
|
+
assert_equal(resp.class, LittleSMS::Responce)
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
data/test/test_little_sms.rb
CHANGED
@@ -1,33 +1,30 @@
|
|
1
|
-
require
|
2
|
-
require 'shoulda'
|
3
|
-
require_relative '../lib/little_sms'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
4
2
|
|
5
3
|
class LittleSMSTest < Test::Unit::TestCase
|
6
4
|
include Auth
|
7
|
-
context "A LittleSMS" do
|
8
|
-
def setup
|
9
|
-
@api_user, @api_key = self.auth
|
10
|
-
@sms = LittleSMS.new @api_user, @api_key
|
11
|
-
end
|
12
5
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
def setup
|
7
|
+
@api_user, @api_key = self.auth
|
8
|
+
@sms = LittleSMS.new @api_user, @api_key
|
9
|
+
end
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
assert_equal(LittleSMS::Component, mes.class)
|
24
|
-
end
|
11
|
+
must "create Component for unknown method" do
|
12
|
+
@sms.foo
|
13
|
+
assert_equal(@sms.instance_eval { @components[:foo].class }, LittleSMS::Component)
|
14
|
+
end
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
must "accept block" do
|
17
|
+
mes = nil
|
18
|
+
LittleSMS.new @api_user, @api_key do
|
19
|
+
mes = message
|
30
20
|
end
|
21
|
+
assert_equal(LittleSMS::Component, mes.class)
|
22
|
+
end
|
23
|
+
|
24
|
+
must "send message" do
|
25
|
+
api = LittleSMS.new(@api_user, @api_key)
|
26
|
+
resp = api.message.send(:recipients => "+79213752462", :message => "Test", :test => "1")
|
27
|
+
assert_equal(resp.success?, true)
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
data/test/test_responce.rb
CHANGED
@@ -1,55 +1,50 @@
|
|
1
|
-
require "
|
2
|
-
require "shoulda"
|
3
|
-
require_relative "../lib/little_sms/responce"
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/helper")
|
4
2
|
|
5
3
|
class ResponceTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
should "create new responce object" do
|
13
|
-
assert_equal(@resp.instance_eval { @json }, @simple_json)
|
14
|
-
end
|
4
|
+
def setup
|
5
|
+
@simple_json = {:foo => "bar"}
|
6
|
+
@resp = LittleSMS::Responce.new(@simple_json)
|
7
|
+
end
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
assert_equal(resp.error?, false)
|
20
|
-
end
|
9
|
+
must "create new responce object" do
|
10
|
+
assert_equal(@resp.instance_eval { @json }, @simple_json)
|
11
|
+
end
|
21
12
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
must "success?" do
|
14
|
+
resp = LittleSMS::Responce.new({:status => "success"})
|
15
|
+
assert_equal(resp.success?, true)
|
16
|
+
assert_equal(resp.error?, false)
|
17
|
+
end
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
19
|
+
must "error?" do
|
20
|
+
resp = LittleSMS::Responce.new({:status => "error"})
|
21
|
+
assert_equal(resp.error?, true)
|
22
|
+
assert_equal(resp.success?, false)
|
23
|
+
end
|
34
24
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
must "return error code and message" do
|
26
|
+
responce_json = {:status => "error", :error => 2, :message => "invalid signature"}
|
27
|
+
resp = LittleSMS::Responce.new(responce_json)
|
28
|
+
assert_equal(resp.error, responce_json[:error])
|
29
|
+
assert_equal(resp.message, responce_json[:message])
|
30
|
+
end
|
31
|
+
|
32
|
+
must "map responce fields to methods" do
|
33
|
+
responce_json = {:recipients=>["79213752462"], :price=>0.5, :balance=>0, :test=>1}
|
34
|
+
resp = LittleSMS::Responce.new(responce_json)
|
35
|
+
assert_equal(resp.price, 0.5)
|
36
|
+
assert_equal(resp.balance, 0)
|
37
|
+
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
must "respond to mapped method" do
|
40
|
+
assert_respond_to(@resp, :foo)
|
41
|
+
end
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
43
|
+
must "raise error if unknown methods invoked" do
|
44
|
+
resp = LittleSMS::Responce.new({:foo => "foo"})
|
45
|
+
assert_raise NoMethodError do
|
46
|
+
resp.bar
|
51
47
|
end
|
52
|
-
|
53
48
|
end
|
54
49
|
end
|
55
50
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: little_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_pure
|
17
|
-
requirement: &
|
17
|
+
requirement: &12770400 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,21 +22,21 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *12770400
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: rbx-require-relative
|
28
|
+
requirement: &12768680 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
-
type: :
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *12768680
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &12767580 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *12767580
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: jeweler
|
50
|
-
requirement: &
|
50
|
+
requirement: &12765980 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *12765980
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rcov
|
61
|
-
requirement: &
|
61
|
+
requirement: &12764660 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *12764660
|
70
70
|
description: LittleSMS.ru API binding
|
71
71
|
email: tweekane@gmail.com
|
72
72
|
executables: []
|
@@ -76,7 +76,6 @@ extra_rdoc_files:
|
|
76
76
|
- README.md
|
77
77
|
files:
|
78
78
|
- Gemfile
|
79
|
-
- Gemfile.lock
|
80
79
|
- LICENSE.txt
|
81
80
|
- README.md
|
82
81
|
- Rakefile
|
@@ -87,7 +86,7 @@ files:
|
|
87
86
|
- lib/little_sms/little_sms.rb
|
88
87
|
- lib/little_sms/responce.rb
|
89
88
|
- little_sms.gemspec
|
90
|
-
- test/
|
89
|
+
- test/helper.rb
|
91
90
|
- test/test_component.rb
|
92
91
|
- test/test_little_sms.rb
|
93
92
|
- test/test_responce.rb
|
@@ -107,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
106
|
version: '0'
|
108
107
|
segments:
|
109
108
|
- 0
|
110
|
-
hash:
|
109
|
+
hash: 2522468301336257385
|
111
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
111
|
none: false
|
113
112
|
requirements:
|
data/Gemfile.lock
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
git (1.2.5)
|
5
|
-
jeweler (1.5.2)
|
6
|
-
bundler (~> 1.0.0)
|
7
|
-
git (>= 1.2.5)
|
8
|
-
rake
|
9
|
-
json_pure (1.4.6)
|
10
|
-
rake (0.8.7)
|
11
|
-
rcov (0.9.9)
|
12
|
-
shoulda (2.11.3)
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
bundler
|
19
|
-
jeweler
|
20
|
-
json_pure
|
21
|
-
rcov
|
22
|
-
shoulda
|