Class: MailruClient
- Inherits:
-
Object
show all
- Defined in:
- lib/authlogic_connect_mailru/mailru_client.rb
Constant Summary
collapse
- ENDPOINT =
'http://www.appsmail.ru/platform/api'
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MailruClient.
5
6
7
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 5
def initialize( token )
@token = token
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
13
14
15
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 13
def method_missing( m, *args, &block )
call_api( m.to_s.split('_').join('.'), *args )
end
|
Instance Method Details
#api?(method) ⇒ Boolean
17
18
19
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 17
def api?( method )
method =~ /^[a-z]+_[a-zA-Z]+$/
end
|
#call_api(method, params = {}) ⇒ Object
21
22
23
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 21
def call_api( method, params = {} )
JSON.parse(Net::HTTP.get_response(prepare_uri method, params).body)
end
|
#convert_params(params) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 42
def convert_params( params )
params.inject({}) do |hash, keyval|
hash[keyval.first] = case value = keyval.last
when Array then
value.join(',')
else
value.to_s
end
hash
end
end
|
#prepare_uri(method, params) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 25
def prepare_uri( method, params )
params_to_sign = {
:method => method,
:app_id => @token.class.app_id,
:secure => '1',
:format => 'json'
}.merge(convert_params params)
if @token.exp < Time.now.to_i
params_to_sign[:session_key] = @token.session_key
else
params_to_sign[:uid] = @token.key
end
URI.parse("#{ENDPOINT}?#{params_to_sign.to_query}&sig=#{@token.class.sign params_to_sign}")
end
|
#respond_to?(m, *args) ⇒ Boolean
9
10
11
|
# File 'lib/authlogic_connect_mailru/mailru_client.rb', line 9
def respond_to?( m, *args )
super || api?( m )
end
|