mailru-api 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65a98b4ade3ffc3528f7febafa33a1e43bfab58a
4
+ data.tar.gz: 4a5a918b8c7716d7c52e1dd7a10e7e461921fc40
5
+ SHA512:
6
+ metadata.gz: c15ec67f786d7400521495557ab602011b08431cdbe642bc10e1b53d7616d3c0cea7ab8f05114726c081269561044eb270df9088e8fc541ce715c18ae1da16e1
7
+ data.tar.gz: 147d1a8a458707e0dd47fc0249163d98c611ef55de28336e7143e9a4f63aadb6a6b94625bb10cdae449dda4bbf147c0c27d9f7781fc1b1e6fc0ccd9bd561dc92
@@ -1,170 +1,7 @@
1
1
  #:encoding: utf-8
2
2
 
3
+ require 'mailru-api/api'
4
+ require 'mailru-api/dsl'
3
5
  require 'mailru-api/error'
4
6
  require 'mailru-api/request'
5
- require 'mailru-api/dsl'
6
-
7
- module MailRU
8
- class APIConfiguration
9
- attr_accessor :app_id, :secret_key, :private_key, :session_key, :uid, :format
10
- end
11
-
12
- class APIConfigurationBuilder
13
- attr_reader :configuration
14
-
15
- def initialize(&block)
16
- if block_given?
17
- @configuration = APIConfiguration.new
18
- instance_eval(&block)
19
- end
20
- end
21
-
22
- def app_id value
23
- @configuration.app_id = value
24
- end
25
-
26
- def secret_key value
27
- @configuration.secret_key = value
28
- end
29
-
30
- def private_key value
31
- @configuration.private_key = value
32
- end
33
-
34
- def session_key value
35
- @configuration.session_key = value
36
- end
37
-
38
- def uid value
39
- @configuration.uid = value
40
- end
41
-
42
- def format value
43
- @configuration.format = value
44
- end
45
- end
46
-
47
- class API
48
- module Format
49
- XML = 'xml'
50
- JSON = 'json'
51
- end
52
-
53
- PATH = 'http://www.appsmail.ru/platform/api'
54
-
55
- attr_accessor :app_id, :secret_key, :private_key, :session_key, :uid, :format
56
-
57
- def initialize options = {}, &block
58
- @app_id = options[:app_id]
59
- @secret_key = options[:secret_key]
60
- @private_key = options[:private_key]
61
- @session_key = options[:session_key]
62
- @uid = options[:uid]
63
- @format = options[:format]
64
-
65
- if block_given?
66
- if block.arity == 1
67
- yield self
68
- else
69
- configuration = APIConfigurationBuilder.new(&block).configuration
70
-
71
- unless configuration.nil?
72
- @app_id = configuration.app_id || @app_id
73
- @secret_key = configuration.secret_key || @secret_key
74
- @private_key = configuration.private_key || @private_key
75
- @session_key = configuration.session_key || @session_key
76
- @uid = configuration.uid || @uid
77
- @format = configuration.format || @format
78
- end
79
- end
80
- end
81
- end
82
-
83
- def audio
84
- DSL.new(self, 'audio') do
85
- api 'get'
86
- api 'link'
87
- api 'search'
88
- end
89
- end
90
-
91
- def events
92
- DSL.new(self, 'events') do
93
- api 'getNewCount'
94
- end
95
- end
96
-
97
- def friends
98
- DSL.new(self, 'friends') do
99
- api 'get'
100
- api 'getAppUsers'
101
- api 'getInvitationsCount'
102
- api 'getOnline'
103
- end
104
- end
105
-
106
- def guestbook
107
- DSL.new(self, 'guestbook') do
108
- api 'get'
109
- api 'post', :post
110
- end
111
- end
112
-
113
- def mail
114
- DSL.new(self, 'mail') do
115
- api 'getUnreadCount'
116
- end
117
- end
118
-
119
- def messages
120
- DSL.new(self, 'messages') do
121
- api 'getThread'
122
- api 'getThreadsList'
123
- api 'getUnreadCount'
124
- api 'post', :post
125
- end
126
- end
127
-
128
- def mobile
129
- DSL.new(self, 'mobile') do
130
- api 'getCanvas', :get, Request::Secure::No
131
- end
132
- end
133
-
134
- def notifications
135
- DSL.new(self, 'notifications') do
136
- api 'send', :get, Request::Secure::Yes
137
- end
138
- end
139
-
140
- def photos
141
- DSL.new(self, 'photos') do
142
- api 'createAlbum'
143
- api 'get'
144
- api 'getAlbums'
145
- api 'upload', :post
146
- end
147
- end
148
-
149
- def stream
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
159
- end
160
7
 
161
- def users
162
- DSL.new(self, 'users') do
163
- api 'getBalance'
164
- api 'getInfo'
165
- api 'hasAppPermission'
166
- api 'isAppUser'
167
- end
168
- end
169
- end
170
- end
@@ -0,0 +1,149 @@
1
+ #:encoding: utf-8
2
+
3
+ module MailRU
4
+ class API
5
+ PATH = 'http://www.appsmail.ru/platform/api'
6
+ PARAMS = [:app_id, :secret_key, :private_key, :session_key, :uid, :format]
7
+
8
+ module Format
9
+ XML = 'xml'
10
+ JSON = 'json'
11
+ end
12
+
13
+ class ConfigurationBuilder
14
+ attr_reader :configuration
15
+
16
+ def initialize(&block)
17
+ @configuration = {}
18
+ instance_eval(&block) if block_given?
19
+ end
20
+
21
+ PARAMS.each do |param|
22
+ class_eval <<-EOV, __FILE__, __LINE__ + 1
23
+ def #{param}(value) # def app_id(value)
24
+ @configuration[:#{param}] = value # @configuration[:app_id] = value
25
+ end # end
26
+ EOV
27
+ end
28
+ end
29
+
30
+ def initialize options = {}, &block
31
+ @configuration = options
32
+
33
+ if block_given?
34
+ if block.arity == 1
35
+ yield self
36
+ else
37
+ @configuration.merge! ConfigurationBuilder.new(&block).configuration
38
+ end
39
+ end
40
+ end
41
+
42
+ PARAMS.each do |param|
43
+ class_eval <<-EOV, __FILE__, __LINE__ + 1
44
+ def #{param}=(value) # def app_id=(value)
45
+ @configuration[:#{param}] = value # @configuration[:app_id] = value
46
+ end # end
47
+
48
+ def #{param} # def app_id
49
+ @configuration[:#{param}] # @configuration[:app_id]
50
+ end # end
51
+ EOV
52
+ end
53
+
54
+ def get name, params = {}, secure = Request::Secure::Any
55
+ GetRequest.new(self, name, params, secure).get
56
+ end
57
+
58
+ def post name, params = {}, secure = Request::Secure::Any
59
+ PostRequest.new(self, name, params, secure).post
60
+ end
61
+
62
+ def audio
63
+ DSL.new(self, 'audio') do
64
+ api 'get'
65
+ api 'link'
66
+ api 'search'
67
+ end
68
+ end
69
+
70
+ def events
71
+ DSL.new(self, 'events') do
72
+ api 'getNewCount'
73
+ end
74
+ end
75
+
76
+ def friends
77
+ DSL.new(self, 'friends') do
78
+ api 'get'
79
+ api 'getAppUsers'
80
+ api 'getInvitationsCount'
81
+ api 'getOnline'
82
+ end
83
+ end
84
+
85
+ def guestbook
86
+ DSL.new(self, 'guestbook') do
87
+ api 'get'
88
+ api 'post', :post
89
+ end
90
+ end
91
+
92
+ def mail
93
+ DSL.new(self, 'mail') do
94
+ api 'getUnreadCount'
95
+ end
96
+ end
97
+
98
+ def messages
99
+ DSL.new(self, 'messages') do
100
+ api 'getThread'
101
+ api 'getThreadsList'
102
+ api 'getUnreadCount'
103
+ api 'post', :post
104
+ end
105
+ end
106
+
107
+ def mobile
108
+ DSL.new(self, 'mobile') do
109
+ api 'getCanvas', :get, Request::Secure::No
110
+ end
111
+ end
112
+
113
+ def notifications
114
+ DSL.new(self, 'notifications') do
115
+ api 'send', :get, Request::Secure::Yes
116
+ end
117
+ end
118
+
119
+ def photos
120
+ DSL.new(self, 'photos') do
121
+ api 'createAlbum'
122
+ api 'get'
123
+ api 'getAlbums'
124
+ api 'upload', :post
125
+ end
126
+ end
127
+
128
+ def stream
129
+ DSL.new(self, 'stream') do
130
+ api 'comment'
131
+ api 'get'
132
+ api 'getByAuthor'
133
+ api 'like'
134
+ api 'post', :post
135
+ api 'share', :post
136
+ api 'unlike'
137
+ end
138
+ end
139
+
140
+ def users
141
+ DSL.new(self, 'users') do
142
+ api 'getBalance'
143
+ api 'getInfo'
144
+ api 'hasAppPermission'
145
+ api 'isAppUser'
146
+ end
147
+ end
148
+ end
149
+ end
@@ -6,21 +6,23 @@ module MailRU
6
6
  def initialize api, group, &block
7
7
  @api = api
8
8
  @group = group
9
- if block_given?
10
- instance_eval(&block)
11
- end
9
+ instance_eval(&block) if block_given?
12
10
  end
13
11
 
14
12
  def api name, method = :get, secure = Request::Secure::Any
15
- self.class.send(:define_method, underscore(name)) do |params = {}|
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!')
13
+ raise Error.create(0, 'HTTP method must be GET or POST!') unless [:get, :post].include?(method)
14
+
15
+ method(SEND).call(:define_singleton_method, underscore(name)) do |params = {}|
16
+ return @api.get("#{@group}.#{name}", params, secure) if method == :get
17
+ return @api.post("#{@group}.#{name}", params, secure) if method == :post
19
18
  end
20
19
  end
21
20
 
22
21
  private
23
22
 
23
+ SEND = (0...6).map{ (65 + rand(26)).chr }.join
24
+ alias_method(SEND, :send)
25
+
24
26
  def underscore s
25
27
  s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
26
28
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
@@ -16,7 +16,7 @@ module MailRU
16
16
  Any = 2
17
17
  end
18
18
 
19
- def initialize api, method, method_params, secure = Secure::Any
19
+ def initialize api, method, method_params = {}, secure = Secure::Any
20
20
  @api = api
21
21
  @method = method
22
22
  @method_params = method_params
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailru-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alexey Demin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2013-10-13 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Ruby @Mail.RU API
15
14
  email: demin.alexey@inbox.ru
@@ -18,33 +17,32 @@ extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
19
  - lib/mailru-api.rb
20
+ - lib/mailru-api/api.rb
21
21
  - lib/mailru-api/error.rb
22
22
  - lib/mailru-api/request.rb
23
23
  - lib/mailru-api/dsl.rb
24
24
  homepage: https://github.com/ademin/mailru-api
25
25
  licenses:
26
26
  - MIT
27
+ metadata: {}
27
28
  post_install_message:
28
29
  rdoc_options: []
29
30
  require_paths:
30
31
  - lib
31
32
  required_ruby_version: !ruby/object:Gem::Requirement
32
- none: false
33
33
  requirements:
34
- - - ! '>='
34
+ - - '>='
35
35
  - !ruby/object:Gem::Version
36
36
  version: 1.9.3
37
37
  required_rubygems_version: !ruby/object:Gem::Requirement
38
- none: false
39
38
  requirements:
40
- - - ! '>='
39
+ - - '>='
41
40
  - !ruby/object:Gem::Version
42
41
  version: '0'
43
42
  requirements: []
44
43
  rubyforge_project:
45
- rubygems_version: 1.8.24
44
+ rubygems_version: 2.0.3
46
45
  signing_key:
47
- specification_version: 3
46
+ specification_version: 4
48
47
  summary: Ruby @Mail.RU API
49
48
  test_files: []
50
- has_rdoc: