lemur 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzYxMjg2NDZlM2NjOGQ2NzQwNTAyMTBhNjY5ZDQ3YjE0NzNjODFjOQ==
5
+ data.tar.gz: !binary |-
6
+ ZmNjNjZmMjVhOTNiMDYyNzlhODA0ODg2ZDhkNDdjY2Y5ZWIxNWMyNw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MjNlODEzMjUwOTZjMDYxOGFmOGNkNTJmNmI0YTVhYjU3OGU5YzgwZTA3ZjJl
10
+ ZWJjODI1NmQxMDU0MWJmZDEyNWRhYzg4MmZhYjZlZDllZDVkNjhjMDdkMjI1
11
+ ODU3ZDdhMWMzOTc1NzI1ZWQ1MDQ0NTQyNDMwMDM4MTJlYjZhYWE=
12
+ data.tar.gz: !binary |-
13
+ ZTA1Y2RlZTY4MDAyYTA1MTE2NzRiZGExOWFjNmRjZjE1YTBkMmRkYmM3MDc4
14
+ ZTg5N2VjYjRlOTRmNWE5ZDM0MjdhNDUyMmI2OWMwNGM0NjMyZThmMWRiYjQx
15
+ MmU2NDQ3MDhhYjlmNWU1OWRhZjliNDA3YTlmZDI5OWU3OWVjZDU=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lemur.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 edikgat
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Lemur
2
+
3
+ Api for Odnoklassniki Social Network
4
+
5
+ Lemur is a lightweight, flexible Ruby SDK for Odnoklassniki. It allows read/write access to Odnoklassniki API. To work with Lemur you need VALUABLE ACCESS to odnoklassniki api. This api work only with access_token that gives you odnoklassniki, when you authorize with omniauth.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'lemur'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lemur
20
+
21
+ ## Usage
22
+ To use odnoklassniki api methods you should have [VALUABLE ACCESS](http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=12878032) to odnoklassniki.
23
+ ###Initialize
24
+
25
+ api = Lemur::API.newe(application_secret_key, application_key, access_token, application_id = nil, refresh_token = nil)
26
+
27
+ application_id and refresh_token parameter needed only for 'get_new_token' action
28
+
29
+ ###Methods examples
30
+
31
+ api.get({method: 'friends.get')
32
+
33
+ api.get({method: 'users.getCurrentUser'})
34
+
35
+ api.get_new_token
36
+
37
+ api.get({method: 'users.getInfo', uids: uid, fields: 'uid,first_name,last_name,current_location,gender,pic_1,pic_2,pic_3,pic_4,pic_5'})
38
+
39
+ [See all api methods here](http://dev.odnoklassniki.ru/wiki/display/ok/Odnoklassniki+REST+API+ru)
40
+
41
+ api.get_request({method: 'users.getInfo', uids: uid, fields: 'uid,first_name,last_name,current_location,gender,pic_1,pic_2,pic_3,pic_4,pic_5'})
42
+
43
+ get_request methods don't use JSON parsing and returns Foreman response
44
+
45
+ ###Gem parameters methods
46
+ api.security_options
47
+ api.request_options
48
+ api.response
49
+
50
+
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lemur/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lemur"
8
+ spec.version = Lemur::VERSION
9
+ spec.authors = ["Eduard Gataullin"]
10
+ spec.email = ["edikgat@gmail.com"]
11
+ spec.description = %q{Lemur is a lightweight, flexible Ruby SDK for Odnoklassniki. It allows read/write access to Odnoklassniki API. To work with Lemur you need VALUABLE ACCESS to odnoklassniki api. This api work only with access_token that gives you odnoklassniki, when you authorize with omniauth.}
12
+ spec.summary = %q{Api for www.odnoklassniki.ru }
13
+ spec.homepage = "https://github.com/edikgat/lemur"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency("faraday")
25
+ end
@@ -0,0 +1,88 @@
1
+ require "lemur/version"
2
+
3
+ require 'json'
4
+ require 'digest/md5'
5
+
6
+ module Lemur
7
+ class API
8
+
9
+ def initialize(application_secret_key, application_key, access_token, application_id = nil, refresh_token = nil)
10
+ start_faraday
11
+ @security_options = {
12
+ application_secret_key: application_secret_key,
13
+ application_key: application_key, access_token: access_token,
14
+ application_id: application_id, refresh_token: refresh_token
15
+ }
16
+ end
17
+
18
+ attr_reader :security_options, :request_options, :response, :connection
19
+
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
+ def get_new_token
39
+ if @security_options[:application_id].blank? || @security_options[:refresh_token].blank?
40
+ raise ArgumentError, 'wrong number of arguments'
41
+ end
42
+ faraday_options = {
43
+ :headers['Content-Type'] => 'application/json',
44
+ :url => 'http://api.odnoklassniki.ru/oauth/token.do'
45
+ }
46
+ conn = init_faraday(faraday_options)
47
+ new_token_response = conn.post do |req|
48
+ req.params = {
49
+ refresh_token: @security_options[:refresh_token], grant_type: 'refresh_token',
50
+ client_id: @security_options[:application_id],
51
+ client_secret: @security_options[:application_secret_key]
52
+ }
53
+ end
54
+ new_token_response = JSON.parse(new_token_response.body)
55
+ @security_options[:access_token] = new_token_response['access_token']
56
+ new_token_response['access_token']
57
+ end
58
+
59
+ def final_request_params(request_params, access_token)
60
+ request_params.merge(sig: odnoklassniki_signature(request_params, access_token, security_options[:application_secret_key]),
61
+ access_token: security_options[:access_token],
62
+ application_key: security_options[:application_key])
63
+ end
64
+
65
+ def odnoklassniki_signature(request_params, access_token, application_secret_key)
66
+ sorted_params_string = ""
67
+ request_params = Hash[request_params.sort]
68
+ request_params.each {|key, value| sorted_params_string += "#{key}=#{value}"}
69
+ secret_part = Digest::MD5.hexdigest("#{access_token}#{application_secret_key}")
70
+ Digest::MD5.hexdigest("#{sorted_params_string}#{secret_part}")
71
+ end
72
+
73
+ def get_request(request_params)
74
+ @request_options = request_params
75
+ @response = @connection.get do |request|
76
+ request.params = final_request_params(@request_options.merge(application_key: security_options[:application_key]),
77
+ security_options[:access_token])
78
+ end
79
+ end
80
+
81
+ def get(request_params)
82
+ @response = get_request(request_params)
83
+ JSON.parse(response.body)
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,3 @@
1
+ module Lemur
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lemur
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eduard Gataullin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Lemur is a lightweight, flexible Ruby SDK for Odnoklassniki. It allows
56
+ read/write access to Odnoklassniki API. To work with Lemur you need VALUABLE ACCESS
57
+ to odnoklassniki api. This api work only with access_token that gives you odnoklassniki,
58
+ when you authorize with omniauth.
59
+ email:
60
+ - edikgat@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lemur.gemspec
71
+ - lib/lemur.rb
72
+ - lib/lemur/version.rb
73
+ homepage: https://github.com/edikgat/lemur
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Api for www.odnoklassniki.ru
97
+ test_files: []