little_sms 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,9 +7,9 @@ gem "json_pure"
7
7
  # Add dependencies to develop your gem here.
8
8
  # Include everything needed to run rake, tests, features, etc.
9
9
  group :development do
10
- gem "shoulda", ">= 0"
11
- gem "bundler", "~> 1.0.0"
12
- gem "jeweler", "~> 1.5.2"
13
- gem "rcov", ">= 0"
10
+ gem "shoulda"
11
+ gem "bundler"
12
+ gem "jeweler"
13
+ gem "rcov"
14
14
  end
15
15
 
data/Gemfile.lock CHANGED
@@ -15,8 +15,8 @@ PLATFORMS
15
15
  ruby
16
16
 
17
17
  DEPENDENCIES
18
- bundler (~> 1.0.0)
19
- jeweler (~> 1.5.2)
18
+ bundler
19
+ jeweler
20
20
  json_pure
21
21
  rcov
22
22
  shoulda
data/README.md CHANGED
@@ -7,16 +7,26 @@ This gem provides access to LittleSMS.ru API from ruby.
7
7
  # Usage
8
8
  require "little_sms"
9
9
  api = LittleSMS.new(:apiuser, :apikey)
10
- api.message.send(:recipients => "112", :message => "Sos!")
10
+ api.message.send(:recipients => "+79211234567", :message => "Test", :test => 1)
11
11
 
12
12
  Also you can pass a block to LittleSMS object:
13
13
 
14
14
  LittleSMS.new(:apiuser, :apikey) do
15
- msg = message.send(:recipients => "112", :message => "Sos!")
16
- if msg[:status] == :success
17
- messages_id = msg[:messages_id].join
15
+ msg = message.send(:recipients => "+79211234567", :message => "Test")
16
+ if msg.success?
17
+ messages_id = msg.messages_id.join
18
18
  status = message.status(:messages_id => messages_id)
19
- puts "Message #{status[:messages][messages_id]}" if status[:status] == :success
19
+ puts "Message #{status.messages[messages_id]}" unless status.error? # => Message delivered
20
+ end
21
+ end
22
+
23
+ In case of error:
24
+
25
+ LittleSMS.new(:apiuser, :apikey) do
26
+ msg = message.send(:recipients => "112", :message => "Test")
27
+ if msg.error?
28
+ puts msg.error # => 4
29
+ puts msg.message # => "incorrect or empty recipients list"
20
30
  end
21
31
  end
22
32
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -3,6 +3,7 @@ require "net/http"
3
3
  require "net/https"
4
4
  require 'digest/md5'
5
5
  require 'digest/sha1'
6
+ require_relative "responce"
6
7
 
7
8
  class LittleSMS
8
9
  class Component
@@ -12,7 +13,7 @@ class LittleSMS
12
13
 
13
14
  def initialize(component, api_user, api_key)
14
15
  @api_uri = URI.parse("https://littlesms.ru:443/api/")
15
- @auth = {:user => api_user, :key => api_key}
16
+ @api_user, @api_key = api_user, api_key
16
17
  @component = component # Component name. E.g. message or user.
17
18
  end
18
19
 
@@ -23,13 +24,10 @@ class LittleSMS
23
24
  private
24
25
  def request_api_method(method, options = {})
25
26
  options ||= {}
26
- options.merge!(@auth)
27
-
28
- # Replace original sort method
29
- options.extend(self.class::Options)
30
- options.method_path = {:method => method, :component => @component }
31
-
27
+ options = Hash[options.sort]
32
28
  options[:sign] = sign_request(options)
29
+ options[:user] = @api_user
30
+
33
31
  uri = @api_uri.merge("#{@component}/#{method}")
34
32
  req = Net::HTTP::Post.new(uri.path)
35
33
  req.set_form_data(options.delete_if {|k, v| k == :key})
@@ -44,32 +42,14 @@ class LittleSMS
44
42
 
45
43
  case res = res.start {|http| http.request(req) }
46
44
  when Net::HTTPSuccess, Net::HTTPRedirection
47
- return format_output(JSON.parse(res.body))
45
+ return Responce.new(JSON.parse(res.body))
48
46
  else
49
47
  res.error!
50
48
  end
51
49
  end
52
50
 
53
51
  def sign_request(options)
54
- Digest::MD5.hexdigest(
55
- Digest::SHA1.hexdigest(options.sort.map {|e| e[1]}.join)
56
- )
57
- end
58
-
59
- # Convert all strings keys to symbols
60
- def format_output(hash)
61
- format = lambda do |v|
62
- if v.respond_to?(:map)
63
- format_output(v)
64
- else
65
- v
66
- end
67
- end
68
- if hash.kind_of? Hash
69
- Hash[ hash.map { |k, v| [k.to_sym, format.call(v)] } ]
70
- else
71
- hash.map { |v| format.call(v) }
72
- end
52
+ Digest::MD5.hexdigest(Digest::SHA1.hexdigest("#{@api_user}#{options.values.join}#{@api_key}"))
73
53
  end
74
54
  end
75
55
  end
@@ -0,0 +1,12 @@
1
+ # Convert all keys to symbols
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)] } ]
7
+ else
8
+ self.map { |v| symbolize.call(v) }
9
+ end
10
+ end
11
+ end
12
+
@@ -10,6 +10,7 @@ class LittleSMS
10
10
  @components = {}
11
11
  self.instance_eval &block if block_given?
12
12
  end
13
+
13
14
  def method_missing(name, *args)
14
15
  @components[name] ||= Component.new(name, @api_user, @api_key)
15
16
  end
@@ -0,0 +1,38 @@
1
+ require_relative "enumerable"
2
+
3
+ class LittleSMS
4
+ class Responce
5
+ def initialize(json)
6
+ @json = json.recursive_symbolize_keys
7
+ end
8
+
9
+ def success?
10
+ @json[:status] == "success"
11
+ end
12
+
13
+ def error?
14
+ @json[:status] == "error"
15
+ end
16
+
17
+ def error
18
+ if error? then @json[:error] else nil end
19
+ end
20
+
21
+ def message
22
+ if error? then @json[:message] else nil end
23
+ end
24
+
25
+ def method_missing(name, *args)
26
+ unless args.empty?
27
+ super
28
+ else
29
+ @json[name] || super
30
+ end
31
+ end
32
+
33
+ def respond_to?(method)
34
+ @json.has_key?(method) || super
35
+ end
36
+ end
37
+ end
38
+
data/lib/little_sms.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  libdir = File.dirname(__FILE__)
2
2
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
3
 
4
- require "#{libdir}/little_sms/options"
5
4
  require "#{libdir}/little_sms/component"
6
5
  require "#{libdir}/little_sms/little_sms"
7
6
 
data/little_sms.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{little_sms}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
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"]
12
- s.date = %q{2011-03-06}
12
+ s.date = %q{2011-07-06}
13
13
  s.description = %q{LittleSMS.ru API binding}
14
14
  s.email = %q{tweekane@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,51 +25,42 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/little_sms.rb",
27
27
  "lib/little_sms/component.rb",
28
+ "lib/little_sms/enumerable.rb",
28
29
  "lib/little_sms/little_sms.rb",
29
- "lib/little_sms/options.rb",
30
- "lib/little_sms/ordering/contact.yaml",
31
- "lib/little_sms/ordering/message.yaml",
32
- "lib/little_sms/ordering/tag.yaml",
33
- "lib/little_sms/ordering/task.yaml",
34
- "lib/little_sms/ordering/user.yaml",
30
+ "lib/little_sms/responce.rb",
35
31
  "little_sms.gemspec",
32
+ "test/auth.rb",
36
33
  "test/test_component.rb",
37
34
  "test/test_little_sms.rb",
38
- "test/test_options.rb"
35
+ "test/test_responce.rb"
39
36
  ]
40
37
  s.homepage = %q{http://github.com/TweeKane/little_sms}
41
38
  s.licenses = ["MIT"]
42
39
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.7}
40
+ s.rubygems_version = %q{1.6.2}
44
41
  s.summary = %q{LittleSMS.ru API binding}
45
- s.test_files = [
46
- "test/test_component.rb",
47
- "test/test_little_sms.rb",
48
- "test/test_options.rb"
49
- ]
50
42
 
51
43
  if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
44
  s.specification_version = 3
54
45
 
55
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
47
  s.add_runtime_dependency(%q<json_pure>, [">= 0"])
57
48
  s.add_development_dependency(%q<shoulda>, [">= 0"])
58
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
59
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
60
51
  s.add_development_dependency(%q<rcov>, [">= 0"])
61
52
  else
62
53
  s.add_dependency(%q<json_pure>, [">= 0"])
63
54
  s.add_dependency(%q<shoulda>, [">= 0"])
64
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_dependency(%q<bundler>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, [">= 0"])
66
57
  s.add_dependency(%q<rcov>, [">= 0"])
67
58
  end
68
59
  else
69
60
  s.add_dependency(%q<json_pure>, [">= 0"])
70
61
  s.add_dependency(%q<shoulda>, [">= 0"])
71
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
72
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
62
+ s.add_dependency(%q<bundler>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, [">= 0"])
73
64
  s.add_dependency(%q<rcov>, [">= 0"])
74
65
  end
75
66
  end
data/test/auth.rb ADDED
@@ -0,0 +1,10 @@
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
+
@@ -1,25 +1,32 @@
1
1
  require 'test/unit'
2
2
  require 'shoulda'
3
- require 'lib/little_sms'
3
+ require_relative '../lib/little_sms'
4
+ require_relative "auth"
4
5
 
5
6
  class ComponentTest < Test::Unit::TestCase
7
+ include Auth
6
8
  context "A LittleSMS::Component" do
7
9
  def setup
8
- @options = {:message=>"sos", :recipients=>"112", :user=>'free', :key=>'Jesus'}
9
- @options.extend(LittleSMS::Component::Options)
10
- @options.method_path = {:method => :send, :component => :message }
10
+ @api_user, @api_key = self.auth
11
+ @options = {:message=>"test", :recipients=>"+79213752462", :user=>@api_user, :key=>@api_key}
11
12
  @component = LittleSMS::Component.new(:message, "Christ", "Jesus")
12
13
  end
13
14
 
14
15
  should "should sign request" do
15
16
  sign = @component.method(:sign_request).call(@options)
16
- assert_equal "9ee9ac110901dae9ee9f97fde09f3268", sign
17
+ assert_equal "b616ddc6d0e15aaa92ce79ca78806337", sign
17
18
  end
18
19
 
19
20
  should "format output" do
20
21
  out = {"recipients"=>["911", "112"], "messages_id"=>[], "count"=>1, "parts"=>1, "price"=>0.5, "balance"=>9, "test"=>1, "status"=>"success"}
21
22
  formatted = {:recipients=>["911", "112"], :messages_id=>[], :count=>1, :parts=>1, :price=>0.5, :balance=>9, :test=>1, :status=>"success"}
22
- assert_equal formatted, @component.instance_eval("format_output(#{out})")
23
+ assert_equal formatted, out.recursive_symbolize_keys
24
+ end
25
+
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)
23
30
  end
24
31
  end
25
32
  end
@@ -1,12 +1,12 @@
1
1
  require 'test/unit'
2
2
  require 'shoulda'
3
- require 'lib/little_sms'
3
+ require_relative '../lib/little_sms'
4
4
 
5
5
  class LittleSMSTest < Test::Unit::TestCase
6
+ include Auth
6
7
  context "A LittleSMS" do
7
8
  def setup
8
- @api_user = :testapiuser
9
- @api_key = :testapikeystring
9
+ @api_user, @api_key = self.auth
10
10
  @sms = LittleSMS.new @api_user, @api_key
11
11
  end
12
12
 
@@ -22,6 +22,12 @@ class LittleSMSTest < Test::Unit::TestCase
22
22
  end
23
23
  assert_equal(LittleSMS::Component, mes.class)
24
24
  end
25
+
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)
30
+ end
25
31
  end
26
32
  end
27
33
 
@@ -0,0 +1,55 @@
1
+ require "test/unit"
2
+ require "shoulda"
3
+ require_relative "../lib/little_sms/responce"
4
+
5
+ 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
15
+
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
21
+
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
27
+
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
34
+
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
41
+
42
+ should "respond to mapped method" do
43
+ assert_respond_to(@resp, :foo)
44
+ end
45
+
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
51
+ end
52
+
53
+ end
54
+ end
55
+
metadata CHANGED
@@ -1,107 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: little_sms
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Artyom Bolshakov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-06 00:00:00 +03:00
12
+ date: 2011-07-06 00:00:00.000000000 +04:00
19
13
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: json_pure
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &21494940 !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
32
23
  type: :runtime
33
24
  prerelease: false
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *21494940
26
+ - !ruby/object:Gem::Dependency
36
27
  name: shoulda
37
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &21485800 !ruby/object:Gem::Requirement
38
29
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  type: :development
47
35
  prerelease: false
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *21485800
37
+ - !ruby/object:Gem::Dependency
50
38
  name: bundler
51
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &21484880 !ruby/object:Gem::Requirement
52
40
  none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 23
57
- segments:
58
- - 1
59
- - 0
60
- - 0
61
- version: 1.0.0
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
62
45
  type: :development
63
46
  prerelease: false
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *21484880
48
+ - !ruby/object:Gem::Dependency
66
49
  name: jeweler
67
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &21483820 !ruby/object:Gem::Requirement
68
51
  none: false
69
- requirements:
70
- - - ~>
71
- - !ruby/object:Gem::Version
72
- hash: 7
73
- segments:
74
- - 1
75
- - 5
76
- - 2
77
- version: 1.5.2
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
78
56
  type: :development
79
57
  prerelease: false
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *21483820
59
+ - !ruby/object:Gem::Dependency
82
60
  name: rcov
83
- requirement: &id005 !ruby/object:Gem::Requirement
61
+ requirement: &21482980 !ruby/object:Gem::Requirement
84
62
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
92
67
  type: :development
93
68
  prerelease: false
94
- version_requirements: *id005
69
+ version_requirements: *21482980
95
70
  description: LittleSMS.ru API binding
96
71
  email: tweekane@gmail.com
97
72
  executables: []
98
-
99
73
  extensions: []
100
-
101
- extra_rdoc_files:
74
+ extra_rdoc_files:
102
75
  - LICENSE.txt
103
76
  - README.md
104
- files:
77
+ files:
105
78
  - Gemfile
106
79
  - Gemfile.lock
107
80
  - LICENSE.txt
@@ -110,52 +83,41 @@ files:
110
83
  - VERSION
111
84
  - lib/little_sms.rb
112
85
  - lib/little_sms/component.rb
86
+ - lib/little_sms/enumerable.rb
113
87
  - lib/little_sms/little_sms.rb
114
- - lib/little_sms/options.rb
115
- - lib/little_sms/ordering/contact.yaml
116
- - lib/little_sms/ordering/message.yaml
117
- - lib/little_sms/ordering/tag.yaml
118
- - lib/little_sms/ordering/task.yaml
119
- - lib/little_sms/ordering/user.yaml
88
+ - lib/little_sms/responce.rb
120
89
  - little_sms.gemspec
90
+ - test/auth.rb
121
91
  - test/test_component.rb
122
92
  - test/test_little_sms.rb
123
- - test/test_options.rb
93
+ - test/test_responce.rb
124
94
  has_rdoc: true
125
95
  homepage: http://github.com/TweeKane/little_sms
126
- licenses:
96
+ licenses:
127
97
  - MIT
128
98
  post_install_message:
129
99
  rdoc_options: []
130
-
131
- require_paths:
100
+ require_paths:
132
101
  - lib
133
- required_ruby_version: !ruby/object:Gem::Requirement
102
+ required_ruby_version: !ruby/object:Gem::Requirement
134
103
  none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- hash: 3
139
- segments:
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
140
109
  - 0
141
- version: "0"
142
- required_rubygems_version: !ruby/object:Gem::Requirement
110
+ hash: 423631933341830267
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
112
  none: false
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- hash: 3
148
- segments:
149
- - 0
150
- version: "0"
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
151
117
  requirements: []
152
-
153
118
  rubyforge_project:
154
- rubygems_version: 1.3.7
119
+ rubygems_version: 1.6.2
155
120
  signing_key:
156
121
  specification_version: 3
157
122
  summary: LittleSMS.ru API binding
158
- test_files:
159
- - test/test_component.rb
160
- - test/test_little_sms.rb
161
- - test/test_options.rb
123
+ test_files: []
@@ -1,32 +0,0 @@
1
- require "yaml"
2
-
3
- class LittleSMS
4
- class Component
5
- # This module should be mixed with request options hash.
6
- # to overwite Hash#sort method
7
- module Options
8
- class NoMethodError < StandardError; end
9
- class NoComponentError < StandardError; end
10
- attr_accessor :method_path
11
- def sort
12
- order = load_order(@method_path[:component], @method_path[:method])
13
- self.to_a.sort do |a,b|
14
- order.find_index(a[0]) <=> order.find_index(b[0])
15
- end
16
- end
17
-
18
- private
19
- # load sorting order from yaml file
20
- def load_order(component, method)
21
- begin
22
- order = YAML.load_file("#{File.dirname(__FILE__)}/ordering/#{component}.yaml")[method]
23
- raise NoMethodError, "There is no such method in #{component} file: #{method}" if order.nil?
24
- order
25
- rescue Errno::ENOENT
26
- raise NoComponentError, "There is no such file: #{component}"
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
@@ -1,20 +0,0 @@
1
- ---
2
- :list:
3
- - :user
4
- - :key
5
- :create:
6
- - :user
7
- - :phone
8
- - :name
9
- - :description
10
- - :tags
11
- - :key
12
- :update:
13
- - :user
14
- - :id
15
- - :key
16
- :delete:
17
- - :user
18
- - :id
19
- - :key
20
-
@@ -1,32 +0,0 @@
1
- ---
2
- :send:
3
- - :user
4
- - :recipients
5
- - :message
6
- - :sender
7
- - :test
8
- - :sign
9
- - :key
10
- :status:
11
- - :user
12
- - :sign
13
- - :messages_id
14
- - :key
15
- :price:
16
- - :user
17
- - :sign
18
- - :recipients
19
- - :message
20
- - :key
21
- :history:
22
- - :user
23
- - :sign
24
- - :history_id
25
- - :recipient
26
- - :sender
27
- - :status
28
- - :date_from
29
- - :date_to
30
- - :id
31
- - :key
32
-
@@ -1,9 +0,0 @@
1
- ---
2
- :list:
3
- - :user
4
- - :key
5
- :delete:
6
- - :user
7
- - :id
8
- - :key
9
-
@@ -1,6 +0,0 @@
1
- ---
2
- :delete:
3
- - :user
4
- - :id
5
- - :key
6
-
@@ -1,6 +0,0 @@
1
- ---
2
- :balance:
3
- - :user
4
- - :sign
5
- - :key
6
-
data/test/test_options.rb DELETED
@@ -1,37 +0,0 @@
1
- require 'test/unit'
2
- require 'shoulda'
3
- require 'lib/little_sms'
4
-
5
- class OptionsTest < Test::Unit::TestCase
6
- context "A Options" do
7
- def setup
8
- @order = [:user, :recipients, :message, :sender, :test, :sign, :key]
9
- @options = {:message=>"sos", :recipients=>"112"}
10
- @options.extend(LittleSMS::Component::Options)
11
- @options.method_path = {:method => :send, :component => :message }
12
- end
13
-
14
- should "load order from file" do
15
- assert_equal(@order, @options.instance_eval("load_order(:message, :send)"))
16
- end
17
-
18
- should "sort with loaded order" do
19
- assert_equal @options.sort, [[:recipients, "112"], [:message, "sos"]]
20
- end
21
-
22
- should "fail if unknown method called" do
23
- @options.method_path = {:method => :unknown, :component => :message }
24
- assert_raise LittleSMS::Component::Options::NoMethodError do
25
- @options.sort
26
- end
27
- end
28
-
29
- should "fail if unknown component accessed" do
30
- @options.method_path = {:method => :unknown, :component => :unknown }
31
- assert_raise LittleSMS::Component::Options::NoComponentError do
32
- @options.sort
33
- end
34
- end
35
- end
36
- end
37
-