Module: RCracy

Defined in:
lib/rcracy/kcy.rb,
lib/rcracy/nut.rb,
lib/rcracy/user.rb,
lib/rcracy/domain.rb,
lib/rcracy/version.rb,
lib/rcracy/wrapper.rb,
lib/rcracy/response.rb,
lib/rcracy/configuration.rb

Defined Under Namespace

Classes: Configuration, Domain, Kcy, Nut, Response, User

Constant Summary collapse

VERSION =
"0.1.2"
API_BASE_URL =

Remove from here.

'http://karmacracy.com/api/v1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



4
5
6
# File 'lib/rcracy/configuration.rb', line 4

def configuration
  @configuration
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



7
8
9
10
# File 'lib/rcracy/configuration.rb', line 7

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.get_domains(username, from = 1, num = 10) ⇒ Object

Returns an Array of RCracy::Domain objects



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rcracy/wrapper.rb', line 51

def self.get_domains(username, from = 1, num = 10)

  request_url = "#{API_BASE_URL}/domains/?u=#{username}&from=#{from}&num=#{num}&appkey=#{RCracy.configuration.app_key}"

  http_response = Net::HTTP.get_response(URI.parse(request_url))

  hashed_domains = JSON.parse(http_response.body)['data']['domain']

  domains = []

  hashed_domains.each do |hashed_domain|

    domains.push(RCracy::Domain.new(hashed_domain))

  end

  return domains

end

.get_kcys_from(username, from = 1, num = 10) ⇒ Object

Returns an Array of RCracy::Kcy objects



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rcracy/wrapper.rb', line 28

def self.get_kcys_from(username, from = 1, num = 10)

  request_url = "#{API_BASE_URL}/user/#{username}?kcy=1&from=#{from}&num=#{num}&appkey=#{RCracy.configuration.app_key}"

  http_response = Net::HTTP.get_response(URI.parse(request_url))

  hashed_kcys = JSON.parse(http_response.body)['data']['user'][0]['kcys']

  kcys = []

  hashed_kcys.each do |hashed_kcy|

    kcys.push(RCracy::Kcy.new(hashed_kcy))

  end

  return kcys

end

.get_nut_details_from(username, id, lang = 'en') ⇒ Object

Returns an RCracy::Nut object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rcracy/wrapper.rb', line 97

def self.get_nut_details_from(username, id, lang = 'en')

  request_url = "#{API_BASE_URL}/awards/#{username}/nut/#{id}?lang=#{lang}&appkey=#{RCracy.configuration.app_key}"

  http_response = Net::HTTP.get_response(URI.parse(request_url))

  hashed_nut = JSON.parse(http_response.body)['data']['nut']

  return RCracy::Nut.new(hashed_nut)

end

.get_nuts_from(username, type = 'All') ⇒ Object

Returns an Array of RCracy::Nut objects



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rcracy/wrapper.rb', line 74

def self.get_nuts_from(username, type = 'All')

  request_url = "#{API_BASE_URL}/awards/#{username}?t=#{type}&appkey=#{RCracy.configuration.app_key}"

  http_response = Net::HTTP.get_response(URI.parse(request_url))

  hashed_nuts = JSON.parse(http_response.body)['data']['nut']

  nuts = []

  hashed_nuts.each do |hashed_nut|

    nuts.push(RCracy::Nut.new(hashed_nut))

  end

  return nuts

end

.get_user_private_key(username, password, regenerate = false) ⇒ Object

Returns a RCracy::Response object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rcracy/wrapper.rb', line 11

def self.get_user_private_key(username, password, regenerate = false)

  request_url = "#{API_BASE_URL}/key/?u=#{username}&p=#{password}&appkey=#{RCracy.configuration.app_key}"

  request_url += "&regenerate=1" unless !regenerate

  http_response = Net::HTTP.get_response(URI.parse(request_url))

  hashed_response = JSON.parse(http_response.body)

  return RCracy::Response.new(hashed_response)

end

.get_users_by_kcy_rank(from = 1, num = 10, now = 0) ⇒ Object

Returns an Array of RCracy::User objects



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/rcracy/wrapper.rb', line 112

def self.get_users_by_kcy_rank(from = 1, num = 10, now = 0)

  request_url = "#{API_BASE_URL}/rank/?from=#{from}&num=#{num}&now=#{now}&appkey=#{RCracy.configuration.app_key}"

  http_response = Net::HTTP.get_response(URI.parse(request_url))

  hashed_users = JSON.parse(http_response.body)['data']['user']

  users = []

  hashed_users.each do |hashed_user|

    users.push(RCracy::User.new(hashed_user))

  end

  return users

end