Class: Rflak::Flaker
Overview
Utility class for fetching ‘flak’s from the web.
Example:
Flaker.fetch('user') do |flak|
flak.login 'seban'
flak.limit 2
flak.tag 'ruby'
end
Constant Summary collapse
- FLAK_API_URL =
'http://api.flaker.pl/api'
Instance Attribute Summary collapse
-
#perform_url ⇒ Object
readonly
Returns the value of attribute perform_url.
Class Method Summary collapse
-
.auth_connection(user) ⇒ Object
Authorize connetion by user’s credentials (login and api key) and perform instruction passed in block.
- .fetch(type) {|flak| ... } ⇒ Object
- .parse_response(response) ⇒ Object
Instance Method Summary collapse
- #avatars(value) ⇒ Object
- #comments(value) ⇒ Object
- #entry_id(value) ⇒ Object
- #from(value) ⇒ Object
-
#initialize(type) ⇒ Flaker
constructor
A new instance of Flaker.
- #limit(value) ⇒ Object
- #login(value) ⇒ Object
- #mode(value) ⇒ Object
- #since(value) ⇒ Object
- #sort(value) ⇒ Object
- #source(value) ⇒ Object
- #start(value) ⇒ Object
- #story(story_id) ⇒ Object
- #tag(value) ⇒ Object
- #url(value) ⇒ Object
Constructor Details
#initialize(type) ⇒ Flaker
Returns a new instance of Flaker.
19 20 21 |
# File 'lib/flaker.rb', line 19 def initialize(type) @perform_url = FLAK_API_URL + "/type:#{ type }" end |
Instance Attribute Details
#perform_url ⇒ Object (readonly)
Returns the value of attribute perform_url.
17 18 19 |
# File 'lib/flaker.rb', line 17 def perform_url @perform_url end |
Class Method Details
.auth_connection(user) ⇒ Object
Authorize connetion by user’s credentials (login and api key) and perform instruction passed in block. Raises NotAuthorize exception when user has bad login or api key.
- user
-
User
35 36 37 38 39 40 41 42 |
# File 'lib/flaker.rb', line 35 def self.auth_connection(user) user.auth unless user. raise NotAuthorized.new('Not authorized') unless user. Flaker.basic_auth(user.login, user.api_key) response = yield(Flaker) Flaker.basic_auth('','') return response end |
Instance Method Details
#avatars(value) ⇒ Object
87 88 89 |
# File 'lib/flaker.rb', line 87 def avatars(value) @perform_url += "/avatars:#{ value }" end |
#comments(value) ⇒ Object
117 118 119 |
# File 'lib/flaker.rb', line 117 def comments(value) @perform_url += "/comments:#{ value }" end |
#entry_id(value) ⇒ Object
62 63 64 |
# File 'lib/flaker.rb', line 62 def entry_id(value) @perform_url += "/entry_id:#{ value }" end |
#from(value) ⇒ Object
97 98 99 |
# File 'lib/flaker.rb', line 97 def from(value) @perform_url += "/from:#{ value }" end |
#limit(value) ⇒ Object
92 93 94 |
# File 'lib/flaker.rb', line 92 def limit(value) @perform_url += "/limit:#{ value }" end |
#login(value) ⇒ Object
52 53 54 |
# File 'lib/flaker.rb', line 52 def login(value) @perform_url += "/login:#{ value }" end |
#mode(value) ⇒ Object
82 83 84 |
# File 'lib/flaker.rb', line 82 def mode(value) @perform_url += "/mode:#{ value }" end |
#since(value) ⇒ Object
107 108 109 |
# File 'lib/flaker.rb', line 107 def since(value) @perform_url += "/since:#{ value }" end |
#sort(value) ⇒ Object
112 113 114 |
# File 'lib/flaker.rb', line 112 def sort(value) @perform_url += "/sort:#{ value }" end |
#source(value) ⇒ Object
72 73 74 |
# File 'lib/flaker.rb', line 72 def source(value) @perform_url += "/source:#{ value }" end |
#start(value) ⇒ Object
102 103 104 |
# File 'lib/flaker.rb', line 102 def start(value) @perform_url += "/start:#{ value }" end |
#story(story_id) ⇒ Object
67 68 69 |
# File 'lib/flaker.rb', line 67 def story(story_id) @perform_url += "/story:#{ story_id }" end |
#tag(value) ⇒ Object
77 78 79 |
# File 'lib/flaker.rb', line 77 def tag(value) @perform_url += "/tag:#{ value }" end |
#url(value) ⇒ Object
57 58 59 |
# File 'lib/flaker.rb', line 57 def url(value) @perform_url += "/url:#{ value }" end |