namba 0.0.1
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.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +64 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +7 -0
- data/lib/namba.rb +21 -0
- data/lib/namba/api_methods.rb +50 -0
- data/lib/namba/client.rb +17 -0
- data/lib/namba/config.rb +34 -0
- data/lib/namba/error.rb +4 -0
- data/lib/namba/version.rb +3 -0
- data/namba.gemspec +25 -0
- data/spec/namba/namba_spec.rb +45 -0
- data/spec/spec_helper.rb +8 -0
- metadata +120 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
namba (0.0.1)
|
5
|
+
multi_json
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.2.8)
|
11
|
+
crack (0.3.1)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
ffi (1.0.11)
|
14
|
+
guard (1.1.1)
|
15
|
+
listen (>= 0.4.2)
|
16
|
+
thor (>= 0.14.6)
|
17
|
+
guard-bundler (0.1.3)
|
18
|
+
bundler (>= 1.0.0)
|
19
|
+
guard (>= 0.2.2)
|
20
|
+
guard-rspec (1.0.1)
|
21
|
+
guard (>= 1.1)
|
22
|
+
libnotify (0.7.2)
|
23
|
+
ffi (~> 1.0.0)
|
24
|
+
listen (0.4.5)
|
25
|
+
rb-fchange (~> 0.0.5)
|
26
|
+
rb-fsevent (~> 0.9.1)
|
27
|
+
rb-inotify (~> 0.8.8)
|
28
|
+
multi_json (1.3.6)
|
29
|
+
rack (1.4.1)
|
30
|
+
rack-test (0.6.1)
|
31
|
+
rack (>= 1.0)
|
32
|
+
rake (0.9.2.2)
|
33
|
+
rb-fchange (0.0.5)
|
34
|
+
ffi
|
35
|
+
rb-fsevent (0.9.1)
|
36
|
+
rb-inotify (0.8.8)
|
37
|
+
ffi (>= 0.5.0)
|
38
|
+
rspec (2.7.0)
|
39
|
+
rspec-core (~> 2.7.0)
|
40
|
+
rspec-expectations (~> 2.7.0)
|
41
|
+
rspec-mocks (~> 2.7.0)
|
42
|
+
rspec-core (2.7.1)
|
43
|
+
rspec-expectations (2.7.0)
|
44
|
+
diff-lcs (~> 1.1.2)
|
45
|
+
rspec-mocks (2.7.0)
|
46
|
+
thor (0.15.2)
|
47
|
+
webmock (1.8.7)
|
48
|
+
addressable (>= 2.2.7)
|
49
|
+
crack (>= 0.1.7)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
guard
|
56
|
+
guard-bundler
|
57
|
+
guard-rspec
|
58
|
+
libnotify
|
59
|
+
multi_json
|
60
|
+
namba!
|
61
|
+
rack-test
|
62
|
+
rake
|
63
|
+
rspec (~> 2.7.0)
|
64
|
+
webmock
|
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sergey Kishenin
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
## The Namba Ruby gem
|
2
|
+
|
3
|
+
A Ruby wrapper for the Namba API. The full API description is available [here][]
|
4
|
+
|
5
|
+
[here]: http://dev.namba.kg/api_description.php
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
require 'namba'
|
10
|
+
|
11
|
+
Namba.configure do |config|
|
12
|
+
config.username = "your_username"
|
13
|
+
config.password = "secret"
|
14
|
+
config.locale = :kg
|
15
|
+
end
|
16
|
+
|
17
|
+
n = Namba.new()
|
18
|
+
|
19
|
+
Use `:kz` locale if you want to access [namba.kz][] API. Default value is `:kg`
|
20
|
+
|
21
|
+
## Methods spread on all Namba API
|
22
|
+
|
23
|
+
n.get_user_info(name) # returns specific user information
|
24
|
+
n.get_user_video(name) # returns specific user's video list
|
25
|
+
n.get_user_photo(name) # returns specific user's photo list
|
26
|
+
n.get_friends_list(name) # returns specific user's friends list
|
27
|
+
|
28
|
+
Eg.:
|
29
|
+
|
30
|
+
n.get_user_info("puzanov")
|
31
|
+
|
32
|
+
Leave `name` parameter blank to get information about configured user. Eg.:
|
33
|
+
|
34
|
+
n.get_user_info()
|
35
|
+
|
36
|
+
## Methods dealing with personal stuff only
|
37
|
+
|
38
|
+
n.set_status(text) # sets user status with `text`
|
39
|
+
n.get_events # returns user's friends' events
|
40
|
+
n.get_new_mail_count # returns count of unread messages
|
41
|
+
n.get_last_mail # returns list of inbox messages ordered by creation date. 20 messages is maximum
|
42
|
+
|
43
|
+
[namba.kz]: http://www.namba.kz
|
44
|
+
## Licence
|
45
|
+
|
46
|
+
MIT License Copyright (c) 2012 ZERO.ONE
|
47
|
+
|
data/Rakefile
ADDED
data/lib/namba.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "namba/version"
|
2
|
+
require 'namba/client'
|
3
|
+
require 'namba/config'
|
4
|
+
|
5
|
+
module Namba
|
6
|
+
extend Config
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Alias for Namba::Client.new()
|
11
|
+
def new(opts = {})
|
12
|
+
Namba::Client.new(opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Alias for Namba::Config.configure
|
16
|
+
def configure &block
|
17
|
+
Namba::Config.configure &block
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Namba
|
5
|
+
module APIMethods
|
6
|
+
def get_user_info name = self.username
|
7
|
+
get_responce_from "http://api.namba.#{self.locale}/getUserInfo.php?username=" + name
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_user_video name = self.username
|
11
|
+
get_responce_from "http://api.namba.#{self.locale}/getVideo.php?username=" + name
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_user_photo name = self.username
|
15
|
+
get_responce_from "http://api.namba.#{self.locale}/getPhoto.php?username=" + name
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_friends_list name = self.username
|
19
|
+
get_responce_from "http://api.namba.#{self.locale}/friends.php?username=" + name
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_status text
|
23
|
+
post_data_to "http://api.namba.#{self.locale}/setStatus.php", { username: self.username, password: self.password, status: text }
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_events
|
27
|
+
post_data_to "http://api.namba.#{self.locale}/getEvents.php"
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_new_mail_count
|
31
|
+
post_data_to "http://api.namba.#{self.locale}/getNewMailCount.php"
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_last_mail
|
35
|
+
post_data_to "http://api.namba.#{self.locale}/getLastMail.php"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def get_responce_from url
|
41
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
42
|
+
MultiJson.decode(response.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
def post_data_to url, params = { username: self.username, password: self.password }
|
46
|
+
response = Net::HTTP.post_form(URI.parse(url), params)
|
47
|
+
MultiJson.decode(response.body)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/namba/client.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'namba/config'
|
2
|
+
require 'namba/api_methods'
|
3
|
+
|
4
|
+
module Namba
|
5
|
+
class Client
|
6
|
+
extend Config
|
7
|
+
include APIMethods
|
8
|
+
attr_accessor *Config::VALID_KEYS
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
opts = Namba::Config.options.merge(opts)
|
12
|
+
Config::VALID_KEYS.each do |key|
|
13
|
+
instance_variable_set("@#{key}".to_sym, opts[key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/namba/config.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'namba/error'
|
2
|
+
|
3
|
+
module Namba
|
4
|
+
module Config
|
5
|
+
extend self
|
6
|
+
|
7
|
+
VALID_KEYS = [
|
8
|
+
:username,
|
9
|
+
:password,
|
10
|
+
:locale
|
11
|
+
]
|
12
|
+
|
13
|
+
attr_accessor *VALID_KEYS
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield self
|
17
|
+
|
18
|
+
# Setting default configuraion options
|
19
|
+
# if not provided
|
20
|
+
self.tap do |s|
|
21
|
+
s.username = "" if s.username.nil?
|
22
|
+
s.password = "" if s.password.nil?
|
23
|
+
s.locale = :kg if s.locale.nil?
|
24
|
+
end
|
25
|
+
raise ConfigurationError, "Available locales are only 'kg' and 'kz'" unless [:kg, :kz].include?(self.locale)
|
26
|
+
end
|
27
|
+
|
28
|
+
def options
|
29
|
+
options = {}
|
30
|
+
VALID_KEYS.each {|k| options[k] = send(k)}
|
31
|
+
options
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/namba/error.rb
ADDED
data/namba.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "namba/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["Sergey Kishenin"]
|
7
|
+
gem.email = ["sergey.kishenin@gmail.com"]
|
8
|
+
gem.description = %q{Ruby wrapper for Namba API}
|
9
|
+
gem.summary = %q{Ruby wrapper for Namba API}
|
10
|
+
gem.homepage = "https://github.com/ZeroOneStudio/namba"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "namba"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Namba::VERSION
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'multi_json'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec', '~> 2.7.0'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'webmock'
|
24
|
+
gem.add_development_dependency 'rack-test'
|
25
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Namba do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Namba.configure do |config|
|
7
|
+
config.username = nil
|
8
|
+
config.password = nil
|
9
|
+
config.locale = nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set configuration information" do
|
14
|
+
Namba.configure do |config|
|
15
|
+
config.username = "name"
|
16
|
+
config.password = "secret"
|
17
|
+
config.locale = :kz
|
18
|
+
end
|
19
|
+
|
20
|
+
n = Namba.new()
|
21
|
+
|
22
|
+
n.username.should == "name"
|
23
|
+
n.password.should == "secret"
|
24
|
+
n.locale.should == :kz
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set defaults when it is not set in configuration block" do
|
28
|
+
Namba.configure do |config|
|
29
|
+
end
|
30
|
+
|
31
|
+
n = Namba.new()
|
32
|
+
|
33
|
+
n.username.should == ""
|
34
|
+
n.password.should == ""
|
35
|
+
n.locale.should == :kg
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not allow to set any locale except :kg or :kz" do
|
39
|
+
expect {
|
40
|
+
Namba.configure do |config|
|
41
|
+
config.locale = :ru
|
42
|
+
end
|
43
|
+
}.should raise_error
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: namba
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sergey Kishenin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: &73665700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *73665700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &73664960 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.7.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *73664960
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &73663380 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *73663380
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: webmock
|
49
|
+
requirement: &73662600 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *73662600
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rack-test
|
60
|
+
requirement: &73661920 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *73661920
|
69
|
+
description: Ruby wrapper for Namba API
|
70
|
+
email:
|
71
|
+
- sergey.kishenin@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- Guardfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- lib/namba.rb
|
85
|
+
- lib/namba/api_methods.rb
|
86
|
+
- lib/namba/client.rb
|
87
|
+
- lib/namba/config.rb
|
88
|
+
- lib/namba/error.rb
|
89
|
+
- lib/namba/version.rb
|
90
|
+
- namba.gemspec
|
91
|
+
- spec/namba/namba_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/ZeroOneStudio/namba
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.8.10
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Ruby wrapper for Namba API
|
117
|
+
test_files:
|
118
|
+
- spec/namba/namba_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc:
|