rcracy 0.0.5 → 0.0.6
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/lib/rcracy/nut.rb +23 -0
- data/lib/rcracy/user.rb +18 -0
- data/lib/rcracy/version.rb +1 -1
- data/lib/rcracy.rb +51 -10
- metadata +3 -1
data/lib/rcracy/nut.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module RCracy
|
2
|
+
|
3
|
+
class Nut
|
4
|
+
|
5
|
+
attr_reader :id, :name, :date_since, :history, :small_img, :big_img, :description,
|
6
|
+
:flag_type, :level, :date_received_or_last, :number
|
7
|
+
|
8
|
+
def initialize(attrs)
|
9
|
+
@id = attrs['id']
|
10
|
+
@name = attrs['name']
|
11
|
+
@date_since = attrs['dateSince']
|
12
|
+
@history = attrs['history']
|
13
|
+
@small_image = attrs['imageSmall']
|
14
|
+
@big_image = attrs['imageBig']
|
15
|
+
@description = attrs['description']
|
16
|
+
@flag_type = attrs['flg_type']
|
17
|
+
@level = attrs['level']
|
18
|
+
@date_received_or_last = attrs['dateReceivedOrLast']
|
19
|
+
@number = attrs['number']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/rcracy/user.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module RCracy
|
2
|
+
|
3
|
+
class User
|
4
|
+
|
5
|
+
attr_reader :username, :kcy_rank, :image, :total_awards
|
6
|
+
|
7
|
+
def initialize(attrs)
|
8
|
+
|
9
|
+
@username = attrs['username']
|
10
|
+
@kcy_rank = attrs['kcyrank']
|
11
|
+
@image = attrs['img']
|
12
|
+
@total_awards = attrs['totalawards']
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/rcracy/version.rb
CHANGED
data/lib/rcracy.rb
CHANGED
@@ -2,6 +2,8 @@ require 'json'
|
|
2
2
|
require 'net/http'
|
3
3
|
require File.dirname(__FILE__) + '/rcracy/version.rb'
|
4
4
|
require File.dirname(__FILE__) + '/rcracy/kcy.rb'
|
5
|
+
require File.dirname(__FILE__) + '/rcracy/nut.rb'
|
6
|
+
require File.dirname(__FILE__) + '/rcracy/user.rb'
|
5
7
|
|
6
8
|
module RCracy
|
7
9
|
|
@@ -23,28 +25,67 @@ module RCracy
|
|
23
25
|
|
24
26
|
kcys = []
|
25
27
|
|
26
|
-
hashed_kcys.each
|
28
|
+
hashed_kcys.each do |hashed_kcy|
|
29
|
+
|
30
|
+
kcys.push(RCracy::Kcy.new(hashed_kcy))
|
31
|
+
|
32
|
+
end
|
27
33
|
|
28
34
|
return kcys
|
29
35
|
|
30
36
|
end
|
31
37
|
|
32
|
-
|
38
|
+
# Fix nut type
|
39
|
+
def get_nuts_from(username, type = 'All')
|
40
|
+
|
33
41
|
request_url = "#{API_BASE_URL}/awards/#{username}?t=#{type}&appkey=#{@app_key}"
|
34
|
-
|
35
|
-
|
42
|
+
|
43
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
44
|
+
|
45
|
+
hashed_nuts = JSON.parse(http_response.body)['data']['nut']
|
46
|
+
|
47
|
+
nuts = []
|
48
|
+
|
49
|
+
hashed_nuts.each do |hashed_nut|
|
50
|
+
|
51
|
+
nuts.push(RCracy::Nut.new(hashed_nut))
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
return nuts
|
56
|
+
|
36
57
|
end
|
37
58
|
|
38
|
-
def get_nut_details_from(username, id, lang =
|
59
|
+
def get_nut_details_from(username, id, lang = 'en')
|
60
|
+
|
39
61
|
request_url = "#{API_BASE_URL}/awards/#{username}/nut/#{id}?lang=#{lang}&appkey=#{@app_key}"
|
40
|
-
|
41
|
-
|
62
|
+
|
63
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
64
|
+
|
65
|
+
hashed_nut = JSON.parse(http_response.body)['data']['nut']
|
66
|
+
|
67
|
+
return RCracy::Nut.new (hashed_nut)
|
68
|
+
|
42
69
|
end
|
43
70
|
|
44
|
-
def
|
71
|
+
def get_kcy_rank(from = 1, num = 10, now = 0)
|
72
|
+
|
45
73
|
request_url = "#{API_BASE_URL}/rank/?from=#{from}&num=#{num}&now=#{now}&appkey=#{@app_key}"
|
46
|
-
|
47
|
-
|
74
|
+
|
75
|
+
http_response = Net::HTTP.get_response(URI.parse(request_url))
|
76
|
+
|
77
|
+
hashed_users = JSON.parse(http_response.body)['data']['user']
|
78
|
+
|
79
|
+
users = []
|
80
|
+
|
81
|
+
hashed_users.each do |hashed_user|
|
82
|
+
|
83
|
+
users.push(RCracy::User.new(hashed_user))
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
return users
|
88
|
+
|
48
89
|
end
|
49
90
|
|
50
91
|
def shorten_link(url, username, user_private_key)
|
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.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -41,6 +41,8 @@ files:
|
|
41
41
|
- Rakefile
|
42
42
|
- lib/rcracy.rb
|
43
43
|
- lib/rcracy/kcy.rb
|
44
|
+
- lib/rcracy/nut.rb
|
45
|
+
- lib/rcracy/user.rb
|
44
46
|
- lib/rcracy/version.rb
|
45
47
|
- rcracy.gemspec
|
46
48
|
homepage: ''
|