lemur 0.0.1 → 0.0.2
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.
- checksums.yaml +8 -8
- data/README.md +2 -0
- data/lib/lemur.rb +34 -29
- data/lib/lemur/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzFiMmVjZTU2OGMzNmVlYmQ5ZGExZjBmMmZiZjVmYTdiMTJjODI0Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzczMjFkNmJjMmU1YmM1YTlmYzQ4ZjlhZTg1YzBjZjgxOGExZmVmNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZWRiYmUyNTEwZWFmNmU1YzE4YzA1NzUxMzhlMzU3MmRhYTU5MThhMTA4NDEy
|
10
|
+
YjA2YWE4YjBkNDZiMmRiMTI1ZmUwMWVjNTE4YjY0ZmVhZjliNWQ2Y2MzYzAx
|
11
|
+
ZGQzZmViYjM4YzQwODhhMDA5NzM2OGUzODIxZGFiODhmMTBmNzc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWEwN2JlN2ViNzFlN2FlMTgxMjVlMTcyMmJiM2NiMmNkNmYzMDliMTg5OWQz
|
14
|
+
YzEzMDdkMzUwZDY3NWMwYWZjMzUyNzc5M2I1YzlkYmUwOTBhMzg3Yzg0NWU0
|
15
|
+
ZjY2MjM5MTFkMjUwYTFmN2Q0MzI1OWQ2ZTE0OGVkYWQ0NWVjMDA=
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@ Lemur is a lightweight, flexible Ruby SDK for Odnoklassniki. It allows read/writ
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
gem 'lemur'
|
12
|
+
or instal gem with latest changes
|
13
|
+
gem 'lemur', :git => "git@github.com:edikgat/lemur.git"
|
12
14
|
|
13
15
|
And then execute:
|
14
16
|
|
data/lib/lemur.rb
CHANGED
@@ -4,6 +4,9 @@ require 'json'
|
|
4
4
|
require 'digest/md5'
|
5
5
|
|
6
6
|
module Lemur
|
7
|
+
ODNOKLASSNIKI_API_URL = 'http://api.odnoklassniki.ru/fb.do'
|
8
|
+
ODNOKLASSNIKI_NEW_TOKEN_URL = 'http://api.odnoklassniki.ru/oauth/token.do'
|
9
|
+
|
7
10
|
class API
|
8
11
|
|
9
12
|
def initialize(application_secret_key, application_key, access_token, application_id = nil, refresh_token = nil)
|
@@ -17,31 +20,13 @@ module Lemur
|
|
17
20
|
|
18
21
|
attr_reader :security_options, :request_options, :response, :connection
|
19
22
|
|
20
|
-
def start_faraday
|
21
|
-
faraday_options = {
|
22
|
-
:headers['Content-Type'] => 'application/json',
|
23
|
-
:url => 'http://api.odnoklassniki.ru/fb.do'
|
24
|
-
}
|
25
|
-
@connection = init_faraday(faraday_options)
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def init_faraday(faraday_options)
|
30
|
-
Faraday.new(faraday_options) do |faraday|
|
31
|
-
faraday.request :url_encoded
|
32
|
-
faraday.response :logger
|
33
|
-
faraday.adapter Faraday.default_adapter
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
23
|
def get_new_token
|
39
24
|
if @security_options[:application_id].blank? || @security_options[:refresh_token].blank?
|
40
25
|
raise ArgumentError, 'wrong number of arguments'
|
41
26
|
end
|
42
27
|
faraday_options = {
|
43
28
|
:headers['Content-Type'] => 'application/json',
|
44
|
-
:url =>
|
29
|
+
:url => Lemur::ODNOKLASSNIKI_NEW_TOKEN_URL
|
45
30
|
}
|
46
31
|
conn = init_faraday(faraday_options)
|
47
32
|
new_token_response = conn.post do |req|
|
@@ -56,6 +41,21 @@ module Lemur
|
|
56
41
|
new_token_response['access_token']
|
57
42
|
end
|
58
43
|
|
44
|
+
def get_request(request_params)
|
45
|
+
@request_options = request_params
|
46
|
+
@response = @connection.get do |request|
|
47
|
+
request.params = final_request_params(@request_options.merge(application_key: security_options[:application_key]),
|
48
|
+
security_options[:access_token])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def get(request_params)
|
53
|
+
@response = get_request(request_params)
|
54
|
+
JSON.parse(response.body)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
59
|
def final_request_params(request_params, access_token)
|
60
60
|
request_params.merge(sig: odnoklassniki_signature(request_params, access_token, security_options[:application_secret_key]),
|
61
61
|
access_token: security_options[:access_token],
|
@@ -70,19 +70,24 @@ module Lemur
|
|
70
70
|
Digest::MD5.hexdigest("#{sorted_params_string}#{secret_part}")
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
def start_faraday
|
74
|
+
faraday_options = {
|
75
|
+
:headers['Content-Type'] => 'application/json',
|
76
|
+
:url => Lemur::ODNOKLASSNIKI_API_URL
|
77
|
+
}
|
78
|
+
@connection = init_faraday(faraday_options)
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
|
82
|
+
def init_faraday(faraday_options)
|
83
|
+
Faraday.new(faraday_options) do |faraday|
|
84
|
+
faraday.request :url_encoded
|
85
|
+
faraday.response :logger
|
86
|
+
faraday.adapter Faraday.default_adapter
|
87
|
+
end
|
84
88
|
end
|
85
89
|
|
90
|
+
|
86
91
|
end
|
87
92
|
|
88
93
|
end
|
data/lib/lemur/version.rb
CHANGED