userapi-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Max Riveiro
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = userapi-ruby
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Max Riveiro. See LICENSE for details.
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require 'httparty'
4
+ require 'userapi/auth'
5
+ require 'userapi/user'
6
+
7
+ module VK
8
+
9
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require 'singleton'
4
+
5
+ module VK
6
+ class Auth
7
+ include Singleton
8
+ include HTTParty
9
+
10
+ base_uri 'login.userapi.com'
11
+
12
+ class << self
13
+ attr_reader :sid, :user_id
14
+ end
15
+
16
+ def self.login!(login,password)
17
+ begin
18
+ self.get "/auth?login=force&site=2&email=#{login}&pass=#{password}", :no_follow => true
19
+ rescue HTTParty::RedirectionTooDeep => response
20
+ @sid = /.*;sid=(\w*)$/.match(response.response.header['location'])[1]
21
+ @user_id = /remixmid=(\d+)/.match(response.response.header['set-cookie'])[1]
22
+ return true
23
+ else
24
+ raise VK::AuthFail
25
+ end
26
+ end
27
+ end
28
+
29
+ class AuthFail < Exception; end
30
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'json'
4
+
5
+ module VK
6
+ class User
7
+ include HTTParty
8
+ base_uri 'userapi.com'
9
+
10
+ def initialize(id)
11
+ @id = id
12
+ end
13
+
14
+ def method_missing(method, *args)
15
+ JSON.parse(self.class.get "/data", :query => {:act => method, :id => @id, :sid => VK::Auth.sid})
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'webmock/rspec'
6
+
7
+ require 'userapi'
8
+
9
+ require 'spec'
10
+ require 'spec/autorun'
11
+
12
+ Spec::Runner.configure do |config|
13
+ config.include WebMock
14
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe VK::Auth do
4
+ context "with valid email and password" do
5
+ before do
6
+ stub_request(:any, 'login.userapi.com/auth').with(:query => {
7
+ "site" => "2",
8
+ "pass" => "password",
9
+ "login" => "force",
10
+ "email" => "test@test.com"}).to_return(:headers => {
11
+ "Location" => ";sid=123",
12
+ "Set-Cookie" => "remixmid=123"},
13
+ :status => 302)
14
+ end
15
+
16
+ it 'should #login! properly' do
17
+ VK::Auth.login!("test@test.com", "password").should be(true)
18
+ end
19
+
20
+ context "should return proper" do
21
+ before do
22
+ VK::Auth.login!("test@test.com", "password")
23
+ end
24
+
25
+ it '#sid' do
26
+ VK::Auth.sid.should eql "123"
27
+ end
28
+
29
+ it '#user_id' do
30
+ VK::Auth.user_id.should eql "123"
31
+ end
32
+ end
33
+ end
34
+
35
+ context "with invalid email and password" do
36
+ before do
37
+ stub_request(:any, 'login.userapi.com/auth').with(:query => {
38
+ "site" => "2",
39
+ "pass" => "password",
40
+ "login" => "force",
41
+ "email" => "test@test.com"})
42
+ end
43
+
44
+ it "should error an exception" do
45
+ lambda { VK::Auth.login!("test@test.com", "password") }.should raise_error(VK::AuthFail)
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: userapi-ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Max Riveiro
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-02 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 0
32
+ - 6
33
+ - 1
34
+ version: 0.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 9
50
+ version: 1.2.9
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: fakeweb
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 2
65
+ - 8
66
+ version: 1.2.8
67
+ type: :development
68
+ version_requirements: *id003
69
+ description: UserAPI is an application programming interface (API), which enables anyone to create social networks and other projects based on Vkontakte data storage. And I have a little problem - there is no Ruby Gem to work with this API. So this Gem will realize some features of UserAPI
70
+ email: kavu13@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE
77
+ - README.rdoc
78
+ files:
79
+ - lib/userapi.rb
80
+ - lib/userapi/auth.rb
81
+ - lib/userapi/user.rb
82
+ - LICENSE
83
+ - README.rdoc
84
+ - spec/spec_helper.rb
85
+ - spec/userapi/auth_spec.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/kavu/userapi-ruby
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --charset=UTF-8
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Ruby Gem for interacting with VKontakte.Ru UserAPI
120
+ test_files:
121
+ - spec/spec_helper.rb
122
+ - spec/userapi/auth_spec.rb