Class: Wonderfl::Client
- Inherits:
-
Object
- Object
- Wonderfl::Client
- Defined in:
- lib/wonderfl/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
-
#get_code(code_id) ⇒ Object
Returns a Wonderfl::Code object detailing the code information.
-
#get_code_forks(code_id) ⇒ Object
Returns a Wonderfl::CodeForks object (Wonderfl::Code collection) detailing the recent 50 codes information forked from specified code.
-
#get_user(user_name) ⇒ Object
Returns a Wonderfl::User object detailing the user information.
-
#get_user_codes(user_name) ⇒ Object
Returns a Wonderfl::UserCodes object (Wonderfl::Code collection) detailing the recent 20 codes information posted by specified user.
-
#initialize(api_key = nil, options = {}) ⇒ Client
constructor
Requires api key, get yours from your account page (wonderfl.net/account/api_keys/create).
Constructor Details
#initialize(api_key = nil, options = {}) ⇒ Client
Requires api key, get yours from your account page (wonderfl.net/account/api_keys/create)
9 10 11 12 13 |
# File 'lib/wonderfl/client.rb', line 9 def initialize(api_key = nil, = {}) @api_key = api_key @cache = Wonderfl::Utils::Cache.new([:cache_file], [:expire]) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/wonderfl/client.rb', line 4 def api_key @api_key end |
Instance Method Details
#get_code(code_id) ⇒ Object
Returns a Wonderfl::Code object detailing the code information.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wonderfl/client.rb', line 48 def get_code(code_id) _validate?(code_id) path = '/code/' + code_id @cache.transaction do data = @cache[path] if data.nil? @cache[path] = Code.new(_request(path)[:body]['code'], code_id) else data end end end |
#get_code_forks(code_id) ⇒ Object
Returns a Wonderfl::CodeForks object (Wonderfl::Code collection) detailing the recent 50 codes information forked from specified code.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wonderfl/client.rb', line 64 def get_code_forks(code_id) _validate?(code_id) path = '/code/' + code_id + '/forks' @cache.transaction do data = @cache[path] if data.nil? @cache[path] = CodeForks.new(_request(path)[:body]['forks']) else data end end end |
#get_user(user_name) ⇒ Object
Returns a Wonderfl::User object detailing the user information.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wonderfl/client.rb', line 17 def get_user(user_name) _validate?(user_name) path = '/user/' + user_name @cache.transaction do data = @cache[path] if data.nil? @cache[path] = User.new(_request(path)[:body]['user']) else data end end end |
#get_user_codes(user_name) ⇒ Object
Returns a Wonderfl::UserCodes object (Wonderfl::Code collection) detailing the recent 20 codes information posted by specified user.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wonderfl/client.rb', line 33 def get_user_codes(user_name) _validate?(user_name) path = '/user/' + user_name + '/codes' @cache.transaction do data = @cache[path] if data.nil? @cache[path] = UserCodes.new(_request(path)[:body]['codes']) else data end end end |