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 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
@@ -1,5 +1,5 @@
1
1
  # LittleSMS
2
- This gem provides access to LittleSMS.ru API from ruby.
2
+ This gem provides access to LittleSMS.ru API from ruby (mri 1.8.7 and 1.9.2 supported).
3
3
 
4
4
  # Installation
5
5
  $ gem install little_sms
@@ -1,9 +1,7 @@
1
- libdir = File.dirname(__FILE__)
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
 
@@ -1,8 +1,8 @@
1
1
  require "json"
2
2
  require "net/http"
3
3
  require "net/https"
4
- require 'digest/md5'
5
- require 'digest/sha1'
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
- ['https', 443, true]
34
+ ["https", 443, true]
37
35
  else
38
- ['http', 80, false]
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
- Digest::MD5.hexdigest(Digest::SHA1.hexdigest("#{@api_user}#{options.values.join}#{@api_key}"))
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 recursive_symbolize_keys
4
- symbolize = lambda { |v| v.respond_to?(:map) ? v.recursive_symbolize_keys : v }
5
- if self.kind_of? Hash
6
- Hash[ self.map { |k, v| [k.to_sym, symbolize.call(v)] } ]
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.map { |v| symbolize.call(v) }
15
+ self
9
16
  end
10
17
  end
11
18
  end
@@ -3,7 +3,7 @@ require_relative "enumerable"
3
3
  class LittleSMS
4
4
  class Responce
5
5
  def initialize(json)
6
- @json = json.recursive_symbolize_keys
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
- if error? then @json[:error] else nil end
18
+ @json[:error] if error?
19
19
  end
20
20
 
21
21
  def message
22
- if error? then @json[:message] else nil end
22
+ @json[:message] if error?
23
23
  end
24
24
 
25
25
  def method_missing(name, *args)
@@ -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.0"
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/auth.rb",
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.add_development_dependency(%q<shoulda>, [">= 0"])
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<shoulda>, [">= 0"])
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<shoulda>, [">= 0"])
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"])
@@ -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
+
@@ -1,33 +1,28 @@
1
- require 'test/unit'
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
- context "A LittleSMS::Component" do
9
- def setup
10
- @api_user, @api_key = self.auth
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
- should "should sign request" do
16
- sign = @component.method(:sign_request).call(@options)
17
- assert_equal "b616ddc6d0e15aaa92ce79ca78806337", sign
18
- end
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
- should "format output" do
21
- out = {"recipients"=>["911", "112"], "messages_id"=>[], "count"=>1, "parts"=>1, "price"=>0.5, "balance"=>9, "test"=>1, "status"=>"success"}
22
- formatted = {:recipients=>["911", "112"], :messages_id=>[], :count=>1, :parts=>1, :price=>0.5, :balance=>9, :test=>1, :status=>"success"}
23
- assert_equal formatted, out.recursive_symbolize_keys
24
- end
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
- should "return LittleSMS::Responce object" do
27
- api = LittleSMS.new(@api_user, @api_key)
28
- resp = api.message.send(:recipients => "+79213752462", :message => "Test", :test => "1")
29
- assert_equal(resp.class, LittleSMS::Responce)
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
 
@@ -1,33 +1,30 @@
1
- require 'test/unit'
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
- should "create Component for unknown method" do
14
- @sms.foo
15
- assert_equal(@sms.instance_eval { @components[:foo].class }, LittleSMS::Component)
16
- end
6
+ def setup
7
+ @api_user, @api_key = self.auth
8
+ @sms = LittleSMS.new @api_user, @api_key
9
+ end
17
10
 
18
- should "accept block" do
19
- mes = nil
20
- LittleSMS.new @api_user, @api_key do
21
- mes = message
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
- should "send message" do
27
- api = LittleSMS.new(@api_user, @api_key)
28
- resp = api.message.send(:recipients => "+79213752462", :message => "Test", :test => "1")
29
- assert_equal(resp.success?, true)
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
 
@@ -1,55 +1,50 @@
1
- require "test/unit"
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
- context "A Responce" do
7
- def setup
8
- @simple_json = {:foo => "bar"}
9
- @resp = LittleSMS::Responce.new(@simple_json)
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
- should "success?" do
17
- resp = LittleSMS::Responce.new({:status => "success"})
18
- assert_equal(resp.success?, true)
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
- should "error?" do
23
- resp = LittleSMS::Responce.new({:status => "error"})
24
- assert_equal(resp.error?, true)
25
- assert_equal(resp.success?, false)
26
- end
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
- should "return error code and message" do
29
- responce_json = {:status => "error", :error => 2, :message => "invalid signature"}
30
- resp = LittleSMS::Responce.new(responce_json)
31
- assert_equal(resp.error, responce_json[:error])
32
- assert_equal(resp.message, responce_json[:message])
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
- should "map responce fields to methods" do
36
- responce_json = {:recipients=>["79213752462"], :price=>0.5, :balance=>0, :test=>1}
37
- resp = LittleSMS::Responce.new(responce_json)
38
- assert_equal(resp.price, 0.5)
39
- assert_equal(resp.balance, 0)
40
- end
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
- should "respond to mapped method" do
43
- assert_respond_to(@resp, :foo)
44
- end
39
+ must "respond to mapped method" do
40
+ assert_respond_to(@resp, :foo)
41
+ end
45
42
 
46
- should "raise error if unknown methods invoked" do
47
- resp = LittleSMS::Responce.new({:foo => "foo"})
48
- assert_raise NoMethodError do
49
- resp.bar
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.0
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: &21494940 !ruby/object:Gem::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: *21494940
25
+ version_requirements: *12770400
26
26
  - !ruby/object:Gem::Dependency
27
- name: shoulda
28
- requirement: &21485800 !ruby/object:Gem::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: :development
34
+ type: :runtime
35
35
  prerelease: false
36
- version_requirements: *21485800
36
+ version_requirements: *12768680
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &21484880 !ruby/object:Gem::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: *21484880
47
+ version_requirements: *12767580
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: jeweler
50
- requirement: &21483820 !ruby/object:Gem::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: *21483820
58
+ version_requirements: *12765980
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rcov
61
- requirement: &21482980 !ruby/object:Gem::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: *21482980
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/auth.rb
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: 423631933341830267
109
+ hash: 2522468301336257385
111
110
  required_rubygems_version: !ruby/object:Gem::Requirement
112
111
  none: false
113
112
  requirements:
@@ -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
@@ -1,10 +0,0 @@
1
- module Auth
2
- def self.included(other)
3
- other.class_eval do
4
- def auth
5
- [:"acc-4fe53b2b", :"OZkgGZ7g"]
6
- end
7
- end
8
- end
9
- end
10
-