rcracy 0.0.9 → 0.1.0
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/README.md +1 -1
- data/lib/rcracy/api.rb +115 -0
- data/lib/rcracy/configuration.rb +16 -0
- data/lib/rcracy/domain.rb +4 -6
- data/lib/rcracy/kcy.rb +11 -8
- data/lib/rcracy/nut.rb +8 -8
- data/lib/rcracy/user.rb +4 -4
- data/lib/rcracy/version.rb +1 -1
- data/lib/rcracy.rb +2 -109
- data/rcracy.gemspec +3 -7
- metadata +8 -24
- data/.gitignore +0 -17
- data/Rakefile +0 -9
data/README.md
CHANGED
data/lib/rcracy/api.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module RCracy
|
5
|
+
|
6
|
+
API_BASE_URL = 'http://karmacracy.com/api/v1' # Remove from here.
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns an Array of RCracy::Kcy objects
|
10
|
+
|
11
|
+
def self.get_kcys_from(username, from = 1, num = 10)
|
12
|
+
|
13
|
+
request_url = "#{API_BASE_URL}/user/#{username}?kcy=1&from=#{from}&num=#{num}&appkey=#{RCracy.configuration.app_key}"
|
14
|
+
|
15
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
16
|
+
|
17
|
+
hashed_kcys = JSON.parse(http_response.body)['data']['user'][0]['kcys']
|
18
|
+
|
19
|
+
kcys = []
|
20
|
+
|
21
|
+
hashed_kcys.each do |hashed_kcy|
|
22
|
+
|
23
|
+
kcys.push(RCracy::Kcy.new(hashed_kcy))
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
return kcys
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Returns an Array of RCracy::Domain objects
|
33
|
+
|
34
|
+
def self.get_domains(username, from = 1, num = 10)
|
35
|
+
|
36
|
+
request_url = "#{API_BASE_URL}/domains/?u=#{username}&from=#{from}&num=#{num}&appkey=#{RCracy.configuration.app_key}"
|
37
|
+
|
38
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
39
|
+
|
40
|
+
hashed_domains = JSON.parse(http_response.body)['data']['domain']
|
41
|
+
|
42
|
+
domains = []
|
43
|
+
|
44
|
+
hashed_domains.each do |hashed_domain|
|
45
|
+
|
46
|
+
domains.push(RCracy::Domain.new(hashed_domain))
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
return domains
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Returns an Array of RCracy::Nut objects
|
56
|
+
|
57
|
+
def self.get_nuts_from(username, type = 'All')
|
58
|
+
|
59
|
+
request_url = "#{API_BASE_URL}/awards/#{username}?t=#{type}&appkey=#{RCracy.configuration.app_key}"
|
60
|
+
|
61
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
62
|
+
|
63
|
+
hashed_nuts = JSON.parse(http_response.body)['data']['nut']
|
64
|
+
|
65
|
+
nuts = []
|
66
|
+
|
67
|
+
hashed_nuts.each do |hashed_nut|
|
68
|
+
|
69
|
+
nuts.push(RCracy::Nut.new(hashed_nut))
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
return nuts
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Returns an RCracy::Nut object
|
79
|
+
|
80
|
+
def self.get_nut_details_from(username, id, lang = 'en')
|
81
|
+
|
82
|
+
request_url = "#{API_BASE_URL}/awards/#{username}/nut/#{id}?lang=#{lang}&appkey=#{RCracy.configuration.app_key}"
|
83
|
+
|
84
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
85
|
+
|
86
|
+
hashed_nut = JSON.parse(http_response.body)['data']['nut']
|
87
|
+
|
88
|
+
return RCracy::Nut.new(hashed_nut)
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Returns an Array of RCracy::User objects
|
94
|
+
|
95
|
+
def self.get_users_by_kcy_rank(from = 1, num = 10, now = 0)
|
96
|
+
|
97
|
+
request_url = "#{API_BASE_URL}/rank/?from=#{from}&num=#{num}&now=#{now}&appkey=#{RCracy.configuration.app_key}"
|
98
|
+
|
99
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
100
|
+
|
101
|
+
hashed_users = JSON.parse(http_response.body)['data']['user']
|
102
|
+
|
103
|
+
users = []
|
104
|
+
|
105
|
+
hashed_users.each do |hashed_user|
|
106
|
+
|
107
|
+
users.push(RCracy::User.new(hashed_user))
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
return users
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/lib/rcracy/domain.rb
CHANGED
@@ -5,14 +5,12 @@ module RCracy
|
|
5
5
|
attr_reader :domain, :rank, :kclicks, :others
|
6
6
|
|
7
7
|
def initialize(attrs)
|
8
|
-
|
9
|
-
@
|
10
|
-
@rank = attrs['rank']
|
8
|
+
@domain = attrs['domain']
|
9
|
+
@rank = attrs['rank']
|
11
10
|
@kclicks = attrs['clicks']
|
12
|
-
@others
|
13
|
-
|
11
|
+
@others = attrs['numPersonas']
|
14
12
|
end
|
15
13
|
|
16
14
|
end
|
17
15
|
|
18
|
-
end
|
16
|
+
end
|
data/lib/rcracy/kcy.rb
CHANGED
@@ -5,16 +5,19 @@ module RCracy
|
|
5
5
|
attr_reader :title, :long_url, :short_url, :kclicks, :date, :award_id, :award_img, :award_desc, :others
|
6
6
|
|
7
7
|
def initialize(attrs)
|
8
|
-
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
8
|
+
|
9
|
+
@title = attrs['title']
|
10
|
+
@long_url = attrs['longurl']
|
11
|
+
@short_url = attrs['shorturl']
|
12
|
+
@kclicks = attrs['kclicks']
|
13
|
+
@date = attrs['date']
|
14
|
+
@award_id = attrs['awardId']
|
15
|
+
@award_img = attrs['awardImg']
|
15
16
|
@award_desc = attrs['awardDesc']
|
16
|
-
@others
|
17
|
+
@others = attrs['others']
|
18
|
+
|
17
19
|
end
|
20
|
+
|
18
21
|
end
|
19
22
|
|
20
23
|
end
|
data/lib/rcracy/nut.rb
CHANGED
@@ -6,17 +6,17 @@ module RCracy
|
|
6
6
|
:flag_type, :level, :date_received_or_last, :number
|
7
7
|
|
8
8
|
def initialize(attrs)
|
9
|
-
@id
|
10
|
-
@name
|
11
|
-
@date_since
|
12
|
-
@history
|
9
|
+
@id = attrs['id']
|
10
|
+
@name = attrs['name']
|
11
|
+
@date_since = attrs['dateSince']
|
12
|
+
@history = attrs['history']
|
13
13
|
@small_image = attrs['imageSmall']
|
14
|
-
@big_image
|
14
|
+
@big_image = attrs['imageBig']
|
15
15
|
@description = attrs['description']
|
16
|
-
@flag_type
|
17
|
-
@level
|
16
|
+
@flag_type = attrs['flg_type']
|
17
|
+
@level = attrs['level']
|
18
18
|
@date_received_or_last = attrs['dateReceivedOrLast']
|
19
|
-
@number
|
19
|
+
@number = attrs['number']
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
data/lib/rcracy/user.rb
CHANGED
@@ -6,13 +6,13 @@ module RCracy
|
|
6
6
|
|
7
7
|
def initialize(attrs)
|
8
8
|
|
9
|
-
@username
|
10
|
-
@kcy_rank
|
11
|
-
@image
|
9
|
+
@username = attrs['username']
|
10
|
+
@kcy_rank = attrs['kcyrank']
|
11
|
+
@image = attrs['img']
|
12
12
|
@total_awards = attrs['totalawards']
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
-
end
|
18
|
+
end
|
data/lib/rcracy/version.rb
CHANGED
data/lib/rcracy.rb
CHANGED
@@ -1,114 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
require 'net/http'
|
1
|
+
require File.dirname(__FILE__) + '/rcracy/api.rb'
|
3
2
|
require File.dirname(__FILE__) + '/rcracy/version.rb'
|
4
3
|
require File.dirname(__FILE__) + '/rcracy/kcy.rb'
|
5
4
|
require File.dirname(__FILE__) + '/rcracy/nut.rb'
|
6
5
|
require File.dirname(__FILE__) + '/rcracy/user.rb'
|
7
6
|
require File.dirname(__FILE__) + '/rcracy/domain.rb'
|
8
|
-
|
9
|
-
module RCracy
|
10
|
-
|
11
|
-
class Instance
|
12
|
-
|
13
|
-
API_BASE_URL = 'http://karmacracy.com/api/v1'
|
14
|
-
|
15
|
-
def initialize(app_key)
|
16
|
-
@app_key = app_key
|
17
|
-
end
|
18
|
-
|
19
|
-
def get_kcys(username, from = 1, num = 10)
|
20
|
-
|
21
|
-
request_url = "#{API_BASE_URL}/user/#{username}?kcy=1&from=#{from}&num=#{num}&appkey=#{@app_key}"
|
22
|
-
|
23
|
-
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
24
|
-
|
25
|
-
hashed_kcys = JSON.parse(http_response.body)['data']['user'][0]['kcys']
|
26
|
-
|
27
|
-
kcys = []
|
28
|
-
|
29
|
-
hashed_kcys.each do |hashed_kcy|
|
30
|
-
|
31
|
-
kcys.push(RCracy::Kcy.new(hashed_kcy))
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
return kcys
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
def get_domains(username, from = 1, num = 10)
|
40
|
-
|
41
|
-
request_url = "#{API_BASE_URL}/domains/?u=#{username}&from=#{from}&num=#{num}&appkey=#{@app_key}"
|
42
|
-
|
43
|
-
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
44
|
-
|
45
|
-
hashed_domains = JSON.parse(http_response.body)['data']['domain']
|
46
|
-
|
47
|
-
domains = []
|
48
|
-
|
49
|
-
hashed_domains.each do |hashed_domain|
|
50
|
-
|
51
|
-
domains.push(RCracy::Domain.new(hashed_domain))
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
return domains
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
# Fix nut type
|
60
|
-
def get_nuts(username, type = 'All')
|
61
|
-
|
62
|
-
request_url = "#{API_BASE_URL}/awards/#{username}?t=#{type}&appkey=#{@app_key}"
|
63
|
-
|
64
|
-
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
65
|
-
|
66
|
-
hashed_nuts = JSON.parse(http_response.body)['data']['nut']
|
67
|
-
|
68
|
-
nuts = []
|
69
|
-
|
70
|
-
hashed_nuts.each do |hashed_nut|
|
71
|
-
|
72
|
-
nuts.push(RCracy::Nut.new(hashed_nut))
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
return nuts
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
def get_nut_details(username, id, lang = 'en')
|
81
|
-
|
82
|
-
request_url = "#{API_BASE_URL}/awards/#{username}/nut/#{id}?lang=#{lang}&appkey=#{@app_key}"
|
83
|
-
|
84
|
-
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
85
|
-
|
86
|
-
hashed_nut = JSON.parse(http_response.body)['data']['nut']
|
87
|
-
|
88
|
-
return RCracy::Nut.new (hashed_nut)
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_users_by_kcy_rank(from = 1, num = 10, now = 0)
|
93
|
-
|
94
|
-
request_url = "#{API_BASE_URL}/rank/?from=#{from}&num=#{num}&now=#{now}&appkey=#{@app_key}"
|
95
|
-
|
96
|
-
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
97
|
-
|
98
|
-
hashed_users = JSON.parse(http_response.body)['data']['user']
|
99
|
-
|
100
|
-
users = []
|
101
|
-
|
102
|
-
hashed_users.each do |hashed_user|
|
103
|
-
|
104
|
-
users.push(RCracy::User.new(hashed_user))
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
|
-
return users
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
7
|
+
require File.dirname(__FILE__) + '/rcracy/configuration.rb'
|
data/rcracy.gemspec
CHANGED
@@ -8,15 +8,11 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = RCracy::VERSION
|
9
9
|
gem.authors = ["Pablo Elices"]
|
10
10
|
gem.email = ["pablodanielgomezelices@gmail.com"]
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{
|
13
|
-
gem.homepage = ""
|
14
|
-
|
11
|
+
gem.description = %q{Simple wrapper for karmacracy.com API}
|
12
|
+
gem.summary = %q{Simple wrapper for karmacracy.com API}
|
13
|
+
gem.homepage = "https://github.com/pabloelices/rcracy"
|
15
14
|
gem.files = `git ls-files`.split($/)
|
16
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
17
|
gem.require_paths = ["lib"]
|
19
|
-
|
20
|
-
# Delete next line? :-)
|
21
|
-
gem.add_development_dependency 'rake'
|
22
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcracy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,44 +9,28 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
description: RCracy first testing. DO NOT USE.
|
12
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple wrapper for karmacracy.com API
|
31
15
|
email:
|
32
16
|
- pablodanielgomezelices@gmail.com
|
33
17
|
executables: []
|
34
18
|
extensions: []
|
35
19
|
extra_rdoc_files: []
|
36
20
|
files:
|
37
|
-
- .gitignore
|
38
21
|
- Gemfile
|
39
22
|
- LICENSE.txt
|
40
23
|
- README.md
|
41
|
-
- Rakefile
|
42
24
|
- lib/rcracy.rb
|
25
|
+
- lib/rcracy/api.rb
|
26
|
+
- lib/rcracy/configuration.rb
|
43
27
|
- lib/rcracy/domain.rb
|
44
28
|
- lib/rcracy/kcy.rb
|
45
29
|
- lib/rcracy/nut.rb
|
46
30
|
- lib/rcracy/user.rb
|
47
31
|
- lib/rcracy/version.rb
|
48
32
|
- rcracy.gemspec
|
49
|
-
homepage:
|
33
|
+
homepage: https://github.com/pabloelices/rcracy
|
50
34
|
licenses: []
|
51
35
|
post_install_message:
|
52
36
|
rdoc_options: []
|
@@ -69,5 +53,5 @@ rubyforge_project:
|
|
69
53
|
rubygems_version: 1.8.24
|
70
54
|
signing_key:
|
71
55
|
specification_version: 3
|
72
|
-
summary:
|
56
|
+
summary: Simple wrapper for karmacracy.com API
|
73
57
|
test_files: []
|
data/.gitignore
DELETED