mailru-api 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mailru-api.rb +55 -21
- data/lib/mailru-api/dsl.rb +33 -0
- data/lib/mailru-api/error.rb +2 -0
- data/lib/mailru-api/request.rb +2 -2
- metadata +2 -12
- data/lib/mailru-api/audio.rb +0 -23
- data/lib/mailru-api/events.rb +0 -15
- data/lib/mailru-api/friends.rb +0 -31
- data/lib/mailru-api/guestbook.rb +0 -19
- data/lib/mailru-api/mail.rb +0 -15
- data/lib/mailru-api/messages.rb +0 -23
- data/lib/mailru-api/mobile.rb +0 -18
- data/lib/mailru-api/notifications.rb +0 -15
- data/lib/mailru-api/photos.rb +0 -27
- data/lib/mailru-api/stream.rb +0 -39
- data/lib/mailru-api/users.rb +0 -27
data/lib/mailru-api.rb
CHANGED
@@ -2,16 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'mailru-api/error'
|
4
4
|
require 'mailru-api/request'
|
5
|
-
require 'mailru-api/
|
6
|
-
require 'mailru-api/events'
|
7
|
-
require 'mailru-api/friends'
|
8
|
-
require 'mailru-api/guestbook'
|
9
|
-
require 'mailru-api/mail'
|
10
|
-
require 'mailru-api/mobile'
|
11
|
-
require 'mailru-api/notifications'
|
12
|
-
require 'mailru-api/photos'
|
13
|
-
require 'mailru-api/stream'
|
14
|
-
require 'mailru-api/users'
|
5
|
+
require 'mailru-api/dsl'
|
15
6
|
|
16
7
|
module MailRU
|
17
8
|
class APIConfiguration
|
@@ -90,47 +81,90 @@ module MailRU
|
|
90
81
|
end
|
91
82
|
|
92
83
|
def audio
|
93
|
-
|
84
|
+
DSL.new(self.clone, 'audio') do
|
85
|
+
api 'get'
|
86
|
+
api 'link'
|
87
|
+
api 'search'
|
88
|
+
end
|
94
89
|
end
|
95
90
|
|
96
91
|
def events
|
97
|
-
|
92
|
+
DSL.new(self.clone, 'events') do
|
93
|
+
api 'getNewCount'
|
94
|
+
end
|
98
95
|
end
|
99
96
|
|
100
97
|
def friends
|
101
|
-
|
98
|
+
DSL.new(self.clone, 'friends') do
|
99
|
+
api 'get'
|
100
|
+
api 'getAppUsers'
|
101
|
+
api 'getInvitationsCount'
|
102
|
+
api 'getOnline'
|
103
|
+
end
|
102
104
|
end
|
103
105
|
|
104
106
|
def guestbook
|
105
|
-
|
107
|
+
DSL.new(self, 'guestbook') do
|
108
|
+
api 'get'
|
109
|
+
api 'post', :post
|
110
|
+
end
|
106
111
|
end
|
107
112
|
|
108
113
|
def mail
|
109
|
-
|
114
|
+
DSL.new(self, 'mail') do
|
115
|
+
api 'getUnreadCount'
|
116
|
+
end
|
110
117
|
end
|
111
118
|
|
112
119
|
def messages
|
113
|
-
|
120
|
+
DSL.new(self, 'messages') do
|
121
|
+
api 'getThread'
|
122
|
+
api 'getThreadsList'
|
123
|
+
api 'getUnreadCount'
|
124
|
+
api 'post', :post
|
125
|
+
end
|
114
126
|
end
|
115
127
|
|
116
128
|
def mobile
|
117
|
-
|
129
|
+
DSL.new(self, 'mobile') do
|
130
|
+
api 'getCanvas'
|
131
|
+
end
|
118
132
|
end
|
119
133
|
|
120
134
|
def notifications
|
121
|
-
|
135
|
+
DSL.new(self, 'notifications') do
|
136
|
+
api 'send'
|
137
|
+
end
|
122
138
|
end
|
123
139
|
|
124
140
|
def photos
|
125
|
-
|
141
|
+
DSL.new(self, 'photos') do
|
142
|
+
api 'createAlbum'
|
143
|
+
api 'get'
|
144
|
+
api 'getAlbums'
|
145
|
+
api 'upload', :post
|
146
|
+
end
|
126
147
|
end
|
127
148
|
|
128
149
|
def stream
|
129
|
-
|
150
|
+
DSL.new(self, 'stream') do
|
151
|
+
api 'comment'
|
152
|
+
api 'get'
|
153
|
+
api 'getByAuthor'
|
154
|
+
api 'like'
|
155
|
+
api 'post', :post
|
156
|
+
api 'share', :post
|
157
|
+
api 'unlike'
|
158
|
+
end
|
130
159
|
end
|
131
160
|
|
132
161
|
def users
|
133
|
-
|
162
|
+
DSL.new(self, 'users') do
|
163
|
+
api 'getBalance'
|
164
|
+
api 'getInfo'
|
165
|
+
api 'hasAppPermission'
|
166
|
+
api 'isAppUser'
|
167
|
+
end
|
134
168
|
end
|
135
169
|
end
|
136
170
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#:encoding: utf-8
|
2
|
+
|
3
|
+
module MailRU
|
4
|
+
class API
|
5
|
+
class DSL
|
6
|
+
def initialize api, group, &block
|
7
|
+
@api = api
|
8
|
+
@group = group
|
9
|
+
if block_given?
|
10
|
+
instance_eval(&block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def api name, method = :get
|
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!')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def underscore s
|
25
|
+
s.gsub(/::/, '/').
|
26
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
27
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
28
|
+
tr("-", "_").
|
29
|
+
downcase
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/mailru-api/error.rb
CHANGED
data/lib/mailru-api/request.rb
CHANGED
@@ -65,7 +65,7 @@ module MailRU
|
|
65
65
|
|
66
66
|
error = response if response.name == 'error'
|
67
67
|
if error
|
68
|
-
raise
|
68
|
+
raise Error.create(
|
69
69
|
error.elements['error_code'].text,
|
70
70
|
error.elements['error_msg'].text
|
71
71
|
)
|
@@ -75,7 +75,7 @@ module MailRU
|
|
75
75
|
if response.is_a?(Hash)
|
76
76
|
error = response['error']
|
77
77
|
if error
|
78
|
-
raise
|
78
|
+
raise Error.create(error['error_code'], error['error_msg'])
|
79
79
|
end
|
80
80
|
end
|
81
81
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,19 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/mailru-api.rb
|
21
|
-
- lib/mailru-api/audio.rb
|
22
21
|
- lib/mailru-api/error.rb
|
23
|
-
- lib/mailru-api/events.rb
|
24
|
-
- lib/mailru-api/friends.rb
|
25
|
-
- lib/mailru-api/guestbook.rb
|
26
|
-
- lib/mailru-api/mail.rb
|
27
|
-
- lib/mailru-api/messages.rb
|
28
|
-
- lib/mailru-api/mobile.rb
|
29
|
-
- lib/mailru-api/notifications.rb
|
30
|
-
- lib/mailru-api/photos.rb
|
31
22
|
- lib/mailru-api/request.rb
|
32
|
-
- lib/mailru-api/
|
33
|
-
- lib/mailru-api/users.rb
|
23
|
+
- lib/mailru-api/dsl.rb
|
34
24
|
homepage: ''
|
35
25
|
licenses:
|
36
26
|
- MIT
|
data/lib/mailru-api/audio.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Audio
|
6
|
-
def initialize api
|
7
|
-
@api = api
|
8
|
-
end
|
9
|
-
|
10
|
-
def get params = {}
|
11
|
-
GetRequest.new(@api, 'audio.get', params).get
|
12
|
-
end
|
13
|
-
|
14
|
-
def link params = {}
|
15
|
-
GetRequest.new(@api, 'audio.link', params).get
|
16
|
-
end
|
17
|
-
|
18
|
-
def search params = {}
|
19
|
-
GetRequest.new(@api, 'audio.search', params).get
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/mailru-api/events.rb
DELETED
data/lib/mailru-api/friends.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Friends
|
6
|
-
RETURN_OBJECTS = 1
|
7
|
-
RETURN_UIDS = 0
|
8
|
-
|
9
|
-
def initialize api
|
10
|
-
@api = api
|
11
|
-
end
|
12
|
-
|
13
|
-
def get params = {}
|
14
|
-
GetRequest.new(@api, 'friends.get', params).get
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_app_users params = {}
|
18
|
-
GetRequest.new(@api, 'friends.getAppUsers', params).get
|
19
|
-
end
|
20
|
-
|
21
|
-
def get_invitations_count params = {}
|
22
|
-
GetRequest.new(@api, 'friends.getInvitationsCount', params).get
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_online params = {}
|
26
|
-
GetRequest.new(@api, 'friends.getOnline', params).get
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
data/lib/mailru-api/guestbook.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Guestbook
|
6
|
-
def initialize api
|
7
|
-
@api = api
|
8
|
-
end
|
9
|
-
|
10
|
-
def get params = {}
|
11
|
-
GetRequest.new(@api, 'guestbook.get', params).get
|
12
|
-
end
|
13
|
-
|
14
|
-
def post params = {}
|
15
|
-
PostRequest.new(@api, 'guestbook.post', params).post
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/mailru-api/mail.rb
DELETED
data/lib/mailru-api/messages.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MyMailRU
|
4
|
-
class API
|
5
|
-
class Messages
|
6
|
-
def get_thread params = {}
|
7
|
-
GetRequest.new(@api, 'messages.getThread', params).get
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_threads_list params = {}
|
11
|
-
GetRequest.new(@api, 'messages.getThreadsList', params).get
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_unread_count params = {}
|
15
|
-
GetRequest.new(@api, 'messages.getUnreadCount', params).get
|
16
|
-
end
|
17
|
-
|
18
|
-
def post params = {}
|
19
|
-
PostRequest.new(@api, 'messages.post', params).post
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/mailru-api/mobile.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Mobile
|
6
|
-
BASIC = 'basic'
|
7
|
-
SMARTPHONE = 'smartphone'
|
8
|
-
|
9
|
-
def initialize api
|
10
|
-
@api = api
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_canvas params = {}
|
14
|
-
GetRequest.new(@api, 'mobile.getCanvas', params, Request::Secure::No).get
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/mailru-api/photos.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Photos
|
6
|
-
def initialize api
|
7
|
-
@api = api
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_album params = {}
|
11
|
-
GetRequest.new(@api, 'photos.createAlbum', params).get
|
12
|
-
end
|
13
|
-
|
14
|
-
def get params = {}
|
15
|
-
GetRequest.new(@api, 'photos.get', params).get
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_albums params = {}
|
19
|
-
GetRequest.new(@api, 'photos.getAlbums', params).get
|
20
|
-
end
|
21
|
-
|
22
|
-
def upload params = {}
|
23
|
-
PostRequest.new(@api, 'photos.upload', params).post
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/mailru-api/stream.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Stream
|
6
|
-
def initialize api
|
7
|
-
@api = api
|
8
|
-
end
|
9
|
-
|
10
|
-
def comment params = {}
|
11
|
-
GetRequest.new(@api, 'stream.comment', params).get
|
12
|
-
end
|
13
|
-
|
14
|
-
def get params = {}
|
15
|
-
GetRequest.new(@api, 'stream.get', params).get
|
16
|
-
end
|
17
|
-
|
18
|
-
def get_by_author params = {}
|
19
|
-
GetRequest.new(@api, 'stream.getByAuthor', params).get
|
20
|
-
end
|
21
|
-
|
22
|
-
def like params = {}
|
23
|
-
GetRequest.new(@api, 'stream.like', params).get
|
24
|
-
end
|
25
|
-
|
26
|
-
def post params = {}
|
27
|
-
PostRequest.new(@api, 'stream.post', params).post
|
28
|
-
end
|
29
|
-
|
30
|
-
def share params ={}
|
31
|
-
PostRequest.new(@api, 'stream.share', params).post
|
32
|
-
end
|
33
|
-
|
34
|
-
def unlike params = {}
|
35
|
-
GetRequest.new(@api, 'stream.unlike', params).get
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/mailru-api/users.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#:encoding: utf-8
|
2
|
-
|
3
|
-
module MailRU
|
4
|
-
class API
|
5
|
-
class Users
|
6
|
-
def initialize api
|
7
|
-
@api = api
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_balance
|
11
|
-
GetRequest.new(@api, 'users.getBalance', params).get
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_info params = {}
|
15
|
-
GetRequest.new(@api, 'users.getInfo', params).get
|
16
|
-
end
|
17
|
-
|
18
|
-
def has_app_permission params = {}
|
19
|
-
GetRequest.new(@api, 'users.hasAppPermission', params).get
|
20
|
-
end
|
21
|
-
|
22
|
-
def is_app_user
|
23
|
-
GetRequest.new(@api, 'users.isAppUser', params).get
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|