mailru-api 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,8 +22,7 @@ module MailRU
22
22
  private
23
23
 
24
24
  def underscore s
25
- s.gsub(/::/, '/').
26
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
25
+ s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
27
26
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
28
27
  tr("-", "_").
29
28
  downcase
@@ -14,7 +14,7 @@ module MailRU
14
14
 
15
15
  def self.create(code, description)
16
16
  case code
17
- when 1 then UnknwonError.new(code, description)
17
+ when 1 then UnknownError.new(code, description)
18
18
  when 2 then UnknownMethodCalledError.new(code, description)
19
19
  when 3 then MethodIsDeprecatedError.new(code, description)
20
20
  when 100 then InvalidParameterError.new(code, description)
@@ -36,44 +36,25 @@ module MailRU
36
36
  def signature
37
37
  return s2s_signature if use_s2s?
38
38
  return c2s_signature if use_c2s?
39
-
40
- if @secure == Secure::Yes and @api.secret_key.nil?
41
- raise Error.create(0, 'secret_key must be specified for secure requests.')
42
- end
43
-
44
- if @secure == Secure::No and @api.private_key.nil?
45
- raise Error.create(0, 'private_key must be specified for non secure requests.')
46
- end
47
-
48
- if @secure == Secure::Any and @api.secret_key.nil? and @api.private_key.nil?
49
- raise Error.create(0, 'secret_key or private_key must be specified.')
50
- end
51
-
52
- if @secure == Secure::No and @api.uid.nil?
53
- raise Error.create(0, 'uid must be specified for non secure requests.')
54
- end
55
-
56
- if @secure == Secure::Any and @api.secret_key.nil? and @api.uid.nil?
57
- raise Error.create(0, 'uid must be specified for non secure requests.')
58
- end
59
-
60
- raise Error.create(0, 'unknown error.')
61
39
  end
62
40
 
63
- def c2s_signature
64
- Digest::MD5.hexdigest(@api.uid + parameters.sort.join + @api.private_key)
41
+ def s2s_signature
42
+ Digest::MD5.hexdigest(parameters.sort.join + (@api.secret_key || ''))
65
43
  end
66
44
 
67
- def s2s_signature
68
- Digest::MD5.hexdigest(parameters.sort.join + @api.secret_key)
45
+ def c2s_signature
46
+ Digest::MD5.hexdigest((@api.uid || '')+ parameters.sort.join + (@api.private_key || ''))
69
47
  end
70
48
 
71
49
  def parameters
72
- params = {app_id: @api.app_id, method: @method}
50
+ params = {}
51
+ params.merge!({app_id: @api.app_id}) if @api.app_id
52
+ params.merge!({method: @method}) if @method
73
53
  params.merge!({session_key: @api.session_key}) if @api.session_key
74
54
  params.merge!({format: @api.format}) if @api.format
75
- params.merge!(@method_params) if @method_params
55
+ params.merge!({uid: @api.uid}) if @api.uid
76
56
  params.merge!({secure: 1}) if use_s2s?
57
+ params.merge!(@method_params) if @method_params
77
58
 
78
59
  params.to_a.map{|p| p.join('=')}
79
60
  end
@@ -86,10 +67,7 @@ module MailRU
86
67
 
87
68
  error = response if response.name == 'error'
88
69
  if error
89
- raise Error.create(
90
- error.elements['error_code'].text,
91
- error.elements['error_msg'].text
92
- )
70
+ raise Error.create(Integer(error.elements['error_code'].text), error.elements['error_msg'].text)
93
71
  end
94
72
  else
95
73
  response = JSON.parse(response)
@@ -106,7 +84,7 @@ module MailRU
106
84
  end
107
85
 
108
86
  class GetRequest < Request
109
- def get
87
+ def get
110
88
  request = URI.escape(PATH + '?' + parameters.push("sig=#{signature}").join('&'))
111
89
  handle_response(Net::HTTP.get(URI(request)))
112
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailru-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-22 00:00:00.000000000 Z
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby @Mail.RU API
15
15
  email: demin.alexey@inbox.ru
@@ -33,7 +33,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - ! '>='
35
35
  - !ruby/object:Gem::Version
36
- version: '0'
36
+ version: 1.9.3
37
37
  required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements: