mailru-api 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mailru-api.rb CHANGED
@@ -81,7 +81,7 @@ module MailRU
81
81
  end
82
82
 
83
83
  def audio
84
- DSL.new(self.clone, 'audio') do
84
+ DSL.new(self, 'audio') do
85
85
  api 'get'
86
86
  api 'link'
87
87
  api 'search'
@@ -89,13 +89,13 @@ module MailRU
89
89
  end
90
90
 
91
91
  def events
92
- DSL.new(self.clone, 'events') do
92
+ DSL.new(self, 'events') do
93
93
  api 'getNewCount'
94
94
  end
95
95
  end
96
96
 
97
97
  def friends
98
- DSL.new(self.clone, 'friends') do
98
+ DSL.new(self, 'friends') do
99
99
  api 'get'
100
100
  api 'getAppUsers'
101
101
  api 'getInvitationsCount'
@@ -127,13 +127,13 @@ module MailRU
127
127
 
128
128
  def mobile
129
129
  DSL.new(self, 'mobile') do
130
- api 'getCanvas'
130
+ api 'getCanvas', :get, Request::Secure::No
131
131
  end
132
132
  end
133
133
 
134
134
  def notifications
135
135
  DSL.new(self, 'notifications') do
136
- api 'send'
136
+ api 'send', :get, Request::Secure::Yes
137
137
  end
138
138
  end
139
139
 
@@ -11,11 +11,11 @@ module MailRU
11
11
  end
12
12
  end
13
13
 
14
- def api name, method = :get
14
+ def api name, method = :get, secure = Request::Secure::Any
15
15
  self.class.send(:define_method, underscore(name)) do |params = {}|
16
- return GetRequest.new(@api, "#{@group}.#{name}", params).get if method == :get
17
- return PostRequest.new(@api, "#{@group}.#{name}", params).post if method == :post
18
- raise Error.create(0, 'Internal Error: HTTP method must be GET or POST!')
16
+ return GetRequest.new(@api, "#{@group}.#{name}", params, secure).get if method == :get
17
+ return PostRequest.new(@api, "#{@group}.#{name}", params, secure).post if method == :post
18
+ raise Error.create(0, 'HTTP method must be GET or POST!')
19
19
  end
20
20
  end
21
21
 
@@ -25,7 +25,7 @@ module MailRU
25
25
  when 200 then PermissionDeniedError.new(code, description)
26
26
  when 202 then AccessToObjectDeniedError.new(code, description)
27
27
  when 501 then IncorrectImageError.new(code, description)
28
- else Error.new(code, description)
28
+ else Error.new(code, "Internal Error: #{description}")
29
29
  end
30
30
  end
31
31
  end
@@ -30,13 +30,34 @@ module MailRU
30
30
  end
31
31
 
32
32
  def use_c2s?
33
- @api.private_key and (@secure == Secure::No or @secure == Secure::Any)
33
+ @api.private_key and (@secure == Secure::No or @secure == Secure::Any) and @api.uid
34
34
  end
35
35
 
36
36
  def signature
37
37
  return s2s_signature if use_s2s?
38
38
  return c2s_signature if use_c2s?
39
- ''
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.')
40
61
  end
41
62
 
42
63
  def c2s_signature
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.0
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,9 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-01 00:00:00.000000000 Z
12
+ date: 2013-09-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: MailRU API for Ruby
14
+ description: Ruby @Mail.RU API
15
15
  email: demin.alexey@inbox.ru
16
16
  executables: []
17
17
  extensions: []
@@ -21,7 +21,7 @@ files:
21
21
  - lib/mailru-api/error.rb
22
22
  - lib/mailru-api/request.rb
23
23
  - lib/mailru-api/dsl.rb
24
- homepage: ''
24
+ homepage: https://github.com/ademin/mailru-api
25
25
  licenses:
26
26
  - MIT
27
27
  post_install_message:
@@ -45,6 +45,6 @@ rubyforge_project:
45
45
  rubygems_version: 1.8.24
46
46
  signing_key:
47
47
  specification_version: 3
48
- summary: MailRU API for Ruby
48
+ summary: Ruby @Mail.RU API
49
49
  test_files: []
50
50
  has_rdoc: